1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | var __importStar = (this && this.__importStar) || function (mod) {
|
6 | if (mod && mod.__esModule) return mod;
|
7 | var result = {};
|
8 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
9 | result["default"] = mod;
|
10 | return result;
|
11 | };
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | const path_1 = __importDefault(require("path"));
|
14 | const util_1 = __importDefault(require("util"));
|
15 | const child_process_1 = __importDefault(require("child_process"));
|
16 | const request = __importStar(require("./request"));
|
17 | const types_1 = require("./types");
|
18 | const pExec = util_1.default.promisify(child_process_1.default.exec);
|
19 | async function exec(command) {
|
20 | return await pExec(command);
|
21 | }
|
22 | exports.exec = exec;
|
23 | function getHostOS() {
|
24 | return process.env.OPS_HOST_PLATFORM || 'unknown';
|
25 | }
|
26 | exports.getHostOS = getHostOS;
|
27 | function getInterfaceType() {
|
28 | return process.env.SDK_INTERFACE_TYPE || types_1.Interfaces.Terminal;
|
29 | }
|
30 | exports.getInterfaceType = getInterfaceType;
|
31 | function homeDir() {
|
32 | return process.env.SDK_HOME_DIR || '/root';
|
33 | }
|
34 | exports.homeDir = homeDir;
|
35 | function log(...args) {
|
36 | console.log(...args);
|
37 | }
|
38 | exports.log = log;
|
39 |
|
40 | function getStatePath() {
|
41 | return path_1.default.resolve(process.env.SDK_STATE_DIR || '');
|
42 | }
|
43 | exports.getStatePath = getStatePath;
|
44 |
|
45 | function getConfigPath() {
|
46 | return path_1.default.resolve(process.env.SDK_CONFIG_DIR || '');
|
47 | }
|
48 | exports.getConfigPath = getConfigPath;
|
49 |
|
50 | async function setState(key, value) {
|
51 | await request.setState({ key, value });
|
52 | return request.getKVAll('state/get-all');
|
53 | }
|
54 | exports.setState = setState;
|
55 |
|
56 | async function getAllState() {
|
57 | return request.getKVAll('state/get-all');
|
58 | }
|
59 | exports.getAllState = getAllState;
|
60 |
|
61 | async function getState(key) {
|
62 | return request.getKV('state/get', key);
|
63 | }
|
64 | exports.getState = getState;
|
65 | async function setConfig(key, value) {
|
66 | await request.setConfig({ key, value });
|
67 | return request.getKVAll('config/get-all');
|
68 | }
|
69 | exports.setConfig = setConfig;
|
70 | async function getConfig(key) {
|
71 | return request.getKV('config/get', key);
|
72 | }
|
73 | exports.getConfig = getConfig;
|
74 | async function getAllConfig() {
|
75 | return request.getKVAll('config/get-all');
|
76 | }
|
77 | exports.getAllConfig = getAllConfig;
|
78 | async function deleteConfig(key) {
|
79 | return request.deleteKV('config/delete', key);
|
80 | }
|
81 | exports.deleteConfig = deleteConfig;
|
82 | async function getSecret(key, hidden = true) {
|
83 | return await request.getSecret(key, hidden);
|
84 | }
|
85 | exports.getSecret = getSecret;
|
86 | async function setSecret(key, value) {
|
87 | return await request.setSecret(key, value);
|
88 | }
|
89 | exports.setSecret = setSecret;
|
90 |
|
91 | async function track(tags, metadata) {
|
92 | try {
|
93 | await request.track(Object.assign({ tags: Array.isArray(tags) ? tags : [tags] }, metadata));
|
94 | }
|
95 | catch (e) {
|
96 |
|
97 | }
|
98 | }
|
99 | exports.track = track;
|
100 | async function events(start, end) {
|
101 | return await request.events(start, end || new Date().toISOString());
|
102 | }
|
103 | exports.events = events;
|