Source: api/SandboxesApi.js

/*
 * Signadot API
 * API for Signadot Sandboxes
 *
 * OpenAPI spec version: 1.0
 *
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen.git
 *
 * Swagger Codegen version: 2.4.25
 *
 * Do not edit the class manually.
 *
 */

import {ApiClient} from "../ApiClient";
import {ApierrsResponse} from '../model/ApierrsResponse';
import {CreateSandboxRequest} from '../model/CreateSandboxRequest';
import {CreateSandboxResponse} from '../model/CreateSandboxResponse';
import {GetSandboxByIdResponse} from '../model/GetSandboxByIdResponse';
import {GetSandboxesResponse} from '../model/GetSandboxesResponse';
import {HandlerEmptyResponse} from '../model/HandlerEmptyResponse';
import {SandboxReadyResponse} from '../model/SandboxReadyResponse';
import {SandboxStatusResponse} from '../model/SandboxStatusResponse';
import {UpsertPRWorkspacesRequest} from '../model/UpsertPRWorkspacesRequest';
import {UpsertWorkspaceResponse} from '../model/UpsertWorkspaceResponse';

/**
* Sandboxes service.
* @module api/SandboxesApi
*/
export class SandboxesApi {

    /**
    * Constructs a new SandboxesApi. 
    * @alias module:api/SandboxesApi
    * @class
    * @param {module:ApiClient} [apiClient] Optional API client implementation to use,
    * default to {@link module:ApiClient#instance} if unspecified.
    */
    constructor(apiClient) {
        this.apiClient = apiClient || ApiClient.instance;
    }



    /**
     * Create a new sandbox
     * Creates a new sandbox with the provided parameters
     * @param {String} orgName Signadot Org Name
     * @param {module:model/CreateSandboxRequest} data Request to create sandbox
     * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/CreateSandboxResponse} and HTTP response
     */
    createNewSandboxWithHttpInfo(orgName, data) {
      let postBody = data;

      // verify the required parameter 'orgName' is set
      if (orgName === undefined || orgName === null) {
        throw new Error("Missing the required parameter 'orgName' when calling createNewSandbox");
      }

      // verify the required parameter 'data' is set
      if (data === undefined || data === null) {
        throw new Error("Missing the required parameter 'data' when calling createNewSandbox");
      }


      let pathParams = {
        'orgName': orgName
      };
      let queryParams = {
      };
      let headerParams = {
      };
      let formParams = {
      };

      let authNames = ['ApiKeyAuth'];
      let contentTypes = ['application/json'];
      let accepts = ['application/json'];
      let returnType = CreateSandboxResponse;

      return this.apiClient.callApi(
        '/orgs/{orgName}/sandboxes', 'POST',
        pathParams, queryParams, headerParams, formParams, postBody,
        authNames, contentTypes, accepts, returnType
      );
    }

    /**
     * Create a new sandbox
     * Creates a new sandbox with the provided parameters
     * @param {String} orgName Signadot Org Name
     * @param {module:model/CreateSandboxRequest} data Request to create sandbox
     * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/CreateSandboxResponse}
     */
    createNewSandbox(orgName, data) {
      return this.createNewSandboxWithHttpInfo(orgName, data)
        .then(function(response_and_data) {
          return response_and_data.data;
        });
    }


    /**
     * Delete a Sandbox by ID
     * Delete the sandbox when its ID is specified
     * @param {String} orgName Signadot Org Name
     * @param {String} sandboxID Sandbox ID
     * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/HandlerEmptyResponse} and HTTP response
     */
    deleteSandboxByIdWithHttpInfo(orgName, sandboxID) {
      let postBody = null;

      // verify the required parameter 'orgName' is set
      if (orgName === undefined || orgName === null) {
        throw new Error("Missing the required parameter 'orgName' when calling deleteSandboxById");
      }

      // verify the required parameter 'sandboxID' is set
      if (sandboxID === undefined || sandboxID === null) {
        throw new Error("Missing the required parameter 'sandboxID' when calling deleteSandboxById");
      }


      let pathParams = {
        'orgName': orgName,
        'sandboxID': sandboxID
      };
      let queryParams = {
      };
      let headerParams = {
      };
      let formParams = {
      };

      let authNames = ['ApiKeyAuth'];
      let contentTypes = ['application/json'];
      let accepts = ['application/json'];
      let returnType = HandlerEmptyResponse;

      return this.apiClient.callApi(
        '/orgs/{orgName}/sandboxes/{sandboxID}', 'DELETE',
        pathParams, queryParams, headerParams, formParams, postBody,
        authNames, contentTypes, accepts, returnType
      );
    }

