@ductape/cli 0.4.9 → 0.5.2

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.
@@ -0,0 +1,113 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { classifyEntry, describePlan, parseDotenv, planScan } from '../lib/env-scan.js';
4
+ import { printJson } from '../lib/output.js';
5
+ import { getSdkProxyForContext } from '../lib/proxy/context.js';
6
+ import { requireWorkspaceContext } from '../lib/workspace-context.js';
7
+ function proxyStore() {
8
+ const ctx = requireWorkspaceContext();
9
+ const proxy = getSdkProxyForContext(ctx);
10
+ return {
11
+ async keys() {
12
+ const result = await proxy.execute('secrets', 'list', []);
13
+ const list = Array.isArray(result) ? result : Array.isArray(result?.data) ? result.data : Array.isArray(result?.secrets) ? result.secrets : [];
14
+ return list.map((item) => (typeof item === 'string' ? item : String(item?.key ?? ''))).filter(Boolean);
15
+ },
16
+ async create(input) { await proxy.execute('secrets', 'create', [input]); },
17
+ async update(key, input) { await proxy.execute('secrets', 'update', [key, input]); },
18
+ };
19
+ }
20
+ /** The file to read: the one named, or `.env` in the project folder. When there is none, the ones that are there are named, never read. */
21
+ export function locateEnvFile(options, cwd = process.cwd()) {
22
+ const dir = path.resolve(cwd, options.dir ?? '.');
23
+ if (options.envFile) {
24
+ const file = path.resolve(dir, options.envFile);
25
+ if (!fs.existsSync(file))
26
+ throw new Error(`The file ${file} does not exist`);
27
+ return file;
28
+ }
29
+ const file = path.join(dir, '.env');
30
+ if (fs.existsSync(file))
31
+ return file;
32
+ const others = fs.existsSync(dir) ? fs.readdirSync(dir).filter((name) => name.startsWith('.env') && fs.statSync(path.join(dir, name)).isFile()).sort() : [];
33
+ throw new Error(`There is no .env in ${dir}.${others.length ? ` These are here: ${others.join(', ')}. Name one with --env-file.` : ' Name the file with --env-file.'}`);
34
+ }
35
+ /**
36
+ * Reads a .env file on this machine, decides which variables are secrets, and (only with `apply`) saves them to the workspace's secrets. A value
37
+ * goes from the file to the workspace and nowhere else: it is not printed, not logged and not in any result, and an error from the workspace is
38
+ * stripped of any value before it is shown.
39
+ */
40
+ export async function scanEnvFile(options, store = proxyStore(), cwd = process.cwd()) {
41
+ if (options.env !== undefined && !/^[a-z0-9][a-z0-9_-]{0,31}$/i.test(options.env))
42
+ throw new Error('--env must be an environment slug such as stg or prd');
43
+ const file = locateEnvFile(options, cwd);
44
+ const entries = parseDotenv(fs.readFileSync(file, 'utf8'));
45
+ if (entries.length === 0)
46
+ throw new Error(`${file} has no variables in it`);
47
+ const existing = new Set(await store.keys());
48
+ const rows = planScan(entries, existing, options);
49
+ const source = path.basename(file);
50
+ const failures = [];
51
+ const done = new Map();
52
+ if (options.apply) {
53
+ const byName = new Map(entries.map((e) => [e.name, e]));
54
+ const values = entries.map((e) => e.value).filter((v) => v.length >= 4).sort((a, b) => b.length - a.length);
55
+ const scrub = (message) => values.reduce((text, value) => text.split(value).join('[redacted]'), message);
56
+ for (const row of rows) {
57
+ if (row.action !== 'create' && row.action !== 'update')
58
+ continue;
59
+ const entry = byName.get(row.name);
60
+ const description = `Imported from ${source}${options.env ? ` for ${options.env}` : ''}`;
61
+ try {
62
+ if (row.action === 'create')
63
+ await store.create({ key: row.key, value: entry.value, description, ...(options.env ? { envs: [options.env] } : {}) });
64
+ else
65
+ await store.update(row.key, { value: entry.value, description });
66
+ done.set(row.key, row.action === 'create' ? 'created' : 'updated');
67
+ }
68
+ catch (error) {
69
+ done.set(row.key, 'failed');
70
+ failures.push({ key: row.key, message: scrub(error instanceof Error ? error.message : String(error)) });
71
+ }
72
+ }
73
+ }
74
+ const description = describePlan(rows, source, Boolean(options.apply));
75
+ if (options.apply) {
76
+ for (const variable of description.variables) {
77
+ const outcome = done.get(String(variable.key));
78
+ if (outcome)
79
+ variable.result = outcome;
80
+ }
81
+ description.summary.failed = failures.length;
82
+ }
83
+ const result = { ...description, ...(failures.length ? { failures } : {}) };
84
+ return { rows, applied: Boolean(options.apply), failures, result };
85
+ }
86
+ /** A workspace that cannot be asked: used for a preview when nobody is logged in, so the file can still be scanned. It cannot be written to. */
87
+ const unreachableWorkspace = {
88
+ async keys() { return []; },
89
+ async create() { throw new Error('Not logged in: log in to save secrets to a workspace (ductape login)'); },
90
+ async update() { throw new Error('Not logged in: log in to save secrets to a workspace (ductape login)'); },
91
+ };
92
+ export async function runSecretsScanEnv(options) {
93
+ let store;
94
+ let asked = true;
95
+ try {
96
+ store = proxyStore();
97
+ }
98
+ catch (error) {
99
+ // Saving needs a workspace. A preview does not: it can still say what the file holds and what would be saved.
100
+ if (options.apply)
101
+ throw error;
102
+ store = unreachableWorkspace;
103
+ asked = false;
104
+ }
105
+ const outcome = await scanEnvFile(options, store);
106
+ const result = asked
107
+ ? outcome.result
108
+ : { ...outcome.result, workspace_checked: false, note: `${String(outcome.result.note)} You are not logged in, so the workspace was not asked which secrets it already has: anything it has is marked create here and would be left alone when saved.` };
109
+ printJson(result, Boolean(options.json));
110
+ if (outcome.failures.length > 0)
111
+ process.exitCode = 1;
112
+ }
113
+ export { classifyEntry };
package/dist/index.js CHANGED
@@ -23,10 +23,12 @@ import { runSessionsValidate } from './commands/sessions-validate.js';
23
23
  import { runRateLimits } from './commands/rate-limits.js';
