Esempio n. 1
0
        public Task <ICredentialKey> GenerateKey(Spi.Input.Options options)
        {
            // TODO magic boo
            var uri = new UriBuilder()
            {
                UserName = options.ValueOrDefault("user"),
                Host     = options.ValueOrDefault("host"),
                Scheme   = options.ValueOrDefault("protocol"),
                Path     = options.ValueOrDefault("path")
            };

            return(Task.FromResult(new GcmwCredentialKey(uri.Uri) as ICredentialKey));
        }
 protected string GetValue(List <string> aliases, Spi.Input.Options options)
 {
     return(aliases
            .Select(a => options.ValueOrDefault(a))
            .Where(v => !string.IsNullOrWhiteSpace(v))
            .FirstOrDefault());
 }
        public override string Run(Spi.Input.Options options)
        {
            // get host
            var host = _hosts
                       .Select(h => new
            {
                Handler = h,
                Weight  = h.CanHandle(
                    options.ValueOrDefault(Manager.Options.Command.Host.CanonicalName)
                    ).Result
            }
                               )
                       .OrderBy(a => a.Weight).Where(a => a.Weight >= 1)
                       .FirstOrDefault().Handler;
            //read from credential store
            var foundCredentials = Task.Run(() => _credentialStore.Read(_credentialKeyFactory.GenerateKey(options).Result)).Result;

            if (foundCredentials != null)
            {
                return(foundCredentials.GetResponse());
            }

            if (!IsInteractive(options))
            {
                return(null);
            }
            var guiHost = host as Spi.Gui.Hosts.IHost;

            if (UseModalPrompt(options) && guiHost != null)
            {
                Program.BuildAvaloniaApp().Start((app, args) =>
                {
                    foundCredentials = guiHost.PromptGui(app);
                },
                                                 System.Environment.GetCommandLineArgs());

                return(foundCredentials.GetResponse());
            }
            else
            {
                foundCredentials = Task.Run(() => host.PromptCli()).Result;
                return(foundCredentials.GetResponse());
            }
        }
Esempio n. 4
0
 public Credentials(Spi.Input.Options options) : this(options.ValueOrDefault("user"), options.ValueOrDefault("protocol"), options.ValueOrDefault("host"), options.ValueOrDefault("path"), options.ValueOrDefault("password"))
 {
 }