use of com.amazonaws.services.identitymanagement.model.UploadServerCertificateRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class SSLSetupTest method testSetupSSLCertificateNoCertificate.
@Test
public void testSetupSSLCertificateNoCertificate() {
String expectedCertName = config.getSSLCertificateName(StackEnvironmentType.REPO);
String expectedCertArn = "expectedCertArn";
// Returned in 1st call to FindCertificate() --> empty
// ServerCertificateMetadata scmdList1 = new ServerCertificateMetadata().withServerCertificateName(expectedCertName);
List<ServerCertificateMetadata> expectedLstSrvCertMetadata1 = new LinkedList<ServerCertificateMetadata>();
// expectedLstSrvCertMetadata1.add(scmdList1);
// Returned in 2nd call to FindCertificate()
ServerCertificateMetadata scmdList2 = new ServerCertificateMetadata().withServerCertificateName(expectedCertName).withArn(expectedCertArn);
List<ServerCertificateMetadata> expectedLstSrvCertMetadata2 = new LinkedList<ServerCertificateMetadata>();
expectedLstSrvCertMetadata1.add(scmdList2);
// listServerCertificates() should return empty list, then uploaded cert
ListServerCertificatesResult expectedLstssr1 = new ListServerCertificatesResult().withServerCertificateMetadataList(expectedLstSrvCertMetadata1);
ListServerCertificatesResult expectedLstssr2 = new ListServerCertificatesResult().withServerCertificateMetadataList(expectedLstSrvCertMetadata2);
when(mockAmznIamClient.listServerCertificates()).thenReturn(expectedLstssr1, expectedLstssr2);
// Call to uploadServerCertificate()
ServerCertificateMetadata srvCertMeta = new ServerCertificateMetadata().withServerCertificateName(expectedCertName).withArn(expectedCertArn);
UploadServerCertificateRequest uscr = new UploadServerCertificateRequest().withServerCertificateName(expectedCertName);
UploadServerCertificateResult expectedUscr = new UploadServerCertificateResult().withServerCertificateMetadata(srvCertMeta);
when(mockAmznIamClient.uploadServerCertificate(uscr)).thenReturn(expectedUscr);
SSLSetup sslSetup = new SSLSetup(factory, config, resources);
sslSetup.setupSSLCertificate(StackEnvironmentType.REPO);
// Meta for upload server cert should be in resources
assertEquals(expectedCertName, resources.getSslCertificate(StackEnvironmentType.REPO).getServerCertificateName());
assertEquals(expectedCertArn, resources.getSslCertificate(StackEnvironmentType.REPO).getArn());
}
use of com.amazonaws.services.identitymanagement.model.UploadServerCertificateRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class SSLSetup method setupSSLCertificate.
/**
* Setup the SSL certificate.
*/
public void setupSSLCertificate(StackEnvironmentType env) {
// First determine if the certificate already exists already exists
ServerCertificateMetadata meta = findCertificate(config.getSSLCertificateName(env));
if (meta == null) {
// Upload the parts of the certificate.
UploadServerCertificateRequest request = new UploadServerCertificateRequest();
request.setServerCertificateName(config.getSSLCertificateName(env));
request.setPrivateKey(getCertificateStringFromS3(config.getSSlCertificatePrivateKeyName(env)));
request.setCertificateBody(getCertificateStringFromS3(config.getSSLCertificateBodyKeyName(env)));
request.setCertificateChain(getCertificateStringFromS3(config.getSSLCertificateChainKeyName(env)));
UploadServerCertificateResult result = iamClient.uploadServerCertificate(request);
log.debug("Created SSL certificate: " + result);
// Search for it
meta = findCertificate(config.getSSLCertificateName(env));
}
if (meta == null)
throw new IllegalStateException("Failed to find or create the SSL certificate: " + config.getSSLCertificateName(env));
// Also set the SSL Cert arn as a property
// config.setSSLCertificateARN(prefix, meta.getArn());
resources.setSslCertificate(env, meta);
}
Aggregations