-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SALTO-6720: (Salesforce) Store Profiles And PermissionSets broken pat…
…hs on fetch (#6631)
- Loading branch information
Showing
14 changed files
with
387 additions
and
111 deletions.
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
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
59 changes: 59 additions & 0 deletions
59
packages/salesforce-adapter/src/filters/profiles_and_permission_sets_broken_paths.ts
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,59 @@ | ||
/* | ||
* Copyright 2024 Salto Labs Ltd. | ||
* Licensed under the Salto Terms of Use (the "License"); | ||
* You may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.salto.io/terms-of-use | ||
* | ||
* CERTAIN THIRD PARTY SOFTWARE MAY BE CONTAINED IN PORTIONS OF THE SOFTWARE. See NOTICE FILE AT https://github.com/salto-io/salto/blob/main/NOTICES | ||
*/ | ||
import _ from 'lodash' | ||
import { logger } from '@salto-io/logging' | ||
import { inspectValue } from '@salto-io/adapter-utils' | ||
import { ElemID, InstanceElement } from '@salto-io/adapter-api' | ||
import { ArtificialTypes } from '../constants' | ||
import { FilterCreator } from '../filter' | ||
import { buildElementsSourceForFetch, ensureSafeFilterFetch, getProfilesAndPermissionSetsBrokenPaths } from './utils' | ||
import { | ||
getProfilesAndPsBrokenReferenceFields, | ||
isProfileOrPermissionSetInstance, | ||
} from '../custom_references/profiles_and_permission_sets' | ||
|
||
const log = logger(module) | ||
|
||
const filter: FilterCreator = ({ config }) => ({ | ||
name: 'profilesAndPermissionSetsBrokenPaths', | ||
onFetch: ensureSafeFilterFetch({ | ||
config, | ||
warningMessage: 'Error occurred while calculating Profiles and PermissionSets broken paths', | ||
fetchFilterFunc: async elements => { | ||
const elementsSource = buildElementsSourceForFetch(elements, config) | ||
const profilesAndPermissionSets = elements.filter(isProfileOrPermissionSetInstance) | ||
if (profilesAndPermissionSets.length === 0) { | ||
return | ||
} | ||
const { paths } = await getProfilesAndPsBrokenReferenceFields({ | ||
elementsSource, | ||
profilesAndPermissionSets, | ||
metadataQuery: config.fetchProfile.metadataQuery, | ||
}) | ||
if (paths.length === 0) { | ||
return | ||
} | ||
const uniquePaths = _.uniq( | ||
paths.concat( | ||
// We should concat the existing broken paths in case of partial fetch, and override them in full fetch | ||
config.fetchProfile.metadataQuery.isPartialFetch() | ||
? await getProfilesAndPermissionSetsBrokenPaths(elementsSource) | ||
: [], | ||
), | ||
) | ||
log.debug('Profiles and PermissionSets broken paths: %s', inspectValue(uniquePaths, { maxArrayLength: 100 })) | ||
elements.push( | ||
new InstanceElement(ElemID.CONFIG_NAME, ArtificialTypes.ProfilesAndPermissionSetsBrokenPaths, { | ||
paths: uniquePaths, | ||
}), | ||
) | ||
}, | ||
}), | ||
}) | ||
|
||
export default filter |
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
Oops, something went wrong.