    /**
     * Delete a Sandbox by ID
     * Delete the sandbox when its ID is specified
     * @param {String} orgName Signadot Org Name
     * @param {String} sandboxID Sandbox ID
     * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/HandlerEmptyResponse}
     */
    deleteSandboxById(orgName, sandboxID) {
      return this.deleteSandboxByIdWithHttpInfo(orgName, sandboxID)
        .then(function(response_and_data) {
          return response_and_data.data;
        });
    }


    /**
     * Delete Sandbox By Name
     * Delete Sandbox with given name
     * @param {String} orgName Signadot Org Name
     * @param {String} name Sandbox Name to search for
     * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/HandlerEmptyResponse} and HTTP response
     */
    deleteSandboxByNameWithHttpInfo(orgName, name) {
      let postBody = null;

      // verify the required parameter 'orgName' is set
      if (orgName === undefined || orgName === null) {
        throw new Error("Missing the required parameter 'orgName' when calling deleteSandboxByName");
      }

      // verify the required parameter 'name' is set
      if (name === undefined || name === null) {
        throw new Error("Missing the required parameter 'name' when calling deleteSandboxByName");
      }


      let pathParams = {
        'orgName': orgName,
        'name': name
      };
      let queryParams = {
      };
      let headerParams = {
      };
      let formParams = {
      };

      let authNames = ['ApiKeyAuth'];
      let contentTypes = [];
      let accepts = ['application/json'];
      let returnType = HandlerEmptyResponse;

      return this.apiClient.callApi(
        '/orgs/{orgName}/sandboxes/by-name/{name}', 'DELETE',
        pathParams, queryParams, headerParams, formParams, postBody,
        authNames, contentTypes, accepts, returnType
      );
    }

    /**
     * Delete Sandbox By Name
     * Delete Sandbox with given name
     * @param {String} orgName Signadot Org Name
     * @param {String} name Sandbox Name to search for
     * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/HandlerEmptyResponse}
     */
    deleteSandboxByName(orgName, name) {
      return this.deleteSandboxByNameWithHttpInfo(orgName, name)
        .then(function(response_and_data) {
          return response_and_data.data;
        });
    }


    /**
     * Get a Sandbox by ID
     * Fetch the details about a sandbox when its ID is specified
     * @param {String} orgName Signadot Org Name
     * @param {String} sandboxID Sandbox ID
     * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/GetSandboxByIdResponse} and HTTP response
     */
    getSandboxByIdWithHttpInfo(orgName, sandboxID) {
      let postBody = null;

      // verify the required parameter 'orgName' is set
      if (orgName === undefined || orgName === null) {
        throw new Error("Missing the required parameter 'orgName' when calling getSandboxById");
      }

      // verify the required parameter 'sandboxID' is set
      if (sandboxID === undefined || sandboxID === null) {
        throw new Error("Missing the required parameter 'sandboxID' when calling getSandboxById");
      }


      let pathParams = {
        'orgName': orgName,
        'sandboxID': sandboxID
      };
      let queryParams = {
      };
      let headerParams = {
      };
      let formParams = {
      };

      let authNames = ['ApiKeyAuth'];
      let contentTypes = ['application/json'];
      let accepts = ['application/json'];
      let returnType = GetSandboxByIdResponse;

      return this.apiClient.callApi(
        '/orgs/{orgName}/sandboxes/{sandboxID}', 'GET',
        pathParams, queryParams, headerParams, formParams, postBody,
        authNames, contentTypes, accepts, returnType
      );
    }

    /**
     * Get a Sandbox by ID
     * Fetch the details about a sandbox when its ID is specified
     * @param {String} orgName Signadot Org Name
     * @param {String} sandboxID Sandbox ID
     * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/GetSandboxByIdResponse}
     */
    getSandboxById(orgName, sandboxID) {
      return this.getSandboxByIdWithHttpInfo(orgName, sandboxID)
        .then(function(response_and_data) {
          return response_and_data.data;
        });
    }