24
24
  import { runDeploy } from './commands/deploy.js';
25
25
  import { runDeployRemote } from './commands/deploy-remote.js';
26
+ import { runDeployWorker } from './commands/deploy-worker.js';
26
27
  import { runDeployBuilds } from './commands/deploy-builds.js';
27
28
  import { runDbSchemaGenerate, runDbSchemaPush } from './commands/db-schema.js';
28
29
  import { runGraph } from './commands/graph.js';
29
30
  import { runSecretImportEnv, runSecrets } from './commands/secrets.js';
31
+ import { runSecretsScanEnv } from './commands/secrets-scan.js';
30
32
  import { runWorkspacesCurrent, runWorkspacesList, runWorkspacesRefresh, runWorkspacesUse, } from './commands/workspaces.js';
31
33
  import { runGeneratePayload, runGenerateSnippet } from './commands/generate.js';
32
34
  import { runCompletion } from './commands/completion.js';
@@ -107,20 +109,48 @@ const op = (operation) => wrap((...args) => {
107
109
  return runDeployRemote(operation, { ...options, version: options.fnVersion, id: positional[0] });
108
110
  });
109
111
  remote('releases', 'register', 'Register an immutable release from a JSON file', (c) => c.requiredOption('--file <file>', 'Release JSON')).action(op('releases.register'));
112
+ remote('releases', 'publish-worker', 'Publish a Cloudflare Worker release: the bundle is stored in your own Cloudflare account (not kept by Ductape) and a release is registered from it', (c) => c.requiredOption('--file <file>', 'Release JSON: product, function, version, contract, config, verification (no image)')
113
+ .requiredOption('--connection <tag>', 'A Cloudflare connection made with the deploy scope')
114
+ .option('--bundle <file>', 'A bundle you built: one ES module with a default fetch handler')
115
+ .option('--entry <file>', 'Source to bundle here with esbuild (esbuild must be installed in the project)')).action(wrap((options) => runDeployWorker(options)));
116
+ remote('releases', 'list', 'List releases', (c) => c.option('--product <tag>').option('--function <name>', 'a function or service name').option('--fn-version <version>')).action(op('releases.list'));
117
+ remote('releases', 'get <releaseHash>', 'Show one release: its image, contract and configuration (secret references only, never values)').action(op('releases.get'));
118
+ remote('capabilities', 'show', 'Show what this control plane will do: whether changes are on, whether it reads your cloud itself, step-up and which clouds it can deploy to').action(op('capabilities'));
119
+ remote('connections', 'orphans <connection>', 'List what this workspace made in a cloud account (Google Cloud, AWS, Azure or Cloudflare) that no deployment accounts for (read only)', (c) => c.option('--region <region>')).action(op('orphans'));
120
+ const grantOption = (c) => c.option('--grant-env <VAR>', 'Name of the environment variable holding a step-up grant, when this server asks for an emailed code (see: deploy step-up)');
121
+ const codeTarget = (c) => c
122
+ .option('--plan <planId>', 'the code is for approving this plan')
123
+ .option('--retire', 'the code is for retiring a version (with --product --function --fn-version)')
124
+ .option('--policy', 'the code is for changing an environment\'s policy (with --product --env)')
125
+ .option('--scope <scope>', 'what the code is for, exactly as the server asks')
126
+ .option('--product <tag>').option('--function <name>').option('--fn-version <version>').option('--env <slug>');
127
+ remote('step-up', 'start', 'Email yourself a six-digit code for one change (a person only)', codeTarget).action(op('stepup.start'));
128
+ remote('step-up', 'verify', 'Check the code and print a grant, good for ten minutes and for that one change; put it in an environment variable and pass its name with --grant-env', (c) => codeTarget(c).requiredOption('--code <code>', 'the six-digit code from your email')).action(op('stepup.verify'));
110
129
  remote('plans', 'create', 'Create a plan from a JSON file; nothing is changed', (c) => c.requiredOption('--file <file>', 'Plan request JSON')).action(op('plans.create'));
