garage-admin-sdk-js/src/api/KeyApi.js

376 lines
14 KiB
JavaScript

/**
* Garage Administration API v0+garage-v0.8.0
* Administrate your Garage cluster programatically, including status, layout, keys, buckets, and maintainance tasks. *Disclaimer: The API is not stable yet, hence its v0 tag. The API can change at any time, and changes can include breaking backward compatibility. Read the changelog and upgrade your scripts before upgrading. Additionnaly, this specification is very early stage and can contain bugs, especially on error return codes/types that are not tested yet. Do not expect a well finished and polished product!*
*
* The version of the OpenAPI document: v0.8.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*
*/
import ApiClient from "../ApiClient";
import AddKeyRequest from '../model/AddKeyRequest';
import ImportKeyRequest from '../model/ImportKeyRequest';
import KeyInfo from '../model/KeyInfo';
import ListKeys200ResponseInner from '../model/ListKeys200ResponseInner';
import UpdateKeyRequest from '../model/UpdateKeyRequest';
/**
* Key service.
* @module api/KeyApi
* @version v0.8.0
*/
export default class KeyApi {
/**
* Constructs a new KeyApi.
* @alias module:api/KeyApi
* @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 API key
* Creates a new API access key.
* @param {module:model/AddKeyRequest} addKeyRequest \"You can set a friendly name for this key, send an empty string instead\"
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/KeyInfo} and HTTP response
*/
addKeyWithHttpInfo(addKeyRequest) {
let postBody = addKeyRequest;
// verify the required parameter 'addKeyRequest' is set
if (addKeyRequest === undefined || addKeyRequest === null) {
throw new Error("Missing the required parameter 'addKeyRequest' when calling addKey");
}
let pathParams = {
};
let queryParams = {
};
let headerParams = {
};
let formParams = {
};
let authNames = ['bearerAuth'];
let contentTypes = ['application/json'];
let accepts = ['application/json'];
let returnType = KeyInfo;
return this.apiClient.callApi(
'/key', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, null
);
}
/**
* Create a new API key
* Creates a new API access key.
* @param {module:model/AddKeyRequest} addKeyRequest \"You can set a friendly name for this key, send an empty string instead\"
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/KeyInfo}
*/
addKey(addKeyRequest) {
return this.addKeyWithHttpInfo(addKeyRequest)
.then(function(response_and_data) {
return response_and_data.data;
});
}
/**
* Delete a key
* Delete a key from the cluster. Its access will be removed from all the buckets. Buckets are not automatically deleted and can be dangling. You should manually delete them before.
* @param {String} accessKey The exact API access key generated by Garage
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing HTTP response
*/
deleteKeyWithHttpInfo(accessKey) {
let postBody = null;
// verify the required parameter 'accessKey' is set
if (accessKey === undefined || accessKey === null) {
throw new Error("Missing the required parameter 'accessKey' when calling deleteKey");
}
let pathParams = {
'access_key': accessKey
};
let queryParams = {
};
let headerParams = {
};
let formParams = {
};
let authNames = ['bearerAuth'];
let contentTypes = [];
let accepts = [];
let returnType = null;
return this.apiClient.callApi(
'/key?id={access_key}', 'DELETE',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, null
);
}
/**
* Delete a key
* Delete a key from the cluster. Its access will be removed from all the buckets. Buckets are not automatically deleted and can be dangling. You should manually delete them before.
* @param {String} accessKey The exact API access key generated by Garage
* @return {Promise} a {@link https://www.promisejs.org/|Promise}
*/
deleteKey(accessKey) {
return this.deleteKeyWithHttpInfo(accessKey)
.then(function(response_and_data) {
return response_and_data.data;
});
}
/**
* Get key information
* Return information about a specific key and return its information
* @param {String} accessKey The exact API access key generated by Garage
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/KeyInfo} and HTTP response
*/
getKeyWithHttpInfo(accessKey) {
let postBody = null;
// verify the required parameter 'accessKey' is set
if (accessKey === undefined || accessKey === null) {
throw new Error("Missing the required parameter 'accessKey' when calling getKey");
}
let pathParams = {
'access_key': accessKey
};
let queryParams = {
};
let headerParams = {
};
let formParams = {
};
let authNames = ['bearerAuth'];
let contentTypes = [];
let accepts = ['application/json'];
let returnType = KeyInfo;
return this.apiClient.callApi(
'/key?id={access_key}', 'GET',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, null
);
}
/**
* Get key information
* Return information about a specific key and return its information
* @param {String} accessKey The exact API access key generated by Garage
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/KeyInfo}
*/
getKey(accessKey) {
return this.getKeyWithHttpInfo(accessKey)
.then(function(response_and_data) {
return response_and_data.data;
});
}
/**
* Import an existing key
* Imports an existing API key. This feature must only be used for migrations and backup restore. **Do not use it to generate custom key identifiers or you will break your Garage cluster.**
* @param {module:model/ImportKeyRequest} importKeyRequest Information on the key to import
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/KeyInfo} and HTTP response
*/
importKeyWithHttpInfo(importKeyRequest) {
let postBody = importKeyRequest;
// verify the required parameter 'importKeyRequest' is set
if (importKeyRequest === undefined || importKeyRequest === null) {
throw new Error("Missing the required parameter 'importKeyRequest' when calling importKey");
}
let pathParams = {
};
let queryParams = {
};
let headerParams = {
};
let formParams = {
};
let authNames = ['bearerAuth'];
let contentTypes = ['application/json'];
let accepts = ['application/json'];
let returnType = KeyInfo;
return this.apiClient.callApi(
'/key/import', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, null
);
}
/**
* Import an existing key
* Imports an existing API key. This feature must only be used for migrations and backup restore. **Do not use it to generate custom key identifiers or you will break your Garage cluster.**
* @param {module:model/ImportKeyRequest} importKeyRequest Information on the key to import
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/KeyInfo}
*/
importKey(importKeyRequest) {
return this.importKeyWithHttpInfo(importKeyRequest)
.then(function(response_and_data) {
return response_and_data.data;
});
}
/**
* List all keys
* Returns all API access keys in the cluster.
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link Array.<module:model/ListKeys200ResponseInner>} and HTTP response
*/
listKeysWithHttpInfo() {
let postBody = null;
let pathParams = {
};
let queryParams = {
};
let headerParams = {
};
let formParams = {
};
let authNames = ['bearerAuth'];
let contentTypes = [];
let accepts = ['application/json'];
let returnType = [ListKeys200ResponseInner];
return this.apiClient.callApi(
'/key', 'GET',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, null
);
}
/**
* List all keys
* Returns all API access keys in the cluster.
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link Array.<module:model/ListKeys200ResponseInner>}
*/
listKeys() {
return this.listKeysWithHttpInfo()
.then(function(response_and_data) {
return response_and_data.data;
});
}
/**
* Select key by pattern
* Find the first key matching the given pattern based on its identifier aor friendly name and return its information.
* @param {String} pattern A pattern (beginning or full string) corresponding to a key identifier or friendly name
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/KeyInfo} and HTTP response
*/
searchKeyWithHttpInfo(pattern) {
let postBody = null;
// verify the required parameter 'pattern' is set
if (pattern === undefined || pattern === null) {
throw new Error("Missing the required parameter 'pattern' when calling searchKey");
}
let pathParams = {
'pattern': pattern
};
let queryParams = {
};
let headerParams = {
};
let formParams = {
};
let authNames = ['bearerAuth'];
let contentTypes = [];
let accepts = ['application/json'];
let returnType = KeyInfo;
return this.apiClient.callApi(
'/key?search={pattern}', 'GET',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, null
);
}
/**
* Select key by pattern
* Find the first key matching the given pattern based on its identifier aor friendly name and return its information.
* @param {String} pattern A pattern (beginning or full string) corresponding to a key identifier or friendly name
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/KeyInfo}
*/
searchKey(pattern) {
return this.searchKeyWithHttpInfo(pattern)
.then(function(response_and_data) {
return response_and_data.data;
});
}
/**
* Update a key
* Updates information about the specified API access key.
* @param {String} accessKey The exact API access key generated by Garage
* @param {module:model/UpdateKeyRequest} updateKeyRequest For a given key, provide a first set with the permissions to grant, and a second set with the permissions to remove
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/KeyInfo} and HTTP response
*/
updateKeyWithHttpInfo(accessKey, updateKeyRequest) {
let postBody = updateKeyRequest;
// verify the required parameter 'accessKey' is set
if (accessKey === undefined || accessKey === null) {
throw new Error("Missing the required parameter 'accessKey' when calling updateKey");
}
// verify the required parameter 'updateKeyRequest' is set
if (updateKeyRequest === undefined || updateKeyRequest === null) {
throw new Error("Missing the required parameter 'updateKeyRequest' when calling updateKey");
}
let pathParams = {
'access_key': accessKey
};
let queryParams = {
};
let headerParams = {
};
let formParams = {
};
let authNames = ['bearerAuth'];
let contentTypes = ['application/json'];
let accepts = ['application/json'];
let returnType = KeyInfo;
return this.apiClient.callApi(
'/key?id={access_key}', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, null
);
}
/**
* Update a key
* Updates information about the specified API access key.
* @param {String} accessKey The exact API access key generated by Garage
* @param {module:model/UpdateKeyRequest} updateKeyRequest For a given key, provide a first set with the permissions to grant, and a second set with the permissions to remove
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/KeyInfo}
*/
updateKey(accessKey, updateKeyRequest) {
return this.updateKeyWithHttpInfo(accessKey, updateKeyRequest)
.then(function(response_and_data) {
return response_and_data.data;
});
}
}