Split into modules #11

Split Spring Cloud Vault Config into multiple modules: Core, Config, Database/Consul/RabbitMQ integrations.
This commit is contained in:
Mark Paluch
2016-06-21 00:12:43 +02:00
parent c19d2926de
commit c0da914b00
81 changed files with 1912 additions and 839 deletions

View File

@@ -0,0 +1,49 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.vault.config.databases;
import org.springframework.cloud.vault.VaultSecretBackend;
/**
* Configuration properties interface for database secrets.
*/
public interface DatabaseSecretProperties extends VaultSecretBackend {
/**
* Role name.
*
* @return the role name
*/
String getRole();
/**
* Backend path.
*
* @return the backend path.
*/
String getBackend();
/**
* Name of the target property for the obtained username.
*/
String getUsernameProperty();
/**
* Name of the target property for the obtained password.
*/
String getPasswordProperty();
}

View File

@@ -0,0 +1,59 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.vault.config.databases;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import lombok.Data;
/**
* Configuration properties for Vault using the Apache Cassandra integration.
*
* @author Mark Paluch
*/
@ConfigurationProperties("spring.cloud.vault.cassandra")
@Data
public class VaultCassandraProperties implements DatabaseSecretProperties {
/**
* Enable cassandra backend usage.
*/
private boolean enabled = false;
/**
* Role name for credentials.
*/
private String role;
/**
* Cassandra backend path.
*/
@NotEmpty
private String backend = "cassandra";
/**
* Target property for the obtained username.
*/
@NotEmpty
private String usernameProperty = "spring.data.cassandra.username";
/**
* Target property for the obtained password.
*/
@NotEmpty
private String passwordProperty = "spring.data.cassandra.password";
}

View File

@@ -0,0 +1,108 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.vault.config.databases;
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.vault.SecureBackendAccessor;
import org.springframework.cloud.vault.config.SecureBackendAccessorFactory;
import org.springframework.cloud.vault.VaultSecretBackend;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;
/**
* @author Mark Paluch
*/
@Configuration
@EnableConfigurationProperties
public class VaultConfigDatabaseBootstrapConfiguration {
@Bean
public SecureBackendAccessorFactory<DatabaseSecretProperties> secureBackendAccessorFactory() {
return new DatabaseSecureBackendAccessorFactory();
}
@Bean
public VaultMySqlProperties mySqlProperties() {
return new VaultMySqlProperties();
}
@Bean
public VaultPostgreSqlProperties postgreSqlProperties() {
return new VaultPostgreSqlProperties();
}
@Bean
public VaultCassandraProperties cassandraProperties() {
return new VaultCassandraProperties();
}
static class DatabaseSecureBackendAccessorFactory
implements SecureBackendAccessorFactory<DatabaseSecretProperties> {
@Override
public SecureBackendAccessor createSecureBackendAccessor(
DatabaseSecretProperties properties) {
return forDatabase(properties);
}
@Override
public boolean supports(VaultSecretBackend secretBackend) {
return secretBackend instanceof DatabaseSecretProperties;
}
/**
* Creates a {@link SecureBackendAccessor} for a secure backend using
* {@link DatabaseSecretProperties}. This accessor transforms Vault's
* username/password property names to names provided with
* {@link DatabaseSecretProperties#getUsernameProperty()} and
* {@link DatabaseSecretProperties#getPasswordProperty()}.
*
* @param properties must not be {@literal null}.
* @return the {@link SecureBackendAccessor}
*/
public static SecureBackendAccessor forDatabase(
final DatabaseSecretProperties properties) {
Assert.notNull(properties, "DatabaseSecretProperties must not be null");
return new SecureBackendAccessor() {
@Override
public Map<String, String> variables() {
Map<String, String> variables = new HashMap<>();
variables.put("backend", properties.getBackend());
variables.put("key", String.format("creds/%s", properties.getRole()));
return variables;
}
@Override
public Map<String, String> transformProperties(
Map<String, String> input) {
Map<String, String> result = new HashMap();
result.put(properties.getUsernameProperty(), input.get("username"));
result.put(properties.getPasswordProperty(), input.get("password"));
return result;
}
};
}
}
}

View File

@@ -0,0 +1,45 @@
package org.springframework.cloud.vault.config.databases;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.vault.VaultSecretBackend;
import lombok.Data;
/**
* Configuration properties for Vault using the MySQL integration.
*
* @author Mark Paluch
*/
@ConfigurationProperties("spring.cloud.vault.mysql")
@Data
public class VaultMySqlProperties implements DatabaseSecretProperties, VaultSecretBackend {
/**
* Enable mysql backend usage.
*/
private boolean enabled = false;
/**
* Role name for credentials.
*/
private String role;
/**
* mysql backend path.
*/
@NotEmpty
private String backend = "mysql";
/**
* Target property for the obtained username.
*/
@NotEmpty
private String usernameProperty = "spring.datasource.username";
/**
* Target property for the obtained username.
*/
@NotEmpty
private String passwordProperty = "spring.datasource.password";
}

View File

@@ -0,0 +1,59 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.vault.config.databases;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import lombok.Data;
/**
* Configuration properties for Vault using the PostgreSQL integration.
*
* @author Mark Paluch
*/
@ConfigurationProperties("spring.cloud.vault.postgresql")
@Data
public class VaultPostgreSqlProperties implements DatabaseSecretProperties {
/**
* Enable postgresql backend usage.
*/
private boolean enabled = false;
/**
* Role name for credentials.
*/
private String role;
/**
* postgresql backend path.
*/
@NotEmpty
private String backend = "postgresql";
/**
* Target property for the obtained username.
*/
@NotEmpty
private String usernameProperty = "spring.datasource.username";
/**
* Target property for the obtained username.
*/
@NotEmpty
private String passwordProperty = "spring.datasource.password";
}

View File

@@ -0,0 +1,5 @@
/**
* Database integration with Vault.
* @author Mark Paluch
*/
package org.springframework.cloud.vault.config.databases;

View File

@@ -0,0 +1,3 @@
# Bootstrap Configuration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.cloud.vault.config.databases.VaultConfigDatabaseBootstrapConfiguration