Skip to content

Commit

Permalink
DXCDT-701:Preserve keywords in client audience:
Browse files Browse the repository at this point in the history
clientGrants needs client_id value instead of
client name for keywords preservation
to work.
  • Loading branch information
kushalshit27 committed Sep 4, 2024
1 parent 0ac0038 commit 568ccd3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/context/yaml/handlers/clientGrants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { YAMLHandler } from '.';
import YAMLContext from '..';
import { ParsedAsset } from '../../../types';
import { ClientGrant } from '../../../tools/auth0/handlers/clientGrants';
import { convertClientNameToId } from '../../../tools/utils';

type ParsedClientGrants = ParsedAsset<'clientGrants', ClientGrant[]>;

Expand All @@ -11,13 +12,24 @@ async function parse(context: YAMLContext): Promise<ParsedClientGrants> {

if (!clientGrants) return { clientGrants: null };

// can not use client from context.assets because it does not have the client_id
const clients = await context.mgmtClient.clients.getAll({
paginate: true,
include_totals: true,
});

return {
clientGrants,
clientGrants: clientGrants.map((grant) => {
const dumpGrant = { ...grant };
dumpGrant.client_id = convertClientNameToId(dumpGrant.client_id, clients || []);
return dumpGrant;
}),
};
}

async function dump(context: YAMLContext): Promise<ParsedClientGrants> {
let { clientGrants, clients } = context.assets;
const { clientGrants } = context.assets;
let { clients } = context.assets;

if (!clientGrants) return { clientGrants: null };

Expand Down
2 changes: 1 addition & 1 deletion src/keywordPreservation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { get as getByDotNotation, set as setByDotNotation } from 'dot-prop';
import { cloneDeep, isArray } from 'lodash';
import { keywordReplace } from './tools/utils';
import { AssetTypes, KeywordMappings } from './types';
import { keywordReplaceArrayRegExp, keywordReplaceStringRegExp } from './tools/utils';
import { cloneDeep, forEach, isArray } from 'lodash';
import APIHandler from './tools/auth0/handlers/default';

/*
Expand Down

0 comments on commit 568ccd3

Please sign in to comment.