Skip to content

Commit f1f9c91

Browse files
authored
Fix: AUTH0_EXCLUDED_ options not respected during export (#1342)
* fix: apply AUTH0_EXCLUDED_CLIENTS filtering during export for clients and clientGrants * fix: extend export exclusion filtering to rules, databases, connections, and resourceServers
1 parent 39acc9d commit f1f9c91

24 files changed

Lines changed: 389 additions & 12 deletions

src/context/directory/handlers/clientGrants.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function parse(context: DirectoryContext): ParsedClientGrants {
4242
}
4343

4444
async function dump(context: DirectoryContext): Promise<void> {
45-
const { clientGrants } = context.assets;
45+
let { clientGrants } = context.assets;
4646

4747
if (!clientGrants) return; // Skip, nothing to dump
4848

@@ -51,6 +51,8 @@ async function dump(context: DirectoryContext): Promise<void> {
5151

5252
if (clientGrants.length === 0) return;
5353

54+
const excludedClientsByNames = (context.assets.exclude && context.assets.exclude.clients) || [];
55+
5456
const allResourceServers = await paginate<ResourceServer>(
5557
context.mgmtClient.resourceServers.list,
5658
{
@@ -64,6 +66,18 @@ async function dump(context: DirectoryContext): Promise<void> {
6466
include_totals: true,
6567
});
6668

69+
// Filter out grants for excluded clients
70+
if (excludedClientsByNames.length) {
71+
const excludedClientIds = new Set(
72+
allClients
73+
.filter((c) => c.name !== undefined && excludedClientsByNames.includes(c.name))
74+
.map((c) => c.client_id)
75+
);
76+
clientGrants = clientGrants.filter(
77+
(grant: ClientGrant) => !excludedClientIds.has(grant.client_id)
78+
);
79+
}
80+
6781
// Convert client_id to the client name for readability
6882
clientGrants.forEach((grant: ClientGrant) => {
6983
const dumpGrant = { ...grant };

src/context/directory/handlers/clients.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,17 @@ function parse(context: DirectoryContext): ParsedClients {
5353
}
5454

5555
async function dump(context: DirectoryContext): Promise<void> {
56-
const { clients } = context.assets;
56+
let { clients } = context.assets;
5757
const { userAttributeProfiles, connectionProfiles } = context.assets;
5858

5959
if (!clients) return; // Skip, nothing to dump
6060

61+
// Filter excluded clients
62+
const excludedClients = (context.assets.exclude && context.assets.exclude.clients) || [];
63+
if (excludedClients.length) {
64+
clients = clients.filter((client) => !excludedClients.includes(client.name ?? ''));
65+
}
66+
6167
const clientsFolder = path.join(context.filePath, constants.CLIENTS_DIRECTORY);
6268
fs.ensureDirSync(clientsFolder);
6369

src/context/directory/handlers/connections.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,17 @@ function parse(context: DirectoryContext): ParsedConnections {
6161
}
6262

6363
async function dump(context: DirectoryContext): Promise<void> {
64-
const { connections, clientsOrig } = context.assets;
64+
let { connections } = context.assets;
65+
const { clientsOrig } = context.assets;
6566

6667
if (!connections) return; // Skip, nothing to dump
6768

69+
// Filter excluded connections
70+
const excludedConnections = (context.assets.exclude && context.assets.exclude.connections) || [];
71+
if (excludedConnections.length) {
72+
connections = connections.filter((connection) => !excludedConnections.includes(connection.name));
73+
}
74+
6875
const connectionsFolder = path.join(context.filePath, constants.CONNECTIONS_DIRECTORY);
6976
fs.ensureDirSync(connectionsFolder);
7077

src/context/directory/handlers/databases.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,16 @@ function parse(context: DirectoryContext): ParsedDatabases {
103103
}
104104

105105
async function dump(context: DirectoryContext): Promise<void> {
106-
const { databases } = context.assets;
106+
let { databases } = context.assets;
107107

108108
if (!databases) return; // Skip, nothing to dump
109109

110+
// Filter excluded databases
111+
const excludedDatabases = (context.assets.exclude && context.assets.exclude.databases) || [];
112+
if (excludedDatabases.length) {
113+
databases = databases.filter((database) => !excludedDatabases.includes(database.name));
114+
}
115+
110116
const databasesFolder = path.join(context.filePath, constants.DATABASE_CONNECTIONS_DIRECTORY);
111117
fs.ensureDirSync(databasesFolder);
112118

src/context/directory/handlers/resourceServers.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,20 @@ function parse(context: DirectoryContext): ParsedResourceServers {
3939
}
4040

4141
async function dump(context: DirectoryContext): Promise<void> {
42-
const { resourceServers } = context.assets;
42+
let { resourceServers } = context.assets;
4343
let { clients } = context.assets;
4444

4545
if (!resourceServers) return; // Skip, nothing to dump
4646

47+
// Filter excluded resource servers
48+
const excludedResourceServers =
49+
(context.assets.exclude && context.assets.exclude.resourceServers) || [];
50+
if (excludedResourceServers.length) {
51+
resourceServers = resourceServers.filter(
52+
(resourceServer) => !excludedResourceServers.includes(resourceServer.name ?? '')
53+
);
54+
}
55+
4756
const resourceServersFolder = path.join(context.filePath, constants.RESOURCE_SERVERS_DIRECTORY);
4857
fs.ensureDirSync(resourceServersFolder);
4958

src/context/directory/handlers/rules.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,16 @@ function parse(context: DirectoryContext): ParsedRules {
3636
}
3737

3838
async function dump(context: DirectoryContext): Promise<void> {
39-
const { rules } = context.assets;
39+
let { rules } = context.assets;
4040

4141
if (!rules) return; // Skip, nothing to dump
4242

43+
// Filter excluded rules
44+
const excludedRules = (context.assets.exclude && context.assets.exclude.rules) || [];
45+
if (excludedRules.length) {
46+
rules = rules.filter((rule) => !excludedRules.includes(rule.name));
47+
}
48+
4349
// Create Rules folder
4450
const rulesFolder = path.join(context.filePath, constants.RULES_DIRECTORY);
4551
fs.ensureDirSync(rulesFolder);

src/context/yaml/handlers/clientGrants.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async function parse(context: YAMLContext): Promise<ParsedClientGrants> {
2020

2121
async function dump(context: YAMLContext): Promise<ParsedClientGrants> {
2222
let { clients } = context.assets;
23-
const { clientGrants } = context.assets;
23+
let { clientGrants } = context.assets;
2424

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

@@ -31,6 +31,17 @@ async function dump(context: YAMLContext): Promise<ParsedClientGrants> {
3131
});
3232
}
3333

34+
// Filter out grants for excluded clients
35+
const excludedClientsByNames = (context.assets.exclude && context.assets.exclude.clients) || [];
36+
if (excludedClientsByNames.length) {
37+
const excludedClientIds = new Set(
38+
(clients || [])
39+
.filter((c) => c.name !== undefined && excludedClientsByNames.includes(c.name))
40+
.map((c) => c.client_id)
41+
);
42+
clientGrants = clientGrants.filter((grant) => !excludedClientIds.has(grant.client_id));
43+
}
44+
3445
// Convert client_id to the client name for readability
3546
return {
3647
clientGrants: clientGrants.map((grant) => {

src/context/yaml/handlers/clients.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ async function dump(context: YAMLContext): Promise<ParsedClients> {
4646

4747
if (!clients) return { clients: null };
4848

49+
// Filter excluded clients
50+
const excludedClients = (context.assets.exclude && context.assets.exclude.clients) || [];
51+
if (excludedClients.length) {
52+
clients = clients.filter((client) => !excludedClients.includes(client.name ?? ''));
53+
}
54+
4955
// map ids to names for user attribute profiles and connection profiles
5056
clients = clients.map((client) => {
5157
const userAttributeProfileId = client?.express_configuration?.user_attribute_profile_id;

src/context/yaml/handlers/connections.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,17 @@ const getFormattedOptions = (connection, clients) => {
6464
};
6565

6666
async function dump(context: YAMLContext): Promise<ParsedConnections> {
67-
const { connections, clients } = context.assets;
67+
let { connections } = context.assets;
68+
const { clients } = context.assets;
6869

6970
if (!connections) return { connections: null };
7071

72+
// Filter excluded connections
73+
const excludedConnections = (context.assets.exclude && context.assets.exclude.connections) || [];
74+
if (excludedConnections.length) {
75+
connections = connections.filter((connection) => !excludedConnections.includes(connection.name));
76+
}
77+
7178
return {
7279
connections: connections.map((connection) => {
7380
let dumpedConnection = {

src/context/yaml/handlers/databases.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,17 @@ async function parse(context: YAMLContext): Promise<ParsedDatabases> {
3737
}
3838

3939
async function dump(context: YAMLContext): Promise<ParsedDatabases> {
40-
const { databases, clients } = context.assets;
40+
let { databases } = context.assets;
41+
const { clients } = context.assets;
4142

4243
if (!databases) return { databases: null };
4344

45+
// Filter excluded databases
46+
const excludedDatabases = (context.assets.exclude && context.assets.exclude.databases) || [];
47+
if (excludedDatabases.length) {
48+
databases = databases.filter((database) => !excludedDatabases.includes(database.name));
49+
}
50+
4451
const sortCustomScripts = ([name1]: [string, Function], [name2]: [string, Function]): number => {
4552
if (name1 === name2) return 0;
4653
return name1 > name2 ? 1 : -1;

0 commit comments

Comments
 (0)