Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCC-1337, PCC-1461 Add delete site command. More human-friendly 404 message for admin commands #284

Merged
merged 4 commits into from
Jul 9, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/tough-zebras-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pantheon-systems/pcc-cli": minor
---

New command: site delete.
3 changes: 2 additions & 1 deletion packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
### Patch Changes

- 0c75736: CLI replaces "--version" command with "version"
- 1fd7c4d: Added support for setting preferred webhook events. Webhook notifications will only be sent on events matching preferred events
- 1fd7c4d: Added support for setting preferred webhook events. Webhook
notifications will only be sent on events matching preferred events
- Updated dependencies [183ad17]
- @pantheon-systems/[email protected]

Expand Down
15 changes: 15 additions & 0 deletions packages/cli/src/cli/commands/sites/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ export const createSite = errorHandler<string>(async (url: string) => {
}
});

export const deleteSite = errorHandler<{
id: string;
transferToSiteId: string | null | undefined;
force: boolean;
}>(async ({ id, transferToSiteId, force }) => {
const spinner = ora("Deleting site...").start();
try {
const siteId = await AddOnApiHelper.deleteSite(id, transferToSiteId, force);
spinner.succeed(`Successfully deleted the site with id "${siteId}"`);
} catch (e) {
spinner.fail();
throw e;
}
});

export const listSites = errorHandler<{
withStatus?: boolean;
}>(async ({ withStatus }) => {
Expand Down
30 changes: 30 additions & 0 deletions packages/cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
import {
configurableSiteProperties,
createSite,
deleteSite,
listSites,
SITE_EXAMPLES,
updateSiteConfig,
Expand Down Expand Up @@ -379,6 +380,35 @@ yargs(hideBin(process.argv))
},
async (args) => await createSite(args.url as string),
)
.command(
"create [options]",
"Delete site.",
(yargs) => {
yargs.option("id", {
describe: "Site id",
type: "string",
demandOption: true,
});
yargs.option("transferToSiteId", {
describe:
"Id of site to transfer connected documents to. Required if force is not used.",
type: "string",
demandOption: false,
});
yargs.option("force", {
describe:
"If true, delete even if documents are connected to it.",
type: "string",
demandOption: false,
});
},
async (args) =>
await deleteSite({
id: args.id as string,
transferToSiteId: args.transferToSiteId as string,
force: args.force === "true",
}),
)
.command(
"componentschema [command] [options]",
"Make changes & inspect the component schema for a site",
Expand Down
25 changes: 25 additions & 0 deletions packages/cli/src/lib/addonApiHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SmartComponentMapZod } from "@pantheon-systems/pcc-sdk-core/types";
import axios, { AxiosError, HttpStatusCode } from "axios";
import { Credentials } from "google-auth-library";
import ora from "ora";
import queryString from "query-string";
import login from "../cli/commands/login";
import { HTTPNotFound, UserNotLoggedIn } from "../cli/exceptions";
import { getApiConfig } from "./apiConfig";
Expand Down Expand Up @@ -290,6 +291,30 @@ class AddOnApiHelper {
return resp.data.id as string;
}

static async deleteSite(
id: string,
transferToSiteId: string | null | undefined,
force: boolean,
): Promise<string> {
const idToken = await this.getIdToken();

const resp = await axios.delete(
queryString.stringifyUrl({
url: `${(await getApiConfig()).SITE_ENDPOINT}/${id}`,
query: {
transferToSiteId,
force,
},
}),
{
headers: {
Authorization: `Bearer ${idToken}`,
},
},
);
return resp.data.id as string;
}

static async listSites({
withConnectionStatus,
}: {
Expand Down
Loading