2024-01-29 20:14:05 +00:00
|
|
|
import { HetznerServer } from './classes.server.js';
|
2024-01-29 20:08:05 +00:00
|
|
|
import * as plugins from './hetznercloud.plugins.js';
|
|
|
|
|
|
|
|
export class HetznerAccount {
|
|
|
|
public token: string;
|
|
|
|
constructor(tokenArg: string) {
|
|
|
|
this.token = tokenArg;
|
|
|
|
}
|
|
|
|
|
2024-01-29 20:14:05 +00:00
|
|
|
public async getServers() {
|
|
|
|
return HetznerServer.getServers(this);
|
2024-01-29 20:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|