@layr-labs/ecloud-cli 0.1.0-dev.1 → 0.1.0-dev.3
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/README.md +6 -4
- package/VERSION +2 -2
- package/dist/commands/auth/generate.js +184 -46
- package/dist/commands/auth/generate.js.map +1 -1
- package/dist/commands/auth/login.js +234 -93
- package/dist/commands/auth/login.js.map +1 -1
- package/dist/commands/auth/logout.js +170 -30
- package/dist/commands/auth/logout.js.map +1 -1
- package/dist/commands/auth/migrate.js +216 -76
- package/dist/commands/auth/migrate.js.map +1 -1
- package/dist/commands/auth/whoami.js +145 -17
- package/dist/commands/auth/whoami.js.map +1 -1
- package/dist/commands/billing/cancel.js +164 -30
- package/dist/commands/billing/cancel.js.map +1 -1
- package/dist/commands/billing/status.js +213 -80
- package/dist/commands/billing/status.js.map +1 -1
- package/dist/commands/billing/subscribe.js +179 -45
- package/dist/commands/billing/subscribe.js.map +1 -1
- package/dist/commands/compute/app/create.js +148 -20
- package/dist/commands/compute/app/create.js.map +1 -1
- package/dist/commands/compute/app/deploy.js +244 -146
- package/dist/commands/compute/app/deploy.js.map +1 -1
- package/dist/commands/compute/app/info.js +2 -1
- package/dist/commands/compute/app/info.js.map +1 -1
- package/dist/commands/compute/app/list.js +194 -111
- package/dist/commands/compute/app/list.js.map +1 -1
- package/dist/commands/compute/app/logs.js +105 -20
- package/dist/commands/compute/app/logs.js.map +1 -1
- package/dist/commands/compute/app/profile/set.js +153 -64
- package/dist/commands/compute/app/profile/set.js.map +1 -1
- package/dist/commands/compute/app/start.js +132 -43
- package/dist/commands/compute/app/start.js.map +1 -1
- package/dist/commands/compute/app/stop.js +132 -43
- package/dist/commands/compute/app/stop.js.map +1 -1
- package/dist/commands/compute/app/terminate.js +131 -44
- package/dist/commands/compute/app/terminate.js.map +1 -1
- package/dist/commands/compute/app/upgrade.js +210 -109
- package/dist/commands/compute/app/upgrade.js.map +1 -1
- package/dist/commands/compute/environment/list.js +104 -12
- package/dist/commands/compute/environment/list.js.map +1 -1
- package/dist/commands/compute/environment/set.js +103 -18
- package/dist/commands/compute/environment/set.js.map +1 -1
- package/dist/commands/compute/environment/show.js +122 -30
- package/dist/commands/compute/environment/show.js.map +1 -1
- package/dist/commands/compute/undelegate.js +113 -13
- package/dist/commands/compute/undelegate.js.map +1 -1
- package/dist/commands/telemetry.js +213 -0
- package/dist/commands/telemetry.js.map +1 -0
- package/dist/commands/upgrade.js +159 -19
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/commands/version.js +163 -23
- package/dist/commands/version.js.map +1 -1
- package/package.json +2 -2
|
@@ -5,7 +5,7 @@ import { Command, Args, Flags as Flags2 } from "@oclif/core";
|
|
|
5
5
|
|
|
6
6
|
// src/client.ts
|
|
7
7
|
import {
|
|
8
|
-
|
|
8
|
+
createComputeModule,
|
|
9
9
|
createBillingModule,
|
|
10
10
|
getEnvironmentConfig as getEnvironmentConfig2,
|
|
11
11
|
requirePrivateKey,
|
|
@@ -52,6 +52,7 @@ import * as path from "path";
|
|
|
52
52
|
import * as os from "os";
|
|
53
53
|
import { load as loadYaml, dump as dumpYaml } from "js-yaml";
|
|
54
54
|
import { getBuildType } from "@layr-labs/ecloud-sdk";
|
|
55
|
+
import * as crypto from "crypto";
|
|
55
56
|
var GLOBAL_CONFIG_FILE = "config.yaml";
|
|
56
57
|
var PROFILE_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
57
58
|
function getGlobalConfigDir() {
|
|
@@ -98,6 +99,10 @@ function getDefaultEnvironment() {
|
|
|
98
99
|
const config = loadGlobalConfig();
|
|
99
100
|
return config.default_environment;
|
|
100
101
|
}
|
|
102
|
+
function getGlobalTelemetryPreference() {
|
|
103
|
+
const config = loadGlobalConfig();
|
|
104
|
+
return config.telemetry_enabled;
|
|
105
|
+
}
|
|
101
106
|
function getProfileCache(environment) {
|
|
102
107
|
const config = loadGlobalConfig();
|
|
103
108
|
const cacheEntry = config.profile_cache?.[environment];
|
|
@@ -121,6 +126,24 @@ function setProfileCache(environment, profiles) {
|
|
|
121
126
|
};
|
|
122
127
|
saveGlobalConfig(config);
|
|
123
128
|
}
|
|
129
|
+
function getOrCreateUserUUID() {
|
|
130
|
+
const config = loadGlobalConfig();
|
|
131
|
+
if (config.user_uuid) {
|
|
132
|
+
return config.user_uuid;
|
|
133
|
+
}
|
|
134
|
+
const uuid = generateUUID();
|
|
135
|
+
config.user_uuid = uuid;
|
|
136
|
+
config.first_run = false;
|
|
137
|
+
saveGlobalConfig(config);
|
|
138
|
+
return uuid;
|
|
139
|
+
}
|
|
140
|
+
function generateUUID() {
|
|
141
|
+
const bytes = crypto.randomBytes(16);
|
|
142
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
143
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
144
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
|
|
145
|
+
return hex.slice(0, 4).join("") + hex.slice(4, 6).join("") + "-" + hex.slice(6, 8).join("") + "-" + hex.slice(8, 10).join("") + "-" + hex.slice(10, 12).join("") + "-" + hex.slice(12, 16).join("");
|
|
146
|
+
}
|
|
124
147
|
|
|
125
148
|
// src/utils/appNames.ts
|
|
126
149
|
import * as fs2 from "fs";
|
|
@@ -168,7 +191,7 @@ function listApps(environment) {
|
|
|
168
191
|
|
|
169
192
|
// src/utils/version.ts
|
|
170
193
|
function getCliVersion() {
|
|
171
|
-
return true ? "0.1.0-dev.
|
|
194
|
+
return true ? "0.1.0-dev.3" : "0.0.0";
|
|
172
195
|
}
|
|
173
196
|
function getClientId() {
|
|
174
197
|
return `ecloud-cli/v${getCliVersion()}`;
|
|
@@ -585,7 +608,7 @@ async function validateCommonFlags(flags) {
|
|
|
585
608
|
}
|
|
586
609
|
|
|
587
610
|
// src/client.ts
|
|
588
|
-
async function
|
|
611
|
+
async function createComputeClient(flags) {
|
|
589
612
|
flags = await validateCommonFlags(flags);
|
|
590
613
|
const environment = flags.environment;
|
|
591
614
|
const environmentConfig = getEnvironmentConfig2(environment);
|
|
@@ -596,12 +619,14 @@ async function createAppClient(flags) {
|
|
|
596
619
|
if (flags.verbose) {
|
|
597
620
|
console.log(`Using private key from: ${source}`);
|
|
598
621
|
}
|
|
599
|
-
return
|
|
622
|
+
return createComputeModule({
|
|
600
623
|
verbose: flags.verbose,
|
|
601
624
|
privateKey,
|
|
602
625
|
rpcUrl,
|
|
603
626
|
environment,
|
|
604
|
-
clientId: getClientId()
|
|
627
|
+
clientId: getClientId(),
|
|
628
|
+
skipTelemetry: true
|
|
629
|
+
// CLI already has telemetry, skip SDK telemetry
|
|
605
630
|
});
|
|
606
631
|
}
|
|
607
632
|
|
|
@@ -613,6 +638,66 @@ import {
|
|
|
613
638
|
isMainnet
|
|
614
639
|
} from "@layr-labs/ecloud-sdk";
|
|
615
640
|
import chalk from "chalk";
|
|
641
|
+
|
|
642
|
+
// src/telemetry.ts
|
|
643
|
+
import {
|
|
644
|
+
createTelemetryClient,
|
|
645
|
+
createAppEnvironment,
|
|
646
|
+
createMetricsContext,
|
|
647
|
+
addMetric,
|
|
648
|
+
addMetricWithDimensions,
|
|
649
|
+
emitMetrics,
|
|
650
|
+
getBuildType as getBuildType2
|
|
651
|
+
} from "@layr-labs/ecloud-sdk";
|
|
652
|
+
function createCLITelemetryClient() {
|
|
653
|
+
const userUUID = getOrCreateUserUUID();
|
|
654
|
+
const environment = createAppEnvironment(userUUID);
|
|
655
|
+
const telemetryEnabled = getGlobalTelemetryPreference();
|
|
656
|
+
return createTelemetryClient(environment, "ecloud-cli", {
|
|
657
|
+
telemetryEnabled: telemetryEnabled === true
|
|
658
|
+
// Only enabled if explicitly set to true
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
async function withTelemetry(command, action) {
|
|
662
|
+
const client = createCLITelemetryClient();
|
|
663
|
+
const metrics = createMetricsContext();
|
|
664
|
+
metrics.properties["source"] = "ecloud-cli";
|
|
665
|
+
metrics.properties["command"] = command.id || command.constructor.name;
|
|
666
|
+
const environment = getDefaultEnvironment() || "sepolia";
|
|
667
|
+
metrics.properties["environment"] = environment;
|
|
668
|
+
const buildType = getBuildType2() || "prod";
|
|
669
|
+
metrics.properties["build_type"] = buildType;
|
|
670
|
+
const cliVersion = command.config.version;
|
|
671
|
+
if (cliVersion) {
|
|
672
|
+
metrics.properties["cli_version"] = cliVersion;
|
|
673
|
+
}
|
|
674
|
+
addMetric(metrics, "Count", 1);
|
|
675
|
+
let actionError;
|
|
676
|
+
let result;
|
|
677
|
+
try {
|
|
678
|
+
result = await action();
|
|
679
|
+
return result;
|
|
680
|
+
} catch (err) {
|
|
681
|
+
actionError = err instanceof Error ? err : new Error(String(err));
|
|
682
|
+
throw err;
|
|
683
|
+
} finally {
|
|
684
|
+
const resultValue = actionError ? "Failure" : "Success";
|
|
685
|
+
const dimensions = {};
|
|
686
|
+
if (actionError) {
|
|
687
|
+
dimensions["error"] = actionError.message;
|
|
688
|
+
}
|
|
689
|
+
addMetricWithDimensions(metrics, resultValue, 1, dimensions);
|
|
690
|
+
const duration = Date.now() - metrics.startTime.getTime();
|
|
691
|
+
addMetric(metrics, "DurationMilliseconds", duration);
|
|
692
|
+
try {
|
|
693
|
+
await emitMetrics(client, metrics);
|
|
694
|
+
await client.close();
|
|
695
|
+
} catch {
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// src/commands/compute/app/terminate.ts
|
|
616
701
|
var AppLifecycleTerminate = class _AppLifecycleTerminate extends Command {
|
|
617
702
|
static description = "Terminate app (terminate GCP instance) permanently";
|
|
618
703
|
static args = {
|
|
@@ -630,49 +715,51 @@ var AppLifecycleTerminate = class _AppLifecycleTerminate extends Command {
|
|
|
630
715
|
})
|
|
631
716
|
};
|
|
632
717
|
async run() {
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
718
|
+
return withTelemetry(this, async () => {
|
|
719
|
+
const { args, flags } = await this.parse(_AppLifecycleTerminate);
|
|
720
|
+
const compute = await createComputeClient(flags);
|
|
721
|
+
const environment = flags.environment || "sepolia";
|
|
722
|
+
const environmentConfig = getEnvironmentConfig3(environment);
|
|
723
|
+
const rpcUrl = flags.rpcUrl || environmentConfig.defaultRPCURL;
|
|
724
|
+
const privateKey = flags["private-key"] || await getPrivateKeyInteractive(environment);
|
|
725
|
+
const appId = await getOrPromptAppID({
|
|
726
|
+
appID: args["app-id"],
|
|
727
|
+
environment: flags["environment"],
|
|
728
|
+
privateKey,
|
|
729
|
+
rpcUrl,
|
|
730
|
+
action: "terminate"
|
|
731
|
+
});
|
|
732
|
+
const callData = encodeTerminateAppData(appId);
|
|
733
|
+
const estimate = await estimateTransactionGas({
|
|
734
|
+
privateKey,
|
|
735
|
+
rpcUrl,
|
|
736
|
+
environmentConfig,
|
|
737
|
+
to: environmentConfig.appControllerAddress,
|
|
738
|
+
data: callData
|
|
739
|
+
});
|
|
740
|
+
if (!flags.force) {
|
|
741
|
+
const costInfo = isMainnet(environmentConfig) ? ` (cost: up to ${estimate.maxCostEth} ETH)` : "";
|
|
742
|
+
const confirmed = await confirm(`\u26A0\uFE0F Permanently destroy app ${appId}${costInfo}?`);
|
|
743
|
+
if (!confirmed) {
|
|
744
|
+
this.log(`
|
|
659
745
|
${chalk.gray(`Termination aborted`)}`);
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
}
|
|
663
|
-
const res = await app.terminate(appId, {
|
|
664
|
-
gas: {
|
|
665
|
-
maxFeePerGas: estimate.maxFeePerGas,
|
|
666
|
-
maxPriorityFeePerGas: estimate.maxPriorityFeePerGas
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
667
748
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
749
|
+
const res = await compute.app.terminate(appId, {
|
|
750
|
+
gas: {
|
|
751
|
+
maxFeePerGas: estimate.maxFeePerGas,
|
|
752
|
+
maxPriorityFeePerGas: estimate.maxPriorityFeePerGas
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
if (!res.tx) {
|
|
756
|
+
this.log(`
|
|
671
757
|
${chalk.gray(`Termination failed`)}`);
|
|
672
|
-
|
|
673
|
-
|
|
758
|
+
} else {
|
|
759
|
+
this.log(`
|
|
674
760
|
\u2705 ${chalk.green(`App terminated successfully`)}`);
|
|
675
|
-
|
|
761
|
+
}
|
|
762
|
+
});
|
|
676
763
|
}
|
|
677
764
|
};
|
|
678
765
|
export {
|