use of org.platformlayer.crypto.KeyParser in project platformlayer by platformlayer.
the class GoogleComputeClientFactory method getComputeClient.
public GoogleComputeClient getComputeClient(GoogleCloud cloud) throws OpsException {
KeyParser parser = new KeyParser();
Object parsed = parser.parse(cloud.serviceAccountKey.plaintext());
PrivateKey privateKey;
if (parsed == null) {
throw new OpsException("Cannot parse private key");
} else if (parsed instanceof PrivateKey) {
privateKey = (PrivateKey) parsed;
} else {
throw new OpsException("Expected private key, found: " + parsed.getClass().getSimpleName());
}
// Build service account credential.
GoogleCredential credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT).setJsonFactory(JSON_FACTORY).setServiceAccountId(cloud.serviceAccountId).setServiceAccountScopes(ComputeScopes.COMPUTE).setServiceAccountPrivateKey(privateKey).build();
Compute compute = new Compute(HTTP_TRANSPORT, JSON_FACTORY, credential);
return new GoogleComputeClient(platformLayerClient, compute, cloud.projectId);
}
Aggregations