UNPKG

mongodb-atlas-api-client

Version:
105 lines (92 loc) 3.4 kB
const {getQueryStringFromOptions} = require("./helper"); class Cluster { constructor(client, baseUrl, projectId) { this.client_ = client; this.baseUrl_ = baseUrl; this.projectId_ = projectId; } async get(clustername, options = {}) { const queryString = getQueryStringFromOptions(options); const httpOptions = options.httpOptions; const response = ( await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/clusters/${clustername}?${queryString}`, httpOptions) ); return response; } async getAdvanceConfiguration(clustername, options = {}) { const queryString = getQueryStringFromOptions(options); const httpOptions = options.httpOptions; const response = ( await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/clusters/${clustername}/processArgs?${queryString}`, httpOptions) ); return response; } async getAll(options = {}) { const queryString = getQueryStringFromOptions(options); const httpOptions = options.httpOptions; const response = ( await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/clusters?${queryString}`, httpOptions) ); return response; } async delete(clustername, options = {}) { const queryString = getQueryStringFromOptions(options); const httpOptions = options.httpOptions; await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/clusters/${clustername}?${queryString}`, { "method": "DELETE", ...httpOptions }); return true; } async update(clustername, body, options = {}) { const queryString = getQueryStringFromOptions(options); const httpOptions = options.httpOptions; const response = ( await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/clusters/${clustername}?${queryString}`, { "method": "PATCH", "data": body, "headers": {"Content-Type": "application/json"}, ...httpOptions }) ); return response; } async updateAdvanceConfiguration(clustername, body, options = {}) { const queryString = getQueryStringFromOptions(options); const httpOptions = options.httpOptions; const response = ( await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/clusters/${clustername}/processArgs?${queryString}`, { "method": "PATCH", "data": body, "headers": {"Content-Type": "application/json"}, ...httpOptions }) ); return response; } async testPrimaryFailOver(clustername, options = {}) { const queryString = getQueryStringFromOptions(options); const httpOptions = options.httpOptions; const response = ( await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/clusters/${clustername}/restartPrimaries?${queryString}`, { "method": "POST", ...httpOptions }) ); return response; } async create(body, options = {}) { const queryString = getQueryStringFromOptions(options); const httpOptions = options.httpOptions; const response = ( await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/clusters?${queryString}`, { "method": "POST", "data": body, "headers": {"Content-Type": "application/json"}, ...httpOptions }) ); return response; } } module.exports = Cluster;