To use this function add it to the class library file named OrchestratorPluginVRAService.ts
GitHub Repository: https://github.com/SimonSparksUK/Orchestrator
Filename: OrchestratorPluginVRAService.ts
Description: Orchestrator Function to Create and Execute a vRA REST Request
Public Function: VraRestGet
public VraRestGet<T>(objVraHost: VraHost, strUri: string, objPropertiesHeaders: Properties): T {
return this.VraRestRequest<T>(objVraHost, strUri, "GET", objPropertiesHeaders);
}Public Function: VraRestDelete
public VraRestDelete<T>(objVraHost: VraHost, strUri: string, objPropertiesHeaders: Properties): T {
return this.VraRestRequest<T>(objVraHost, strUri, "DELETE", objPropertiesHeaders);
}Public Function: VraRestPatch
public VraRestPatch<T>(objVraHost: VraHost, strUri: string, objPropertiesHeaders: Properties, objPayload: any): T {
return this.VraRestRequest(objVraHost, strUri, "PATCH", objPropertiesHeaders, objPayload);
}Public Function: VraRestPost
public VraRestPost<T>(objVraHost: VraHost, strUri: string, objPropertiesHeaders: Properties, objPayload: any): T {
return this.VraRestRequest<T>(objVraHost, strUri, "POST", objPropertiesHeaders, objPayload);
}Public Function: VraRestPut
public VraRestPut<T>(objVraHost: VraHost, strUri: string, objPropertiesHeaders: Properties, objPayload: any): T {
return this.VraRestRequest<T>(objVraHost, strUri, "PUT", objPropertiesHeaders, objPayload);
}Private Function: VraRestRequest
private VraRestRequest<T>(objVraHost: VraHost, strUri: string, strMethod: "GET" | "DELETE" | "PATCH" | "POST" | "PUT", objPropertiesHeaders: Properties = new Properties(), objPayload: any = null): T {
let objVraGenericRestClient: VraGenericRestClient = objVraHost.createRestClient();
let objVraRestRequest: VraRestRequest = objVraGenericRestClient.createRequest(strMethod, strUri, objPayload);
objPropertiesHeaders.keys.forEach((strKey: string): void => {
objVraRestRequest.setHeader(strKey, objPropertiesHeaders.get(strKey));
});
let objVraRestResponse: VraRestResponse = objVraGenericRestClient.execute(objVraRestRequest);
this.objLogger.info("Status code: " + objVraRestResponse.statusCode);
this.objLogger.info("Status Message: " + objVraRestResponse.statusMessage);
this.objLogger.info("Content as string: " + objVraRestResponse.contentAsString);
let objHeaders: { [key: string]: string } = objVraRestResponse.allHeaders;
let arrHeaderKey: string[] = Object.keys(objHeaders);
arrHeaderKey.forEach((strHeaderKey: string): void => {
objVraRestRequest.setHeader(strHeaderKey, objHeaders[strHeaderKey]);
});
let objReturn: T = JSON.parse(objVraRestResponse.contentAsString);
return objReturn;
}Discover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
