-
Notifications
You must be signed in to change notification settings - Fork 329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds multiple account functionality. Closes #3587 #5576
Conversation
d4a8bee
to
2e34ede
Compare
2e34ede
to
7b32c69
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice start. Let's clean this up a little. Something I noticed across the board:
- let's avoid using
!
to suppress type checking. If something is optional, let's check that it's indeed set. If it's not, let update the type. Using!
exposes us to runtime exceptions for which we use TypeScript to avoid - let's stick to existing functionality where possible (returned data, exception handling, etc)
- let's try to use clear name that communicate the purpose of variables, types and methods. Where it's not always possible, let's use comments.
@@ -368,7 +368,18 @@ describe(commands.PAGE_ADD, () => { | |||
|
|||
throw 'Invalid request'; | |||
}); | |||
|
|||
sinon.stub(Cli, 'executeCommand').callsFake(async (command): Promise<any> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are these changes related to the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember why, I'll recheck. I believe some tests started failing for some reason.
@@ -209,7 +209,18 @@ describe(commands.PAGE_SET, () => { | |||
|
|||
throw 'Invalid request'; | |||
}); | |||
|
|||
sinon.stub(Cli, 'executeCommandWithOutput').callsFake(async (command): Promise<any> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are these changes related to the PR?
@@ -191,10 +191,4 @@ describe(commands.SITE_ENSURE, () => { | |||
|
|||
await assert.rejects(command.action(logger, { options: { url: 'https://contoso.sharepoint.com/sites/team1', title: 'Team 1', type: 'CommunicationSite' } } as any)); | |||
}); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are these changes related to the PR?
await logger.log(auth.getIdentityDetails(auth.service, this.debug)); | ||
} | ||
|
||
public async action(logger: Logger, args: CommandArgs): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why we're overriding the base action?
@@ -441,6 +441,25 @@ describe(commands.FILE_GET, () => { | |||
assert.strictEqual(getStub.lastCall.args[0].url, `https://contoso.sharepoint.com/_api/web/GetFileByServerRelativePath(DecodedUrl=@f)?@f='%2FDocuments%2FTest1.docx'`); | |||
}); | |||
|
|||
it('uses correct API url when tenant root URL option is passed in combination with asListItem', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are these changes related to the PR?
Thanks @waldekmastykarz! I'll go through your feedback. Using ! By the way is the same as casting variables as a type, which we also do a lot or in the codebase. I agree with you in principle, though I typically only use it in situations where I've already done null-checks. Anyway, it's a tricky thing that's true. |
Seems like something we should definitely pay attention to because it's circumventing design time typesafety and is exposing us to runtime errors.
If the types are null-checked, shouldn't TypeScript see the assertion and handle it correctly without requiring you to suppress the null-type? |
It should, but I've seen situations where it doesn't. As soon as i find a nice example i'll show you. |
It could happen when we check it in a parent method and then pass the value to a child which loses track of it. This is dangerous though because in the child we're making an assumption about how it's called, which could be a signal that we should consider refactoring the code and perhaps destructure the object to specific properties to make fewer assumptions |
<TabItem value="Text"> | ||
|
||
```text | ||
identityName authType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also show here which one is active?
tl;dr:
|
ca96949
to
c808366
Compare
6f55c46
to
4feba45
Compare
Found some time and refactored the auth class. The rest to be done later. |
Abandoned because of a new PR #5790 |
Closes #3587
🚀 Adds multiple account functionality 🚀
Time for some extra juice, peeps 😊
What needs to be done in another iteration:
m365 identity set
without options.Points of attention
I need to test if Managed Identity still works. That's the only one I haven't tested yet.
The discovered SharePoint root url...I had forgotten its implications. I've fixed that now, but it shows how important it is to keep a good lookout for potential issues.
Graceful fallback I've changed the shape of the data that's saved to the
.cli-m365-tokens.json
file. This calls for a graceful fallback to older versions of that file. I've implemented that even if I'm not entirely sure what the best route is here. Ideas appreciated.Specifically I've added:
identityName
identityId
availableIdentities
I've also added the properties identityId and identityName to the output of commands like
m365 status
,m365 login
,m365 identity list
andm365 identity set
.Deprecated connectedAs: As I've added
identityName
to the output ofm365 status
andm365 login
. This now meansconnectedAs
andidentityName
have the same value.connectedAs
should be deprecated and removed in the next major version.