|
| 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