public async override Task RunAsync() { if (Console.IsOutputRedirected || Console.IsInputRedirected) { if (string.IsNullOrEmpty(TemplateName) || string.IsNullOrEmpty(FunctionName)) { ColoredConsole .Error .WriteLine(ErrorColor("Running with stdin\\stdout redirected. Command must specify --template, and --name explicitly.")) .WriteLine(ErrorColor("See 'func help function' for more details")); return; } } var templates = await _templatesManager.Templates; templates = templates.Concat(_templatesManager.PythonTemplates); var language = _secretsManager.GetSecrets().FirstOrDefault(s => s.Key.Equals(Constants.FunctionsLanguageSetting, StringComparison.OrdinalIgnoreCase)).Value; if (string.IsNullOrWhiteSpace(language)) { ColoredConsole.Write("Select a language: "); language = Language ?? SelectionMenuHelper.DisplaySelectionWizard(templates.Select(t => t.Metadata.Language).Distinct()); ColoredConsole.WriteLine(TitleColor(language)); language = InitAction.NormalizeLanguage(language); _secretsManager.SetSecret(Constants.FunctionsLanguageSetting, language); ColoredConsole .WriteLine(WarningColor("Starting from 2.0.1-beta.26 it's required to set a language for your project in your settings")) .WriteLine(WarningColor($"'{language}' has been set in your local.settings.json")); } if (language.Equals("csharp", StringComparison.OrdinalIgnoreCase)) { language = "C#"; } ColoredConsole.Write("Select a template: "); var name = TemplateName ?? SelectionMenuHelper.DisplaySelectionWizard(templates.Where(t => t.Metadata.Language.Equals(language, StringComparison.OrdinalIgnoreCase)).Select(t => t.Metadata.Name).Distinct()); ColoredConsole.WriteLine(TitleColor(name)); var template = templates.FirstOrDefault(t => t.Metadata.Name.Equals(name, StringComparison.OrdinalIgnoreCase) && t.Metadata.Language.Equals(language, StringComparison.OrdinalIgnoreCase)); if (template == null) { ColoredConsole.Error.WriteLine(ErrorColor($"Can't find template \"{name}\" in \"{language}\"")); } else { ColoredConsole.Write($"Function name: [{template.Metadata.DefaultFunctionName}] "); var functionName = FunctionName ?? Console.ReadLine(); functionName = string.IsNullOrEmpty(functionName) ? template.Metadata.DefaultFunctionName : functionName; await _templatesManager.Deploy(functionName, template); } }
public override async Task RunAsync() { var functionApp = await AzureHelper.GetFunctionApp(FunctionAppName, AccessToken); if (functionApp != null) { ColoredConsole.WriteLine(TitleColor("App Settings:")); foreach (var pair in functionApp.AzureAppSettings) { ColoredConsole.WriteLine($"Loading {pair.Key} = *****"); _secretsManager.SetSecret(pair.Key, pair.Value); } ColoredConsole.WriteLine(); ColoredConsole.WriteLine(TitleColor("Connection Strings:")); foreach (var connectionString in functionApp.ConnectionStrings) { ColoredConsole.WriteLine($"Loading {connectionString.Key} = *****"); _secretsManager.SetConnectionString(connectionString.Key, connectionString.Value.value); } } else { ColoredConsole.Error.WriteLine(ErrorColor($"Can't find function app by name {FunctionAppName}")); } }
internal static WorkerRuntime SetWorkerRuntime(ISecretsManager secretsManager, string language) { var worker = NormalizeWorkerRuntime(language); secretsManager.SetSecret(Constants.FunctionsWorkerRuntime, worker.ToString()); ColoredConsole .WriteLine(WarningColor("Starting from 2.0.1-beta.26 it's required to set a language for your project in your settings")) .WriteLine(WarningColor($"'{worker}' has been set in your local.settings.json")); return(worker); }
public override async Task RunAsync() { var storageAccount = await AzureHelper.GetStorageAccount(StorageAccountName, AccessToken, ManagementURL); var name = $"{storageAccount.StorageAccountName}_STORAGE"; _secretsManager.SetSecret(name, storageAccount.ConnectionString); ColoredConsole .WriteLine($"Secret saved locally in {SecretsManager.AppSettingsFileName} under name {ExampleColor(name)}.") .WriteLine(); }
public override Task RunAsync() { if (string.IsNullOrEmpty(Value)) { ColoredConsole.Write("Please enter the value: "); Value = SecurityHelpers.ReadPassword(); } if (IsConnectionString) { _secretsManager.SetConnectionString(Name, Value); } else { _secretsManager.SetSecret(Name, Value); } return(Task.CompletedTask); }
public override async Task RunAsync() { var storageAccounts = await _armManager.GetStorageAccountsAsync(); var storageAccount = storageAccounts.FirstOrDefault(st => st.StorageAccountName.Equals(StorageAccountName, StringComparison.OrdinalIgnoreCase)); if (storageAccount == null) { ColoredConsole .Error .WriteLine(ErrorColor($"Can't find storage account with name {StorageAccountName} in current subscription ({_settings.CurrentSubscription})")); } else { storageAccount = await _armManager.LoadAsync(storageAccount); var name = $"{storageAccount.StorageAccountName}_STORAGE"; _secretsManager.SetSecret(name, storageAccount.GetConnectionString()); ColoredConsole .WriteLine($"Secret saved locally in {ExampleColor(name)}") .WriteLine(); } }
public async override Task RunAsync() { if (Console.IsOutputRedirected || Console.IsInputRedirected) { if (string.IsNullOrEmpty(TemplateName) || string.IsNullOrEmpty(FunctionName)) { ColoredConsole .Error .WriteLine(ErrorColor("Running with stdin\\stdout redirected. Command must specify --template, and --name explicitly.")) .WriteLine(ErrorColor("See 'func help function' for more details")); return; } } var templates = await _templatesManager.Templates; var workerRuntime = _secretsManager.GetSecrets().FirstOrDefault(s => s.Key.Equals(Constants.FunctionsWorkerRuntime, StringComparison.OrdinalIgnoreCase)).Value; if (!string.IsNullOrWhiteSpace(workerRuntime) && !string.IsNullOrWhiteSpace(Language)) { // validate var worker = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(workerRuntime); var language = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(Language); if (worker != language) { throw new CliException("Selected language doesn't match worker set in local.settings.json." + $"Selected worker is: {worker} and selected language is: {language}"); } } else if (string.IsNullOrWhiteSpace(Language)) { if (string.IsNullOrWhiteSpace(workerRuntime)) { ColoredConsole.Write("Select a language: "); Language = SelectionMenuHelper.DisplaySelectionWizard(templates.Select(t => t.Metadata.Language).Where(l => !l.Equals("python", StringComparison.OrdinalIgnoreCase)).Distinct()); var worker = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(Language); _secretsManager.SetSecret(Constants.FunctionsWorkerRuntime, worker.ToString()); ColoredConsole .WriteLine(WarningColor("Starting from 2.0.1-beta.26 it's required to set a language for your project in your settings")) .WriteLine(WarningColor($"'{worker}' has been set in your local.settings.json")); } else { var worker = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(workerRuntime); var languages = WorkerRuntimeLanguageHelper.LanguagesForWorker(worker); ColoredConsole.Write("Select a language: "); var displayList = templates .Select(t => t.Metadata.Language) .Where(l => languages.Contains(l, StringComparer.OrdinalIgnoreCase)) .Distinct() .ToArray(); if (displayList.Length == 1) { Language = displayList.First(); } else { Language = SelectionMenuHelper.DisplaySelectionWizard(displayList); } } } else if (!string.IsNullOrWhiteSpace(Language)) { var worker = WorkerRuntimeLanguageHelper.NormalizeWorkerRuntime(Language); _secretsManager.SetSecret(Constants.FunctionsWorkerRuntime, worker.ToString()); ColoredConsole .WriteLine(WarningColor("Starting from 2.0.1-beta.26 it's required to set a language for your project in your settings")) .WriteLine(WarningColor($"'{worker}' has been set in your local.settings.json")); } ColoredConsole.Write("Select a template: "); var name = TemplateName ?? SelectionMenuHelper.DisplaySelectionWizard(templates.Where(t => t.Metadata.Language.Equals(Language, StringComparison.OrdinalIgnoreCase)).Select(t => t.Metadata.Name).Distinct()); ColoredConsole.WriteLine(TitleColor(name)); var template = templates.FirstOrDefault(t => t.Metadata.Name.Equals(name, StringComparison.OrdinalIgnoreCase) && t.Metadata.Language.Equals(Language, StringComparison.OrdinalIgnoreCase)); if (template == null) { ColoredConsole.Error.WriteLine(ErrorColor($"Can't find template \"{name}\" in \"{Language}\"")); } else { ColoredConsole.Write($"Function name: [{template.Metadata.DefaultFunctionName}] "); var functionName = FunctionName ?? Console.ReadLine(); functionName = string.IsNullOrEmpty(functionName) ? template.Metadata.DefaultFunctionName : functionName; await _templatesManager.Deploy(functionName, template); } }