    /**
     * Check sandbox readiness
     * Checks readiness of a sandbox with rate limiting enforced by polling.  Deprecated, please use getSandboxStatusById instead.
     * @param {String} orgName Signadot Org Name
     * @param {String} sandboxID Sandbox ID
     * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/SandboxReadyResponse} and HTTP response
     */
    getSandboxReadyWithHttpInfo(orgName, sandboxID) {
      let postBody = null;

      // verify the required parameter 'orgName' is set
      if (orgName === undefined || orgName === null) {
        throw new Error("Missing the required parameter 'orgName' when calling getSandboxReady");
      }

      // verify the required parameter 'sandboxID' is set
      if (sandboxID === undefined || sandboxID === null) {
        throw new Error("Missing the required parameter 'sandboxID' when calling getSandboxReady");
      }


      let pathParams = {
        'orgName': orgName,
        'sandboxID': sandboxID
      };
      let queryParams = {
      };
      let headerParams = {
      };
      let formParams = {
      };

      let authNames = ['ApiKeyAuth'];
      let contentTypes = ['application/json'];
      let accepts = ['application/json'];
      let returnType = SandboxReadyResponse;

      return this.apiClient.callApi(
        '/orgs/{orgName}/sandboxes/{sandboxID}/ready', 'GET',
        pathParams, queryParams, headerParams, formParams, postBody,
        authNames, contentTypes, accepts, returnType
      );
    }

    /**
     * Check sandbox readiness
     * Checks readiness of a sandbox with rate limiting enforced by polling.  Deprecated, please use getSandboxStatusById instead.
     * @param {String} orgName Signadot Org Name
     * @param {String} sandboxID Sandbox ID
     * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/SandboxReadyResponse}
     */
    getSandboxReady(orgName, sandboxID) {
      return this.getSandboxReadyWithHttpInfo(orgName, sandboxID)
        .then(function(response_and_data) {
          return response_and_data.data;
        });
    }


    /**
     * Get Sandbox Status by Sandbox ID with rate limiting.
     * Gets
     * @param {String} orgName Signadot Org Name
     * @param {String} sandboxID Sandbox ID
     * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/SandboxStatusResponse} and HTTP response
     */
    getSandboxStatusByIdWithHttpInfo(orgName, sandboxID) {
      let postBody = null;

      // verify the required parameter 'orgName' is set
      if (orgName === undefined || orgName === null) {
        throw new Error("Missing the required parameter 'orgName' when calling getSandboxStatusById");
      }

      // verify the required parameter 'sandboxID' is set
      if (sandboxID === undefined || sandboxID === null) {
        throw new Error("Missing the required parameter 'sandboxID' when calling getSandboxStatusById");
      }


      let pathParams = {
        'orgName': orgName,
        'sandboxID': sandboxID
      };
      let queryParams = {
      };
      let headerParams = {
      };
      let formParams = {
      };

      let authNames = ['ApiKeyAuth'];
      let contentTypes = ['application/json'];
      let accepts = ['application/json'];
      let returnType = SandboxStatusResponse;

      return this.apiClient.callApi(
        '/orgs/{orgName}/sandboxes/{sandboxID}/status', 'GET',
        pathParams, queryParams, headerParams, formParams, postBody,
        authNames, contentTypes, accepts, returnType
      );
    }

    /**
     * Get Sandbox Status by Sandbox ID with rate limiting.
     * Gets
     * @param {String} orgName Signadot Org Name
     * @param {String} sandboxID Sandbox ID
     * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/SandboxStatusResponse}
     */
    getSandboxStatusById(orgName, sandboxID) {
      return this.getSandboxStatusByIdWithHttpInfo(orgName, sandboxID)
        .then(function(response_and_data) {
          return response_and_data.data;
        });
    }


    /**
     * List Sandboxes
     * List all sandboxes under the specified Signadot org.
     * @param {String} orgName Signadot Org Name
     * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/GetSandboxesResponse} and HTTP response
     */
    getSandboxesWithHttpInfo(orgName) {
      let postBody = null;

      // verify the required parameter 'orgName' is set
      if (orgName === undefined || orgName === null) {
        throw new Error("Missing the required parameter 'orgName' when calling getSandboxes");
      }


      let pathParams = {
        'orgName': orgName
      };
      let queryParams = {
      };
      let headerParams = {
      };
      let formParams = {
      };

      let authNames = ['ApiKeyAuth'];
      let contentTypes = ['application/json'];
      let accepts = ['application/json'];
      let returnType = GetSandboxesResponse;

      return this.apiClient.callApi(
        '/orgs/{orgName}/sandboxes', 'GET',
        pathParams, queryParams, headerParams, formParams, postBody,
        authNames, contentTypes, accepts, returnType
      );
    }

