Skip to content

Commit

Permalink
fix(pull): default on resources user has access to (#1481)
Browse files Browse the repository at this point in the history
https://coveord.atlassian.net/browse/CDX-1592

Testing: Manual. Hard to test as its a corner case :/
  • Loading branch information
louis-bompart authored Sep 3, 2024
1 parent 1951961 commit d3ef51b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/cli/core/src/commands/org/resources/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {CLICommand} from '@coveo/cli-commons/command/cliCommand';
import {Example} from '@oclif/core/lib/interfaces';
import {organization} from '../../../lib/flags/platformCommonFlags';
import {getTargetOrg} from '../../../lib/utils/platform';
import {AuthenticatedClient} from '@coveo/cli-commons/platform/authenticatedClient';

const PullCommandStrings = {
projectOverwriteQuestion: (
Expand Down Expand Up @@ -82,7 +83,7 @@ export default class Pull extends CLICommand {
description: 'The resources types to pull from the organization.',
multiple: true,
options: allowedResourceType,
default: allowedResourceType,
required: false,
}),
model: Flags.custom<SnapshotPullModel>({
parse: (input: string): Promise<SnapshotPullModel> => {
Expand Down Expand Up @@ -226,6 +227,10 @@ export default class Pull extends CLICommand {
);
}

private async getClient(targetOrg: string) {
return await new AuthenticatedClient().getClient({organization: targetOrg});
}

private async getWaitOption(): Promise<WaitUntilDoneOptions> {
const flags = await this.getFlags();
return {wait: flags.wait};
Expand All @@ -239,7 +244,15 @@ export default class Pull extends CLICommand {
const flags = await this.getFlags();
return flags.model
? flags.model.resourcesToExport
: buildResourcesToExport(flags.resourceTypes!);
: flags.resourceTypes?.length
? buildResourcesToExport(flags.resourceTypes)
: await this.getAllAvailableResourceTypes();
}

private async getAllAvailableResourceTypes(): Promise<SnapshotPullModelResources> {
const client = await this.getClient(await this.getTargetOrg());
const resourceTypes = await client.resourceSnapshot.listResourceAccess();
return buildResourcesToExport(resourceTypes);
}

private async getTargetOrg() {
Expand Down

0 comments on commit d3ef51b

Please sign in to comment.