UNPKG

jamsocket

Version:

A CLI for the Jamsocket platform

113 lines (112 loc) 4.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Jamsocket = void 0; const api_1 = require("./api"); const jamsocket_config_1 = require("./jamsocket-config"); const docker_1 = require("./lib/docker"); class Jamsocket { constructor(config, api) { this.config = config; this.api = api; } static fromEnvironment() { const config = jamsocket_config_1.JamsocketConfig.fromSaved(); const api = api_1.JamsocketApi.fromEnvironment(); return new Jamsocket(config, api); } expectAuthorized() { if (this.config === null) { throw new Error('No user credentials found. Log in with jamsocket login'); } return this.config; } async serviceImage(service) { const config = this.expectAuthorized(); const result = await this.api.serviceImage(config.getAccount(), service, config); return result.imageName; } async push(service, image, tag) { const config = this.expectAuthorized(); let prefixedImage = await this.serviceImage(service); if (tag) prefixedImage += `:${tag}`; console.log(`Tagging (${prefixedImage}).`); (0, docker_1.tag)(image, prefixedImage); console.log('Pushing.'); const auth = config.getRegistryAuth(); await (0, docker_1.push)(prefixedImage, auth); console.log('Done.'); } // eslint-ignore-next-line max-params spawn(service, serviceEnvironment, env, grace, lock) { const config = this.expectAuthorized(); const body = { env, grace_period_seconds: grace, lock, service_environment: serviceEnvironment, }; return this.api.spawn(config.getAccount(), service, config, body); } connect(service, serviceEnvironment, body) { const config = this.expectAuthorized(); return this.api.connect(config.getAccount(), service, serviceEnvironment, config, body); } terminate(backend, hard) { const config = this.expectAuthorized(); return this.api.terminate(backend, hard, config); } terminateAllBackends(serviceName, body) { const config = this.expectAuthorized(); return this.api.terminateAllBackends(config.getAccount(), serviceName, body, config); } backendInfo(backend) { const config = this.expectAuthorized(); return this.api.backendInfo(backend, config); } listRunningBackends() { const config = this.expectAuthorized(); return this.api.listRunningBackends(config.getAccount(), config); } serviceCreate(service) { const config = this.expectAuthorized(); return this.api.serviceCreate(config.getAccount(), service, config); } serviceDelete(service) { const config = this.expectAuthorized(); return this.api.serviceDelete(config.getAccount(), service, config); } serviceInfo(service) { const config = this.expectAuthorized(); return this.api.serviceInfo(config.getAccount(), service, config); } serviceList() { const config = this.expectAuthorized(); return this.api.serviceList(config.getAccount(), config); } updateEnvironment(service, environment, imageTag) { const config = this.expectAuthorized(); return this.api.updateEnvironment(config.getAccount(), service, environment, config, { image_tag: imageTag, }); } imagesList(service) { const config = this.expectAuthorized(); return this.api.imagesList(config.getAccount(), service, config); } streamLogs(backend, callback) { const config = this.expectAuthorized(); return this.api.streamLogs(backend, config, callback); } streamMetrics(backend, callback) { const config = this.expectAuthorized(); return this.api.streamMetrics(backend, config, callback); } streamStatus(backend, callback, config) { return this.api.streamStatus(backend, callback, config); } status(backend, config) { return this.api.status(backend, config); } } exports.Jamsocket = Jamsocket;