    /**
     * List Sandboxes
     * List all sandboxes under the specified Signadot org.
     * @param {String} orgName Signadot Org Name
     * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/GetSandboxesResponse}
     */
    getSandboxes(orgName) {
      return this.getSandboxesWithHttpInfo(orgName)
        .then(function(response_and_data) {
          return response_and_data.data;
        });
    }


    /**
     * Create or Update workspace from Pull Request
     * Create a workspace that is associated with a specified pull request. If no workspaces already exist for the given pull request, this creates a new workspace. Otherwise, the new changes are applied to the existing workspaces. This endpoint uses the old terminology \"workspace\" instead of \"sandbox\" for backward compatability. ### Example  Here's an example to create/update a workspace from a pull request in the [HotROD](https://github.com/signadot/hotrod) application. To simplify the use case, consider that only the [Route Service](https://github.com/signadot/hotrod/tree/main/services/route) had changes, and that the changes were published to an image file named `signadot/hotrod-route` and tag `4e75b0b822ecbbbb4c917b0fffeb337589d82456`. This could be tagged as anything e.g. `latest`, `e2e-test` etc.  As a part of workspace creation, Signadot creates forked Kubernetes workloads (such as deployments) from existing workloads using the provided images. In order to access the forked workloads(s), `endpoints` are specified and corresponding to each endpoint, a preview URL is generated. These preview URLs are returned as part of the response. In the example below, we're dealing with a deployment named `route` in the `hotrod` namespace that is running the docker image `signadot/hotrod-route`.  In the below request to create a workspace, the deployment named `route` is forked and the fork will be created with the new docker image tag as specified by `newTag`. The new deployment that is created will be running the a new docker image tag as specified by `newTag`. There will be a single preview URL associated with this workspace as specified in `endpoints` and it will point to the fork of the `route` deployment that was created.  ```json {   \"cluster\": \"signadot\",   \"namespace\": \"hotrod\",   \"headCommit\": \"5e35abfa94626c4853eca51ecd435a779ded4123\",   \"images\": [     {       \"name\": \"signadot/hotrod-route\",       \"newTag\": \"4e75b0b822ecbbbb4c917b0fffeb337589d82456\"     }   ],   \"endpoints\": [     {       \"routeType\": \"fork\",       \"protocol\": \"http\",       \"forkOf\": {         \"kind\": \"Deployment\",         \"name\": \"route\",         \"namespace\": \"hotrod\"       }     }   ] } ```  In response the API call returns us a confirmation of the workspace created / updated along with the information on preview endpoints.  ```json {   \"workspaceIDs\": [     \"xtc54uh8p2rhs\"   ],   \"previewEndpoints\": [     {       \"id\": \"fbm4983sxb111\",       \"routeType\": \"fork\",       \"name\": \"route\",       \"protocol\": \"http\",       \"clusterID\": \"55rjfjf3rn222\",       \"cluster\": \"signadot\",       \"forkOf\": {         \"kind\": \"Deployment\",         \"namespace\": \"hotrod\",         \"name\": \"route\"       },       \"previewURL\": \"https://route--hotrod-131.preview.signadot.com\"     }   ] }  ```  You can parse the `previewEndpoints` section in the response to find the previewURL associated with the endpoint created as part of the workspace. 
     * @param {String} githubOrg GitHub Org Name
     * @param {String} githubRepo GitHub Repository Name
     * @param {Number} prNumber Pull Request Number
     * @param {module:model/UpsertPRWorkspacesRequest} data Request to upsert workspace
     * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/UpsertWorkspaceResponse} and HTTP response
     */
    upsertPrWorkspaceWithHttpInfo(githubOrg, githubRepo, prNumber, data) {
      let postBody = data;

      // verify the required parameter 'githubOrg' is set
      if (githubOrg === undefined || githubOrg === null) {
        throw new Error("Missing the required parameter 'githubOrg' when calling upsertPrWorkspace");
      }

      // verify the required parameter 'githubRepo' is set
      if (githubRepo === undefined || githubRepo === null) {
        throw new Error("Missing the required parameter 'githubRepo' when calling upsertPrWorkspace");
      }

      // verify the required parameter 'prNumber' is set
      if (prNumber === undefined || prNumber === null) {
        throw new Error("Missing the required parameter 'prNumber' when calling upsertPrWorkspace");
      }

      // verify the required parameter 'data' is set
      if (data === undefined || data === null) {
        throw new Error("Missing the required parameter 'data' when calling upsertPrWorkspace");
      }


      let pathParams = {
        'githubOrg': githubOrg,
        'githubRepo': githubRepo,
        'prNumber': prNumber
      };
      let queryParams = {
      };
      let headerParams = {
      };
      let formParams = {
      };

      let authNames = ['ApiKeyAuth'];
      let contentTypes = ['application/json'];
      let accepts = ['application/json'];
      let returnType = UpsertWorkspaceResponse;

      return this.apiClient.callApi(
        '/repos/{githubOrg}/{githubRepo}/pulls/{prNumber}/workspaces', 'POST',
        pathParams, queryParams, headerParams, formParams, postBody,
        authNames, contentTypes, accepts, returnType
      );
    }

