Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/components/ConnectionConfig.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ describe('ConnectionConfig', () => {
});
});

it('should auto select GrafanaAssumeRole if it is enabled and set as an allowed auth provider', async () => {
config.featureToggles.awsDatasourcesTempCredentials = true;
config.awsAllowedAuthProviders = [AwsAuthType.Credentials, AwsAuthType.GrafanaAssumeRole];
const onOptionsChange = jest.fn();
const props = getProps({ onOptionsChange });
const overwriteOptions = { ...props.options, type: 'cloudwatch' };
render(<ConnectionConfig {...props} options={overwriteOptions} />);
await waitFor(() => expect(screen.getByTestId('connection-config')).toBeInTheDocument());
expect(onOptionsChange).toHaveBeenCalledWith({
...overwriteOptions,
jsonData: {
...overwriteOptions.jsonData,
authType: AwsAuthType.GrafanaAssumeRole,
},
});
});

it('should show secret field if auth type is keys', async () => {
const props = getProps({ options: { jsonData: { authType: AwsAuthType.Keys } } });
render(<ConnectionConfig {...props} />);
Expand Down
6 changes: 5 additions & 1 deletion src/components/ConnectionConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ export const ConnectionConfig: FC<ConnectionConfigProps> = (props: ConnectionCon
useEffect(() => {
// Make sure a authType exists in the current model
if (!currentProvider && awsAllowedAuthProviders.length) {
let defaultAuthType = awsAllowedAuthProviders[0];
if (awsAllowedAuthProviders.includes(AwsAuthType.GrafanaAssumeRole)) {
defaultAuthType = AwsAuthType.GrafanaAssumeRole;
}
onOptionsChange({
...options,
jsonData: {
...options.jsonData,
authType: awsAllowedAuthProviders[0],
authType: defaultAuthType,
},
});
}
Expand Down