use of com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest in project photon-model by vmware.
the class VSphereEndpointAdapterService method handlePatch.
@Override
public void handlePatch(Operation op) {
if (!op.hasBody()) {
op.fail(new IllegalArgumentException("body is required"));
return;
}
EndpointConfigRequest body = op.getBody(EndpointConfigRequest.class);
if (body.requestType == RequestType.CHECK_IF_ACCOUNT_EXISTS) {
checkIfAccountExistsAndGetExistingDocuments(body, op);
return;
}
EndpointAdapterUtils.handleEndpointRequest(this, op, body, credentials(), computeDesc(), compute(), endpoint(), validate(body));
}
use of com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest in project photon-model by vmware.
the class AWSEndpointAdapterService method handlePatch.
@Override
public void handlePatch(Operation op) {
if (!op.hasBody()) {
op.fail(new IllegalArgumentException("body is required"));
return;
}
EndpointConfigRequest body = op.getBody(EndpointConfigRequest.class);
if (body.requestType == RequestType.CHECK_IF_ACCOUNT_EXISTS) {
checkIfAccountExistsAndGetExistingDocuments(body, op);
return;
}
EndpointAdapterUtils.handleEndpointRequest(this, op, body, credentials(), computeDesc(), compute(), endpoint(), validate(body));
}
use of com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest in project photon-model by vmware.
the class AzureEndpointAdapterService method validate.
private BiConsumer<AuthCredentialsServiceState, BiConsumer<ServiceErrorResponse, Throwable>> validate(EndpointConfigRequest body) {
return (credentials, callback) -> {
try {
Boolean shouldProvision = Boolean.parseBoolean(body.endpointProperties.get(AZURE_PROVISIONING_PERMISSION));
validateEndpointUniqueness(credentials, body.checkForEndpointUniqueness, body.tenantLinks).thenCompose(aVoid -> validateCredentials(credentials)).thenCompose(subscription -> getPermissions(credentials)).thenCompose(permList -> verifyPermissions(permList, shouldProvision)).whenComplete((aVoid, e) -> {
if (e == null) {
callback.accept(null, null);
return;
}
if (e instanceof CompletionException) {
e = e.getCause();
}
final LocalizableValidationException localizableExc;
if (e instanceof LocalizableValidationException) {
localizableExc = (LocalizableValidationException) e;
} else {
// Azure doesn't send us any meaningful status code to work with
localizableExc = new LocalizableValidationException(e, PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE, PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE_CODE);
}
ServiceErrorResponse rsp = Utils.toServiceErrorResponse(localizableExc);
rsp.statusCode = STATUS_CODE_UNAUTHORIZED;
callback.accept(rsp, localizableExc);
});
} catch (Throwable e) {
logSevere(e);
ServiceErrorResponse rsp = new ServiceErrorResponse();
rsp.message = "Invalid Azure credentials";
rsp.statusCode = STATUS_CODE_UNAUTHORIZED;
callback.accept(rsp, e);
}
};
}
use of com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest in project photon-model by vmware.
the class EndpointAllocationTaskService method validateCredentials.
private void validateCredentials(EndpointAllocationTaskState currentState, SubStage next) {
EndpointConfigRequest req = new EndpointConfigRequest();
req.requestType = RequestType.VALIDATE;
req.endpointProperties = currentState.endpointState.endpointProperties;
req.tenantLinks = currentState.tenantLinks;
req.checkForEndpointUniqueness = currentState.checkForEndpointUniqueness;
if (currentState.endpointState.documentSelfLink != null) {
req.resourceReference = UriUtils.extendUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE), currentState.endpointState.documentSelfLink);
}
req.isMockRequest = currentState.options.contains(TaskOption.IS_MOCK);
Operation.createPatch(currentState.adapterReference).setBody(req).setCompletion((o, e) -> {
if (e != null) {
logWarning(() -> e.getMessage());
sendFailurePatch(this, currentState, e);
return;
}
EndpointAllocationTaskState st = createUpdateSubStageTask(next);
if (o.hasBody() && currentState.taskSubStage == SubStage.VALIDATE_CREDENTIALS) {
CertificateInfoServiceErrorResponse errorResponse = o.getBody(CertificateInfoServiceErrorResponse.class);
if (CertificateInfoServiceErrorResponse.KIND.equals(errorResponse.documentKind)) {
st.taskInfo.failure = errorResponse;
st.taskInfo.stage = TaskStage.FAILED;
if (errorResponse.certificateInfo != null) {
st.certificateInfo = errorResponse.certificateInfo;
}
}
}
sendSelfPatch(st);
}).sendWith(this);
}
Aggregations