support auto-login
This commit is contained in:
Родитель
245a1a3135
Коммит
93d3915fdc
|
@ -87,7 +87,7 @@ namespace ARMClient.Authentication.AADAuthentication
|
|||
{
|
||||
foreach (var authResult in authResults)
|
||||
{
|
||||
Console.WriteLine(authResult.UserInfo.UserId);
|
||||
Trace.WriteLine(authResult.UserInfo.UserId);
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Multiple users found. Please specify user argument!");
|
||||
|
@ -131,10 +131,10 @@ namespace ARMClient.Authentication.AADAuthentication
|
|||
tenantId = tenantId
|
||||
};
|
||||
|
||||
Console.WriteLine("App: {0}, Tenant: {1}", appId, tenantId);
|
||||
Trace.WriteLine(String.Format("App: {0}, Tenant: {1}", appId, tenantId));
|
||||
|
||||
var subscriptions = await GetSubscriptions(authResult);
|
||||
Console.WriteLine("\tThere are {0} subscriptions", subscriptions.Length);
|
||||
Trace.WriteLine(String.Format("\tThere are {0} subscriptions", subscriptions.Length));
|
||||
|
||||
info.subscriptions = subscriptions.Select(subscription => new SubscriptionCacheInfo
|
||||
{
|
||||
|
@ -144,7 +144,7 @@ namespace ARMClient.Authentication.AADAuthentication
|
|||
|
||||
foreach (var subscription in subscriptions)
|
||||
{
|
||||
Console.WriteLine("\tSubscription {0} ({1})", subscription.subscriptionId, subscription.displayName);
|
||||
Trace.WriteLine(String.Format("\tSubscription {0} ({1})", subscription.subscriptionId, subscription.displayName));
|
||||
}
|
||||
|
||||
tenantCache[tenantId] = info;
|
||||
|
@ -336,7 +336,7 @@ namespace ARMClient.Authentication.AADAuthentication
|
|||
protected async Task<Dictionary<string, TenantCacheInfo>> GetTokenForTenants(Dictionary<TokenCacheKey, string> tokenCache, AuthenticationResult authResult)
|
||||
{
|
||||
var tenantIds = await GetTenantIds(authResult);
|
||||
Console.WriteLine("User {0} belongs to {1} tenants", authResult.UserInfo.UserId, tenantIds.Length);
|
||||
Trace.WriteLine(string.Format("User {0} belongs to {1} tenants", authResult.UserInfo.UserId, tenantIds.Length));
|
||||
|
||||
var tenantCache = this.TenantStorage.GetCache();
|
||||
foreach (var tenantId in tenantIds)
|
||||
|
|
|
@ -106,17 +106,25 @@ namespace ARMClient
|
|||
|| String.Equals(verb, "post", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var path = _parameters.Get(1, keyName: "url");
|
||||
var verbose = _parameters.Get("-verbose", requires: false) != null;
|
||||
var baseUri = new Uri(ARMClient.Authentication.Constants.CSMUrls[(int)AzureEnvironments.Prod]);
|
||||
var uri = new Uri(baseUri, path);
|
||||
|
||||
// TODO: acquire token
|
||||
EnsureTokenCache(persistentAuthHelper);
|
||||
if (!verbose)
|
||||
{
|
||||
Trace.Listeners.Clear();
|
||||
}
|
||||
|
||||
if (!persistentAuthHelper.IsCacheValid())
|
||||
{
|
||||
persistentAuthHelper.AzureEnvironments = GetAzureEnvironments(uri);
|
||||
persistentAuthHelper.AcquireTokens().Wait();
|
||||
}
|
||||
|
||||
var env = persistentAuthHelper.AzureEnvironments;
|
||||
baseUri = new Uri(ARMClient.Authentication.Constants.CSMUrls[(int)env]);
|
||||
uri = new Uri(baseUri, path);
|
||||
var content = ParseHttpContent(verb, _parameters);
|
||||
var verbose = _parameters.Get("-verbose", requires: false) != null;
|
||||
_parameters.ThrowIfUnknown();
|
||||
|
||||
var subscriptionId = GetSubscription(uri);
|
||||
|
@ -141,14 +149,9 @@ namespace ARMClient
|
|||
PrintUsage();
|
||||
return 1;
|
||||
}
|
||||
catch (CommandLineException ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
return -1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
Console.WriteLine(ex.GetBaseException().Message);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ namespace ARMClient.Library
|
|||
using (var client = new HttpClient(new HttpClientHandler()))
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("Authorization", this._authorizationHeader);
|
||||
client.DefaultRequestHeaders.Add("User-Agent", "CSMClient-" + Environment.MachineName);
|
||||
client.DefaultRequestHeaders.Add("User-Agent", "ARMClient-" + Environment.MachineName);
|
||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
|
||||
HttpResponseMessage response = null;
|
||||
|
|
Загрузка…
Ссылка в новой задаче