gigadrive 2.12.0 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +169 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +169 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -32,7 +32,7 @@ var import_effect31 = require("effect");
|
|
|
32
32
|
// package.json
|
|
33
33
|
var package_default = {
|
|
34
34
|
name: "gigadrive",
|
|
35
|
-
version: "2.
|
|
35
|
+
version: "2.14.0",
|
|
36
36
|
repository: {
|
|
37
37
|
type: "git",
|
|
38
38
|
url: "https://github.com/Gigadrive/sdk.git",
|
|
@@ -3099,6 +3099,26 @@ var formatImageTable = (images) => formatTable([
|
|
|
3099
3099
|
["NAME", "STATUS", "SOURCE", "ID"],
|
|
3100
3100
|
...images.map((image) => [image.name, image.status, imageSource(image), image.id])
|
|
3101
3101
|
]);
|
|
3102
|
+
var formatWebhookTable = (webhooks) => formatTable([
|
|
3103
|
+
["URL", "EVENTS", "STATUS", "ID"],
|
|
3104
|
+
...webhooks.map((webhook) => [
|
|
3105
|
+
webhook.url,
|
|
3106
|
+
webhook.events.join(","),
|
|
3107
|
+
webhook.enabled ? "enabled" : "disabled",
|
|
3108
|
+
webhook.id
|
|
3109
|
+
])
|
|
3110
|
+
]);
|
|
3111
|
+
var formatDeliveryTable = (deliveries) => formatTable([
|
|
3112
|
+
["CREATED", "EVENT", "STATUS", "ATTEMPTS", "RESPONSE", "MICROVM"],
|
|
3113
|
+
...deliveries.map((delivery) => [
|
|
3114
|
+
delivery.createdAt,
|
|
3115
|
+
delivery.eventType,
|
|
3116
|
+
delivery.status,
|
|
3117
|
+
String(delivery.attempts),
|
|
3118
|
+
delivery.lastStatusCode === null ? delivery.lastError ?? "-" : String(delivery.lastStatusCode),
|
|
3119
|
+
delivery.microvmId
|
|
3120
|
+
])
|
|
3121
|
+
]);
|
|
3102
3122
|
var formatBytes = (bytes) => {
|
|
3103
3123
|
if (bytes < 1024) return `${bytes} B`;
|
|
3104
3124
|
const units = ["KiB", "MiB", "GiB", "TiB"];
|
|
@@ -3518,6 +3538,36 @@ var getCommand = import_cli12.Command.make(
|
|
|
3518
3538
|
for (const line of describeMicroVm(vm)) yield* import_effect24.Console.log(line);
|
|
3519
3539
|
}).pipe(reportErrors2("get the microVM"))
|
|
3520
3540
|
).pipe(import_cli12.Command.withDescription("Show a microVM"));
|
|
3541
|
+
var formatGigabytes = (bytes) => `${(bytes / 1e9).toFixed(1)} GB`;
|
|
3542
|
+
var describeMicroVmMetrics = (metrics) => {
|
|
3543
|
+
const latest = metrics.cpu.at(-1);
|
|
3544
|
+
const peak = metrics.cpu.reduce((max, point) => Math.max(max, point.cpuPercent), 0);
|
|
3545
|
+
return [
|
|
3546
|
+
`CPU (last ${metrics.windowMinutes} min, ${metrics.vcpus} vCPU): ${latest ? `${latest.cpuPercent}% at ${latest.time}, peak ${peak}%` : "no samples"}`,
|
|
3547
|
+
metrics.current ? `Memory: ${formatGigabytes(metrics.current.memoryUsedBytes)} of ${formatGigabytes(metrics.current.memoryTotalBytes)}` : "Memory: unavailable (not running, or no answer)",
|
|
3548
|
+
metrics.current ? `Disk: ${formatGigabytes(metrics.current.diskUsedBytes)} of ${formatGigabytes(metrics.current.diskTotalBytes)}` : "Disk: unavailable (not running, or no answer)"
|
|
3549
|
+
];
|
|
3550
|
+
};
|
|
3551
|
+
var metricsCommand = import_cli12.Command.make(
|
|
3552
|
+
"metrics",
|
|
3553
|
+
{
|
|
3554
|
+
microvmId: microvmIdArg,
|
|
3555
|
+
window: import_cli12.Options.integer("window").pipe(
|
|
3556
|
+
import_cli12.Options.withDescription("Minutes of CPU history, 1 to 1440 (default: 15)"),
|
|
3557
|
+
import_cli12.Options.optional
|
|
3558
|
+
),
|
|
3559
|
+
json: jsonOption2
|
|
3560
|
+
},
|
|
3561
|
+
({ microvmId, window, json }) => import_effect24.Effect.gen(function* () {
|
|
3562
|
+
const apiClient = yield* ApiClientService;
|
|
3563
|
+
const windowMinutes = import_effect24.Option.getOrUndefined(window);
|
|
3564
|
+
const metrics = yield* apiClient.request(
|
|
3565
|
+
(client) => client.microvms.getMetrics(microvmId, windowMinutes === void 0 ? {} : { windowMinutes })
|
|
3566
|
+
);
|
|
3567
|
+
if (json) return yield* import_effect24.Console.log(JSON.stringify(metrics, null, 2));
|
|
3568
|
+
for (const line of describeMicroVmMetrics(metrics)) yield* import_effect24.Console.log(line);
|
|
3569
|
+
}).pipe(reportErrors2("read the microVM metrics"))
|
|
3570
|
+
).pipe(import_cli12.Command.withDescription("Show a microVM's CPU, memory and disk use"));
|
|
3521
3571
|
var execInMicroVm = (flags, io = nodeSessionIo()) => import_effect24.Effect.gen(function* () {
|
|
3522
3572
|
const env = yield* keyValues("--env", flags.env);
|
|
3523
3573
|
const timeout = yield* optionalDuration("--timeout", flags.timeout);
|
|
@@ -3915,10 +3965,126 @@ var imagesCommand = import_cli12.Command.make("images", {}, () => import_effect2
|
|
|
3915
3965
|
import_cli12.Command.withDescription("Built-in and custom microVM images"),
|
|
3916
3966
|
import_cli12.Command.withSubcommands([imagesListCommand, imagesCreateCommand, imagesRemoveCommand])
|
|
3917
3967
|
);
|
|
3968
|
+
var WEBHOOK_EVENTS = [
|
|
3969
|
+
"microvm.created",
|
|
3970
|
+
"microvm.running",
|
|
3971
|
+
"microvm.paused",
|
|
3972
|
+
"microvm.stopped",
|
|
3973
|
+
"microvm.failed"
|
|
3974
|
+
];
|
|
3975
|
+
var webhookIdArg = import_cli12.Args.text({ name: "webhook-id" }).pipe(import_cli12.Args.withDescription("The webhook ID"));
|
|
3976
|
+
var webhooksListCommand = import_cli12.Command.make(
|
|
3977
|
+
"ls",
|
|
3978
|
+
{ app: appOption6, json: jsonOption2 },
|
|
3979
|
+
({ app, json }) => import_effect24.Effect.gen(function* () {
|
|
3980
|
+
const apiClient = yield* ApiClientService;
|
|
3981
|
+
const applicationId = yield* resolveApplicationId(app);
|
|
3982
|
+
const webhooks = yield* apiClient.request((client) => client.microvms.webhooks.list({ applicationId }));
|
|
3983
|
+
if (json) return yield* import_effect24.Console.log(JSON.stringify(webhooks, null, 2));
|
|
3984
|
+
if (webhooks.length === 0)
|
|
3985
|
+
return yield* import_effect24.Console.log('No webhooks yet. Add one with "gigadrive microvms webhooks add".');
|
|
3986
|
+
for (const line of formatWebhookTable(webhooks)) yield* import_effect24.Console.log(line);
|
|
3987
|
+
}).pipe(reportErrors2("list webhooks"))
|
|
3988
|
+
).pipe(import_cli12.Command.withDescription("List the application's microVM webhooks"));
|
|
3989
|
+
var addWebhook = (flags) => import_effect24.Effect.gen(function* () {
|
|
3990
|
+
const apiClient = yield* ApiClientService;
|
|
3991
|
+
const unknown = flags.events.find((event) => !WEBHOOK_EVENTS.includes(event));
|
|
3992
|
+
if (unknown !== void 0) {
|
|
3993
|
+
return yield* new InvalidMicroVmOptionsError({
|
|
3994
|
+
message: `${unknown} is not a microVM event. Use ${WEBHOOK_EVENTS.join(", ")}.`
|
|
3995
|
+
});
|
|
3996
|
+
}
|
|
3997
|
+
const events = flags.events.length > 0 ? [...new Set(flags.events)] : WEBHOOK_EVENTS;
|
|
3998
|
+
const applicationId = yield* resolveApplicationId(flags.app);
|
|
3999
|
+
const webhook = yield* apiClient.request(
|
|
4000
|
+
(client) => client.microvms.webhooks.create({
|
|
4001
|
+
url: flags.url,
|
|
4002
|
+
events,
|
|
4003
|
+
...import_effect24.Option.isSome(flags.description) ? { description: flags.description.value } : {},
|
|
4004
|
+
...applicationId ? { applicationId } : {}
|
|
4005
|
+
})
|
|
4006
|
+
);
|
|
4007
|
+
if (flags.json) {
|
|
4008
|
+
yield* import_effect24.Console.log(JSON.stringify(webhook, null, 2));
|
|
4009
|
+
} else {
|
|
4010
|
+
yield* import_effect24.Console.log(`Added webhook ${webhook.id} for ${webhook.events.join(", ")}.`);
|
|
4011
|
+
yield* import_effect24.Console.log(`Signing secret (shown only now): ${webhook.secret}`);
|
|
4012
|
+
}
|
|
4013
|
+
return webhook;
|
|
4014
|
+
});
|
|
4015
|
+
var webhooksAddCommand = import_cli12.Command.make(
|
|
4016
|
+
"add",
|
|
4017
|
+
{
|
|
4018
|
+
url: import_cli12.Args.text({ name: "url" }).pipe(import_cli12.Args.withDescription("HTTPS URL on a public host")),
|
|
4019
|
+
events: import_cli12.Options.text("event").pipe(
|
|
4020
|
+
import_cli12.Options.withDescription(`Event to send (repeatable; default: all of ${WEBHOOK_EVENTS.join(", ")})`),
|
|
4021
|
+
import_cli12.Options.repeated
|
|
4022
|
+
),
|
|
4023
|
+
description: import_cli12.Options.text("description").pipe(import_cli12.Options.withDescription("A note for yourself"), import_cli12.Options.optional),
|
|
4024
|
+
app: appOption6,
|
|
4025
|
+
json: jsonOption2
|
|
4026
|
+
},
|
|
4027
|
+
(flags) => addWebhook(flags).pipe(import_effect24.Effect.asVoid, reportErrors2("add the webhook"))
|
|
4028
|
+
).pipe(import_cli12.Command.withDescription("Add an endpoint for microVM lifecycle events and print its signing secret"));
|
|
4029
|
+
var webhooksEnableCommand = (enabled) => import_cli12.Command.make(
|
|
4030
|
+
enabled ? "enable" : "disable",
|
|
4031
|
+
{ webhookId: webhookIdArg },
|
|
4032
|
+
({ webhookId }) => import_effect24.Effect.gen(function* () {
|
|
4033
|
+
const apiClient = yield* ApiClientService;
|
|
4034
|
+
const webhook = yield* apiClient.request((client) => client.microvms.webhooks.update(webhookId, { enabled }));
|
|
4035
|
+
yield* import_effect24.Console.log(`${webhook.url} is ${webhook.enabled ? "enabled" : "disabled"}.`);
|
|
4036
|
+
}).pipe(reportErrors2(enabled ? "enable the webhook" : "disable the webhook"))
|
|
4037
|
+
).pipe(
|
|
4038
|
+
import_cli12.Command.withDescription(
|
|
4039
|
+
enabled ? "Send events to a webhook again" : "Stop sending events to a webhook; waiting retries are held"
|
|
4040
|
+
)
|
|
4041
|
+
);
|
|
4042
|
+
var webhooksSecretCommand = import_cli12.Command.make(
|
|
4043
|
+
"rotate-secret",
|
|
4044
|
+
{ webhookId: webhookIdArg },
|
|
4045
|
+
({ webhookId }) => import_effect24.Effect.gen(function* () {
|
|
4046
|
+
const apiClient = yield* ApiClientService;
|
|
4047
|
+
const webhook = yield* apiClient.request((client) => client.microvms.webhooks.rotateSecret(webhookId));
|
|
4048
|
+
yield* import_effect24.Console.log(`New signing secret (shown only now): ${webhook.secret}`);
|
|
4049
|
+
}).pipe(reportErrors2("replace the signing secret"))
|
|
4050
|
+
).pipe(import_cli12.Command.withDescription("Replace the signing secret; the old one stops signing at once"));
|
|
4051
|
+
var webhooksDeliveriesCommand = import_cli12.Command.make(
|
|
4052
|
+
"deliveries",
|
|
4053
|
+
{ webhookId: webhookIdArg, json: jsonOption2 },
|
|
4054
|
+
({ webhookId, json }) => import_effect24.Effect.gen(function* () {
|
|
4055
|
+
const apiClient = yield* ApiClientService;
|
|
4056
|
+
const deliveries = yield* apiClient.request((client) => client.microvms.webhooks.listDeliveries(webhookId));
|
|
4057
|
+
if (json) return yield* import_effect24.Console.log(JSON.stringify(deliveries, null, 2));
|
|
4058
|
+
if (deliveries.length === 0) return yield* import_effect24.Console.log("Nothing has been sent yet.");
|
|
4059
|
+
for (const line of formatDeliveryTable(deliveries)) yield* import_effect24.Console.log(line);
|
|
4060
|
+
}).pipe(reportErrors2("list the deliveries"))
|
|
4061
|
+
).pipe(import_cli12.Command.withDescription("Show a webhook's 50 most recent deliveries"));
|
|
4062
|
+
var webhooksRemoveCommand = import_cli12.Command.make(
|
|
4063
|
+
"rm",
|
|
4064
|
+
{ webhookId: webhookIdArg },
|
|
4065
|
+
({ webhookId }) => import_effect24.Effect.gen(function* () {
|
|
4066
|
+
const apiClient = yield* ApiClientService;
|
|
4067
|
+
yield* apiClient.request((client) => client.microvms.webhooks.delete(webhookId));
|
|
4068
|
+
yield* import_effect24.Console.log(`Deleted webhook ${webhookId}.`);
|
|
4069
|
+
}).pipe(reportErrors2("delete the webhook"))
|
|
4070
|
+
).pipe(import_cli12.Command.withDescription("Delete a webhook"));
|
|
4071
|
+
var webhooksCommand = import_cli12.Command.make("webhooks", {}, () => import_effect24.Effect.void).pipe(
|
|
4072
|
+
import_cli12.Command.withDescription("Signed HTTPS requests when a microVM is created, starts, pauses, stops or fails"),
|
|
4073
|
+
import_cli12.Command.withSubcommands([
|
|
4074
|
+
webhooksListCommand,
|
|
4075
|
+
webhooksAddCommand,
|
|
4076
|
+
webhooksEnableCommand(true),
|
|
4077
|
+
webhooksEnableCommand(false),
|
|
4078
|
+
webhooksSecretCommand,
|
|
4079
|
+
webhooksDeliveriesCommand,
|
|
4080
|
+
webhooksRemoveCommand
|
|
4081
|
+
])
|
|
4082
|
+
);
|
|
3918
4083
|
var SUBCOMMANDS = [
|
|
3919
4084
|
createCommand,
|
|
3920
4085
|
listCommand2,
|
|
3921
4086
|
getCommand,
|
|
4087
|
+
metricsCommand,
|
|
3922
4088
|
execCommand,
|
|
3923
4089
|
shellCommand,
|
|
3924
4090
|
copyCommand,
|
|
@@ -3926,7 +4092,8 @@ var SUBCOMMANDS = [
|
|
|
3926
4092
|
removeCommand2,
|
|
3927
4093
|
extendCommand,
|
|
3928
4094
|
networkCommand,
|
|
3929
|
-
imagesCommand
|
|
4095
|
+
imagesCommand,
|
|
4096
|
+
webhooksCommand
|
|
3930
4097
|
];
|
|
3931
4098
|
var microvmsCommand = import_cli12.Command.make("microvms", {}, () => import_effect24.Effect.void).pipe(
|
|
3932
4099
|
import_cli12.Command.withDescription("Isolated Linux machines for running code: create, exec, shell, cp, stop"),
|