UNPKG

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