public async Task Aquire(IAzureOptionsCommon options, IInputService _input) { var defaultEnvironment = (await Environment.GetValue()) ?? AzureEnvironments.AzureCloud; var environments = new List <Choice <Func <Task> > >( AzureEnvironments.ResourceManagerUrls .OrderBy(kvp => kvp.Key) .Select(kvp => Choice.Create <Func <Task> >(() => { options.AzureEnvironment = kvp.Key; return(Task.CompletedTask); }, description: kvp.Key, @default: kvp.Key == defaultEnvironment))) { Choice.Create <Func <Task> >(async() => await InputUrl(_input, options), "Use a custom resource manager url") }; var chosen = await _input.ChooseFromMenu("Which Azure environment are you using?", environments); await chosen.Invoke(); options.UseMsi = await UseMsi.GetValue() == true || await _input.PromptYesNo("Do you want to use a managed service identity?", false); if (!options.UseMsi) { // These options are only necessary for client id/secret authentication. options.TenantId = await TenantId.Interactive(_input, "Directory/tenant id").GetValue(); options.ClientId = await ClientId.Interactive(_input, "Application client id").GetValue(); options.Secret = await ClientSecret.Interactive(_input, "Application client secret").GetValue(); } }
public async Task Aquire(IAzureOptionsCommon options) { var az = _arguments.GetArguments <T>(); var environments = new List <Choice <Func <Task> > >( AzureEnvironments.ResourceManagerUrls .OrderBy(kvp => kvp.Key) .Select(kvp => Choice.Create <Func <Task> >(() => { options.AzureEnvironment = kvp.Key; return(Task.CompletedTask); }, description: kvp.Key, @default: kvp.Key == AzureEnvironments.AzureCloud))) { Choice.Create <Func <Task> >(async() => await InputUrl(_input, options), "Use a custom resource manager url") }; var chosen = await _input.ChooseFromMenu("Which Azure environment are you using?", environments); await chosen.Invoke(); options.UseMsi = az.AzureUseMsi || await _input.PromptYesNo("Do you want to use a managed service identity?", true); if (!options.UseMsi) { // These options are only necessary for client id/secret authentication. options.TenantId = await _arguments.TryGetArgument(az.AzureTenantId, _input, "Directory/tenant id"); options.ClientId = await _arguments.TryGetArgument(az.AzureClientId, _input, "Application client id"); options.Secret = new ProtectedString(await _arguments.TryGetArgument(az.AzureSecret, _input, "Application client secret", true)); } }
private async Task InputUrl(IInputService input, IAzureOptionsCommon options) { string raw; do { raw = await input.RequestString("Url"); }while (!ParseUrl(raw, options)); }
public Task Default(IAzureOptionsCommon options) { var az = _arguments.GetArguments <T>(); options.UseMsi = az.AzureUseMsi; options.AzureEnvironment = az.AzureEnvironment; if (!options.UseMsi) { // These options are only necessary for client id/secret authentication. options.TenantId = _arguments.TryGetRequiredArgument(nameof(az.AzureTenantId), az.AzureTenantId); options.ClientId = _arguments.TryGetRequiredArgument(nameof(az.AzureClientId), az.AzureClientId); options.Secret = new ProtectedString(_arguments.TryGetRequiredArgument(nameof(az.AzureSecret), az.AzureSecret)); } return(Task.CompletedTask); }
public async Task Default(IAzureOptionsCommon options) { options.UseMsi = await UseMsi.GetValue() == true; options.AzureEnvironment = await Environment.GetValue(); if (!options.UseMsi) { // These options are only necessary for client id/secret authentication. options.TenantId = await TenantId.GetValue(); options.ClientId = await ClientId.GetValue(); options.Secret = await ClientSecret.GetValue(); } }
private static bool ParseUrl(string url, IAzureOptionsCommon options) { if (string.IsNullOrWhiteSpace(url)) { return(false); } try { var uri = new Uri(url); options.AzureEnvironment = uri.ToString(); return(true); } catch (Exception) { return(false); } }
public AzureHelpers(IAzureOptionsCommon options, ILogService log) { _options = options; ResourceManagersEndpoint = new Uri(AzureEnvironments.ResourceManagerUrls[AzureEnvironments.AzureCloud]); if (!string.IsNullOrEmpty(options.AzureEnvironment)) { if (!AzureEnvironments.ResourceManagerUrls.TryGetValue(options.AzureEnvironment, out var endpoint)) { // Custom endpoint endpoint = options.AzureEnvironment; } try { ResourceManagersEndpoint = new Uri(endpoint); } catch (Exception ex) { log.Error(ex, "Could not parse Azure endpoint url. Falling back to default."); } } }