Search in sources :

Example 6 with SecretResponse

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());
    }
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) Credential(com.sequenceiq.redbeams.dto.Credential) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)

Example 7 with SecretResponse

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);
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) ClusterV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.ClusterV4Response) BlueprintV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.responses.BlueprintV4Response) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AbstractEntityConverterTest(com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest) Test(org.junit.Test)

Example 8 with SecretResponse

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);
}
Also used : LdapConfig(com.sequenceiq.freeipa.ldap.LdapConfig) SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) DescribeLdapConfigResponse(com.sequenceiq.freeipa.api.v1.ldap.model.describe.DescribeLdapConfigResponse) CreateLdapConfigRequest(com.sequenceiq.freeipa.api.v1.ldap.model.create.CreateLdapConfigRequest) Test(org.junit.Test)

Example 9 with SecretResponse

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);
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) HostKeytabRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 10 with SecretResponse

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());
}
Also used : Secret(com.sequenceiq.cloudbreak.service.secret.domain.Secret) SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) HostKeytabResponse(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabResponse) KeytabCache(com.sequenceiq.freeipa.entity.KeytabCache) HostKeytabRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabRequest) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Host(com.sequenceiq.freeipa.client.model.Host) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)27 Test (org.junit.jupiter.api.Test)14 Test (org.junit.Test)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 HostKeytabRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabRequest)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)4 Secret (com.sequenceiq.cloudbreak.service.secret.domain.Secret)4 HostKeytabResponse (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabResponse)4 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)4 Host (com.sequenceiq.freeipa.client.model.Host)4 KeytabCache (com.sequenceiq.freeipa.entity.KeytabCache)4 Stack (com.sequenceiq.freeipa.entity.Stack)4 CredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)3 ProxyResponse (com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse)3 RoleRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest)3 DatabaseServerV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)2 ProxyConfig (com.sequenceiq.cloudbreak.dto.ProxyConfig)2