예제 #1
0
        public override void Execute()
        {
            var vaultConfig = ConfigurationManager.GetVaultConfig(Vault);

            if (vaultConfig == null)
            {
                WriteError($"Unknown vault '{Vault}'");
                return;
            }

            var authConfig = ConfigurationManager.GetAuthConfig(vaultConfig);

            if (authConfig == null)
            {
                WriteError($"No authentication methods have been configured for vault '{Vault}'; see `kv auth`");
                return;
            }

            IKeyVaultService kvService = CreateVaultService(authConfig);

            IEnumerable <SecretItem> secrets;

            try
            {
                secrets = kvService.GetSecrets(new Uri(vaultConfig.Url));
            }
            catch (Exception ex)
            {
                WriteError($"Failed to list secrets in vault '{Vault}'", ex);
                return;
            }

            foreach (var secret in secrets)
            {
                if (Verbose)
                {
                    Console.Out.WriteJson(secret);
                }
                else
                {
                    Console.Out.WriteLine(secret.Identifier.Name);
                }
            }
        }