Skip to content

Commit

Permalink
Set awsAssumeRoleEnabled to true if not defined in the config (#57)
Browse files Browse the repository at this point in the history
* Show assume role input if undefined in the config
* Prepare 0.1.1
  • Loading branch information
idastambuk authored Aug 10, 2023
1 parent 05d19f4 commit 5523d7e
Show file tree
Hide file tree
Showing 4 changed files with 17 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.1

- Set awsAssumeRoleEnabled to true if not defined in the config https://github.com/grafana/grafana-aws-sdk-react/pull/57

## v0.1.0

- Temp Credentials: Display External Id https://github.com/grafana/grafana-aws-sdk-react/pull/54
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.0",
"version": "0.1.1",
"description": "Common AWS features for grafana",
"main": "dist/index.js",
"module": "dist/esm/index.js",
Expand Down
16 changes: 11 additions & 5 deletions src/ConnectionConfig.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { AwsAuthDataSourceJsonData, AwsAuthDataSourceSecureJsonData, AwsAuthType } from './types';
import { ConnectionConfig, ConnectionConfigProps } from './ConnectionConfig';
import selectEvent from 'react-select-event'
import selectEvent from 'react-select-event';
import { config } from '@grafana/runtime';

const getProps = (propOverrides?: object) => {
Expand Down Expand Up @@ -57,18 +57,18 @@ jest.mock('@grafana/runtime', () => ({
...jest.requireActual('@grafana/runtime'),
config: {
awsAllowedAuthProviders: [AwsAuthType.EC2IAMRole, AwsAuthType.Keys, AwsAuthType.Credentials],
awsAssumeRoleEnabled: false,
featureToggles: {
awsDatasourcesTempCredentials: false,
},
},
}));

describe('ConnectionConfig', () => {
beforeEach(() => {
afterEach(() => {
config.awsAllowedAuthProviders = [AwsAuthType.EC2IAMRole, AwsAuthType.Keys, AwsAuthType.Credentials];
config.awsAssumeRoleEnabled = false;
config.featureToggles.awsDatasourcesTempCredentials = false;
//@ts-ignore
config.awsAssumeRoleEnabled = undefined;
});
it('should use auth type from props if its set', async () => {
const onOptionsChange = jest.fn();
Expand Down Expand Up @@ -154,6 +154,12 @@ describe('ConnectionConfig', () => {
expect(screen.queryByText('Assume Role ARN')).not.toBeInTheDocument();
});

it('should render assume role input by default if awsAssumeRoleEnabled is not defined in the config', () => {
const props = getProps();
render(<ConnectionConfig {...props} />);
expect(screen.queryByText('Assume Role ARN')).toBeInTheDocument();
});

it('should render assume role if awsAssumeRoleEnabled was set to true', async () => {
config.awsAssumeRoleEnabled = true;
const props = getProps();
Expand All @@ -178,7 +184,7 @@ describe('ConnectionConfig', () => {
});
it('should render GrafanaAssumeRole as auth type if the feature flag is enabled and auth providers has GrafanaAssumeRole', async () => {
config.featureToggles.awsDatasourcesTempCredentials = true;
config.awsAllowedAuthProviders = [AwsAuthType.GrafanaAssumeRole, AwsAuthType.Credentials]
config.awsAllowedAuthProviders = [AwsAuthType.GrafanaAssumeRole, AwsAuthType.Credentials];
const props = getProps();
render(<ConnectionConfig {...props} />);
await selectEvent.openMenu(screen.getByLabelText('Authentication Provider'));
Expand Down
2 changes: 1 addition & 1 deletion src/ConnectionConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const ConnectionConfig: FC<ConnectionConfigProps> = (props: ConnectionCon
profile = options.database;
}
const tempCredsFeatureEnabled = config.featureToggles.awsDatasourcesTempCredentials;
const awsAssumeRoleEnabled = config.awsAssumeRoleEnabled;
const awsAssumeRoleEnabled = config.awsAssumeRoleEnabled ?? true;
const awsAllowedAuthProviders = useMemo(
() =>
config.awsAllowedAuthProviders
Expand Down

0 comments on commit 5523d7e

Please sign in to comment.