    /**
     * Create or Update workspace from Pull Request
     * Create a workspace that is associated with a specified pull request. If no workspaces already exist for the given pull request, this creates a new workspace. Otherwise, the new changes are applied to the existing workspaces. This endpoint uses the old terminology \"workspace\" instead of \"sandbox\" for backward compatability. ### Example  Here's an example to create/update a workspace from a pull request in the [HotROD](https://github.com/signadot/hotrod) application. To simplify the use case, consider that only the [Route Service](https://github.com/signadot/hotrod/tree/main/services/route) had changes, and that the changes were published to an image file named `signadot/hotrod-route` and tag `4e75b0b822ecbbbb4c917b0fffeb337589d82456`. This could be tagged as anything e.g. `latest`, `e2e-test` etc.  As a part of workspace creation, Signadot creates forked Kubernetes workloads (such as deployments) from existing workloads using the provided images. In order to access the forked workloads(s), `endpoints` are specified and corresponding to each endpoint, a preview URL is generated. These preview URLs are returned as part of the response. In the example below, we're dealing with a deployment named `route` in the `hotrod` namespace that is running the docker image `signadot/hotrod-route`.  In the below request to create a workspace, the deployment named `route` is forked and the fork will be created with the new docker image tag as specified by `newTag`. The new deployment that is created will be running the a new docker image tag as specified by `newTag`. There will be a single preview URL associated with this workspace as specified in `endpoints` and it will point to the fork of the `route` deployment that was created.  ```json {   \"cluster\": \"signadot\",   \"namespace\": \"hotrod\",   \"headCommit\": \"5e35abfa94626c4853eca51ecd435a779ded4123\",   \"images\": [     {       \"name\": \"signadot/hotrod-route\",       \"newTag\": \"4e75b0b822ecbbbb4c917b0fffeb337589d82456\"     }   ],   \"endpoints\": [     {       \"routeType\": \"fork\",       \"protocol\": \"http\",       \"forkOf\": {         \"kind\": \"Deployment\",         \"name\": \"route\",         \"namespace\": \"hotrod\"       }     }   ] } ```  In response the API call returns us a confirmation of the workspace created / updated along with the information on preview endpoints.  ```json {   \"workspaceIDs\": [     \"xtc54uh8p2rhs\"   ],   \"previewEndpoints\": [     {       \"id\": \"fbm4983sxb111\",       \"routeType\": \"fork\",       \"name\": \"route\",       \"protocol\": \"http\",       \"clusterID\": \"55rjfjf3rn222\",       \"cluster\": \"signadot\",       \"forkOf\": {         \"kind\": \"Deployment\",         \"namespace\": \"hotrod\",         \"name\": \"route\"       },       \"previewURL\": \"https://route--hotrod-131.preview.signadot.com\"     }   ] }  ```  You can parse the `previewEndpoints` section in the response to find the previewURL associated with the endpoint created as part of the workspace. 
     * @param {String} githubOrg GitHub Org Name
     * @param {String} githubRepo GitHub Repository Name
     * @param {Number} prNumber Pull Request Number
     * @param {module:model/UpsertPRWorkspacesRequest} data Request to upsert workspace
     * @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/UpsertWorkspaceResponse}
     */
    upsertPrWorkspace(githubOrg, githubRepo, prNumber, data) {
      return this.upsertPrWorkspaceWithHttpInfo(githubOrg, githubRepo, prNumber, data)
        .then(function(response_and_data) {
          return response_and_data.data;
        });
    }


}