-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
432 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/cli/src/commands/widget/version/delete/VersionDeleteArgs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2023 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { CommonWidgetArgs } from "../../CommonWidgetArgs.js"; | ||
|
||
export interface VersionDeleteArgs extends CommonWidgetArgs { | ||
version: string; | ||
yes?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2023 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { CommandModule } from "yargs"; | ||
import type { CommonWidgetArgs } from "../../CommonWidgetArgs.js"; | ||
import type { VersionDeleteArgs } from "./VersionDeleteArgs.js"; | ||
|
||
const command: CommandModule< | ||
CommonWidgetArgs, | ||
VersionDeleteArgs | ||
> = { | ||
command: "delete <version>", | ||
describe: "Delete widget version", | ||
builder: (argv) => { | ||
return argv | ||
.positional("version", { | ||
type: "string", | ||
demandOption: true, | ||
description: "Version to delete", | ||
}) | ||
.option("yes", { | ||
alias: "y", | ||
type: "boolean", | ||
description: "Automatically confirm destructive changes", | ||
}) | ||
.group(["yes"], "Delete Options"); | ||
}, | ||
handler: async (args) => { | ||
const command = await import("./versionDeleteCommand.mjs"); | ||
await command.default(args); | ||
}, | ||
}; | ||
|
||
export default command; |
85 changes: 85 additions & 0 deletions
85
packages/cli/src/commands/widget/version/delete/versionDeleteCommand.mts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright 2023 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { createInternalClientContext } from "#net"; | ||
import { consola } from "consola"; | ||
import { colorize } from "consola/utils"; | ||
import { handlePromptCancel } from "../../../../consola/handlePromptCancel.js"; | ||
import { createFetch } from "../../../../net/createFetch.mjs"; | ||
import type { InternalClientContext } from "../../../../net/internalClientContext.mjs"; | ||
import type { WidgetRid } from "../../../../net/WidgetRid.js"; | ||
import { loadToken } from "../../../../util/token.js"; | ||
import type { VersionDeleteArgs } from "./VersionDeleteArgs.js"; | ||
|
||
export default async function versionDeleteCommand( | ||
{ version, yes, rid, foundryUrl, token, tokenFile }: VersionDeleteArgs, | ||
) { | ||
if (!yes) { | ||
const confirmed = await consola.prompt( | ||
`Are you sure you want to delete the version ${version}?\n${ | ||
colorize("bold", "This action cannot be undone.") | ||
}`, | ||
{ type: "confirm" }, | ||
); | ||
handlePromptCancel(confirmed); | ||
} | ||
|
||
consola.start(`Deleting version ${version}`); | ||
const loadedToken = await loadToken(token, tokenFile); | ||
const tokenProvider = () => loadedToken; | ||
const clientCtx = createInternalClientContext(foundryUrl, tokenProvider); | ||
// TODO: Look at type of locator and decide whether to confirm delete site version | ||
await Promise.all([ | ||
deleteViewRelease(clientCtx, rid, version), | ||
deleteVersion(clientCtx, rid, version), | ||
]); | ||
consola.success(`Deleted version ${version}`); | ||
} | ||
|
||
async function deleteViewRelease( | ||
ctx: InternalClientContext, | ||
// TODO: make repository rid | ||
widgetRid: WidgetRid, | ||
version: string, | ||
): Promise<void> { | ||
const fetch = createFetch(ctx.tokenProvider); | ||
const url = | ||
`${ctx.foundryUrl}/view-registry/api/views/${widgetRid}/releases/${version}`; | ||
await fetch( | ||
url, | ||
{ | ||
method: "DELETE", | ||
}, | ||
); | ||
} | ||
|
||
async function deleteVersion( | ||
ctx: InternalClientContext, | ||
// TODO: make repository rid | ||
widgetRid: WidgetRid, | ||
version: string, | ||
): Promise<void> { | ||
const fetch = createFetch(ctx.tokenProvider); | ||
const url = | ||
`${ctx.foundryUrl}/artifacts/api/repositories/${widgetRid}/contents/release/siteasset/versions/${version}`; | ||
|
||
await fetch( | ||
url, | ||
{ | ||
method: "DELETE", | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2023 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { CommandModule } from "yargs"; | ||
import type { CommonWidgetArgs } from "../CommonWidgetArgs.js"; | ||
import deleteCmd from "./delete/index.js"; | ||
import info from "./info/index.js"; | ||
import list from "./list/index.js"; | ||
|
||
const command: CommandModule< | ||
CommonWidgetArgs, | ||
CommonWidgetArgs | ||
> = { | ||
command: "version", | ||
describe: "Manage widget versions", | ||
builder: (argv) => { | ||
return argv | ||
.command(list) | ||
.command(info) | ||
.command(deleteCmd) | ||
.demandCommand(); | ||
}, | ||
handler: async (args) => {}, | ||
}; | ||
|
||
export default command; |
21 changes: 21 additions & 0 deletions
21
packages/cli/src/commands/widget/version/info/VersionInfoArgs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright 2023 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { CommonWidgetArgs } from "../../CommonWidgetArgs.js"; | ||
|
||
export interface VersionInfoArgs extends CommonWidgetArgs { | ||
version: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2023 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { CommandModule } from "yargs"; | ||
import type { CommonWidgetArgs } from "../../CommonWidgetArgs.js"; | ||
import type { VersionInfoArgs } from "./VersionInfoArgs.js"; | ||
|
||
const command: CommandModule< | ||
CommonWidgetArgs, | ||
VersionInfoArgs | ||
> = { | ||
command: "info <version>", | ||
describe: "Load info about widget version", | ||
builder: (argv) => { | ||
return argv | ||
.positional("version", { | ||
type: "string", | ||
demandOption: true, | ||
description: "Version to load", | ||
}); | ||
}, | ||
handler: async (args) => { | ||
const command = await import("./versionInfoCommand.mjs"); | ||
await command.default(args); | ||
}, | ||
}; | ||
|
||
export default command; |
48 changes: 48 additions & 0 deletions
48
packages/cli/src/commands/widget/version/info/versionInfoCommand.mts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2023 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { createInternalClientContext } from "#net"; | ||
import { consola } from "consola"; | ||
import { createFetch } from "../../../../net/createFetch.mjs"; | ||
import type { InternalClientContext } from "../../../../net/internalClientContext.mjs"; | ||
import type { WidgetRid } from "../../../../net/WidgetRid.js"; | ||
import { loadToken } from "../../../../util/token.js"; | ||
import type { VersionInfoArgs } from "./VersionInfoArgs.js"; | ||
|
||
export default async function versionInfoCommand( | ||
{ version, foundryUrl, rid, token, tokenFile }: VersionInfoArgs, | ||
) { | ||
const loadedToken = await loadToken(token, tokenFile); | ||
const tokenProvider = () => loadedToken; | ||
const clientCtx = createInternalClientContext(foundryUrl, tokenProvider); | ||
consola.start("Loading version info"); | ||
const response = await getViewRelease(clientCtx, rid, version); | ||
consola.success(`Loaded version info for ${version}`); | ||
consola.log(JSON.stringify(response, null, 2)); | ||
} | ||
|
||
async function getViewRelease( | ||
ctx: InternalClientContext, | ||
// TODO: make repository rid | ||
widgetRid: WidgetRid, | ||
version: string, | ||
): Promise<any> { | ||
const fetch = createFetch(ctx.tokenProvider); | ||
const url = | ||
`${ctx.foundryUrl}/view-registry/api/views/${widgetRid}/releases/${version}`; | ||
const response = await fetch(url); | ||
return response.json(); | ||
} |
Oops, something went wrong.