Skip to content

Commit

Permalink
Prevent dumping JSON files with keyword preserve markers in client gr…
Browse files Browse the repository at this point in the history
…ants
  • Loading branch information
kushalshit27 committed Feb 27, 2025
1 parent a82ed70 commit 9effc42
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/context/directory/handlers/clientGrants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import DirectoryContext from '..';
import { ParsedAsset } from '../../../types';
import { ClientGrant } from '../../../tools/auth0/handlers/clientGrants';
import { paginate } from '../../../tools/auth0/client';
import { doesHaveKeywordMarker } from '../../../keywordPreservation';

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

Expand Down Expand Up @@ -71,29 +72,30 @@ async function dump(context: DirectoryContext): Promise<void> {
}

const clientName = (() => {
const associatedClient = allClients.find((client) => {
return client.client_id === grant.client_id;
});
const associatedClient = allClients.find((client) => client.client_id === grant.client_id);

if (associatedClient === undefined) return grant.client_id;

return associatedClient.name;
})();

const apiName = (() => {
const associatedAPI = allResourceServers.find((resourceServer) => {
return resourceServer.identifier === grant.audience;
});
const associatedAPI = allResourceServers.find(
(resourceServer) => resourceServer.identifier === grant.audience
);

if (associatedAPI === undefined) return grant.audience;

return associatedAPI.name;
})();

const name = sanitize(`${clientName}-${apiName}`);
const grantFile = path.join(grantsFolder, `${name}.json`);

dumpJSON(grantFile, dumpGrant);
// If the file name has a keyword preserve marker, we don't want to dump it. only dump if it doesn't have a keyword preserve marker.
if (!doesHaveKeywordMarker(name, context.mappings)) {
const grantFile = path.join(grantsFolder, `${name}.json`);
dumpJSON(grantFile, dumpGrant);
}
});
}

Expand Down

0 comments on commit 9effc42

Please sign in to comment.