-
Notifications
You must be signed in to change notification settings - Fork 159
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
DXCDT-84: Resource Exclusion #468
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
62c303e
Fixing management API type
7d6d7b4
Initial implementation of resource exclusion
05162d1
Adding protection against undefined AUTH0_EXCLUDED value, updating te…
050be2d
Fixing newly failing test cases that don't properly mock config function
7a9e7ac
Merge branch 'typing-Auth0-class' into DXCDT-84-resource-exclusion
f3c278e
Fixing code comment
0d43333
Removing newHandler intermediate value
3c12c55
Adding auth0 class test
eafebdf
Adding resource exclusion to directory handlers
6b3d3b7
Merging with master
6e0c953
Adding AUTH0_EXCLUDED to nonprimitive helper
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,11 @@ import { loadFileAndReplaceKeywords, Auth0 } from '../../tools'; | |
|
||
import cleanAssets from '../../readonly'; | ||
import log from '../../logger'; | ||
import handlers from './handlers'; | ||
import handlers, { DirectoryHandler } from './handlers'; | ||
import { | ||
isDirectory, isFile, stripIdentifiers, toConfigFn | ||
} from '../../utils'; | ||
import { Assets, Auth0APIClient, Config } from '../../types' | ||
import { Assets, Auth0APIClient, Config, AssetTypes } from '../../types' | ||
|
||
type KeywordMappings = { [key: string]: (string | number)[] | string | number } | ||
|
||
|
@@ -78,14 +78,17 @@ export default class DirectoryContext { | |
// Copy clients to be used by handlers which require converting client_id to the name | ||
// Must copy as the client_id will be stripped if AUTH0_EXPORT_IDENTIFIERS is false | ||
//@ts-ignore because assets haven't been typed yet TODO: type assets | ||
this.assets.clientsOrig = [...this.assets.clients]; | ||
this.assets.clientsOrig = [...this.assets.clients || []]; | ||
|
||
// Optionally Strip identifiers | ||
if (!this.config.AUTH0_EXPORT_IDENTIFIERS) { | ||
this.assets = stripIdentifiers(auth0, this.assets); | ||
} | ||
|
||
await Promise.all(Object.entries(handlers).map(async ([name, handler]) => { | ||
await Promise.all(Object.entries(handlers).filter(([handlerName]: [AssetTypes, DirectoryHandler<any>]) => { | ||
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 array filter function is the primary mechanism for exclusion. |
||
const excludedAssetTypes = this.config.AUTH0_EXCLUDED || [] | ||
return !excludedAssetTypes.includes(handlerName) | ||
}).map(async ([name, handler]) => { | ||
try { | ||
await handler.dump(this); | ||
} catch (err) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { expect } from 'chai'; | ||
import Auth0 from '../../../src/tools/auth0' | ||
import { Auth0APIClient, Assets } from '../../../src/types' | ||
|
||
const mockEmptyClient = {} as Auth0APIClient | ||
const mockEmptyAssets = {} as Assets | ||
|
||
describe("#Auth0 class", () => { | ||
|
||
describe("#resource exclusion", () => { | ||
it('should exclude handlers listed in AUTH0_EXCLUDED from Auth0 class', () => { | ||
|
||
const auth0WithoutExclusions = new Auth0(mockEmptyClient, mockEmptyAssets, () => []); | ||
|
||
const AUTH0_EXCLUDED = ['rules', 'organizations', 'connections'] | ||
const auth0WithExclusions = new Auth0(mockEmptyClient, mockEmptyAssets, () => AUTH0_EXCLUDED); | ||
|
||
expect(auth0WithoutExclusions.handlers.length).to.equal(auth0WithExclusions.handlers.length + AUTH0_EXCLUDED.length) // Number of handlers is reduced by number of exclusions | ||
|
||
const areAllExcludedHandlersAbsent = auth0WithExclusions.handlers.some((handler) => { | ||
return AUTH0_EXCLUDED.includes(handler.type) | ||
}) | ||
|
||
expect(areAllExcludedHandlersAbsent).to.be.false; | ||
}) | ||
|
||
it('should not exclude any handlers if AUTH0_EXCLUDED is undefined', () => { | ||
const AUTH0_EXCLUDED = undefined | ||
const auth0 = new Auth0(mockEmptyClient, mockEmptyAssets, () => AUTH0_EXCLUDED); | ||
|
||
expect(auth0.handlers.length).to.be.greaterThan(0) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Clients could theoretically be excluded and thus be empty so need to default to empty array.