Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 163 additions & 25 deletions docs/commands.md

Large diffs are not rendered by default.

110 changes: 69 additions & 41 deletions docs/errors.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions scripts/check-pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ if (result.status !== 0) {
"src/cli.js",
"src/commands/account.js",
"src/commands/compilation.js",
"src/commands/host-command.js",
"src/commands/host.js",
"src/commands/login.js",
"src/commands/logout.js",
"src/commands/note.js",
Expand All @@ -56,6 +58,7 @@ if (result.status !== 0) {
"src/compilation-artifact.js",
"src/credentials.js",
"src/file-system.js",
"src/host-tools.js",
"src/oauth.js",
"src/plan-compile-progress.js",
"src/plan-state.js",
Expand Down
19 changes: 19 additions & 0 deletions scripts/smoke-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,25 @@ try {
"Invalid arguments. Run 'firstdraft compilation cancel --help' for usage.",
});

const invalidHost = spawnPackedCli(
["host", "status", "--canary-secret-option"],
installationDirectory,
);
assertHandledFailure(invalidHost, 2, {
error: "invalid_arguments",
detail: "Invalid arguments. Run 'firstdraft host status --help' for usage.",
});

const unconfirmedDestroy = spawnPackedCli(
["host", "destroy"],
installationDirectory,
);
assertHandledFailure(unconfirmedDestroy, 2, {
error: "confirmation_required",
detail:
"Destroying removes the Droplet and its data. Ask the owner, suggest a database export first, then pass --confirm production. Nothing was sent.",
});

const invalidAccount = spawnPackedCli(
["account", "--canary-secret-option"],
installationDirectory,
Expand Down
44 changes: 44 additions & 0 deletions src/api-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,50 @@ export const SERVICE_ROUTES = {
method: "POST",
path: "/v1/projects/{project_id}/notes",
},
createHost: {
method: "POST",
path: "/v1/projects/{project_id}/environments/{environment_name}/host",
},
readHost: {
method: "GET",
path: "/v1/projects/{project_id}/environments/{environment_name}/host",
},
resizeHost: {
method: "PATCH",
path: "/v1/projects/{project_id}/environments/{environment_name}/host",
},
destroyHost: {
method: "DELETE",
path: "/v1/projects/{project_id}/environments/{environment_name}/host",
},
readBackups: {
method: "GET",
path: "/v1/projects/{project_id}/environments/{environment_name}/host/backups",
},
connectDomain: {
method: "PUT",
path: "/v1/projects/{project_id}/environments/{environment_name}/host/domain",
},
readDomain: {
method: "GET",
path: "/v1/projects/{project_id}/environments/{environment_name}/host/domain",
},
checkDomain: {
method: "POST",
path: "/v1/projects/{project_id}/environments/{environment_name}/host/domain/check",
},
disconnectDomain: {
method: "DELETE",
path: "/v1/projects/{project_id}/environments/{environment_name}/host/domain",
},
readEmail: {
method: "GET",
path: "/v1/projects/{project_id}/environments/{environment_name}/host/email",
},
createSmtpCredentials: {
method: "POST",
path: "/v1/projects/{project_id}/environments/{environment_name}/host/email/smtp-credentials",
},
requestOAuthToken: {
method: "POST",
path: "/oauth/token",
Expand Down
44 changes: 44 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import {
resolveLoginOrigin,
startDeviceLogin,
} from "./commands/login.js";
import { runHost } from "./commands/host-command.js";
import { LogoutFailedError, logout } from "./commands/logout.js";
import { initializePlan } from "./commands/plan-init.js";
import {
Expand Down Expand Up @@ -162,6 +163,7 @@ Commands:
account Show whether this account sends reports
compilation Inspect, download, and cancel Compilations
generate Generate local values
host Create and operate the application's First Draft host
login Log in to First Draft and save a token
logout Revoke and remove the saved token
note Send a note about a problem with First Draft
Expand Down Expand Up @@ -868,6 +870,9 @@ const PINNED_NOT_PUSHED_DETAIL =
* @property {() => number} [loginNow]
* @property {import("./oauth.js").StartLoopbackServer} [startLoopbackServer]
* @property {() => number} [serviceNow] the clock for a limit's retry time
* @property {import("./host-tools.js").ToolRunner} [hostTools] runs gh, ssh-keygen, and ssh
* @property {(ms: number) => Promise<void>} [hostSleep]
* @property {() => number} [hostNow]
*/

/**
Expand Down Expand Up @@ -967,6 +972,9 @@ export async function run({
loginNow,
startLoopbackServer,
serviceNow,
hostTools,
hostSleep,
hostNow,
}) {
const staging = argv[0] === "--staging";
if (staging) argv = argv.slice(1);
Expand Down Expand Up @@ -1099,6 +1107,42 @@ export async function run({
});
}

if (argv[0] === "host") {
const directory = cwd ?? getCwd();
return runHost({
argv: argv.slice(1),
stdout,
stderr,
cwd: directory,
credentials,
fetchFunction,
createRequestSignal,
hostTools,
hostSleep,
hostNow,
shared: {
authenticate: (stagingOption) =>
authenticatePinnedProject({
argv,
stdout,
stderr,
cwd: directory,
getCwd,
fetchFunction,
credentials,
apiUrl,
apiToken,
stagingApiToken,
staging: staging || stagingOption === true,
service,
}),
writeSharedError: writePinnedProjectError,
writeAuthenticationRequired,
settle: (promise) => service.settle(promise),
},
});
}

return runRoot({ argv, stdout, stderr });
}

Expand Down
Loading
Loading