{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":29240,"path":"it-operations-management/cloud-configuration-governance/mid-server-script-includes.md","title":"CAPI classes in MID Server script includes","bundle":null,"doc_type":null,"release":"australia","body":"\n# CAPI classes in MID Server script includes\n\nCloud Provisioning and Governance provides several JavaScript classes that make REST calls to cloud providers. These classes are called from MID Server script includes \\(for Azure by default\\) or from Java calls in the system \\(for AWS by default\\). If you create custom providers, interfaces, or CAPI APIs \\(for any cloud provider\\), you can use MID Server script includes to call the classes.\n\n**Note:** In CAPI APIs, there are no MID Server script includes \\(in Method Mappers\\) that you can customize to call the AWS classes. By default, the CAPI APIs for AWS make Java calls to then call the AWS classes. However, if you create CAPI APIs, you can also create custom script includes to call the classes.\n\nView CAPI classes by navigating to **MID Servers** &gt; **Script Includes** in the base system instance interface \\(not the Cloud Admin Portal\\). You search for the name of a class in the **Go to** search box using the **Name** column:\n\n\\[Omitted image \"capi-classes-finding.png\"\\] Alt text: Searching for MID Server script includes\n\n## Base classes\n\nThese base classes are available by default. They form a basis for the Azure and AWS classes that make the actual REST calls.\n\n-   **CloudAPIBase**\n\n    CloudAPIBase is a provider-agnostic API that communicates with all types of cloud APIs. It provides functions for basic debugging and logging, and for collecting proxy information on the MID Server. It also defines Headers, Parameters, Endpoints, and `this.parameter`.\n\n-   **AWSCloudAPIBase**\n\n    This class is extended from CloudAPIBase and provides functions that call the invoker to make GET, PUT, POST, and DELETE requests. The class provides the option of an `executeAction` method, which is an AWS implementation of GET, or the invoke method, which provides REST API calls.\n\n-   **AzureCloudAPIBase**\n\n    This class is extended from CloudAPIBase and provides functions that do these actions:\n\n    -   Fetch resource IDs.\n    -   Fetch endpoint properties.\n    -   List resources.\n    -   Call the invoker to make GET, PUT, POST, and DELETE requests.\n\nAzureCloudAPIBase utilizes the `_invokeRequest` method to make REST API calls to Azure using the standard REST API calls.\n\n\\[Omitted image \"capi-cloudapibase.png\"\\] Alt text: CloudAPIBase\n\n## Invoker classes\n\nInvoker classes perform the actual REST calls to the cloud provider. If you create a custom CAPI interface and API, you should extend **CloudRestAPIInvoker** to create your REST calls.\n\n-   **CloudRestAPIInvoker**\n\n    This class is an abstracted class for making REST API calls. If there are headers and/or parameters to send with a request, classes that implement the invoker must extend this object. They also must provide overrides for **getEndpointUrl** to return the targeted endpoint, and for **getHeaders** and **getParameters**. For example, with Azure REST APIs, authentication requires the passing of a token as a header. The extension implementing it should provide a response from **getHeaders** that performs the token creation or retrieval and sets it. This base object invokes **getHeaders** and sends whatever it gets back with the request. This class also provides a **getResponse** method to handle the response from the cloud provider.\n\n    If you create a custom CAPI API, you should extend **CloudRestAPIInvoker** to make REST calls to the cloud provider.\n\n-   **AmazonWebServicesAPIInvoker**\n\n    This class is extended from **CloudRestAPIInvoker** and provides methods for making REST API calls to the cloud provider.\n\n-   **AzureAPIInvoker**\n\n    This class is extended from **CloudRestAPIInvoker** and provides functions that make these REST API calls to Azure Resource Manager:\n\n    -   Sets the Service Principal, headers, and parameters for REST calls.\n    -   Gets the endpoint URL, token \\(client ID, tenant ID, and secret key\\), and headers/parameters.\n    -   Retrieves and decodes the JSON response body from the cloud provider.\n-   **AzureEAAPIInvoker**\n\n    This class returns the token for access to the Azure Enterprise Agreement \\(EA\\) REST API.\n\n-   **AzureStorageAPIInvoker**\n\n    This class makes REST calls for Azure storage. The functions in this class can get the token, response, headers, and parameters.\n\n\nThis graphic illustrates how these base classes are used to extend AWS-specific and Azure-specific classes:\n\n\\[Omitted image \"capi-cloudrestapiinvoker.png\"\\] Alt text: CloudRestAPIInvoker\n\n## Exceptions\n\n-   **RESTAPIException**\n\n    This base class handles exceptions that might occur during the REST call. It returns the response code from the cloud provider.\n\n-   **AWSAPIException**\n\n    This class handles exceptions that might occur during the REST call.\n\n-   **AzureAPIException**\n\n    This class throws a runtime exception when needed during Azure API invocation.\n\n\n\\[Omitted image \"capi-restapiexception.png\"\\] Alt text: RESTAPIException\n\n## Classes for credentials\n\n-   **CloudRESTRequestSigningUtil**\n\n    This class uses overrides that are specified in CAPI API Config Overrides. The **AmazonWebServicesRequestSigner** class extends this class. For Azure, many signers are built into the MID Server script includes for Method Mappers in Azure CAPI APIs.\n\n-   **AmazonWebServicesRequestSigner**\n\n    This class sets up a secure session for the REST API call by taking information about a request, and creating a [signature v4](http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html)-signed string for the request. This class is extended from CloudRESTRequestSigningUtil.\n\n\n## Other Azure classes\n\n|Class|Description|\n|-----|-----------|\n|AzureAlertRule|Class to create and delete Azure alert rules.|\n|AzureAuthorizationPolicy|Class to assign tag policies.|\n|AzureComputeAvailabilitySet|Class to fetch Azure availability sets. Refer to: https://docs.microsoft.com/en-us/rest/api/compute/availabilitysets|\n|AzureComputeHardware|Class to fetch Azure sizes. Refer to: https://docs.microsoft.com/en-us/rest/api/compute/virtualmachinesizes|\n|AzureComputeImage|Class to handle Azure API calls against image. Refer to: https://docs.microsoft.com/en-us/rest/api/manageddisks/images/images-rest-api|\n|AzureComputeVirtualMachine|Class to handle Azure API calls against virtual machines. Refer to: https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines VM Size and Capacities: https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-sizes https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-linux-sizes Cloud-Init supported Versions: https://docs.microsoft.com/en-us/azure/virtual-machines/linux/using-cloud-init|\n|AzureDeployment|Class to handle Azure ARM template deployment.|\n|AzureDeploymentOperation|Class to handle Azure ARM template deployment operation.|\n|AzureImages|Class to handle Azure Images.|\n|AzureLoadBalancer|Class to handle Azure API calls against load balancers. Refer to: https://msdn.microsoft.com/en-us/library/azure/mt163651.aspx|\n|AzureLocalNetworkGateways|Class to create and retrieve local network gateways.|\n|AzureNetworkNIC|Class to handle Azure API calls against network interface cards. Refer to: https://msdn.microsoft.com/en-us/library/azure/mt163579.aspx|\n|AzureNetworkPublicIP|Class to handle Azure API calls against public IP addresses. Refer to: https://msdn.microsoft.com/en-us/library/azure/mt163638.aspx|\n|AzureNetworkRouter|Class to handle Azure API calls against route table. Refer to: https://docs.microsoft.com/en-us/rest/api/network/route-tables|\n|AzureNetworkSecurityGroup|Class to handle Azure API calls against network interface cards. Refer to: https://msdn.microsoft.com/en-us/library/azure/mt163579.aspx|\n|AzureNetworkVirtualNetwork|Class to handle Azure API calls against virtual networks.|\n|AzureProvider|Class to get Azure provider details, such as the provider URL and version.|\n|AzureRegion|Class to fetch Azure regions.|\n|AzureResource|Deals with the object referenced by ObjectID in the parameters. It also fetches the API version. This class is Intended mostly to get unsupported types or delete resources.|\n|AzureResourceGroupManager|Class to handle Azure ARM resource groups.|\n|AzureResponseUtil|Class to translate Azure API response to DTO object.|\n|AzureStorageAccount|Class to handle Azure API calls against storage account. Refer to: //https://msdn.microsoft.com/en-us/library/azure/mt163638.aspx|\n|AzureStorageBlob|Class to create and manipulate storage containers and blobs.|\n|AzureStorageManagedDisk|Class to handle Azure API calls against managed disk. Refer to: https://docs.microsoft.com/en-us/rest/api/manageddisks/disks/disks-create-or-update|\n|AzureSubscription|Class to fetch Azure subscriptions.|\n|AzureVirtualNetworkGateways|Class to create and manipulate virtual network gateways.|\n|AzureCloudEAAPIBase|Base object for Azure EA API handlers. Azure EA APIs have a base URL of https://consumption.azure.com and require the enrollment number in the path. This class handles marshalling of the EnrollmentNumber and EnrollmentToken parameters.|\n\n## Other AWS classes\n\n<table id=\"table_dct_f3x_2fb\"><thead><tr><th>\n\nClass\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nAmazonImages\n\n</td><td>\n\nClass to handle Amazon machine images.\n\n http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html\n\n</td></tr><tr><td>\n\nAmazonResponseProcessorUtil\n\n</td><td>\n\nClass to handle AWS REST API response.\n\n</td></tr><tr><td>\n\nAWSAutoScalingGroups\n\n</td><td>\n\nClass to handle AWS API calls to create and manipulate [Auto Scaling Groups](http://docs.aws.amazon.com/AutoScaling/latest/APIReference/API_CreateAutoScalingGroup.html).\n\n</td></tr><tr><td>\n\nAWSCloudFormation\n\n</td><td>\n\nHandler for AWS CloudFormation API calls.\n\n</td></tr><tr><td>\n\nAWSEC2\n\n</td><td>\n\nHandler for AWS EC2 API calls.\n\n</td></tr><tr><td>\n\nAWSKeyValuePair\n\n</td><td>\n\nClass to import and manipulate key pairs.\n\n</td></tr><tr><td>\n\nAWSLaunchConfigurations\n\n</td><td>\n\nHelper class.\n\n</td></tr><tr><td>\n\nAWSS3\n\n</td><td>\n\nHandler for AWS S3 API calls.\n\n</td></tr><tr><td>\n\nAWSTopics\n\n</td><td>\n\nClass with [AWS topics](http://docs.aws.amazon.com/sns/latest/api/API_ListTopics.html).\n\n</td></tr></tbody>\n</table>**Parent Topic:**[Cloud Provisioning and Governance](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/it-operations-management/cloud-configuration-governance/cloud-management-v2-landing-page.md)\n\n"}}