fix(core): update
This commit is contained in:
30
ts/classes.account.ts
Normal file
30
ts/classes.account.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import * as plugins from './hetznercloud.plugins.js';
|
||||
|
||||
export class HetznerAccount {
|
||||
public token: string;
|
||||
constructor(tokenArg: string) {
|
||||
this.token = tokenArg;
|
||||
}
|
||||
|
||||
getServers() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* request things from the hetzner API
|
||||
* @param methodArg
|
||||
* @param pathArg
|
||||
* @param payloadArg
|
||||
*/
|
||||
public request = async (methodArg: string, pathArg: string, payloadArg: any) => {
|
||||
const url = `https://api.hetzner.cloud/v1${pathArg}`;
|
||||
const response = await plugins.smartrequest.request(url, {
|
||||
method: methodArg,
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.token}`,
|
||||
},
|
||||
requestBody: payloadArg,
|
||||
});
|
||||
return response;
|
||||
}
|
||||
}
|
40
ts/classes.server.ts
Normal file
40
ts/classes.server.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import type { HetznerAccount } from './classes.account.js';
|
||||
import * as plugins from './hetznercloud.plugins.js';
|
||||
import * as types from './types.js';
|
||||
|
||||
export class HetznerServer {
|
||||
// STATIC
|
||||
static async create(hetznerAccountRefArg: HetznerAccount, optionsArg: {
|
||||
name: string,
|
||||
datacenter: 'nbg1-dc3',
|
||||
}) {
|
||||
const server = new HetznerServer(hetznerAccountRefArg);
|
||||
|
||||
const createServerUrl = '/servers';
|
||||
const createServerPayload: types.TServerCreateRequestBody =
|
||||
{
|
||||
name: optionsArg.name,
|
||||
datacenter: optionsArg.datacenter,
|
||||
image: '',
|
||||
server_type: '',
|
||||
start_after_create: true,
|
||||
user_data: '',
|
||||
};
|
||||
|
||||
const response = await server.hetznerAccountRef.request('POST', createServerUrl, createServerPayload);
|
||||
server.data = (response.body as types.TServerCreateResponseBody).server;
|
||||
return server;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
public hetznerAccountRef: HetznerAccount;
|
||||
public data: types.IServer;
|
||||
|
||||
constructor(hetznerAccountRefArg: HetznerAccount) {
|
||||
this.hetznerAccountRef = hetznerAccountRefArg;
|
||||
}
|
||||
|
||||
public async delete() {
|
||||
await this.hetznerAccountRef.request('DELETE', `/servers/${this.data.id}`, {});
|
||||
}
|
||||
}
|
@ -1,4 +1,12 @@
|
||||
const removeme = {};
|
||||
import * as hetznerOpenapi from '@tempfix/hetzner-openapi';
|
||||
|
||||
export {
|
||||
removeme
|
||||
hetznerOpenapi
|
||||
}
|
||||
|
||||
// @push.rocks
|
||||
import * as smartrequest from '@push.rocks/smartrequest';
|
||||
|
||||
export {
|
||||
smartrequest,
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
import * as plugins from './hetznercloud.plugins.js';
|
||||
|
||||
export let demoExport = 'Hi there! :) This is an exported string';
|
||||
|
12
ts/types.ts
Normal file
12
ts/types.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import * as plugins from './hetznercloud.plugins.js';
|
||||
|
||||
// datacenters
|
||||
export type TDatacenters = plugins.hetznerOpenapi.paths['/datacenters']['get']['responses']['200']['content']['application/json'];
|
||||
|
||||
// servers
|
||||
export type IServer = plugins.hetznerOpenapi.paths['/servers/{id}']['get']['responses']['200']['content']['application/json']['server'];
|
||||
export type TServersGetRequestBody = {};
|
||||
export type TServersGetResponseBody = plugins.hetznerOpenapi.paths['/servers']['get']['responses']['200']['content']['application/json'];
|
||||
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'];
|
||||
|
Reference in New Issue
Block a user