From 70d497d3692f519597ff953b761e5fb5f5245634 Mon Sep 17 00:00:00 2001 From: Daniel Dyrnes Date: Mon, 31 Oct 2022 13:17:19 +0900 Subject: [PATCH] Added start/stop/delete commands --- package.json | 2 +- src/commands/delete.ts | 35 +++++++++++++++++++++++++++++++++++ src/commands/start.ts | 32 ++++++++++++++++++++++++++++++++ src/commands/stop.ts | 34 ++++++++++++++++++++++++++++++++++ src/index.ts | 9 +++++++++ 5 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/commands/delete.ts create mode 100644 src/commands/start.ts create mode 100644 src/commands/stop.ts diff --git a/package.json b/package.json index 57125ed..cb07d4b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zefhub", - "version": "0.0.12", + "version": "0.0.13", "main": "dist/index.js", "bin": { "zefhub": "dist/index.js" diff --git a/src/commands/delete.ts b/src/commands/delete.ts new file mode 100644 index 0000000..e8ec416 --- /dev/null +++ b/src/commands/delete.ts @@ -0,0 +1,35 @@ +/** + * Copyright 2022 Synchronous Technologies Pte Ltd + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import chalk from "chalk"; +import axios from "axios"; +import config from "../config"; +import { checkAuth } from "../utils/auth"; + +const del = async () => { + const user = await checkAuth(); + + const listResponse = await axios.delete( + `${config.host}/v1/deployment/services`, + { + headers: { + "X-Api-Key": user?.apiKey || "", + }, + } + ); +}; + +export default del; diff --git a/src/commands/start.ts b/src/commands/start.ts new file mode 100644 index 0000000..e48ac50 --- /dev/null +++ b/src/commands/start.ts @@ -0,0 +1,32 @@ +/** + * Copyright 2022 Synchronous Technologies Pte Ltd + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import chalk from "chalk"; +import axios from "axios"; +import config from "../config"; +import { checkAuth } from "../utils/auth"; + +const start = async () => { + const user = await checkAuth(); + + await axios.put(`${config.host}/v1/service/{id}/start`, { + headers: { + "X-Api-Key": user?.apiKey || "", + }, + }); +}; + +export default start; diff --git a/src/commands/stop.ts b/src/commands/stop.ts new file mode 100644 index 0000000..a4de0e3 --- /dev/null +++ b/src/commands/stop.ts @@ -0,0 +1,34 @@ +/** + * Copyright 2022 Synchronous Technologies Pte Ltd + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import chalk from "chalk"; +import axios from "axios"; +import config from "../config"; +import { checkAuth } from "../utils/auth"; + +const stop = async () => { + const user = await checkAuth(); + + await axios.put(`${config.host}/v1/service/{id}/stop`, { + headers: { + "X-Api-Key": user?.apiKey || "", + }, + }); + + console.log(chalk.green("Service stopped")); +}; + +export default stop; diff --git a/src/index.ts b/src/index.ts index bba15e2..c39f22c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,6 +22,9 @@ import up from "./commands/up"; import deploy from "./commands/deploy"; import list from "./commands/list"; import logs from "./commands/logs"; +import start from "./commands/start"; +import stop from "./commands/stop"; +import del from "./commands/delete"; const program = new Command(); @@ -63,4 +66,10 @@ easygraphql easygraphql.command("logs").description("get logs for a service").action(logs); +easygraphql.command("start").description("start a service").action(start); + +easygraphql.command("stop").description("stop a service").action(stop); + +easygraphql.command("delete").description("delete a service").action(del); + program.parse(process.argv);