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.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { Effect as Effect29, Layer, LogLevel, Logger } from "effect";
|
|
|
9
9
|
// package.json
|
|
10
10
|
var package_default = {
|
|
11
11
|
name: "gigadrive",
|
|
12
|
-
version: "2.
|
|
12
|
+
version: "2.14.0",
|
|
13
13
|
repository: {
|
|
14
14
|
type: "git",
|
|
15
15
|
url: "https://github.com/Gigadrive/sdk.git",
|
|
@@ -3089,6 +3089,26 @@ var formatImageTable = (images) => formatTable([
|
|
|
3089
3089
|
["NAME", "STATUS", "SOURCE", "ID"],
|
|
3090
3090
|
...images.map((image) => [image.name, image.status, imageSource(image), image.id])
|
|
3091
3091
|
]);
|
|
3092
|
+
var formatWebhookTable = (webhooks) => formatTable([
|
|
3093
|
+
["URL", "EVENTS", "STATUS", "ID"],
|
|
3094
|
+
...webhooks.map((webhook) => [
|
|
3095
|
+
webhook.url,
|
|
3096
|
+
webhook.events.join(","),
|
|
3097
|
+
webhook.enabled ? "enabled" : "disabled",
|
|
3098
|
+
webhook.id
|
|
3099
|
+
])
|
|
3100
|
+
]);
|
|
3101
|
+
var formatDeliveryTable = (deliveries) => formatTable([
|
|
3102
|
+
["CREATED", "EVENT", "STATUS", "ATTEMPTS", "RESPONSE", "MICROVM"],
|
|
3103
|
+
...deliveries.map((delivery) => [
|
|
3104
|
+
delivery.createdAt,
|
|
3105
|
+
delivery.eventType,
|
|
3106
|
+
delivery.status,
|
|
3107
|
+
String(delivery.attempts),
|
|
3108
|
+
delivery.lastStatusCode === null ? delivery.lastError ?? "-" : String(delivery.lastStatusCode),
|
|
3109
|
+
delivery.microvmId
|
|
3110
|
+
])
|
|
3111
|
+
]);
|
|
3092
3112
|
var formatBytes = (bytes) => {
|
|
3093
3113
|
if (bytes < 1024) return `${bytes} B`;
|
|
3094
3114
|
const units = ["KiB", "MiB", "GiB", "TiB"];
|
|
@@ -3508,6 +3528,36 @@ var getCommand = Command12.make(
|
|
|
3508
3528
|
for (const line of describeMicroVm(vm)) yield* Console12.log(line);
|
|
3509
3529
|
}).pipe(reportErrors2("get the microVM"))
|
|
3510
3530
|
).pipe(Command12.withDescription("Show a microVM"));
|
|
3531
|
+
var formatGigabytes = (bytes) => `${(bytes / 1e9).toFixed(1)} GB`;
|
|
3532
|
+
var describeMicroVmMetrics = (metrics) => {
|
|
3533
|
+
const latest = metrics.cpu.at(-1);
|
|
3534
|
+
const peak = metrics.cpu.reduce((max, point) => Math.max(max, point.cpuPercent), 0);
|
|
3535
|
+
return [
|
|
3536
|
+
`CPU (last ${metrics.windowMinutes} min, ${metrics.vcpus} vCPU): ${latest ? `${latest.cpuPercent}% at ${latest.time}, peak ${peak}%` : "no samples"}`,
|
|
3537
|
+
metrics.current ? `Memory: ${formatGigabytes(metrics.current.memoryUsedBytes)} of ${formatGigabytes(metrics.current.memoryTotalBytes)}` : "Memory: unavailable (not running, or no answer)",
|
|
3538
|
+
metrics.current ? `Disk: ${formatGigabytes(metrics.current.diskUsedBytes)} of ${formatGigabytes(metrics.current.diskTotalBytes)}` : "Disk: unavailable (not running, or no answer)"
|
|
3539
|
+
];
|
|
3540
|
+
};
|
|
3541
|
+
var metricsCommand = Command12.make(
|
|
3542
|
+
"metrics",
|
|
3543
|
+
{
|
|
3544
|
+
microvmId: microvmIdArg,
|
|
3545
|
+
window: Options7.integer("window").pipe(
|
|
3546
|
+
Options7.withDescription("Minutes of CPU history, 1 to 1440 (default: 15)"),
|
|
3547
|
+
Options7.optional
|
|
3548
|
+
),
|
|
3549
|
+
json: jsonOption2
|
|
3550
|
+
},
|
|
3551
|
+
({ microvmId, window, json }) => Effect22.gen(function* () {
|
|
3552
|
+
const apiClient = yield* ApiClientService;
|
|
3553
|
+
const windowMinutes = Option14.getOrUndefined(window);
|
|
3554
|
+
const metrics = yield* apiClient.request(
|
|
3555
|
+
(client) => client.microvms.getMetrics(microvmId, windowMinutes === void 0 ? {} : { windowMinutes })
|
|
3556
|
+
);
|
|
3557
|
+
if (json) return yield* Console12.log(JSON.stringify(metrics, null, 2));
|
|
3558
|
+
for (const line of describeMicroVmMetrics(metrics)) yield* Console12.log(line);
|
|
3559
|
+
}).pipe(reportErrors2("read the microVM metrics"))
|
|
3560
|
+
).pipe(Command12.withDescription("Show a microVM's CPU, memory and disk use"));
|
|
3511
3561
|
var execInMicroVm = (flags, io = nodeSessionIo()) => Effect22.gen(function* () {
|
|
3512
3562
|
const env = yield* keyValues("--env", flags.env);
|
|
3513
3563
|
const timeout = yield* optionalDuration("--timeout", flags.timeout);
|
|
@@ -3905,10 +3955,126 @@ var imagesCommand = Command12.make("images", {}, () => Effect22.void).pipe(
|
|
|
3905
3955
|
Command12.withDescription("Built-in and custom microVM images"),
|
|
3906
3956
|
Command12.withSubcommands([imagesListCommand, imagesCreateCommand, imagesRemoveCommand])
|
|
3907
3957
|
);
|
|
3958
|
+
var WEBHOOK_EVENTS = [
|
|
3959
|
+
"microvm.created",
|
|
3960
|
+
"microvm.running",
|
|
3961
|
+
"microvm.paused",
|
|
3962
|
+
"microvm.stopped",
|
|
3963
|
+
"microvm.failed"
|
|
3964
|
+
];
|
|
3965
|
+
var webhookIdArg = Args5.text({ name: "webhook-id" }).pipe(Args5.withDescription("The webhook ID"));
|
|
3966
|
+
var webhooksListCommand = Command12.make(
|
|
3967
|
+
"ls",
|
|
3968
|
+
{ app: appOption6, json: jsonOption2 },
|
|
3969
|
+
({ app, json }) => Effect22.gen(function* () {
|
|
3970
|
+
const apiClient = yield* ApiClientService;
|
|
3971
|
+
const applicationId = yield* resolveApplicationId(app);
|
|
3972
|
+
const webhooks = yield* apiClient.request((client) => client.microvms.webhooks.list({ applicationId }));
|
|
3973
|
+
if (json) return yield* Console12.log(JSON.stringify(webhooks, null, 2));
|
|
3974
|
+
if (webhooks.length === 0)
|
|
3975
|
+
return yield* Console12.log('No webhooks yet. Add one with "gigadrive microvms webhooks add".');
|
|
3976
|
+
for (const line of formatWebhookTable(webhooks)) yield* Console12.log(line);
|
|
3977
|
+
}).pipe(reportErrors2("list webhooks"))
|
|
3978
|
+
).pipe(Command12.withDescription("List the application's microVM webhooks"));
|
|
3979
|
+
var addWebhook = (flags) => Effect22.gen(function* () {
|
|
3980
|
+
const apiClient = yield* ApiClientService;
|
|
3981
|
+
const unknown = flags.events.find((event) => !WEBHOOK_EVENTS.includes(event));
|
|
3982
|
+
if (unknown !== void 0) {
|
|
3983
|
+
return yield* new InvalidMicroVmOptionsError({
|
|
3984
|
+
message: `${unknown} is not a microVM event. Use ${WEBHOOK_EVENTS.join(", ")}.`
|
|
3985
|
+
});
|
|
3986
|
+
}
|
|
3987
|
+
const events = flags.events.length > 0 ? [...new Set(flags.events)] : WEBHOOK_EVENTS;
|
|
3988
|
+
const applicationId = yield* resolveApplicationId(flags.app);
|
|
3989
|
+
const webhook = yield* apiClient.request(
|
|
3990
|
+
(client) => client.microvms.webhooks.create({
|
|
3991
|
+
url: flags.url,
|
|
3992
|
+
events,
|
|
3993
|
+
...Option14.isSome(flags.description) ? { description: flags.description.value } : {},
|
|
3994
|
+
...applicationId ? { applicationId } : {}
|
|
3995
|
+
})
|
|
3996
|
+
);
|
|
3997
|
+
if (flags.json) {
|
|
3998
|
+
yield* Console12.log(JSON.stringify(webhook, null, 2));
|
|
3999
|
+
} else {
|
|
4000
|
+
yield* Console12.log(`Added webhook ${webhook.id} for ${webhook.events.join(", ")}.`);
|
|
4001
|
+
yield* Console12.log(`Signing secret (shown only now): ${webhook.secret}`);
|
|
4002
|
+
}
|
|
4003
|
+
return webhook;
|
|
4004
|
+
});
|
|
4005
|
+
var webhooksAddCommand = Command12.make(
|
|
4006
|
+
"add",
|
|
4007
|
+
{
|
|
4008
|
+
url: Args5.text({ name: "url" }).pipe(Args5.withDescription("HTTPS URL on a public host")),
|
|
4009
|
+
events: Options7.text("event").pipe(
|
|
4010
|
+
Options7.withDescription(`Event to send (repeatable; default: all of ${WEBHOOK_EVENTS.join(", ")})`),
|
|
4011
|
+
Options7.repeated
|
|
4012
|
+
),
|
|
4013
|
+
description: Options7.text("description").pipe(Options7.withDescription("A note for yourself"), Options7.optional),
|
|
4014
|
+
app: appOption6,
|
|
4015
|
+
json: jsonOption2
|
|
4016
|
+
},
|
|
4017
|
+
(flags) => addWebhook(flags).pipe(Effect22.asVoid, reportErrors2("add the webhook"))
|
|
4018
|
+
).pipe(Command12.withDescription("Add an endpoint for microVM lifecycle events and print its signing secret"));
|
|
4019
|
+
var webhooksEnableCommand = (enabled) => Command12.make(
|
|
4020
|
+
enabled ? "enable" : "disable",
|
|
4021
|
+
{ webhookId: webhookIdArg },
|
|
4022
|
+
({ webhookId }) => Effect22.gen(function* () {
|
|
4023
|
+
const apiClient = yield* ApiClientService;
|
|
4024
|
+
const webhook = yield* apiClient.request((client) => client.microvms.webhooks.update(webhookId, { enabled }));
|
|
4025
|
+
yield* Console12.log(`${webhook.url} is ${webhook.enabled ? "enabled" : "disabled"}.`);
|
|
4026
|
+
}).pipe(reportErrors2(enabled ? "enable the webhook" : "disable the webhook"))
|
|
4027
|
+
).pipe(
|
|
4028
|
+
Command12.withDescription(
|
|
4029
|
+
enabled ? "Send events to a webhook again" : "Stop sending events to a webhook; waiting retries are held"
|
|
4030
|
+
)
|
|
4031
|
+
);
|
|
4032
|
+
var webhooksSecretCommand = Command12.make(
|
|
4033
|
+
"rotate-secret",
|
|
4034
|
+
{ webhookId: webhookIdArg },
|
|
4035
|
+
({ webhookId }) => Effect22.gen(function* () {
|
|
4036
|
+
const apiClient = yield* ApiClientService;
|
|
4037
|
+
const webhook = yield* apiClient.request((client) => client.microvms.webhooks.rotateSecret(webhookId));
|
|
4038
|
+
yield* Console12.log(`New signing secret (shown only now): ${webhook.secret}`);
|
|
4039
|
+
}).pipe(reportErrors2("replace the signing secret"))
|
|
4040
|
+
).pipe(Command12.withDescription("Replace the signing secret; the old one stops signing at once"));
|
|
4041
|
+
var webhooksDeliveriesCommand = Command12.make(
|
|
4042
|
+
"deliveries",
|
|
4043
|
+
{ webhookId: webhookIdArg, json: jsonOption2 },
|
|
4044
|
+
({ webhookId, json }) => Effect22.gen(function* () {
|
|
4045
|
+
const apiClient = yield* ApiClientService;
|
|
4046
|
+
const deliveries = yield* apiClient.request((client) => client.microvms.webhooks.listDeliveries(webhookId));
|
|
4047
|
+
if (json) return yield* Console12.log(JSON.stringify(deliveries, null, 2));
|
|
4048
|
+
if (deliveries.length === 0) return yield* Console12.log("Nothing has been sent yet.");
|
|
4049
|
+
for (const line of formatDeliveryTable(deliveries)) yield* Console12.log(line);
|
|
4050
|
+
}).pipe(reportErrors2("list the deliveries"))
|
|
4051
|
+
).pipe(Command12.withDescription("Show a webhook's 50 most recent deliveries"));
|
|
4052
|
+
var webhooksRemoveCommand = Command12.make(
|
|
4053
|
+
"rm",
|
|
4054
|
+
{ webhookId: webhookIdArg },
|
|
4055
|
+
({ webhookId }) => Effect22.gen(function* () {
|
|
4056
|
+
const apiClient = yield* ApiClientService;
|
|
4057
|
+
yield* apiClient.request((client) => client.microvms.webhooks.delete(webhookId));
|
|
4058
|
+
yield* Console12.log(`Deleted webhook ${webhookId}.`);
|
|
4059
|
+
}).pipe(reportErrors2("delete the webhook"))
|
|
4060
|
+
).pipe(Command12.withDescription("Delete a webhook"));
|
|
4061
|
+
var webhooksCommand = Command12.make("webhooks", {}, () => Effect22.void).pipe(
|
|
4062
|
+
Command12.withDescription("Signed HTTPS requests when a microVM is created, starts, pauses, stops or fails"),
|
|
4063
|
+
Command12.withSubcommands([
|
|
4064
|
+
webhooksListCommand,
|
|
4065
|
+
webhooksAddCommand,
|
|
4066
|
+
webhooksEnableCommand(true),
|
|
4067
|
+
webhooksEnableCommand(false),
|
|
4068
|
+
webhooksSecretCommand,
|
|
4069
|
+
webhooksDeliveriesCommand,
|
|
4070
|
+
webhooksRemoveCommand
|
|
4071
|
+
])
|
|
4072
|
+
);
|
|
3908
4073
|
var SUBCOMMANDS = [
|
|
3909
4074
|
createCommand,
|
|
3910
4075
|
listCommand2,
|
|
3911
4076
|
getCommand,
|
|
4077
|
+
metricsCommand,
|
|
3912
4078
|
execCommand,
|
|
3913
4079
|
shellCommand,
|
|
3914
4080
|
copyCommand,
|
|
@@ -3916,7 +4082,8 @@ var SUBCOMMANDS = [
|
|
|
3916
4082
|
removeCommand2,
|
|
3917
4083
|
extendCommand,
|
|
3918
4084
|
networkCommand,
|
|
3919
|
-
imagesCommand
|
|
4085
|
+
imagesCommand,
|
|
4086
|
+
webhooksCommand
|
|
3920
4087
|
];
|
|
3921
4088
|
var microvmsCommand = Command12.make("microvms", {}, () => Effect22.void).pipe(
|
|
3922
4089
|
Command12.withDescription("Isolated Linux machines for running code: create, exec, shell, cp, stop"),
|