* Merges the env allowlist into a permission config. * If `config` is null and no env allowlist is set, returns null. * If `config` is null but env allowlist is set, returns a default config with only allowedIntegrations set. * If both are set, intersects the two allowlists.
(config: PermissionGroupConfig | null)
| 106 | * If both are set, intersects the two allowlists. |
| 107 | */ |
| 108 | function mergeEnvAllowlist(config: PermissionGroupConfig | null): PermissionGroupConfig | null { |
| 109 | const envAllowlist = getAllowedIntegrationsFromEnv() |
| 110 | |
| 111 | if (envAllowlist === null) { |
| 112 | return config |
| 113 | } |
| 114 | |
| 115 | if (config === null) { |
| 116 | return { ...DEFAULT_PERMISSION_GROUP_CONFIG, allowedIntegrations: envAllowlist } |
| 117 | } |
| 118 | |
| 119 | const merged = |
| 120 | config.allowedIntegrations === null |
| 121 | ? envAllowlist |
| 122 | : config.allowedIntegrations |
| 123 | .map((i) => i.toLowerCase()) |
| 124 | .filter((i) => envAllowlist.includes(i)) |
| 125 | |
| 126 | return { ...config, allowedIntegrations: merged } |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * The permission group that governs a user in a given context, with its parsed |
no test coverage detected