diff --git a/CHANGELOG.md b/CHANGELOG.md index fce8356..9536644 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## v0.1.2 + +- Only show grafana assume role on enabled datasources #58 + ## v0.1.1 - Set awsAssumeRoleEnabled to true if not defined in the config https://github.com/grafana/grafana-aws-sdk-react/pull/57 diff --git a/package.json b/package.json index bc3bf7b..ddd2f0a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@grafana/aws-sdk", - "version": "0.1.1", + "version": "0.1.2", "description": "Common AWS features for grafana", "main": "dist/index.js", "module": "dist/esm/index.js", diff --git a/src/ConnectionConfig.test.tsx b/src/ConnectionConfig.test.tsx index 51df837..bcc3000 100644 --- a/src/ConnectionConfig.test.tsx +++ b/src/ConnectionConfig.test.tsx @@ -14,7 +14,7 @@ const getProps = (propOverrides?: object) => { uid: '', orgId: 1, name: 'aws-plugin-name', - type: 'aws', + type: 'aws-plugin-id', basicAuth: false, basicAuthUser: '', withCredentials: false, @@ -174,6 +174,16 @@ describe('ConnectionConfig', () => { await waitFor(() => expect(screen.queryByLabelText('External ID')).not.toBeInTheDocument()); }); + it('should render GrafanaAssumeRole as auth type if the feature flag is enabled and auth providers has GrafanaAssumeRole and the datasource supports temp credentials', async () => { + config.featureToggles.awsDatasourcesTempCredentials = true; + config.awsAllowedAuthProviders = [AwsAuthType.GrafanaAssumeRole, AwsAuthType.Credentials]; + const props = getProps(); + const overwriteOptions = { ...props.options, type: 'cloudwatch' }; + render(); + await selectEvent.openMenu(screen.getByLabelText('Authentication Provider')); + expect(screen.getByText('Credentials file')).toBeInTheDocument(); + expect(screen.queryByText('Grafana Assume Role')).toBeInTheDocument(); + }); it('should not render GrafanaAssumeRole as auth type if the feature flag is not enabled', async () => { config.featureToggles.awsDatasourcesTempCredentials = false; const props = getProps(); @@ -182,13 +192,13 @@ describe('ConnectionConfig', () => { expect(screen.getByText('Credentials file')).toBeInTheDocument(); expect(screen.queryByText('Grafana Assume Role')).not.toBeInTheDocument(); }); - it('should render GrafanaAssumeRole as auth type if the feature flag is enabled and auth providers has GrafanaAssumeRole', async () => { + it('should not render GrafanaAssumeRole if the datasource is not a supported datasource type', async () => { config.featureToggles.awsDatasourcesTempCredentials = true; config.awsAllowedAuthProviders = [AwsAuthType.GrafanaAssumeRole, AwsAuthType.Credentials]; const props = getProps(); - render(); + const overwriteOptions = { ...props.options, type: 'grafana-athena-datasource' }; + render(); await selectEvent.openMenu(screen.getByLabelText('Authentication Provider')); - expect(screen.getByText('Credentials file')).toBeInTheDocument(); - expect(screen.queryByText('Grafana Assume Role')).toBeInTheDocument(); + expect(screen.queryByText('Grafana Assume Role')).not.toBeInTheDocument(); }); }); diff --git a/src/ConnectionConfig.tsx b/src/ConnectionConfig.tsx index 823e0d0..84ba81c 100644 --- a/src/ConnectionConfig.tsx +++ b/src/ConnectionConfig.tsx @@ -13,6 +13,7 @@ import { AwsAuthDataSourceJsonData, AwsAuthDataSourceSecureJsonData, AwsAuthType import { awsAuthProviderOptions } from './providers'; export const DEFAULT_LABEL_WIDTH = 28; +const DS_TYPES_THAT_SUPPORT_TEMP_CREDS = ['cloudwatch']; const toOption = (value: string) => ({ value, label: value }); const isAwsAuthType = (value: any): value is AwsAuthType => { return typeof value === 'string' && awsAuthProviderOptions.some((opt) => opt.value === value); @@ -41,7 +42,8 @@ export const ConnectionConfig: FC = (props: ConnectionCon if (profile === undefined) { profile = options.database; } - const tempCredsFeatureEnabled = config.featureToggles.awsDatasourcesTempCredentials; + const tempCredsFeatureEnabled = + config.featureToggles.awsDatasourcesTempCredentials && DS_TYPES_THAT_SUPPORT_TEMP_CREDS.includes(options.type); const awsAssumeRoleEnabled = config.awsAssumeRoleEnabled ?? true; const awsAllowedAuthProviders = useMemo( () =>