UNPKG

@al/environments

Version:

A client for interacting with the Alert Logic Environments Public API.

252 lines (244 loc) 11.2 kB
import { AlDefaultClient } from '@al/core'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } var EnvironmentsClient = /** @class */ (function () { function EnvironmentsClient() { /** * Expose AlDefaultClient to Credentials client */ this.alClient = AlDefaultClient; } /** * Add an environment * POST * /environments/v1/:account_id * "https://api.cloudinsight.alertlogic.com/environments/v1/01000001" * -d '{"type":"aws", * "type_id": "123456789012", * "defender_support":true, * "defender_location_id":"defender-us-denver", * "discover":true, * "scan":false}' */ EnvironmentsClient.prototype.addEnvironment = function (accountId, environment) { return __awaiter(this, void 0, void 0, function () { var added; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.alClient.post({ service_name: 'environments', account_id: accountId, data: environment, })]; case 1: added = _a.sent(); return [2 /*return*/, added]; } }); }); }; /** * Delete an environment * DELETE * /environments/v1/:account_id/:environment_id * "https://api.cloudinsight.alertlogic.com/environments/v1/01000001/B37CEE84-6D27-4D0F-943C-F23937587574" */ EnvironmentsClient.prototype.deleteEnvironment = function (accountId, environmentId) { return __awaiter(this, void 0, void 0, function () { var deleted; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.alClient.delete({ service_name: 'environments', account_id: accountId, path: "/" + environmentId, })]; case 1: deleted = _a.sent(); return [2 /*return*/, deleted]; } }); }); }; /** * Get an environment * GET * /environments/v1/:account_id/:environment_id * "https://api.cloudinsight.alertlogic.com/environments/v1/01000001/582C62B4-9D1D-4F1C-9117-BE4198198861" */ EnvironmentsClient.prototype.getEnvironment = function (accountId, environmentId, queryParams) { return __awaiter(this, void 0, void 0, function () { var environment; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.alClient.fetch({ service_name: 'environments', account_id: accountId, path: "/" + environmentId, params: queryParams, })]; case 1: environment = _a.sent(); return [2 /*return*/, environment]; } }); }); }; /** * Get list of accounts with environments * GET * /environments/v1/accounts * "https://api.cloudinsight.alertlogic.com/environments/v1/accounts" */ EnvironmentsClient.prototype.getAccounts = function (accountId, queryParams) { return __awaiter(this, void 0, void 0, function () { var accounts; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.alClient.fetch({ service_name: 'environments', account_id: accountId, path: '/accounts', params: queryParams, })]; case 1: accounts = _a.sent(); return [2 /*return*/, accounts]; } }); }); }; /** * Get environments for an account * GET * /environments/v1/:account_id * "https://api.cloudinsight.alertlogic.com/environments/v1/01000001" */ EnvironmentsClient.prototype.getEnvironments = function (accountId) { return __awaiter(this, void 0, void 0, function () { var accounts; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.alClient.fetch({ service_name: 'environments', account_id: accountId, })]; case 1: accounts = _a.sent(); return [2 /*return*/, accounts]; } }); }); }; /** * Update an environment * POST * /environments/v1/:account_id/:environment_id * "https://api.cloudinsight.alertlogic.com/environments/v1/01000001/039E77DF-C9B9-4103-9DC0-6A938892D8B4" * -d '{"name":"environment5", * "credential_id": "77C12B2C-8340-4AFD-AB25-4D0581443A5E", * "scope": { * "include": [{ * "type": "vpc", * "key": "/aws/us-east-1/vpc/vpc-1234" * }], * "exclude": [{ * "type": "subnet", * "key": "/aws/us-east-1/subnet/subnet-35f42c6c"} * ]}, * "enabled":true}' */ EnvironmentsClient.prototype.updateEnvironment = function (accountId, environmentId, environment) { return __awaiter(this, void 0, void 0, function () { var updated; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.alClient.post({ service_name: 'environments', account_id: accountId, path: "/" + environmentId, data: environment, })]; case 1: updated = _a.sent(); return [2 /*return*/, updated]; } }); }); }; /** * Update environment status * PUT * /environments/v1/:account_id/:environment_id/status * "https://api.cloudinsight.alertlogic.com/environments/v1/01000001/CC4BB141-A2F8-4C80-BC25-CBA1E58EBC5E/status" * -d '{"status":"ok", "timestamp": 1471277293, "details":"status is ok now"}' */ EnvironmentsClient.prototype.updateEnvironmentStatus = function (accountId, environmentId, status) { return __awaiter(this, void 0, void 0, function () { var updated; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.alClient.set({ service_name: 'environments', account_id: accountId, path: "/" + environmentId + "/status", data: status, })]; case 1: updated = _a.sent(); return [2 /*return*/, updated]; } }); }); }; return EnvironmentsClient; }()); var environmentsClient = new EnvironmentsClient(); export { environmentsClient as EnvironmentsClient }; //# sourceMappingURL=index.esm5.js.map