Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 79dad1b

Browse files
Merge pull request #64 from llimllib/add-delete-service-subcommand
add delete service subcommand
2 parents 7ae178b + 8fe3d79 commit 79dad1b

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

api/requests.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,43 @@ function queryStringify(query: Record<string, any>) {
1212
});
1313
}
1414

15+
type httpMethod =
16+
| "GET"
17+
| "HEAD"
18+
| "POST"
19+
| "PUT"
20+
| "DELETE"
21+
| "CONNECT"
22+
| "OPTIONS"
23+
| "TRACE"
24+
| "PATCH";
25+
1526
let apiReqCount = 0;
1627

1728
export function getRequestRaw(
29+
logger: Log.Logger,
30+
cfg: RuntimeConfiguration,
31+
path: string,
32+
query: Record<string, any> = {}
33+
): Promise<Response> {
34+
return requestRaw(logger, cfg, path, query, "GET");
35+
}
36+
37+
export function deleteRequestRaw(
38+
logger: Log.Logger,
39+
cfg: RuntimeConfiguration,
40+
path: string,
41+
query: Record<string, any> = {}
42+
): Promise<Response> {
43+
return requestRaw(logger, cfg, path, query, "DELETE");
44+
}
45+
46+
function requestRaw(
1847
logger: Log.Logger,
1948
cfg: RuntimeConfiguration,
2049
path: string,
2150
query: Record<string, any> = {},
51+
method: httpMethod = "GET"
2252
): Promise<Response> {
2353
return handleApiErrors(logger, async () => {
2454
const reqNumber = apiReqCount++;
@@ -30,14 +60,15 @@ export function getRequestRaw(
3060

3161
const url = `https://${apiHost(cfg)}/v1${path}?${queryStringify(query)}`;
3262

33-
logger.debug(`api dispatch: ${reqNumber}: url ${url} (query: ${JSON.stringify(query)})`);
63+
logger.debug(`api dispatch: ${reqNumber}: method: ${method} url ${url} (query: ${JSON.stringify(query)})`);
3464

3565
const response = await fetch(url, {
3666
headers: {
3767
authorization,
3868
'user-agent': `Render CLI/${VERSION}`,
3969
accept: 'application/json',
4070
},
71+
method: method,
4172
});
4273
if (!response.ok) {
4374
// this kind of has to be a DOMException because it encapsulates the notion of NetworkError

commands/services/delete.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { standardAction, Subcommand } from "../_helpers.ts";
2+
import { getConfig } from "../../config/index.ts";
3+
import { deleteRequestRaw } from "../../api/index.ts";
4+
import { getLogger } from "../../util/logging.ts";
5+
6+
const desc = `Deletes a service`;
7+
8+
export const servicesDeleteCommand = new Subcommand()
9+
.name("list")
10+
.description(desc)
11+
.group("API parameters")
12+
.option("--id <serviceId:string>", "the service ID (e.g. `srv-12345`)")
13+
.action((opts) =>
14+
standardAction({
15+
exitCode: (res) => (res?.status == 204 ? 0 : 1),
16+
interactive: () => undefined,
17+
processing: async () => {
18+
const cfg = await getConfig();
19+
const logger = await getLogger();
20+
21+
const ret = await deleteRequestRaw(logger, cfg, `/services/${opts.id}`);
22+
logger.debug(`deleted service ${opts.id}: ${ret.status}`);
23+
24+
return ret;
25+
},
26+
})
27+
);

commands/services/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { servicesListCommand } from "./list.ts";
33
import { servicesShowCommand } from "./show.ts";
44
import { servicesSshCommand } from "./ssh.ts";
55
import { servicesTailCommand } from "./tail.ts";
6+
import { servicesDeleteCommand } from "./delete.ts";
67

78
const desc =
89
`Commands for observing and managing Render services.`;
@@ -16,6 +17,7 @@ export const servicesCommand =
1617
Deno.exit(1);
1718
})
1819
.command("show", servicesShowCommand)
20+
.command("delete", servicesDeleteCommand)
1921
.command("list", servicesListCommand)
2022
.command("tail", servicesTailCommand)
2123
.command("ssh", servicesSshCommand)

0 commit comments

Comments
 (0)