Skip to content

Commit 44a3faa

Browse files
committed
added ssh keys
1 parent 3709fc5 commit 44a3faa

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

.changeset/swift-eagles-try.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cloudways-js-client": patch
3+
---
4+
5+
added ssh key services

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export * from "./services/projects";
55
export * from "./services/operation";
66
export * from "./services/application";
77
export * from "./services/server";
8+
export * from "./services/ssh-keys";
89

910
// export all the types
1011
export * from "./services/Lists/types";

src/services/ssh-keys/index.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { apiCall } from "../core";
2+
import { HttpMethod } from "../core/types";
3+
4+
/**
5+
* Create an SSH key for a server.
6+
* @param {number} serverId Numeric id of the server.
7+
* @param {string} sshKeyName Label for the SSH key.
8+
* @param {string} sshKey The SSH key.
9+
* @param {number} appCredsId Numeric id of the App Credentials (required for app level SSH keys).
10+
* @returns {Promise<number>} A promise resolving with the id of the created SSH key.
11+
* @example
12+
* ```
13+
* 1234
14+
* ```
15+
*/
16+
export function createSSHKey(
17+
serverId: number,
18+
sshKeyName: string,
19+
sshKey: string,
20+
appCredsId: number
21+
): Promise<number> {
22+
const data = {
23+
server_id: serverId,
24+
ssh_key_name: sshKeyName,
25+
ssh_key: sshKey,
26+
app_creds_id: appCredsId,
27+
};
28+
return apiCall("/ssh_key", HttpMethod.POST, data).then(
29+
(response) => response.id
30+
);
31+
}
32+
33+
/**
34+
* Delete an SSH key from a server.
35+
* @param {number} serverId Numeric id of the server.
36+
* @param {number} sshKeyId Numeric id of the SSH key to delete.
37+
* @returns {Promise<void>} A promise resolving when the SSH key is successfully deleted.
38+
*/
39+
export function deleteSSHKey(
40+
serverId: number,
41+
sshKeyId: number
42+
): Promise<void> {
43+
const endpoint = `/ssh_key/${sshKeyId}`;
44+
const data = { server_id: serverId };
45+
return apiCall(endpoint, HttpMethod.DELETE, data);
46+
}
47+
48+
/**
49+
* Update an SSH key on a server.
50+
* @param {number} serverId Numeric id of the server.
51+
* @param {number} sshKeyId Numeric id of the SSH key to update.
52+
* @param {string} sshKeyName New label for the SSH key.
53+
* @returns {Promise<void>} A promise resolving when the SSH key is successfully updated.
54+
*/
55+
export function updateSSHKey(
56+
serverId: number,
57+
sshKeyId: number,
58+
sshKeyName: string
59+
): Promise<void> {
60+
const endpoint = `/ssh_key/${sshKeyId}`;
61+
const data = {
62+
server_id: serverId,
63+
ssh_key_name: sshKeyName,
64+
};
65+
return apiCall(endpoint, HttpMethod.PUT, data);
66+
}

0 commit comments

Comments
 (0)