diff --git a/test/test.ts b/test/test.ts index 325dbf7..9bc9b72 100644 --- a/test/test.ts +++ b/test/test.ts @@ -6,7 +6,9 @@ const testQenv = new qenv.Qenv('./', './.nogit/'); let testAccount: hetznercloud.HetznerAccount; tap.test('should create a valid hetzer account', async () => { - testAccount = new hetznercloud.HetznerAccount(await testQenv.getEnvVarOnDemand('HETZNER_API_TOKEN')); + testAccount = new hetznercloud.HetznerAccount( + await testQenv.getEnvVarOnDemand('HETZNER_API_TOKEN') + ); expect(testAccount).toBeInstanceOf(hetznercloud.HetznerAccount); }); @@ -14,16 +16,27 @@ tap.test('should be able to list all servers', async () => { const servers = await testAccount.getServers(); expect(servers).toBeArray(); console.log(JSON.stringify(servers, null, 2)); -}) +}); -tap.test('should be able to create a server', async () => { +const testserver = tap.test('should be able to create a server', async (toolsArg) => { const newServer = await testAccount.createServer({ name: 'testserver', location: 'nbg1', - labels: {}, + type: 'cpx41', + labels: { + servezoneId: 'testzone', + }, }); expect(newServer).toBeInstanceOf(hetznercloud.HetznerServer); console.log(newServer); -}) + await toolsArg.delayFor(10000); + return newServer; +}); -tap.start() +tap.test('should be able to delete a server', async () => { + const testServer: hetznercloud.HetznerServer = + await (testserver.testResultPromise as Promise); + // await testServer.delete(); +}); + +tap.start(); diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index a085e80..c37369b 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@apiclient.xyz/hetznercloud', - version: '1.0.11', + version: '1.0.12', description: 'an unofficial api client for the hetzner cloud api' } diff --git a/ts/classes.account.ts b/ts/classes.account.ts index a410066..711793c 100644 --- a/ts/classes.account.ts +++ b/ts/classes.account.ts @@ -32,6 +32,7 @@ export class HetznerAccount { Authorization: `Bearer ${this.token}`, }, requestBody: payloadArg, + keepAlive: false, }); console.log(response.statusCode); console.log(response.body); diff --git a/ts/classes.firewall.ts b/ts/classes.firewall.ts new file mode 100644 index 0000000..e69de29 diff --git a/ts/classes.server.ts b/ts/classes.server.ts index f7f2181..00627ec 100644 --- a/ts/classes.server.ts +++ b/ts/classes.server.ts @@ -8,7 +8,8 @@ export class HetznerServer { hetznerAccountRefArg: HetznerAccount, optionsArg: { name: string; - location: 'nbg1'; + type: types.THetznerCloudServerName; + location: types.THetznerCloudLocationName; labels: {[key: string]: string}, } ) { @@ -18,7 +19,7 @@ export class HetznerServer { const createServerPayload: types.TServerCreateRequestBody = { name: optionsArg.name, image: 'ubuntu-22.04', - server_type: 'cx11', + server_type: optionsArg.type, start_after_create: true, labels: optionsArg.labels || {} as any, location: optionsArg.location, diff --git a/ts/types.ts b/ts/types.ts index 564d180..4712391 100644 --- a/ts/types.ts +++ b/ts/types.ts @@ -10,3 +10,33 @@ export type TServersGetResponseBody = plugins.hetznerOpenapi.paths['/servers'][' export type TServerCreateRequestBody = plugins.hetznerOpenapi.paths['/servers']['post']['requestBody']['content']['application/json']; export type TServerCreateResponseBody = plugins.hetznerOpenapi.paths['/servers']['post']['responses']['201']['content']['application/json']; +// server types +export type THetznerCloudServerName = + | 'cx11' + | 'cx21' + | 'cx31' + | 'cx41' + | 'cx51' + | 'ccx11' + | 'ccx21' + | 'ccx31' + | 'ccx41' + | 'ccx51' + | 'ccx13' + | 'ccx23' + | 'ccx33' + | 'ccx43' + | 'ccx53' + | 'ccx63' + | 'cpx11' + | 'cpx21' + | 'cpx31' + | 'cpx41' + | 'cpx51' + | 'cpx61' + | 'cpx70' + | 'cpx71' + | 'cpx90'; + +// location types +export type THetznerCloudLocationName = 'fsn1' | 'nbg1' | 'hel1' | 'ash' | 'hil'; \ No newline at end of file