use of com.sequenceiq.cloudbreak.service.secret.model.SecretResponse in project cloudbreak by hortonworks.
the class CredentialService method getCredentialByEnvCrn.
/**
* Gets the credential for an environment.
*
* @param envCrn environment CRN
* @return environment credential
*/
public Credential getCredentialByEnvCrn(String envCrn) {
CredentialResponse credentialResponse = credentialEndpoint.getByEnvironmentCrn(envCrn);
SecretResponse secretResponse = credentialResponse.getAttributes();
String attributes = secretService.getByResponse(secretResponse);
if (credentialResponse.getAzure() != null) {
return new Credential(credentialResponse.getCrn(), credentialResponse.getName(), attributes, new Credential.AzureParameters(credentialResponse.getAzure().getSubscriptionId()), credentialResponse.getAccountId());
} else {
return new Credential(credentialResponse.getCrn(), credentialResponse.getName(), attributes, credentialResponse.getAccountId());
}
}
use of com.sequenceiq.cloudbreak.service.secret.model.SecretResponse in project cloudbreak by hortonworks.
the class ClusterToClusterV4ResponseConverterTest method testConvert.
@Test
public void testConvert() {
// GIVEN
getSource().setConfigStrategy(ConfigStrategy.NEVER_APPLY);
getSource().setBlueprint(new Blueprint());
getSource().setExtendedBlueprintText("asdf");
getSource().setFqdn("some.fqdn");
getSource().setCertExpirationState(CertExpirationState.HOST_CERT_EXPIRING);
given(stackUtil.extractClusterManagerIp(any(Stack.class))).willReturn("10.0.0.1");
given(stackUtil.extractClusterManagerAddress(any(Stack.class))).willReturn("some.fqdn");
Cluster source = getSource();
TestUtil.setSecretField(Cluster.class, "cloudbreakAmbariUser", source, "user", "secret/path");
TestUtil.setSecretField(Cluster.class, "cloudbreakAmbariPassword", source, "pass", "secret/path");
TestUtil.setSecretField(Cluster.class, "dpAmbariUser", source, "user", "secret/path");
TestUtil.setSecretField(Cluster.class, "dpAmbariPassword", source, "pass", "secret/path");
when(stringToSecretResponseConverter.convert("secret/path")).thenReturn(new SecretResponse("kv", "pass"));
when(blueprintToBlueprintV4ResponseConverter.convert(getSource().getBlueprint())).thenReturn(new BlueprintV4Response());
when(serviceEndpointCollector.getManagerServerUrl(any(Cluster.class), anyString())).thenReturn("http://server/");
given(proxyConfigDtoService.getByCrn(anyString())).willReturn(ProxyConfig.builder().withCrn("crn").withName("name").build());
// WHEN
ClusterV4Response result = underTest.convert(source);
// THEN
assertEquals(1L, (long) result.getId());
assertEquals(getSource().getExtendedBlueprintText(), result.getExtendedBlueprintText());
assertEquals(CertExpirationState.HOST_CERT_EXPIRING, result.getCertExpirationState());
List<String> skippedFields = Lists.newArrayList("customContainers", "cm", "creationFinished", "cloudStorage", "gateway", "customConfigurationsName", "customConfigurationsCrn");
assertAllFieldsNotNull(result, skippedFields);
}
use of com.sequenceiq.cloudbreak.service.secret.model.SecretResponse in project cloudbreak by hortonworks.
the class LdapConfigV1ServiceTest method testPost.
@Test
public void testPost() {
// GIVEN
CreateLdapConfigRequest createLdapConfigRequest = createCreateLdapConfigRequest();
LdapConfig ldapConfig = createLdapConfig();
ArgumentCaptor<LdapConfig> ldapConfigParam = ArgumentCaptor.forClass(LdapConfig.class);
Mockito.when(stringToSecretResponseConverter.convert(SECRET_BINDDN)).thenReturn(new SecretResponse("enginepath", "binddn-secretpath"));
Mockito.when(stringToSecretResponseConverter.convert(SECRET_PWD)).thenReturn(new SecretResponse("enginepath", "pwd-secretpath"));
Mockito.when(ldapConfigService.createLdapConfig(ldapConfigParam.capture())).thenReturn(ldapConfig);
// WHEN
DescribeLdapConfigResponse actualResponse = underTest.post(createLdapConfigRequest);
// THEN
checkInnerLdapConfig(ldapConfigParam.getValue());
checkResponse(actualResponse);
}
use of com.sequenceiq.cloudbreak.service.secret.model.SecretResponse in project cloudbreak by hortonworks.
the class KerberosMgmtVaultComponentV1Test method testGetSecretResponseForKeytabWithHost.
@Test
public void testGetSecretResponseForKeytabWithHost() throws Exception {
String expectedPath = "account1/HostKeytab/keytab/12345-6789/54321-9876/host1";
SecretResponse expectedSecretResponse = new SecretResponse();
expectedSecretResponse.setEnginePath(ENGINE_PATH);
expectedSecretResponse.setSecretPath(expectedPath);
HostKeytabRequest hostKeytabRequest = new HostKeytabRequest();
hostKeytabRequest.setEnvironmentCrn(ENVIRONMENT_ID);
hostKeytabRequest.setClusterCrn(CLUSTER_ID);
hostKeytabRequest.setServerHostName(HOST);
Mockito.when(secretService.put(anyString(), anyString())).thenReturn(SECRET);
Mockito.when(stringToSecretResponseConverter.convert(anyString())).thenReturn(expectedSecretResponse);
Assertions.assertEquals(expectedSecretResponse, underTest.getSecretResponseForKeytab(hostKeytabRequest, ACCOUNT, KEYTAB));
Mockito.verify(secretService).put(expectedPath, KEYTAB);
Mockito.verify(stringToSecretResponseConverter).convert(SECRET);
}
use of com.sequenceiq.cloudbreak.service.secret.model.SecretResponse in project cloudbreak by hortonworks.
the class HostKeytabServiceTest method testGenerateHostKeytabHostDontHaveKeytab.
@Test
public void testGenerateHostKeytabHostDontHaveKeytab() throws FreeIpaClientException {
HostKeytabRequest request = new HostKeytabRequest();
request.setEnvironmentCrn(ENVIRONMENT_CRN);
request.setRoleRequest(new RoleRequest());
request.setDoNotRecreateKeytab(Boolean.TRUE);
request.setServerHostName("asdf");
Stack stack = new Stack();
when(keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), ACCOUNT_ID)).thenReturn(stack);
FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
when(roleComponent.privilegesExist(request.getRoleRequest(), freeIpaClient)).thenReturn(Boolean.TRUE);
Host host = new Host();
host.setHasKeytab(Boolean.FALSE);
host.setKrbprincipalname("dfdf");
when(keytabCommonService.addHost(request.getServerHostName(), request.getRoleRequest(), freeIpaClient)).thenReturn(host);
KeytabCache keytabCache = mock(KeytabCache.class);
Secret keytabSecret = new Secret("keytab", "keytabSecret");
Secret principalSecret = new Secret("principal", "principalSecret");
when(keytabCache.getKeytab()).thenReturn(keytabSecret);
when(keytabCache.getPrincipal()).thenReturn(principalSecret);
when(keytabCommonService.getKeytab(request.getEnvironmentCrn(), host.getKrbprincipalname(), request.getServerHostName(), freeIpaClient)).thenReturn(keytabCache);
SecretResponse keytabResponse = new SecretResponse();
keytabResponse.setSecretPath("keytabPath");
when(secretResponseConverter.convert(keytabCache.getKeytab().getSecret())).thenReturn(keytabResponse);
SecretResponse principalResponse = new SecretResponse();
principalResponse.setSecretPath("principalPath");
when(secretResponseConverter.convert(keytabCache.getPrincipal().getSecret())).thenReturn(principalResponse);
HostKeytabResponse response = underTest.generateHostKeytab(request, ACCOUNT_ID);
assertEquals(keytabResponse, response.getKeytab());
assertEquals(principalResponse, response.getHostPrincipal());
}
Aggregations