@diagonal-hq/cli 0.42.22 → 0.42.23
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
CHANGED
|
@@ -57,11 +57,11 @@ Then the command runs `npm install`. It exits with 1 when a tarball directory ha
|
|
|
57
57
|
|
|
58
58
|
## Workspace API credentials
|
|
59
59
|
|
|
60
|
-
The API commands read `DIAGONAL_URL` and `DIAGONAL_API_KEY`. Workflow commands require `manage_workflows`. Asset commands require `manage_workspace_settings`. A System Administrator has both permissions. Keep API keys out of the repository.
|
|
60
|
+
The API commands read `DIAGONAL_URL` and `DIAGONAL_API_KEY` from the environment. When the environment sets neither, they read both from `.env` in the current folder, so a `.env` never pairs its URL with a key from the environment. The setup command of the Git Keys tab writes that `.env` with a CLI key, an API key that works only for these commands. Workflow commands require `manage_workflows`. Asset commands require `manage_workspace_settings`. A System Administrator has both permissions. Keep API keys out of the repository.
|
|
61
61
|
|
|
62
62
|
## Run a deployed workflow
|
|
63
63
|
|
|
64
|
-
`diagonal workflows`, `diagonal run`, and `diagonal logs` call the runtime API of a deployed workspace. Set two environment variables first:
|
|
64
|
+
`diagonal workflows`, `diagonal run`, and `diagonal logs` call the runtime API of a deployed workspace. Set two environment variables first, or put them in `.env` of the workspace root:
|
|
65
65
|
|
|
66
66
|
- `DIAGONAL_URL` is the workspace URL, for example `https://acme.diagonal.app`.
|
|
67
67
|
- `DIAGONAL_API_KEY` is an API key of an account with `manage_workflows`.
|
|
@@ -21,6 +21,9 @@ import {
|
|
|
21
21
|
} from "./cli-chunk-KP2RSHLJ.mjs";
|
|
22
22
|
|
|
23
23
|
// scripts/lib/runtime-build/api-cli.mjs
|
|
24
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
25
|
+
import { join } from "node:path";
|
|
26
|
+
import { parseEnv } from "node:util";
|
|
24
27
|
var WORKFLOWS_USAGE = "Usage: diagonal workflows [--json]";
|
|
25
28
|
var RUN_USAGE = "Usage: diagonal run <path> [--input '<json object>'] [--json]";
|
|
26
29
|
var LOGS_USAGE = "Usage: diagonal logs [path | execution id] [--status <success|error|exception|started|pending>] [--limit <1-100>] [--json]";
|
|
@@ -28,6 +31,22 @@ var SUCCESS = "execution.success";
|
|
|
28
31
|
var PENDING = "execution.pending";
|
|
29
32
|
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
30
33
|
var STATUSES = ["success", "error", "exception", "started", "pending"];
|
|
34
|
+
var WORKSPACE_ENV_KEYS = ["DIAGONAL_URL", "DIAGONAL_API_KEY"];
|
|
35
|
+
function withWorkspaceEnv(io) {
|
|
36
|
+
const file = join(io.cwd, ".env");
|
|
37
|
+
const setInEnvironment = WORKSPACE_ENV_KEYS.some((key) => (io.env[key] ?? "").trim() !== "");
|
|
38
|
+
if (setInEnvironment || !existsSync(file)) {
|
|
39
|
+
return io;
|
|
40
|
+
}
|
|
41
|
+
const values = parseEnv(readFileSync(file, "utf8"));
|
|
42
|
+
const env = { ...io.env };
|
|
43
|
+
for (const key of WORKSPACE_ENV_KEYS) {
|
|
44
|
+
if (typeof values[key] === "string") {
|
|
45
|
+
env[key] = values[key];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return { ...io, env };
|
|
49
|
+
}
|
|
31
50
|
function credentials(env, stderr) {
|
|
32
51
|
const url = env.DIAGONAL_URL?.trim().replace(/\/+$/, "") ?? "";
|
|
33
52
|
const apiKey = env.DIAGONAL_API_KEY?.trim() ?? "";
|
|
@@ -615,6 +634,7 @@ export {
|
|
|
615
634
|
WORKFLOWS_USAGE,
|
|
616
635
|
RUN_USAGE,
|
|
617
636
|
LOGS_USAGE,
|
|
637
|
+
withWorkspaceEnv,
|
|
618
638
|
credentials,
|
|
619
639
|
errorText,
|
|
620
640
|
request,
|
package/dist/cli.mjs
CHANGED
|
@@ -102,9 +102,10 @@ import {
|
|
|
102
102
|
runWorkflow,
|
|
103
103
|
showLogs,
|
|
104
104
|
takesAssetReference,
|
|
105
|
+
withWorkspaceEnv,
|
|
105
106
|
writeAssetCatalog,
|
|
106
107
|
writeAssetEntry
|
|
107
|
-
} from "./cli-chunk-
|
|
108
|
+
} from "./cli-chunk-FR2ZNG34.mjs";
|
|
108
109
|
import {
|
|
109
110
|
ASSETS_EXPORT,
|
|
110
111
|
GENERATED_ASSETS_MODULE,
|
|
@@ -11929,20 +11930,20 @@ async function main(argv, io) {
|
|
|
11929
11930
|
case "assets": {
|
|
11930
11931
|
const [subcommand, ...assetArgs] = args;
|
|
11931
11932
|
if (subcommand === "upload")
|
|
11932
|
-
return (await import("./cli-assets-cli-
|
|
11933
|
+
return (await import("./cli-assets-cli-KPJWOWLD.mjs")).uploadAsset(assetArgs, withWorkspaceEnv(io));
|
|
11933
11934
|
if (subcommand === "list")
|
|
11934
|
-
return (await import("./cli-assets-cli-
|
|
11935
|
+
return (await import("./cli-assets-cli-KPJWOWLD.mjs")).listAssets(assetArgs, withWorkspaceEnv(io));
|
|
11935
11936
|
io.stderr.write(`${ASSETS_UPLOAD_USAGE}
|
|
11936
11937
|
${ASSETS_LIST_USAGE}
|
|
11937
11938
|
`);
|
|
11938
11939
|
return 2;
|
|
11939
11940
|
}
|
|
11940
11941
|
case "workflows":
|
|
11941
|
-
return listWorkflows(args, io);
|
|
11942
|
+
return listWorkflows(args, withWorkspaceEnv(io));
|
|
11942
11943
|
case "run":
|
|
11943
|
-
return runWorkflow(args, io);
|
|
11944
|
+
return runWorkflow(args, withWorkspaceEnv(io));
|
|
11944
11945
|
case "logs":
|
|
11945
|
-
return showLogs(args, io);
|
|
11946
|
+
return showLogs(args, withWorkspaceEnv(io));
|
|
11946
11947
|
default:
|
|
11947
11948
|
io.stderr.write(`${USAGE}
|
|
11948
11949
|
`);
|
package/package.json
CHANGED