use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.
the class TestProvisionAWSSecurityGroup method testProvisionAWSSecurityGroup.
@Test
public void testProvisionAWSSecurityGroup() throws Throwable {
// create credentials
Operation authResponse = new Operation();
TestUtils.postCredentials(this.host, authResponse, this.privateKey, this.privateKeyId);
AuthCredentialsServiceState creds = authResponse.getBody(AuthCredentialsServiceState.class);
// create resource pool
Operation poolResponse = new Operation();
TestUtils.postResourcePool(this.host, poolResponse);
ResourcePoolState pool = poolResponse.getBody(ResourcePoolState.class);
// create sg service
Operation securityGroupResponse = new Operation();
SecurityGroupState initialSecurityGroupState = buildSecurityGroupState(creds, pool);
TestUtils.postSecurityGroup(this.host, initialSecurityGroupState, securityGroupResponse);
SecurityGroupState securityGroupState = securityGroupResponse.getBody(SecurityGroupState.class);
// set up security group task state
ProvisionSecurityGroupTaskState task = new ProvisionSecurityGroupTaskState();
task.requestType = SecurityGroupInstanceRequest.InstanceRequestType.CREATE;
task.securityGroupDescriptionLinks = Stream.of(securityGroupState.documentSelfLink).collect(Collectors.toSet());
task.customProperties = new HashMap<>();
task.customProperties.put(NETWORK_STATE_ID_PROP_NAME, this.vpcId);
Operation provision = new Operation();
provisionSecurityGroup(task, provision);
ProvisionSecurityGroupTaskState ps = provision.getBody(ProvisionSecurityGroupTaskState.class);
waitForTaskCompletion(this.host, UriUtils.buildUri(this.host, ps.documentSelfLink));
validateAWSArtifacts(securityGroupState.documentSelfLink, creds);
// reuse previous task, but switch to a delete
task.requestType = SecurityGroupInstanceRequest.InstanceRequestType.DELETE;
Operation remove = new Operation();
provisionSecurityGroup(task, remove);
ProvisionSecurityGroupTaskState removeTask = remove.getBody(ProvisionSecurityGroupTaskState.class);
waitForTaskCompletion(this.host, UriUtils.buildUri(this.host, removeTask.documentSelfLink));
// verify security group state is gone
try {
getSecurityGroupState(securityGroupState.documentSelfLink);
} catch (Exception ex) {
assertTrue(ex instanceof ServiceNotFoundException);
}
}
use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.
the class TestUtils method postCredentials.
public static void postCredentials(VerificationHost host, Operation response, String privateKey, String privateKeyId) throws Throwable {
AuthCredentialsServiceState creds = new AuthCredentialsServiceState();
creds.privateKey = privateKey;
creds.privateKeyId = privateKeyId;
URI authFactory = UriUtils.buildFactoryUri(host, AuthCredentialsService.class);
host.testStart(1);
Operation startPost = Operation.createPost(authFactory).setBody(creds).setCompletion((o, e) -> {
if (e != null) {
host.failIteration(e);
return;
}
response.setBody(o.getBody(AuthCredentialsServiceState.class));
host.completeIteration();
});
host.send(startPost);
host.testWait();
}
use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.
the class TestAWSEnumerationAtScale method initResourcePoolAndComputeHost.
/**
* Creates the state associated with the resource pool, compute host and the VM to be created.
* @throws Throwable
*/
public void initResourcePoolAndComputeHost() throws Throwable {
// Create a resource pool where the VM will be housed
ResourcePoolState resourcePool = createAWSResourcePool(this.host);
AuthCredentialsServiceState auth = createAWSAuthentication(this.host, this.accessKey, this.secretKey);
this.endpointState = TestAWSSetupUtils.createAWSEndpointState(this.host, auth.documentSelfLink, resourcePool.documentSelfLink);
// create a compute host for the AWS EC2 VM
this.computeHost = createAWSComputeHost(this.host, this.endpointState, zoneId, regionId, this.isAwsClientMock, this.awsMockEndpointReference, null);
}
use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.
the class TestAWSEnumerationTask method testGetAvailableRegions.
@Test
public void testGetAvailableRegions() {
URI uri = UriUtils.buildUri(ServiceHost.LOCAL_HOST, host.getPort(), UriPaths.AdapterTypePath.REGION_ENUMERATION_ADAPTER.adapterLink(PhotonModelConstants.EndpointType.aws.toString().toLowerCase()), null);
Operation post = Operation.createPost(uri);
post.setBody(new AuthCredentialsServiceState());
Operation operation = host.getTestRequestSender().sendAndWait(post);
RegionEnumerationResponse result = operation.getBody(RegionEnumerationResponse.class);
assertEquals(Regions.values().length, result.regions.size());
}
use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.
the class AzureSubscriptionEndpointCreationService method createAuthCredentialsState.
private AuthCredentialsServiceState createAuthCredentialsState(EndpointState azureEaEndpoint, AzureSubscriptionEndpointCreationRequest request) {
AuthCredentialsServiceState authCredState = new AuthCredentialsServiceState();
authCredState.userLink = request.subscriptionId;
authCredState.tenantLinks = azureEaEndpoint.tenantLinks;
return authCredState;
}
Aggregations