111
- remote('plans', 'approve <planId>', 'Approve a plan (a person only; refused for agents)').action(op('plans.approve'));
130
+ remote('plans', 'approve <planId>', 'Approve a plan (a person only; refused for agents)', grantOption).action(op('plans.approve'));
131
+ remote('plans', 'list', 'List plans with where each stands: blocked, pending_approval, approved, ready, applied or expired', (c) => c.option('--product <tag>').option('--env <env>').option('--stage <stage>')).action(op('plans.list'));
132
+ remote('plans', 'get <planId>', 'Show one plan: what it would change, its warnings and the state of the cloud it was made from').action(op('plans.get'));
112
133
  remote('plans', 'apply <planId>', 'Apply an approved or permitted plan').action(op('plans.apply'));
113
- remote('deployments', 'list', 'List deployments', (c) => c.option('--product <tag>').option('--env <env>').option('--fn-version <version>')).action(op('deployments.list'));
134
+ remote('deployments', 'list', 'List deployments (functions and services)', (c) => c.option('--product <tag>').option('--env <env>').option('--fn-version <version>').option('--kind <kind>', 'function or service').option('--connection <tag>', 'only what was applied through this cloud connection')).action(op('deployments.list'));
114
135
  remote('deployments', 'get <deploymentId>', 'Show one deployment').action(op('deployments.get'));
115
136
  remote('deployments', 'journal <deploymentId>', 'Show a deployment\'s journal').action(op('deployments.journal'));
116
- remote('functions', 'list', 'List functions with their latest available version', (c) => c.option('--product <tag>')).action(op('functions.list'));
137
+ const planFromDeployment = (c) => c
138
+ .option('--runtime-file <file>', 'Runtime settings JSON that replace the deployment\'s own (cpu, memory, minInstances, maxInstances ...)')
139
+ .option('--observed-file <file>', 'What the provider holds; only while the control plane does not read the provider itself');
140
+ remote('deployments', 'redeploy <deploymentId>', 'Plan running the deployment\'s current release again (retry a failed one); nothing changes until the plan is approved and applied', planFromDeployment).action(op('deployments.redeploy'));
141
+ remote('deployments', 'rollback <deploymentId>', 'Plan putting an earlier release back at full traffic (default: the last one that held all traffic)', (c) => planFromDeployment(c).option('--release-hash <hash>', 'A release this deployment has run')).action(op('deployments.rollback'));
142
+ remote('deployments', 'traffic <deploymentId>', 'Plan a new share of traffic for the current release', (c) => planFromDeployment(c).requiredOption('--percent <n>', 'A whole number from 0 to 100')).action(op('deployments.traffic'));
143
+ remote('environments', 'list', 'List a product\'s environments with how each is governed and what is deployed in it', (c) => c.requiredOption('--product <tag>')).action(op('environments.list'));
144
+ remote('environments', 'policy', 'Set whether applying to an environment needs a person\'s approval (a person only)', (c) => grantOption(c.requiredOption('--product <tag>').requiredOption('--env <slug>').requiredOption('--require-approval <bool>', 'true: a person must approve each plan').requiredOption('--allow-agent-apply <bool>', 'true: an agent may apply without approval (ignored when approval is required)'))).action(op('environments.policy'));
145
+ remote('environments', 'history', 'Show who changed how an environment is governed, and when', (c) => c.requiredOption('--product <tag>').requiredOption('--env <slug>')).action(op('environments.history'));
146
+ remote('functions', 'list', 'List functions and services with their latest available version', (c) => c.option('--product <tag>').option('--kind <kind>', 'function or service')).action(op('functions.list'));
117
147
  const versionTarget = (c) => c.requiredOption('--product <tag>').requiredOption('--function <name>');
118
148
  remote('versions', 'list', 'List the versions of a function', versionTarget).action(op('versions.list'));
119
149
  remote('versions', 'history', 'Show what happened to a version', (c) => versionTarget(c).requiredOption('--fn-version <version>')).action(op('versions.history'));
120
150
  remote('versions', 'deprecate', 'Deprecate a version (existing deployments keep serving)', (c) => versionTarget(c).requiredOption('--fn-version <version>').requiredOption('--reason <text>').option('--sunset <iso-date>').option('--replacement <version>')).action(op('versions.deprecate'));
121
151
  remote('versions', 'undeprecate', 'Make a deprecated version available again', (c) => versionTarget(c).requiredOption('--fn-version <version>')).action(op('versions.undeprecate'));
