Skip to content

Commit

Permalink
Only show grafana assume role on enabled datasources (#58)
Browse files Browse the repository at this point in the history
* Only show grafana assume role on enabled datsources

* Prepare for 0.1.2
  • Loading branch information
sarahzinger authored Aug 21, 2023
1 parent 5523d7e commit 9051594
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
20 changes: 15 additions & 5 deletions src/ConnectionConfig.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(<ConnectionConfig {...props} options={overwriteOptions} />);
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();
Expand All @@ -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(<ConnectionConfig {...props} />);
const overwriteOptions = { ...props.options, type: 'grafana-athena-datasource' };
render(<ConnectionConfig {...props} options={overwriteOptions} />);
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();
});
});
4 changes: 3 additions & 1 deletion src/ConnectionConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -41,7 +42,8 @@ export const ConnectionConfig: FC<ConnectionConfigProps> = (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(
() =>
Expand Down

0 comments on commit 9051594

Please sign in to comment.