-
Notifications
You must be signed in to change notification settings - Fork 0
TA-5049 add content-cli options to list staging variables #325
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
base: main
Are you sure you want to change the base?
Changes from all commits
63eeb6c
a75ec90
57353d2
6608079
c29e6ef
829ddf6
dd38c50
b8d3398
f959483
0c56546
6323acc
ac8c6e9
ccb3f3d
28b0462
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { Context } from "../../../core/command/cli-context"; | ||
| import { FatalError } from "../../../core/utils/logger"; | ||
| import { HttpClient } from "../../../core/http/http-client"; | ||
| import { StagingVariableManifestTransport } from "../interfaces/package-export.interfaces"; | ||
|
|
||
| export class StagingPackageVariablesApi { | ||
| private readonly httpClient: () => HttpClient; | ||
|
|
||
| constructor(context: Context) { | ||
| this.httpClient = () => context.httpClient; | ||
| } | ||
|
|
||
| public async findAllByPackageKeys(packageKeys: string[]): Promise<StagingVariableManifestTransport[]> { | ||
| const path = `/pacman/api/core/staging/packages/variables/by-package-keys`; | ||
| return await this.httpClient() | ||
| .post(path, packageKeys) | ||
| .catch(e => { | ||
| throw new FatalError(`Problem listing staging variables for packages: ${e}`); | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,9 +87,10 @@ class Module extends IModule { | |
| .description("Commands related to variable configs"); | ||
|
|
||
| variablesCommand.command("list") | ||
| .description("Command to list versioned variables of packages") | ||
| .description("List package variables: use --packageKeys for staging (unpublished), or --keysByVersion / --keysByVersionFile for versioned packages") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We try to not use the "published" word as much as we can now, since it's an old term. Let's go with unversioned instead. |
||
| .option("--json", "Return response as json type", "") | ||
| .option("--keysByVersion <keysByVersion...>", "Mapping of package keys and versions", "") | ||
| .option("--packageKeys <packageKeys...>", "Package keys (staging variables only; mutually exclusive with versioned options)", []) | ||
| .option("--keysByVersion <keysByVersion...>", "Mapping of package keys and versions", []) | ||
| .option("--keysByVersionFile <keysByVersionFile>", "Package keys by version mappings file path.", "") | ||
| .action(this.listVariables); | ||
|
|
||
|
|
@@ -203,7 +204,27 @@ class Module extends IModule { | |
| } | ||
|
|
||
| private async listVariables(context: Context, command: Command, options: OptionValues): Promise<void> { | ||
| await new ConfigCommandService(context).listVariables(options.json, options.keysByVersion, options.keysByVersionFile); | ||
| const hasStagingKeys = options.packageKeys.length > 0; | ||
| const hasVersioned = | ||
| options.keysByVersion.length > 0 || options.keysByVersionFile !== ""; | ||
|
|
||
| if (hasStagingKeys && hasVersioned) { | ||
| throw new Error( | ||
| "Please provide either --packageKeys or --keysByVersion/--keysByVersionFile, but not both." | ||
| ); | ||
| } | ||
| if (!hasStagingKeys && !hasVersioned) { | ||
| throw new Error( | ||
| "Please provide --packageKeys for staging, or --keysByVersion / --keysByVersionFile for versioned packages." | ||
| ); | ||
| } | ||
|
|
||
| await new ConfigCommandService(context).listVariables( | ||
| options.json, | ||
| options.keysByVersion, | ||
| options.keysByVersionFile, | ||
| options.packageKeys | ||
| ); | ||
| } | ||
|
|
||
| private async listAssignments(context: Context, command: Command, options: OptionValues): Promise<void> { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,20 +3,23 @@ import { Context } from "../../core/command/cli-context"; | |
| import { FatalError, logger } from "../../core/utils/logger"; | ||
| import { StudioService } from "./studio.service"; | ||
| import { FileService, fileService } from "../../core/utils/file-service"; | ||
| import { PackageKeyAndVersionPair, VariableManifestTransport } from "./interfaces/package-export.interfaces"; | ||
| import { PackageKeyAndVersionPair, StagingVariableManifestTransport, VariableManifestTransport } from "./interfaces/package-export.interfaces"; | ||
| import { BatchImportExportApi } from "./api/batch-import-export-api"; | ||
| import { URLSearchParams } from "url"; | ||
| import { VariableAssignmentCandidatesApi } from "./api/variable-assignment-candidates-api"; | ||
| import { StagingPackageVariablesApi } from "./api/staging-package-variables-api"; | ||
|
|
||
| export class VariableService { | ||
|
|
||
| private batchImportExportApi: BatchImportExportApi; | ||
| private variableAssignmentCandidatesApi: VariableAssignmentCandidatesApi; | ||
| private readonly stagingPackageVariablesApi: StagingPackageVariablesApi; | ||
| private studioService: StudioService; | ||
|
|
||
| constructor(context: Context) { | ||
| this.batchImportExportApi = new BatchImportExportApi(context); | ||
| this.variableAssignmentCandidatesApi = new VariableAssignmentCandidatesApi(context); | ||
| this.stagingPackageVariablesApi = new StagingPackageVariablesApi(context); | ||
| this.studioService = new StudioService(context); | ||
| } | ||
|
|
||
|
|
@@ -50,6 +53,28 @@ export class VariableService { | |
| this.exportToJson(variableManifests); | ||
| } | ||
|
|
||
| public async listStagingVariables(packageKeys: string[]): Promise<void> { | ||
| const byPackage = await this.fetchStagingVariablesByPackageKeys(packageKeys); | ||
| byPackage.forEach(entry => { | ||
| logger.info(JSON.stringify(entry)); | ||
| }); | ||
| } | ||
|
|
||
| public async exportStagingVariables(packageKeys: string[]): Promise<void> { | ||
| const byPackage = await this.fetchStagingVariablesByPackageKeys(packageKeys); | ||
| this.exportToJson(byPackage); | ||
| } | ||
|
|
||
| private async fetchStagingVariablesByPackageKeys( | ||
| packageKeys: string[] | ||
| ): Promise<StagingVariableManifestTransport[]> { | ||
| if (packageKeys.length === 0) { | ||
| throw new FatalError("Please provide at least one package key!"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error never gets thrown since there's a check for package keys list being non-empty here that controls whether the flow proceeds to these methods. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding to this: If the error is never thrown you can remove the whole |
||
| } | ||
|
|
||
| return await this.stagingPackageVariablesApi.findAllByPackageKeys(packageKeys); | ||
| } | ||
|
|
||
| private async getVersionedVariablesByKeyVersionPairs(keysByVersion: string[], keysByVersionFile: string): Promise<VariableManifestTransport[]> { | ||
| const variablesExportRequest: PackageKeyAndVersionPair[] = await this.buildKeyVersionPairs(keysByVersion, keysByVersionFile); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the HttpClient a function that returns an HttpClient and not just a plan HttpClient? Is that a convention?