122
- remote('versions', 'retire', 'Retire a deprecated version that is no longer serving (a person only; final)', (c) => versionTarget(c).requiredOption('--fn-version <version>')).action(op('versions.retire'));
123
- remote('builds', 'create', 'Build source in your own cloud account and register a release from the image', (c) => c.requiredOption('--file <file>', 'Build JSON: productTag, functionName, version, connectionTag, region, contract, config, verification')
152
+ remote('versions', 'retire', 'Retire a deprecated version that is no longer serving (a person only; final)', (c) => grantOption(versionTarget(c).requiredOption('--fn-version <version>'))).action(op('versions.retire'));
153
+ remote('builds', 'create', 'Build source in your own cloud account and register a release from the image', (c) => c.requiredOption('--file <file>', 'Build JSON. A function: product, function, version, connection, region, contract, config, verification. A service: kind "service", product, service, version, connection, region, port, checks, config')
124
154
  .option('--dir <dir>', 'Source directory (default: the current directory)')
125
155
  .option('--builder <builder>', 'dockerfile (default) or buildpacks')
126
156
  .option('--dockerfile <path>', 'Dockerfile inside the source (default: Dockerfile)')
@@ -128,7 +158,8 @@ remote('builds', 'create', 'Build source in your own cloud account and register
128
158
  .option('--wait', 'Wait for the build to finish')
129
159
  .option('--wait-minutes <n>', 'How long --wait waits (default 30)')).action(wrap((options) => runDeployBuilds('create', options)));
130
160
  remote('builds', 'status <buildId>', 'Show a build').action(wrap((...args) => runDeployBuilds('status', { id: args[0] })));
131
- remote('builds', 'list', 'List builds', (c) => c.option('--product <tag>').option('--status <status>')).action(wrap((options) => runDeployBuilds('list', options)));
161
+ remote('builds', 'cancel <buildId>', 'Stop a build that has not finished; a running one is cancelled in your cloud account').action(wrap((...args) => runDeployBuilds('cancel', { id: args[0] })));
162
+ remote('builds', 'list', 'List builds', (c) => c.option('--product <tag>').option('--status <status>').option('--connection <tag>', 'only builds that ran through this cloud connection')).action(wrap((options) => runDeployBuilds('list', options)));
132
163
  program
133
164
  .name('ductape')
134
165
  .description('Ductape CLI — local platform, auth, project linking, and resource CRUD via Workbench-compatible encrypted proxy')
@@ -728,7 +759,7 @@ const apps = program
728
759
  .option('--profile <name>')
729
760
  .option('--status <status>', 'Filter for list', 'all')
730
761
  .option('--id <id>', 'App _id')
731
- .option('-t, --tag <tag>', 'App tag (get; update with --proxy)')
762
+ .option('-t, --tag <tag>', 'App tag (get, delete; update with --proxy)')
732
763
  .option('--proxy', 'Update via sdk-proxy (use with --tag)')
733
764
  .option('-f, --file <path>', 'JSON body')
734
765
  .option('-i, --interactive', 'Prompt for fields (default in TTY when -f omitted)')
@@ -861,23 +892,53 @@ cloud
861
892
  .command('connections <verb> [id]')
862
893
  .description('Cloud connections: guide | create | complete | validate | list | fetch | update | delete. Secrets come from files or environment variables, never from flags.')
863
894
  .option('-f, --file <path>', 'JSON body (flags below override it)')
864
- .option('--provider <name>', 'aws | gcp | azure | mongodb_atlas | neo4j_aura (create, guide)')
895
+ .option('--provider <name>', 'aws | gcp | azure | cloudflare | mongodb_atlas | neo4j_aura (create, guide)')
865
896
  .option('--purpose <purpose>', 'guide: "resources" (default) or "deploy"')
866
897
  .option('--name <name>', 'Display name (create, update)')
867
898
  .option('--tag <tag>', 'Connection tag (create)')
868
899
  .option('--description <text>', 'Description (create, update)')
869
900
  .option('--scopes <list>', 'Comma-separated scopes (create, update)')
870
901
  .option('--auth-mode <mode>', 'iam_role | oauth | service_principal | workload_identity | api_key (create)')
871
- .option('--deploy', 'Add the "deploy" scope so validation checks Ductape Deploy permissions (GCP, create)')
902
+ .option('--deploy', 'Add the "deploy" scope so validation checks Ductape Deploy permissions (GCP, AWS, Azure and Cloudflare, create)')
872
903
  .option('--project-id <id>', 'GCP or Atlas project id (complete)')
873
904
  .option('--service-account-file <path>', 'GCP service account key file; read from disk, never printed (complete)')
874
905
  .option('--runtime-service-account <email>', 'GCP account the deployed services run as (complete)')
875
- .option('--role-arn <arn>', 'AWS IAM role ARN (complete)')
906
+ .option('--role-arn <arn>', 'AWS IAM role ARN Ductape assumes (complete)')
907
+ .option('--runtime-role-arn <arn>', 'AWS role the deployed functions run as (complete)')
908
+ .option('--build-role-arn <arn>', 'AWS role the builds run as (complete)')
909
+ .option('--default-region <region>', 'AWS region used when none is given, such as eu-west-2 (complete)')
910
+ .option('--save-template <file>', 'create, get: write the AWS (CloudFormation) or Azure (deployment) setup template to this file')
911
+ .option('--save-fargate-template <file>', 'create, get: write the AWS Fargate setup stack (CloudFormation) to this file')
912
+ .option('--save-express-template <file>', 'create, get: write the AWS ECS Express Mode stack (CloudFormation) to this file')
913
+ .option('--express-infrastructure-role-arn <arn>', 'AWS ECS Express Mode: the role AWS uses to build the load balancer (complete)')
914
+ .option('--express-outputs-file <file>', 'AWS ECS Express Mode: the saved output of `aws cloudformation describe-stacks --stack-name ductape-ecs-express` (complete)')
915
+ .option('--fargate-outputs-file <file>', 'AWS Fargate: the saved output of `aws cloudformation describe-stacks --stack-name ductape-fargate` (complete)')
916
+ .option('--fargate-cluster <name>', 'AWS Fargate: ECS cluster name (complete)')
917
+ .option('--fargate-listener-arn <arn>', 'AWS Fargate: ARN of the HTTPS listener of the load balancer (complete)')
918
+ .option('--fargate-base-domain <domain>', 'AWS Fargate: the domain every deployment is a name under, such as deploy.example.com (complete)')
919
+ .option('--fargate-vpc-id <id>', 'AWS Fargate: VPC id (complete)')
920
+ .option('--fargate-subnets <list>', 'AWS Fargate: comma-separated subnet ids (complete)')
921
+ .option('--fargate-security-groups <list>', 'AWS Fargate: comma-separated security group ids for the tasks (complete)')
922
+ .option('--fargate-task-role-arn <arn>', 'AWS Fargate: role the tasks run as (complete)')
923
+ .option('--fargate-execution-role-arn <arn>', 'AWS Fargate: role ECS uses to pull images and read secrets (complete)')
924
+ .option('--fargate-log-group <name>', 'AWS Fargate: CloudWatch log group for the tasks (complete)')
925
+ .option('--fargate-scale-down-idle <on|off>', 'AWS Fargate: scale releases that no longer serve to zero tasks, never deleting them (complete)')
926
+ .option('--fargate-internal <on|off>', 'AWS Fargate: the load balancer is internal, so releases are checked through the relay function (complete)')
927
+ .option('--fargate-verifier-function <name>', 'AWS Fargate: the relay function inside your network, the stack output VerifierFunctionName (complete)')
928
+ .option('--fargate-private-tasks', 'AWS Fargate: tasks run in private subnets with no public address (complete)')
876
929
  .option('--tenant-id <id>', 'Azure tenant id (complete)')
877
930
  .option('--subscription-id <id>', 'Azure subscription id (complete)')
878
931
  .option('--client-id <id>', 'Azure client id (complete)')
879
932
  .option('--client-secret-env <VAR>', 'Name of the environment variable holding the Azure client secret (complete)')
880
933
  .option('--default-location <region>', 'Azure default location (complete)')
934
+ .option('--account-id <id>', 'Cloudflare account id, 32 characters (complete)')
935
+ .option('--secrets-store-id <id>', 'Cloudflare Secrets Store that { secret: NAME } references are bound from (complete)')
936
+ .option('--api-token-env <VAR>', 'Name of the environment variable holding the Cloudflare API token (complete)')
937
+ .option('--resource-group <name>', 'Azure resource group Ductape Deploy works in (complete)')
938
+ .option('--registry-name <name>', 'Azure container registry from the setup template (complete)')
939
+ .option('--runtime-identity-id <id>', 'Azure user assigned identity id the apps run as (complete)')
940
+ .option('--key-vault-uri <uri>', 'Azure Key Vault that { secret: NAME } references are read from by the app\'s identity (complete)')
941
+ .option('--environment-name <name>', 'Azure container apps environment from the setup template (complete)')
881
942
  .option('--atlas-public-key <key>', 'Atlas API public key (complete)')
882
943
  .option('--atlas-private-key-env <VAR>', 'Name of the environment variable holding the Atlas private key (complete)')
883
944
  .option('--aura-client-id <id>', 'Aura client id (complete)')
@@ -885,11 +946,12 @@ cloud
885
946
  .option('--aura-instance-id <id>', 'Aura instance id (complete)')
886
947
  .option('--dry-run', 'create, complete, update: print the request that would be sent, with secrets masked, and contact nothing')
887
948
  .option('--json', 'JSON output')
888
- .action(wrap((verb, id, opts) => runCloud('connections', verb, { id, file: opts.file, json: opts.json, purpose: opts.purpose, dryRun: Boolean(opts.dryRun), connection: {
949
+ .action(wrap((verb, id, opts) => runCloud('connections', verb, { id, file: opts.file, json: opts.json, purpose: opts.purpose, saveTemplate: opts.saveTemplate, saveFargateTemplate: opts.saveFargateTemplate, saveExpressTemplate: opts.saveExpressTemplate, dryRun: Boolean(opts.dryRun), connection: {
889
950
  provider: opts.provider, name: opts.name, tag: opts.tag, description: opts.description, scopes: opts.scopes, authMode: opts.authMode,
890
951
  deploy: opts.deploy, projectId: opts.projectId, serviceAccountFile: opts.serviceAccountFile, runtimeServiceAccount: opts.runtimeServiceAccount,
891
- roleArn: opts.roleArn, tenantId: opts.tenantId, subscriptionId: opts.subscriptionId, clientId: opts.clientId, clientSecretEnv: opts.clientSecretEnv,
892
- defaultLocation: opts.defaultLocation, atlasPublicKey: opts.atlasPublicKey, atlasPrivateKeyEnv: opts.atlasPrivateKeyEnv,
952
+ fargateOutputsFile: opts.fargateOutputsFile, fargateInternal: opts.fargateInternal, fargateVerifierFunction: opts.fargateVerifierFunction, fargateCluster: opts.fargateCluster, fargateListenerArn: opts.fargateListenerArn, fargateBaseDomain: opts.fargateBaseDomain, fargateVpcId: opts.fargateVpcId, fargateSubnets: opts.fargateSubnets, fargateSecurityGroups: opts.fargateSecurityGroups, fargateTaskRoleArn: opts.fargateTaskRoleArn, fargateExecutionRoleArn: opts.fargateExecutionRoleArn, fargateLogGroup: opts.fargateLogGroup, fargatePrivateTasks: opts.fargatePrivateTasks, fargateScaleDownIdle: opts.fargateScaleDownIdle, expressInfrastructureRoleArn: opts.expressInfrastructureRoleArn, expressOutputsFile: opts.expressOutputsFile,
953
+ roleArn: opts.roleArn, runtimeRoleArn: opts.runtimeRoleArn, buildRoleArn: opts.buildRoleArn, defaultRegion: opts.defaultRegion, tenantId: opts.tenantId, subscriptionId: opts.subscriptionId, clientId: opts.clientId, clientSecretEnv: opts.clientSecretEnv,
954
+ defaultLocation: opts.defaultLocation, accountId: opts.accountId, apiTokenEnv: opts.apiTokenEnv, secretsStoreId: opts.secretsStoreId, resourceGroup: opts.resourceGroup, registryName: opts.registryName, runtimeIdentityId: opts.runtimeIdentityId, environmentName: opts.environmentName, keyVaultUri: opts.keyVaultUri, atlasPublicKey: opts.atlasPublicKey, atlasPrivateKeyEnv: opts.atlasPrivateKeyEnv,
893
955
  auraClientId: opts.auraClientId, auraClientSecretEnv: opts.auraClientSecretEnv, auraInstanceId: opts.auraInstanceId,
894
956
  } }, [])));
895
957
  cloud
@@ -1107,6 +1169,25 @@ program
1107
1169
  description: opts.description,
1108
1170
  json: Boolean(opts.json),
1109
1171
  })));
1172
+ program
1173
+ .command('secrets-scan-env')
1174
+ .description('Scan a project\'s .env file, find the secrets in it, and save them to the workspace (preview unless --apply; values are never printed)')
1175
+ .option('--env-file <path>', 'The file to read (default: .env in the project folder)')
1176
+ .option('--dir <path>', 'The project folder (default: the current folder)')
1177
+ .option('--env <slug>', 'Limit the saved secrets to this environment (default: every environment)')
1178
+ .option('--all', 'Save every variable that has a real value, not only the ones that look like secrets')
1179
+ .option('--only <names>', 'Save exactly these variables (comma separated), whatever they look like')
1180
+ .option('--exclude <names>', 'Never save these variables (comma separated)')
1181
+ .option('--prefix <text>', 'Put this in front of each name to make the secret\'s key')
1182
+ .option('--overwrite', 'Replace a secret the workspace already has (default: leave it)')
1183
+ .option('--apply', 'Save them. Without it nothing is saved and the result says what would be')
1184
+ .option('--json', 'JSON output (names, decisions and lengths only)')
1185
+ .action(wrap((opts) => runSecretsScanEnv({
1186
+ envFile: opts.envFile, dir: opts.dir, env: opts.env, all: Boolean(opts.all), overwrite: Boolean(opts.overwrite), apply: Boolean(opts.apply), prefix: opts.prefix,
1187
+ only: opts.only ? String(opts.only).split(',').map((s) => s.trim()).filter(Boolean) : undefined,
1188
+ exclude: opts.exclude ? String(opts.exclude).split(',').map((s) => s.trim()).filter(Boolean) : undefined,
1189
+ json: Boolean(opts.json),
1190
+ })));
1110
1191
  const generate = program.command('generate').description('Payload templates & code snippets');
1111
1192
  generate
1112
1193
  .command('payload <family> <method>')
@@ -13,8 +13,10 @@ export class ApiClient {
13
13
  }
14
14
  async request(method, path, body, extraHeaders) {
15
15
  const url = `${this.apiUrl}${path.startsWith('/') ? path : `/${path}`}`;
16
+ // Bytes (a Worker bundle) are sent as they are; everything else is JSON.
17
+ const raw = body instanceof Uint8Array;
16
18
  const headers = {
17
- 'Content-Type': 'application/json',
19
+ 'Content-Type': raw ? 'application/octet-stream' : 'application/json',
18
20
  ...extraHeaders,
19
21
  };
20
22
  if (this.token) {
@@ -25,7 +27,7 @@ export class ApiClient {
25
27
  res = await fetch(url, {
26
28
  method,
27
29
  headers,
28
- body: body !== undefined ? JSON.stringify(body) : undefined,
30
+ body: body === undefined ? undefined : raw ? body : JSON.stringify(body),
29
31
  });
30
32
  }
31
33
  catch (cause) {
@@ -1,4 +1,4 @@
1
- export declare const CLOUD_PROVIDERS: readonly ["aws", "gcp", "azure", "mongodb_atlas", "neo4j_aura"];
1
+ export declare const CLOUD_PROVIDERS: readonly ["aws", "gcp", "azure", "cloudflare", "mongodb_atlas", "neo4j_aura"];
2
2
  export type CloudProviderName = (typeof CLOUD_PROVIDERS)[number];
3
3
  export type GuidePurpose = 'resources' | 'deploy';
4
4
  export interface IConnectionFlags {
@@ -13,11 +13,45 @@ export interface IConnectionFlags {
13
13
  serviceAccountFile?: string;
14
14
  runtimeServiceAccount?: string;
15
15
  roleArn?: string;
16
+ runtimeRoleArn?: string;
17
+ buildRoleArn?: string;
18
+ defaultRegion?: string;
19
+ /** The outputs of the ductape-fargate stack as saved by `aws cloudformation describe-stacks`, read from a file; the individual flags below win over it. */
20
+ fargateOutputsFile?: string;
21
+ fargateCluster?: string;
22
+ fargateListenerArn?: string;
23
+ fargateBaseDomain?: string;
24
+ fargateVpcId?: string;
25
+ fargateSubnets?: string;
26
+ fargateSecurityGroups?: string;
27
+ fargateTaskRoleArn?: string;
28
+ fargateExecutionRoleArn?: string;
29
+ fargateLogGroup?: string;
30
+ fargatePrivateTasks?: boolean;
31
+ /** `on` or `off`: scale releases that no longer serve to zero tasks (never deleted). */
32
+ fargateScaleDownIdle?: string;
33
+ /** `on` or `off`: the load balancer is internal, so releases are checked from inside the network through the relay function. */
34
+ fargateInternal?: string;
35
+ /** The relay function (the ductape-fargate stack's VerifierFunctionName output). Needed when the load balancer is internal. */
36
+ fargateVerifierFunction?: string;
37
+ /** ECS Express Mode: the role AWS uses to build the load balancer (the ductape-ecs-express stack's InfrastructureRoleArn output). */
38
+ expressInfrastructureRoleArn?: string;
39
+ /** The saved output of `aws cloudformation describe-stacks --stack-name ductape-ecs-express`. */
40
+ expressOutputsFile?: string;
16
41
  tenantId?: string;
17
42
  subscriptionId?: string;
18
43
  clientId?: string;
19
44
  clientSecretEnv?: string;
20
45
  defaultLocation?: string;
46
+ resourceGroup?: string;
47
+ registryName?: string;
48
+ runtimeIdentityId?: string;
49
+ environmentName?: string;
50
+ keyVaultUri?: string;
51
+ accountId?: string;
52
+ apiTokenEnv?: string;
53
+ /** Cloudflare Secrets Store that { secret: NAME } references are bound from; empty clears it. */
54
+ secretsStoreId?: string;
21
55
  atlasPublicKey?: string;
22
56
  atlasPrivateKeyEnv?: string;
23
57
  auraClientId?: string;
@@ -29,6 +63,11 @@ export interface IConnectionIo {
29
63
  env: Record<string, string | undefined>;
30
64
  }
31
65
  export declare const realIo: IConnectionIo;
66
+ /**
67
+ * The Fargate fields of a connection: from the saved outputs of the setup stack, then any individual flag on top. Accepts what
68
+ * `aws cloudformation describe-stacks --stack-name ductape-fargate` prints, the bare list of outputs, or a plain object of them.
69
+ */
70
+ export declare function fargateFields(flags: IConnectionFlags, io: IConnectionIo): Record<string, unknown>;
32
71
  /**
33
72
  * Builds the request body for `ductape cloud connections <verb>` from flags, on top of any body read from a file. Flags win.
34
73
  * Nothing secret is accepted as a flag value.
@@ -41,6 +80,11 @@ export interface IGuideStep {
41
80
  title: string;
42
81
  commands?: string[];
43
82
  notes?: string[];
83
+ /** Console pages that do the step without a terminal. */
84
+ links?: Array<{
85
+ label: string;
86
+ url: string;
87
+ }>;
44
88
  }
45
89
  export interface IConnectionGuide {
46
90
  provider: CloudProviderName;
@@ -57,11 +101,76 @@ export interface IConnectionGuide {
57
101
  }>;
58
102
  apis: string[];
59
103
  };
104
+ /** What a deploy connection will make in the customer's project, so nothing is a surprise. */
105
+ creates?: string[];
106
+ /** Errors people meet during setup, and what fixes each. */
107
+ troubleshooting?: Array<{
108
+ problem: string;
109
+ fix: string;
110
+ }>;
111
+ /** An optional second path on the same connection, such as Fargate on top of Lambda. */
112
+ optional?: Array<{
113
+ title: string;
114
+ summary: string;
115
+ steps: IGuideStep[];
116
+ creates: string[];
117
+ limits: string[];
118
+ troubleshooting: Array<{
119
+ problem: string;
120
+ fix: string;
121
+ }>;
122
+ }>;
123
+ /** What to do once the connection is active. */
124
+ next?: string[];
60
125
  }
61
126
  export declare const GCP_DEPLOY_ROLE_LIST: {
62
127
  role: string;
63
128
  for: string;
64
129
  }[];
130
+ /** Everything a deploy through a GCP connection leaves in the customer's project. All of it is labelled as Ductape's. */
131
+ export declare const GCP_DEPLOY_CREATES: string[];
132
+ export declare const GCP_DEPLOY_SAFETY = "Ductape only adds resources it labels as its own (ductape_managed), never changes or reuses one it did not create, and never deletes anything, including what it created. Removing deployed resources is always your own action. Use a dedicated project if you can, so what Ductape adds is easy to see.";
133
+ export declare const GCP_DEPLOY_TROUBLESHOOTING: {
134
+ problem: string;
135
+ fix: string;
136
+ }[];
137
+ export declare const AWS_DEPLOY_ROLE_LIST: {
138
+ role: string;
139
+ for: string;
140
+ }[];
141
+ export declare const AWS_DEPLOY_CREATES: string[];
142
+ export declare const AWS_DEPLOY_SAFETY = "Ductape only adds resources it tags as its own (ductape_managed), never changes or reuses one it did not create, and never deletes anything, including what it created. Removing deployed resources is always your own action. Use a dedicated account if you can, so what Ductape adds is easy to see.";
143
+ export declare const AWS_DEPLOY_TROUBLESHOOTING: {
144
+ problem: string;
145
+ fix: string;
146
+ }[];
147
+ /**
148
+ * Extra steps for a connection that also deploys to AWS Fargate. Lambda needs none of this; Fargate runs your containers behind a load balancer
149
+ * in your account, so it needs a cluster, a certificate for a domain you own, and the permissions to manage them.
150
+ */
151
+ export declare const AWS_FARGATE_OPTIONAL: NonNullable<IConnectionGuide['optional']>[number];
152
+ /** Extra steps for a connection that also deploys to ECS Express Mode. It builds on the Fargate stack and changes what is guaranteed, which the steps say plainly. */
153
+ export declare const AWS_EXPRESS_OPTIONAL: NonNullable<IConnectionGuide['optional']>[number];
154
+ export declare const AZURE_DEPLOY_ROLE_LIST: {
155
+ role: string;
156
+ for: string;
157
+ }[];
158
+ export declare const AZURE_DEPLOY_CREATES: string[];
159
+ export declare const AZURE_DEPLOY_SAFETY = "Ductape only adds resources it tags as its own (ductape_managed), never changes or reuses one it did not create, and never deletes anything, including what it created. It never registers resource providers or changes anything outside the one resource group. Removing deployed resources is always your own action.";
160
+ export declare const AZURE_DEPLOY_TROUBLESHOOTING: {
161
+ problem: string;
162
+ fix: string;
163
+ }[];
164
+ export declare const CLOUDFLARE_DEPLOY_ROLE_LIST: {
165
+ role: string;
166
+ for: string;
167
+ }[];
168
+ export declare const CLOUDFLARE_DEPLOY_CREATES: string[];
169
+ export declare const CLOUDFLARE_DEPLOY_SAFETY = "Ductape only adds resources it tags as its own (ductape_managed), never changes or reuses one it did not create, and never deletes anything, including what it created. Removing deployed Workers is always your own action. A Worker has no cloud-level access check in front of it: the function's own signature check, which every call must pass, is the access control. Only functions can run on Workers, not services, and only TypeScript functions.";
170
+ export declare const CLOUDFLARE_DEPLOY_TROUBLESHOOTING: {
171
+ problem: string;
172
+ fix: string;
173
+ }[];
65
174
  export declare const GCP_DEPLOY_APIS: string[];
66
175
  export declare function connectionGuide(providerInput: string, purposeInput?: string): IConnectionGuide;
67
176
  /** A copy of a request body that is safe to print: secrets and key material are replaced, everything else is kept. */