示例#1
0
        public void Given_env_Variables_When_building_secrets_Then_variables_are_fetched()
        {
            var settings = new SecretSettings
            {
                AccountId        = 1,
                AccountName      = "test",
                AnotherAccountId = 34,
                APIToken         = "234",
                Password         = "******",
                TagId            = "123",
                TagName          = "yey",
                UserId           = "123"
            };

            var prefix    = SecretManager.EnvironmentVariablePrefix;
            var variables = new Dictionary <string, string>
            {
                { $"{prefix}AccountId", settings.AccountId.ToString() },
                { $"{prefix}AccountName", settings.AccountName },
                { $"{prefix}AnotherAccountId", settings.AnotherAccountId.ToString() },
                { $"{prefix}APIToken", settings.APIToken },
                { $"{prefix}Password", settings.Password },
                { $"{prefix}TagId", settings.TagId },
                { $"{prefix}TagName", settings.TagName },
                { $"{prefix}UserId", settings.UserId }
            };

            using var tempEnv = new TemporaryEnvironment(variables);
            var envLoadedSettings = SecretManager.LoadSettings();

            envLoadedSettings.Should().BeEquivalentTo(settings);
        }
示例#2
0
        public static SecretSettings LoadSettings()
        {
            var configuration = new ConfigurationBuilder()
                                .AddUserSecrets <SecretSettings>()
                                .AddEnvironmentVariables(s => s.Prefix = EnvironmentVariablePrefix)
                                .Build();

            var settings = new SecretSettings();

            configuration.Bind(settings);

            if (string.IsNullOrEmpty(settings.UserId) ||
                (string.IsNullOrEmpty(settings.Password) && string.IsNullOrEmpty(settings.APIToken)) ||
                settings.AccountId == 0 ||
                string.IsNullOrEmpty(settings.AccountName) ||
                string.IsNullOrEmpty(settings.TagId) ||
                string.IsNullOrEmpty(settings.TagName))
            {
                throw new InvalidOperationException(
                          $"You'll need to define some user secrets before run Buxfer web tests or environment variables with prefix {EnvironmentVariablePrefix}: " +
                          "UserId, Password or APIToken, AccountId, AccountName, TagId and TagName.");
            }

            return(settings);
        }
示例#3
0
        public static BuxferClient BuildClient(SecretSettings settings, ILogger logger = null)
        {
            logger ??= LoggerFactory.Create(c => c.AddConsole().SetMinimumLevel(LogLevel.Trace))
            .CreateLogger <AuthTest>();

            if (string.IsNullOrEmpty(settings.APIToken))
            {
                return(new BuxferClient(settings.UserId, settings.Password, logger));
            }

            return(new BuxferClient(settings.APIToken, logger));
        }
示例#4
0
 public static BuxferClient BuildClient(out SecretSettings setting, ILogger logger = null)
 {
     setting = SecretManager.LoadSettings();
     return(BuildClient(setting, logger));
 }