Skip to content

Commit 7d64982

Browse files
committed
fix: parameters
1 parent b91a456 commit 7d64982

File tree

8 files changed

+87
-88
lines changed

8 files changed

+87
-88
lines changed

src/common/atlas/apiClient.ts

Lines changed: 22 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import config from "../../config.js";
2-
import createClient, { Middleware } from "openapi-fetch";
2+
import createClient, { FetchOptions, Middleware } from "openapi-fetch";
33

4-
import { paths, ClusterDescription20240805, NetworkPermissionEntry, CloudDatabaseUser } from "./openapi.js";
4+
import { paths, operations } from "./openapi.js";
55

66
export interface OAuthToken {
77
access_token: string;
@@ -238,105 +238,53 @@ export class ApiClient {
238238
}
239239
}
240240

241-
async listProjects() {
242-
const { data } = await this.client.GET(`/api/atlas/v2/groups`);
241+
async listProjects(options?: FetchOptions<operations["listProjects"]>) {
242+
const { data } = await this.client.GET(`/api/atlas/v2/groups`, options);
243243
return data;
244244
}
245245

246-
async listProjectIpAccessLists(groupId: string) {
247-
const { data } = await this.client.GET(`/api/atlas/v2/groups/{groupId}/accessList`, {
248-
params: {
249-
path: {
250-
groupId,
251-
},
252-
},
253-
});
246+
async listProjectIpAccessLists(options: FetchOptions<operations["listProjectIpAccessLists"]>) {
247+
const { data } = await this.client.GET(`/api/atlas/v2/groups/{groupId}/accessList`, options);
254248
return data;
255249
}
256250

257-
async createProjectIpAccessList(groupId: string, ...entries: NetworkPermissionEntry[]) {
258-
const { data } = await this.client.POST(`/api/atlas/v2/groups/{groupId}/accessList`, {
259-
params: {
260-
path: {
261-
groupId,
262-
},
263-
},
264-
body: entries,
265-
});
251+
async createProjectIpAccessList(options: FetchOptions<operations["createProjectIpAccessList"]>) {
252+
const { data } = await this.client.POST(`/api/atlas/v2/groups/{groupId}/accessList`, options);
266253
return data;
267254
}
268255

269-
async getProject(groupId: string) {
270-
const { data } = await this.client.GET(`/api/atlas/v2/groups/{groupId}`, {
271-
params: {
272-
path: {
273-
groupId,
274-
},
275-
},
276-
});
256+
async getProject(options: FetchOptions<operations["getProject"]>) {
257+
const { data } = await this.client.GET(`/api/atlas/v2/groups/{groupId}`, options);
277258
return data;
278259
}
279260

280-
async listClusters(groupId: string) {
281-
const { data } = await this.client.GET(`/api/atlas/v2/groups/{groupId}/clusters`, {
282-
params: {
283-
path: {
284-
groupId,
285-
},
286-
},
287-
});
261+
async listClusters(options: FetchOptions<operations["listClusters"]>) {
262+
const { data } = await this.client.GET(`/api/atlas/v2/groups/{groupId}/clusters`, options);
288263
return data;
289264
}
290265

291-
async listClustersForAllProjects() {
292-
const { data } = await this.client.GET(`/api/atlas/v2/clusters`);
266+
async listClustersForAllProjects(options?: FetchOptions<operations["listClustersForAllProjects"]>) {
267+
const { data } = await this.client.GET(`/api/atlas/v2/clusters`, options);
293268
return data;
294269
}
295270

296-
async getCluster(groupId: string, clusterName: string) {
297-
const { data } = await this.client.GET(`/api/atlas/v2/groups/{groupId}/clusters/{clusterName}`, {
298-
params: {
299-
path: {
300-
groupId,
301-
clusterName,
302-
},
303-
},
304-
});
271+
async getCluster(options: FetchOptions<operations["getCluster"]>) {
272+
const { data } = await this.client.GET(`/api/atlas/v2/groups/{groupId}/clusters/{clusterName}`, options);
305273
return data;
306274
}
307275

308-
async createCluster(groupId: string, cluster: ClusterDescription20240805) {
309-
const { data } = await this.client.POST("/api/atlas/v2/groups/{groupId}/clusters", {
310-
params: {
311-
path: {
312-
groupId,
313-
},
314-
},
315-
body: cluster,
316-
});
276+
async createCluster(options: FetchOptions<operations["createCluster"]>) {
277+
const { data } = await this.client.POST("/api/atlas/v2/groups/{groupId}/clusters", options);
317278
return data;
318279
}
319280

320-
async createDatabaseUser(groupId: string, user: CloudDatabaseUser) {
321-
const { data } = await this.client.POST("/api/atlas/v2/groups/{groupId}/databaseUsers", {
322-
params: {
323-
path: {
324-
groupId,
325-
},
326-
},
327-
body: user,
328-
});
281+
async createDatabaseUser(options: FetchOptions<operations["createDatabaseUser"]>) {
282+
const { data } = await this.client.POST("/api/atlas/v2/groups/{groupId}/databaseUsers", options);
329283
return data;
330284
}
331285

332-
async listDatabaseUsers(groupId: string) {
333-
const { data } = await this.client.GET(`/api/atlas/v2/groups/{groupId}/databaseUsers`, {
334-
params: {
335-
path: {
336-
groupId,
337-
},
338-
},
339-
});
286+
async listDatabaseUsers(options: FetchOptions<operations["listDatabaseUsers"]>) {
287+
const { data } = await this.client.GET(`/api/atlas/v2/groups/{groupId}/databaseUsers`, options);
340288
return data;
341289
}
342290
}

src/tools/atlas/createAccessList.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ export class CreateAccessListTool extends AtlasToolBase {
4444

4545
const inputs = [...ipInputs, ...cidrInputs];
4646

47-
await this.apiClient.createProjectIpAccessList(projectId, ...inputs);
47+
await this.apiClient.createProjectIpAccessList({
48+
params: {
49+
path: {
50+
groupId: projectId,
51+
},
52+
},
53+
body: inputs,
54+
});
4855

4956
return {
5057
content: [

src/tools/atlas/createDBUser.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ export class CreateDBUserTool extends AtlasToolBase {
5353
: undefined,
5454
} as CloudDatabaseUser;
5555

56-
await this.apiClient!.createDatabaseUser(projectId, input);
56+
await this.apiClient!.createDatabaseUser({
57+
params: {
58+
path: {
59+
groupId: projectId,
60+
},
61+
},
62+
body: input
63+
});
5764

5865
return {
5966
content: [{ type: "text", text: `User "${username}" created sucessfully.` }],

src/tools/atlas/createFreeCluster.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ export class CreateFreeClusterTool extends AtlasToolBase {
3838
terminationProtectionEnabled: false,
3939
} as unknown as ClusterDescription20240805;
4040

41-
await this.apiClient.createCluster(projectId, input);
41+
await this.apiClient.createCluster({
42+
params: {
43+
path: {
44+
groupId: projectId,
45+
},
46+
},
47+
body: input,
48+
});
4249

4350
return {
4451
content: [{ type: "text", text: `Cluster "${name}" has been created in region "${region}".` }],

src/tools/atlas/inspectAccessList.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ export class InspectAccessListTool extends AtlasToolBase {
1313
protected async execute({ projectId }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
1414
await this.ensureAuthenticated();
1515

16-
const accessList = await this.apiClient.listProjectIpAccessLists(projectId);
16+
const accessList = await this.apiClient.listProjectIpAccessLists({
17+
params: {
18+
path: {
19+
groupId: projectId,
20+
},
21+
},
22+
});
1723

1824
if (!accessList?.results?.length) {
1925
throw new Error("No access list entries found.");
@@ -26,12 +32,11 @@ export class InspectAccessListTool extends AtlasToolBase {
2632
text:
2733
`IP ADDRESS | CIDR | COMMENT
2834
------|------|------
29-
` +
30-
(accessList.results || [])
31-
.map((entry) => {
32-
return `${entry.ipAddress} | ${entry.cidrBlock} | ${entry.comment}`;
33-
})
34-
.join("\n"),
35+
${(accessList.results || [])
36+
.map((entry) => {
37+
return `${entry.ipAddress} | ${entry.cidrBlock} | ${entry.comment}`;
38+
})
39+
.join("\n")}`,
3540
},
3641
],
3742
};

src/tools/atlas/inspectCluster.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ export class InspectClusterTool extends AtlasToolBase {
1515
protected async execute({ projectId, clusterName }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
1616
await this.ensureAuthenticated();
1717

18-
const cluster = await this.apiClient.getCluster(projectId, clusterName);
18+
const cluster = await this.apiClient.getCluster({
19+
params: {
20+
path: {
21+
groupId: projectId,
22+
clusterName,
23+
},
24+
},
25+
});
1926

2027
return this.formatOutput(cluster);
2128
}

src/tools/atlas/listClusters.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,25 @@ export class ListClustersTool extends AtlasToolBase {
1919

2020
return this.formatAllClustersTable(data);
2121
} else {
22-
const project = await this.apiClient.getProject(projectId);
22+
const project = await this.apiClient.getProject({
23+
params: {
24+
path: {
25+
groupId: projectId,
26+
},
27+
},
28+
});
2329

2430
if (!project?.id) {
2531
throw new Error(`Project with ID "${projectId}" not found.`);
2632
}
2733

28-
const data = await this.apiClient.listClusters(project.id || "");
34+
const data = await this.apiClient.listClusters({
35+
params: {
36+
path: {
37+
groupId: project.id || "",
38+
},
39+
},
40+
});
2941

3042
return this.formatClustersTable(project, data);
3143
}

src/tools/atlas/listDBUsers.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ export class ListDBUsersTool extends AtlasToolBase {
1414
protected async execute({ projectId }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
1515
await this.ensureAuthenticated();
1616

17-
const data = await this.apiClient!.listDatabaseUsers(projectId);
17+
const data = await this.apiClient!.listDatabaseUsers({
18+
params: {
19+
path: {
20+
groupId: projectId,
21+
},
22+
},
23+
});
1824

1925
if (!data?.results?.length) {
2026
throw new Error("No database users found.");

0 commit comments

Comments
 (0)