Skip to content

Commit

Permalink
Merge pull request #168 from atlassian-labs/issue/COMPASS-24239
Browse files Browse the repository at this point in the history
Remove Gitlab Maintainer token FF cloudId-based allowlist
  • Loading branch information
subbuvenk-atlas authored Feb 3, 2025
2 parents d3b081c + f09ec6b commit c43dcfa
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 44 deletions.
8 changes: 2 additions & 6 deletions src/resolvers/admin-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,8 @@ resolver.define('project/import', async (req): Promise<ResolverResponse> => {
return importProject(req);
});

resolver.define('features', (req): ResolverResponse<FeaturesList> => {
const {
context: { cloudId },
} = req;

return getFeatures(cloudId);
resolver.define('features', (): ResolverResponse<FeaturesList> => {
return getFeatures();
});

resolver.define('appId', (): ResolverResponse<string> => {
Expand Down
8 changes: 2 additions & 6 deletions src/resolvers/import-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,8 @@ resolver.define('project/import/clear', async (): Promise<ResolverResponse> => {
}
});

resolver.define('features', (req): ResolverResponse<FeaturesList> => {
const {
context: { cloudId },
} = req;

return getFeatures(cloudId);
resolver.define('features', (): ResolverResponse<FeaturesList> => {
return getFeatures();
});

resolver.define('appId', (): ResolverResponse<string> => {
Expand Down
4 changes: 2 additions & 2 deletions src/resolvers/shared-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import { getGroupProjects } from '../services/fetch-projects';
import { ImportFailedError, importProjects } from '../services/import-projects';
import { getAllComponentTypes as getAllCompassComponentTypes } from '../client/compass';

export const getFeatures = (cloudId: string): ResolverResponse<FeaturesList> => {
export const getFeatures = (): ResolverResponse<FeaturesList> => {
try {
const features = listFeatures(cloudId);
const features = listFeatures();
return {
success: true,
data: features,
Expand Down
19 changes: 0 additions & 19 deletions src/services/feature-flags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,4 @@ describe('listFeatures', () => {

expect(featureFlags.isSendStagingEventsEnabled).toEqual(false);
});

it('uses cloudId to determine if gitlab maintainer token is enabled', async () => {
process.env.ENABLE_GITLAB_MAINTAINER_TOKEN_CLOUD_IDS = 'cloudId1,cloudId2';
process.env.ENABLE_GITLAB_MAINTAINER_TOKEN = 'true';

let featureFlags = listFeatures('cloudId1');
expect(featureFlags.isGitlabMaintainerTokenEnabled).toEqual(true);

featureFlags = listFeatures();
expect(featureFlags.isGitlabMaintainerTokenEnabled).toEqual(true);

featureFlags = listFeatures('cloudId3');
expect(featureFlags.isGitlabMaintainerTokenEnabled).toEqual(false);

process.env.ENABLE_GITLAB_MAINTAINER_TOKEN_CLOUD_IDS = '';

featureFlags = listFeatures('cloudId1');
expect(featureFlags.isGitlabMaintainerTokenEnabled).toEqual(true);
});
});
15 changes: 4 additions & 11 deletions src/services/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,20 @@ const isDocumentComponentLinksDisabled = (defaultValue = false): boolean => {
return process.env.DISABLE_DOCUMENT_COMPONENT_LINKS === 'true' || defaultValue;
};

export const isGitlabMaintainerTokenEnabled = (cloudId?: string, defaultValue = false): boolean => {
// cloudId is available in frontend context when fetching features for AppContext.
// It is not available in all backend contexts, so we will use the default value if it is not provided.
const isEnabledForCloudId =
!!cloudId && !!process.env.ENABLE_GITLAB_MAINTAINER_TOKEN_CLOUD_IDS
? process.env.ENABLE_GITLAB_MAINTAINER_TOKEN_CLOUD_IDS.split(',').includes(cloudId)
: true;

return (process.env.ENABLE_GITLAB_MAINTAINER_TOKEN === 'true' && isEnabledForCloudId) || defaultValue;
export const isGitlabMaintainerTokenEnabled = (defaultValue = false): boolean => {
return process.env.ENABLE_GITLAB_MAINTAINER_TOKEN === 'true' || defaultValue;
};

const isImportAllEnabled = (defaultValue = false): boolean => {
return process.env.FF_IMPORT_ALL_ENABLED === 'true' || defaultValue;
};

export const listFeatures = (cloudId?: string): FeaturesList => {
export const listFeatures = (): FeaturesList => {
return {
[GitlabFeaturesEnum.SEND_STAGING_EVENTS]: isSendStagingEventsEnabled(),
[GitlabFeaturesEnum.DATA_COMPONENT_TYPES]: isDataComponentTypesEnabled(),
[GitlabFeaturesEnum.DISABLE_DOCUMENT_COMPONENT_LINKS]: isDocumentComponentLinksDisabled(),
[GitlabFeaturesEnum.ENABLE_GITLAB_MAINTAINER_TOKEN]: isGitlabMaintainerTokenEnabled(cloudId),
[GitlabFeaturesEnum.ENABLE_GITLAB_MAINTAINER_TOKEN]: isGitlabMaintainerTokenEnabled(),
[GitlabFeaturesEnum.IMPORT_ALL]: isImportAllEnabled(),
};
};

0 comments on commit c43dcfa

Please sign in to comment.