Ejemplo n.º 1
0
        public override string Execute()
        {
            Console.WriteLine($"Trying to login as {Username}...");

            var password = _consoleReader.GetPassword("Enter password:"******"Logged in as {Username}");
            }

            return(null);
        }
Ejemplo n.º 2
0
        public override string Execute()
        {
            Console.WriteLine($"Trying to update password for current user...");

            string message;

            _accountService.UpdatePassword(new UpdatePasswordDto
            {
                OldPassword        = _consoleReader.GetPassword("Enter old password:"******"Enter new password:"******"Re-enter new password:"******"Password for current user has been updated";
            Logger.LogInformation(message);

            return(message);
        }
Ejemplo n.º 3
0
        public override string Execute()
        {
            Console.WriteLine($"Trying to reset password for user {User}...");

            string message;

            _accountService.ResetPassword(User, new ResetPasswordDto
            {
                Token              = Token,
                NewPassword        = _consoleReader.GetPassword("Enter new password:"******"Re-enter new password:"******"Password for user {User} has been reset";
            Logger.LogInformation(message);

            return(message);
        }
Ejemplo n.º 4
0
        public override string Execute()
        {
            Console.WriteLine($"Trying to login as {Username}...");

            var token = _tokenService.RequestToken(new RequestTokenDto
            {
                UserName = Username,
                Password = _consoleReader.GetPassword("Enter password:"******"Logged in as {Username}");
        }
Ejemplo n.º 5
0
        private string ValidateTask(List <CreateJobDefinitionWithTasksDto> jobs)
        {
            var tasks = jobs.SelectMany(j => j.Tasks).ToArray();

            var isProviderOk = ValidateProviders(tasks.Select(t => t.Provider), out var providers);

            if (!isProviderOk)
            {
                return("Please register the required providers first by using \"provider register\" command.");
            }

            var serviceTypeNames = providers.Where(p => p.RequiredServices != null).SelectMany(p => p.RequiredServices);
            var taskConfigs      = tasks.Where(t => t.Configs != null)
                                   .SelectMany(t => t.Configs)
                                   .Where(tc => tc.Key.EndsWith("ExternalService"));

            var isExternalServiceOk = ValidateExternalServices(serviceTypeNames, taskConfigs.ToList());

            if (!isExternalServiceOk)
            {
                return("Please add the required external services first by using \"service add\" command.");
            }

            string repository          = null;
            string isPrivateRepository = null;
            int    count = 1;

            foreach (var task in tasks)
            {
                task.Sequence = count++;

                // prompt for Repository config
                if ((task.Type.ToLower() == JobTaskDefinitionType.Pull.ToLower() ||
                     task.Type.ToLower() == JobTaskDefinitionType.Push.ToLower() ||
                     task.Type.ToLower() == JobTaskDefinitionType.Merge.ToLower() ||
                     task.Type.ToLower() == JobTaskDefinitionType.DeleteRepository.ToLower()) && !task.Configs.ContainsKey("Repository"))
                {
                    if (string.IsNullOrEmpty(repository))
                    {
                        repository = PromptTaskConfig("Repository");
                    }

                    task.Configs["Repository"] = repository;
                }

                // prompt for IsPrivateRepository config
                if (task.Type.ToLower() == JobTaskDefinitionType.Pull.ToLower() && !task.Configs.ContainsKey("IsPrivateRepository"))
                {
                    if (string.IsNullOrEmpty(isPrivateRepository))
                    {
                        isPrivateRepository = PromptTaskConfig("IsPrivateRepository", configType: ConfigType.Boolean);
                    }

                    task.Configs["IsPrivateRepository"] = isPrivateRepository;
                }

                // prompt for provider additional configs
                var provider = providers.FirstOrDefault(p => p.Name == task.Provider);
                if (provider?.AdditionalConfigs != null && provider.AdditionalConfigs.Length > 0)
                {
                    task.AdditionalConfigs = task.AdditionalConfigs ?? new Dictionary <string, string>();
                    Console.WriteLine($"The provider \"{provider.Name}\" of task {task.Name} has some additional config(s):");
                    foreach (var additionalConfig in provider.AdditionalConfigs)
                    {
                        string input;
                        string hint = !string.IsNullOrEmpty(additionalConfig.Hint) ? $" - {additionalConfig.Hint}" : "";
                        string requiredAndHintText = additionalConfig.IsRequired ? $"(Required{hint}):" : $"(Leave blank to use default value{hint}):";
                        string label      = !string.IsNullOrEmpty(additionalConfig.Label) ? additionalConfig.Label : additionalConfig.Name;
                        string prompt     = $"{label} {requiredAndHintText}";
                        bool   validInput = true;

                        do
                        {
                            if (additionalConfig.Type == ConfigType.Boolean)
                            {
                                input = Console.GetYesNoNullable(prompt)?.ToString();
                            }
                            else
                            {
                                input = additionalConfig.IsSecret && (additionalConfig.IsInputMasked ?? true) ? _consoleReader.GetPassword(prompt) : Console.GetString(prompt);
                            }

                            if (!string.IsNullOrEmpty(input))
                            {
                                if (additionalConfig.Type == ConfigType.Number && !double.TryParse(input, out var inputNumber))
                                {
                                    Console.WriteLine($"Input is not valid. Please enter valid number value.");
                                    validInput = false;
                                }
                                else if (additionalConfig.Type == ConfigType.File)
                                {
                                    try
                                    {
                                        validInput = File.Exists(input);

                                        if (validInput)
                                        {
                                            input = File.ReadAllText(input);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine("The file path is not valid");
                                        Logger.LogError("Error while reading file", ex);
                                        validInput = false;
                                    }
                                }
                                else if (additionalConfig.AllowedValues?.Length > 0 && !additionalConfig.AllowedValues.Contains(input))
                                {
                                    Console.WriteLine($"Input is not valid. Please enter the allowed values: {string.Join(',', additionalConfig.AllowedValues)}");
                                    validInput = false;
                                }
                                else
                                {
                                    validInput = true;
                                }
                            }
                        } while (!validInput || (additionalConfig.IsRequired && string.IsNullOrEmpty(input)));

                        if (!string.IsNullOrEmpty(input))
                        {
                            task.AdditionalConfigs[additionalConfig.Name] = input;
                        }
                    }

                    Console.WriteLine();
                }
            }

            return("");
        }