use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class CipherEnvironmentEncryptorTests method shouldDecryptEnvironmentWithKey.
@Test
public void shouldDecryptEnvironmentWithKey() {
// given
String secret = randomUUID().toString();
// when
Environment environment = new Environment("name", "profile", "label");
environment.add(new PropertySource("a", Collections.<Object, Object>singletonMap(environment.getName(), "{cipher}{key:test}" + this.textEncryptor.encrypt(secret))));
// then
assertEquals(secret, this.encryptor.decrypt(environment).getPropertySources().get(0).getSource().get(environment.getName()));
}
use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class VanillaConfigServerIntegrationTests method contextLoads.
@Test
public void contextLoads() {
Environment environment = new TestRestTemplate().getForObject("http://localhost:" + port + "/foo/development/", Environment.class);
assertFalse(environment.getPropertySources().isEmpty());
assertEquals("overrides", environment.getPropertySources().get(0).getName());
assertEquals("{spring.cloud.config.enabled=true}", environment.getPropertySources().get(0).getSource().toString());
}
use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class CustomEnvironmentRepositoryTests method contextLoads.
@Test
public void contextLoads() {
Environment environment = new TestRestTemplate().getForObject("http://localhost:" + port + "/foo/development/", Environment.class);
assertFalse(environment.getPropertySources().isEmpty());
}
use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class ConfigServicePropertySourceLocator method getRemoteEnvironment.
private Environment getRemoteEnvironment(RestTemplate restTemplate, ConfigClientProperties properties, String label, String state) {
String path = "/{name}/{profile}";
String name = properties.getName();
String profile = properties.getProfile();
String token = properties.getToken();
String uri = properties.getRawUri();
Object[] args = new String[] { name, profile };
if (StringUtils.hasText(label)) {
args = new String[] { name, profile, label };
path = path + "/{label}";
}
ResponseEntity<Environment> response = null;
try {
HttpHeaders headers = new HttpHeaders();
if (StringUtils.hasText(token)) {
headers.add(TOKEN_HEADER, token);
}
if (StringUtils.hasText(state)) {
// TODO: opt in to sending state?
headers.add(STATE_HEADER, state);
}
final HttpEntity<Void> entity = new HttpEntity<>((Void) null, headers);
response = restTemplate.exchange(uri + path, HttpMethod.GET, entity, Environment.class, args);
} catch (HttpClientErrorException e) {
if (e.getStatusCode() != HttpStatus.NOT_FOUND) {
throw e;
}
}
if (response == null || response.getStatusCode() != HttpStatus.OK) {
return null;
}
Environment result = response.getBody();
return result;
}
use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class ConfigServicePropertySourceLocatorTests method sunnyDay.
@Test
public void sunnyDay() {
Environment body = new Environment("app", "master");
mockRequestResponseWithoutLabel(new ResponseEntity<>(body, HttpStatus.OK));
this.locator.setRestTemplate(this.restTemplate);
assertNotNull(this.locator.locate(this.environment));
}
Aggregations