-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoauth-clients.ts
More file actions
247 lines (229 loc) · 7.55 KB
/
Copy pathoauth-clients.ts
File metadata and controls
247 lines (229 loc) · 7.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import type { Command } from "commander";
import { withErrorHandler, createClient, getFormat, outputResponse } from "../../helpers.js";
import { parseJsonInput } from "../../input.js";
import { printSuccess } from "../../output.js";
import { addExamples } from "../help.js";
export function registerOAuthClientsCommand(parent: Command): void {
const oauthClients = parent
.command("oauth-clients")
.description("Manage OAuth clients");
// oauth-clients list
const list = oauthClients
.command("list")
.description("List all registered OAuth clients and their configurations")
.action(
withErrorHandler(async (_opts: unknown, cmd: Command) => {
const client = createClient(cmd);
const format = getFormat(cmd);
const response = await client.rawRequest("GET", "/admin/oauth-clients");
outputResponse(response, format);
}),
);
addExamples(list, [
{
description: "List all OAuth clients",
command: "geonic admin oauth-clients list",
},
{
description: "List OAuth clients in table format",
command: "geonic admin oauth-clients list --format table",
},
]);
// oauth-clients get
const get = oauthClients
.command("get <id>")
.description("Get an OAuth client's details — name, client ID, policy, and redirect URIs")
.action(
withErrorHandler(async (id: unknown, _opts: unknown, cmd: Command) => {
const client = createClient(cmd);
const format = getFormat(cmd);
const response = await client.rawRequest(
"GET",
`/admin/oauth-clients/${encodeURIComponent(String(id))}`,
);
outputResponse(response, format);
}),
);
addExamples(get, [
{
description: "Inspect an OAuth client's configuration",
command: "geonic admin oauth-clients get <client-id>",
},
]);
// oauth-clients create
const create = oauthClients
.command("create [json]")
.description(
"Create a new OAuth client\n\n" +
"JSON payload example:\n" +
" {\n" +
' "name": "my-app",\n' +
' "policyId": "<policy-id>"\n' +
" }",
)
.action(
withErrorHandler(async (json: unknown, _opts: unknown, cmd: Command) => {
const body = await parseJsonInput(json as string | undefined);
const client = createClient(cmd);
const format = getFormat(cmd);
const response = await client.rawRequest("POST", "/admin/oauth-clients", {
body,
});
outputResponse(response, format);
printSuccess("OAuth client created.");
}),
);
addExamples(create, [
{
description: "Create with inline JSON",
command: `geonic admin oauth-clients create '{"name":"my-app","policyId":"<policy-id>"}'`,
},
{
description: "Create from a JSON file",
command: "geonic admin oauth-clients create @client.json",
},
{
description: "Create from stdin pipe",
command: "cat client.json | geonic admin oauth-clients create",
},
]);
// oauth-clients update
const update = oauthClients
.command("update <id> [json]")
.description(
"Update an OAuth client\n\n" +
"JSON payload: only specified fields are updated.\n" +
' e.g. {"description": "Updated client"}',
)
.action(
withErrorHandler(
async (id: unknown, json: unknown, _opts: unknown, cmd: Command) => {
const body = await parseJsonInput(json as string | undefined);
const client = createClient(cmd);
const format = getFormat(cmd);
const response = await client.rawRequest(
"PATCH",
`/admin/oauth-clients/${encodeURIComponent(String(id))}`,
{ body },
);
outputResponse(response, format);
printSuccess("OAuth client updated.");
},
),
);
addExamples(update, [
{
description: "Update description",
command: `geonic admin oauth-clients update <client-id> '{"description":"Updated client"}'`,
},
{
description: "Update from a JSON file",
command: "geonic admin oauth-clients update <client-id> @client.json",
},
{
description: "Update from stdin pipe",
command: "cat client.json | geonic admin oauth-clients update <client-id>",
},
]);
// oauth-clients delete
const del = oauthClients
.command("delete <id>")
.description("Delete an OAuth client. Existing tokens issued by this client will be invalidated")
.action(
withErrorHandler(async (id: unknown, _opts: unknown, cmd: Command) => {
const client = createClient(cmd);
await client.rawRequest(
"DELETE",
`/admin/oauth-clients/${encodeURIComponent(String(id))}`,
);
printSuccess("OAuth client deleted.");
}),
);
addExamples(del, [
{
description: "Delete an OAuth client by ID",
command: "geonic admin oauth-clients delete <client-id>",
},
]);
}
export function registerCaddeCommand(parent: Command): void {
const cadde = parent
.command("cadde")
.description("Manage CADDE (data exchange) configuration for cross-platform data sharing");
// cadde get
const caddeGet = cadde
.command("get")
.description("Get the current CADDE data exchange configuration (provider, endpoint, etc.)")
.action(
withErrorHandler(async (_opts: unknown, cmd: Command) => {
const client = createClient(cmd);
const format = getFormat(cmd);
const response = await client.rawRequest("GET", "/admin/cadde");
outputResponse(response, format);
}),
);
addExamples(caddeGet, [
{
description: "View current CADDE configuration",
command: "geonic admin cadde get",
},
{
description: "View CADDE configuration in table format",
command: "geonic admin cadde get --format table",
},
]);
// cadde set
const caddeSet = cadde
.command("set [json]")
.description(
"Set CADDE configuration\n\n" +
"JSON payload example:\n" +
" {\n" +
' "provider": "my-provider",\n' +
' "endpoint": "http://localhost:6000"\n' +
" }",
)
.action(
withErrorHandler(async (json: unknown, _opts: unknown, cmd: Command) => {
const body = await parseJsonInput(json as string | undefined);
const client = createClient(cmd);
const format = getFormat(cmd);
const response = await client.rawRequest("PUT", "/admin/cadde", {
body,
});
outputResponse(response, format);
printSuccess("CADDE configuration set.");
}),
);
addExamples(caddeSet, [
{
description: "Set with inline JSON",
command: `geonic admin cadde set '{"provider":"my-provider","endpoint":"http://localhost:6000"}'`,
},
{
description: "Set from a JSON file",
command: "geonic admin cadde set @cadde-config.json",
},
{
description: "Set from stdin pipe",
command: "cat cadde-config.json | geonic admin cadde set",
},
]);
// cadde delete
const caddeDelete = cadde
.command("delete")
.description("Remove the CADDE data exchange configuration, disabling cross-platform data sharing")
.action(
withErrorHandler(async (_opts: unknown, cmd: Command) => {
const client = createClient(cmd);
await client.rawRequest("DELETE", "/admin/cadde");
printSuccess("CADDE configuration deleted.");
}),
);
addExamples(caddeDelete, [
{
description: "Remove CADDE configuration",
command: "geonic admin cadde delete",
},
]);
}