Пример #1
0
        private static VaultOptions GetOptions(IConfiguration config)
        {
            var options = new VaultOptions();

            if (config.Get <VaultOptions>().Server == null)
            {
                config.Bind("VaultOptions", options);
            }

            if (string.IsNullOrEmpty(options.Server))
            {
                throw new ArgumentNullException(nameof(VaultOptions.Server));
            }

            return(options);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance with <see cref="VaultOptions"/>
        /// </summary>
        /// <param name="options"></param>
        public HashiCorpVaultClientWrapper(VaultOptions options)
        {
            _options = options;

            IAuthenticationInfo authInfo;

            // token present so authetnication with token
            if (!string.IsNullOrWhiteSpace(_options.TokenId))
            {
                authInfo = new TokenAuthenticationInfo(_options.TokenId);
            }
            else
            {
                authInfo = new AppRoleAuthenticationInfo("approle", _options.RoleId, _options.SecretId);
            }

            _vaultClientImpl = VaultClientFactory.CreateVaultClient(new Uri(_options.Server), authInfo);
        }