-
Notifications
You must be signed in to change notification settings - Fork 4k
Managed Service Identity Login #5227
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
Conversation
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.
Awesome! :)
A few random comments.
{ | ||
Id = userId, | ||
Type = AzureAccount.AccountType.ManagedService | ||
}; ; |
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.
Nit: extra semicolon.
Type = AzureAccount.AccountType.ManagedService | ||
}; ; | ||
var environment = AzureEnvironment.PublicEnvironments["AzureCloud"]; | ||
string expectedResource = environment.ActiveDirectoryServiceEndpointResourceId; |
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.
Why not var
like the others?
builder.Query = string.Format("resource={0}", Uri.EscapeDataString(environment.ActiveDirectoryServiceEndpointResourceId)); | ||
var defaultUri = builder.Uri.ToString(); | ||
|
||
IDictionary<string, ManagedServiceTokenInfo> responses = new Dictionary<string, ManagedServiceTokenInfo>(StringComparer.OrdinalIgnoreCase) |
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.
What is our guidance on explicit vs. inferred types?
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 use type inference where it is possible. In this case, because the test class should be able to handle any usage for any type, it is required to explicitly type the input dictionary.
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 mean in the declaration. It doesn't really need to be the interface type, correct?
|
||
public IHttpOperations<T> WithHeader(string name, IEnumerable<string> value) | ||
{ | ||
return this; |
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.
Shouldn't this throw?
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.
No, because we simply aren't using headers in the test operations factory, but it should allow specifying headers in any code that uses it.
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.
👍 ... maybe a comment indicating as much?
{ | ||
return "ManagedService"; | ||
} | ||
} |
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.
These can all be expression-bodied members. E.g.,
public string LoginType => "ManagedService"
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.
These are implementing an interface
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.
That will work, I think? 😄
An expression-bodied member is equivalent to a public get;
...? Maybe?
|
||
if (string.IsNullOrWhiteSpace(tenant)) | ||
{ | ||
tenant = environment.AdTenant?? "Common"; |
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.
Nit: the null-coalesce operator is typically spaced on both sides like the ternary (?:
) operator.
|
||
public async Task DeleteAsync(string requestUri, CancellationToken token) | ||
{ | ||
await SafeSendRequestAsync(new HttpRequestMessage(HttpMethod.Delete, requestUri), token); |
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.
This would be more succinct as:
public Task Func()
{
return ThingyThatReturnsATaskAsync();
}
{ | ||
var exception = new HttpRequestException(string.Format("Unexpected response status code '{0}' received for request '{{{1} {2}}} Body: {{{3}}}", | ||
response.StatusCode, request.Method, request.RequestUri, response.Content.ReadAsStringAsync().GetAwaiter().GetResult())); | ||
ServiceClientTracing.Error(invocationId, exception); |
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.
Any reason to not use string interpolation?
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.
No, but this should probably be a string resource, anyway
@@ -257,7 +258,7 @@ public static string GetHttpResponseLog(string statusCode, IDictionary<string, I | |||
httpResponseLog.AppendLine(string.Format("============================ HTTP RESPONSE ============================{0}", Environment.NewLine)); | |||
httpResponseLog.AppendLine(string.Format("Status Code:{0}{1}{0}", Environment.NewLine, statusCode)); | |||
httpResponseLog.AppendLine(string.Format("Headers:{0}{1}", Environment.NewLine, MessageHeadersToString(headers))); | |||
httpResponseLog.AppendLine(string.Format("Body:{0}{1}{0}", Environment.NewLine, body)); | |||
httpResponseLog.AppendLine(string.Format("Body:{0}{1}{0}", Environment.NewLine, TransformBody(body))); |
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.
Same here for string interpolation.
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.
A few small comments. Otherwise it all looks reasonable to me.
factory = HttpClientOperationsFactory.Create(); | ||
} | ||
|
||
_tokenGetter = factory.GetHttpOperations<ManagedServiceTokenInfo>().WithHeader("Metadata", new[] { "true" }); |
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.
What happens here if the if statement above evaluates to false? Do you need a null check?
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.
In this case, it uses the default implementation of HttpOperationsFactory, which just makes calls using HttpClient
@@ -26,7 +26,7 @@ namespace Microsoft.Azure.Commands.Common.Authentication.Factories | |||
{ | |||
public class AuthenticationFactory : IAuthenticationFactory | |||
{ | |||
public const string CommonAdTenant = "Common"; | |||
public const string CommonAdTenant = "Common", DefaultMSILoginUri = "http://localhost:50342/oauth2/token"; |
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 the default really a localhost? Just curious, I don't entirely understand how MSI works.
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.
@maddieclayton Yes, the default is always localhost - it is hosted on a VM at the loopback address.
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>] | ||
``` | ||
|
||
### ManagedServiceLogin |
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.
Please add an example for the new login
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.
done
@azuresdkci Test this please |
1 similar comment
@azuresdkci Test this please |
Description
This checklist is used to make sure that common guidelines for a pull request are followed. You can find a more complete discussion of PowerShell cmdlet best practices here.
General Guidelines
Testing Guidelines
Cmdlet Signature Guidelines
ShouldProcess
and haveSupportShouldProcess=true
specified in the cmdlet attribute. You can find more information onShouldProcess
here.OutputType
attribute if any output is produced - if the cmdlet produces no output, it should implement aPassThru
parameter.Cmdlet Parameter Guidelines