@Test public void nullKeyConfigurationThrowsException() { when(envProvider.getEnv(anyString())).thenReturn("envVar"); when(config.getKeys()).thenReturn(null); Throwable ex = catchThrowable(() -> awsKeyVaultServiceFactory.create(config, envProvider)); assertThat(ex).isExactlyInstanceOf(ConfigException.class); assertThat(ex.getMessage()) .contains("Trying to create AWS Secrets Manager connection but no configuration provided"); }
@Override public KeyVaultService create(Config config, EnvironmentVariableProvider envProvider) { String accessKeyID = envProvider.getEnv(AWS_ACCESS_KEY_ID); String secretAccessKey = envProvider.getEnv(AWS_SECRET_ACCESS_KEY); if ((accessKeyID != null && secretAccessKey == null) || (secretAccessKey != null && accessKeyID == null)) { throw new IncompleteAWSCredentialsException( "If using environment variables, both " + AWS_ACCESS_KEY_ID + " and " + AWS_SECRET_ACCESS_KEY + " must be set"); } KeyVaultConfig keyVaultConfig = Optional.ofNullable(config.getKeys()) .flatMap(k -> k.getKeyVaultConfig(KeyVaultType.AWS)) .orElseThrow( () -> new ConfigException( new RuntimeException( "Trying to create AWS Secrets Manager connection but no configuration provided"))); return new AWSKeyVaultService(getAwsSecretsManager(keyVaultConfig)); }
AWSKeyVaultServiceFactory implements KeyVaultServiceFactory { @Override public KeyVaultService create(Config config, EnvironmentVariableProvider envProvider) { String accessKeyID = envProvider.getEnv(AWS_ACCESS_KEY_ID); String secretAccessKey = envProvider.getEnv(AWS_SECRET_ACCESS_KEY); if ((accessKeyID != null && secretAccessKey == null) || (secretAccessKey != null && accessKeyID == null)) { throw new IncompleteAWSCredentialsException( "If using environment variables, both " + AWS_ACCESS_KEY_ID + " and " + AWS_SECRET_ACCESS_KEY + " must be set"); } KeyVaultConfig keyVaultConfig = Optional.ofNullable(config.getKeys()) .flatMap(k -> k.getKeyVaultConfig(KeyVaultType.AWS)) .orElseThrow( () -> new ConfigException( new RuntimeException( "Trying to create AWS Secrets Manager connection but no configuration provided"))); return new AWSKeyVaultService(getAwsSecretsManager(keyVaultConfig)); } }
AWSKeyVaultServiceFactory implements KeyVaultServiceFactory { @Override public KeyVaultService create(Config config, EnvironmentVariableProvider envProvider) { String accessKeyID = envProvider.getEnv(AWS_ACCESS_KEY_ID); String secretAccessKey = envProvider.getEnv(AWS_SECRET_ACCESS_KEY); if ((accessKeyID != null && secretAccessKey == null) || (secretAccessKey != null && accessKeyID == null)) { throw new IncompleteAWSCredentialsException( "If using environment variables, both " + AWS_ACCESS_KEY_ID + " and " + AWS_SECRET_ACCESS_KEY + " must be set"); } KeyVaultConfig keyVaultConfig = Optional.ofNullable(config.getKeys()) .flatMap(k -> k.getKeyVaultConfig(KeyVaultType.AWS)) .orElseThrow( () -> new ConfigException( new RuntimeException( "Trying to create AWS Secrets Manager connection but no configuration provided"))); return new AWSKeyVaultService(getAwsSecretsManager(keyVaultConfig)); }  }
AWSKeyVaultServiceFactory implements KeyVaultServiceFactory { @Override public KeyVaultService create(Config config, EnvironmentVariableProvider envProvider) { String accessKeyID = envProvider.getEnv(AWS_ACCESS_KEY_ID); String secretAccessKey = envProvider.getEnv(AWS_SECRET_ACCESS_KEY); if ((accessKeyID != null && secretAccessKey == null) || (secretAccessKey != null && accessKeyID == null)) { throw new IncompleteAWSCredentialsException( "If using environment variables, both " + AWS_ACCESS_KEY_ID + " and " + AWS_SECRET_ACCESS_KEY + " must be set"); } KeyVaultConfig keyVaultConfig = Optional.ofNullable(config.getKeys()) .flatMap(k -> k.getKeyVaultConfig(KeyVaultType.AWS)) .orElseThrow( () -> new ConfigException( new RuntimeException( "Trying to create AWS Secrets Manager connection but no configuration provided"))); return new AWSKeyVaultService(getAwsSecretsManager(keyVaultConfig)); }  @Override KeyVaultService create(Config config, EnvironmentVariableProvider envProvider); @Override KeyVaultType getType(); }
AWSKeyVaultServiceFactory implements KeyVaultServiceFactory { @Override public KeyVaultService create(Config config, EnvironmentVariableProvider envProvider) { String accessKeyID = envProvider.getEnv(AWS_ACCESS_KEY_ID); String secretAccessKey = envProvider.getEnv(AWS_SECRET_ACCESS_KEY); if ((accessKeyID != null && secretAccessKey == null) || (secretAccessKey != null && accessKeyID == null)) { throw new IncompleteAWSCredentialsException( "If using environment variables, both " + AWS_ACCESS_KEY_ID + " and " + AWS_SECRET_ACCESS_KEY + " must be set"); } KeyVaultConfig keyVaultConfig = Optional.ofNullable(config.getKeys()) .flatMap(k -> k.getKeyVaultConfig(KeyVaultType.AWS)) .orElseThrow( () -> new ConfigException( new RuntimeException( "Trying to create AWS Secrets Manager connection but no configuration provided"))); return new AWSKeyVaultService(getAwsSecretsManager(keyVaultConfig)); }  @Override KeyVaultService create(Config config, EnvironmentVariableProvider envProvider); @Override KeyVaultType getType();  }