Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('Get instance data:: ', () => {
region: 'us-west1',
aws_access_key: 'aws-secret-key-example',
aws_secret_key: 'aws-secret-key-example',
aws_role_arn: 'arn:aws:iam::123456789012:role/PmmRdsReadOnlyRole',
az: 'test az',
};
const testInstance = {
Expand All @@ -54,6 +55,7 @@ describe('Get instance data:: ', () => {
region: 'us-west1',
aws_access_key: 'aws-secret-key-example',
aws_secret_key: 'aws-secret-key-example',
aws_role_arn: 'arn:aws:iam::123456789012:role/PmmRdsReadOnlyRole',
az: 'test az',
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const getRDSCredentials = (credentials: any, instanceType: InstanceAvailableType
region: credentials.region,
aws_access_key: credentials.aws_access_key,
aws_secret_key: credentials.aws_secret_key,
aws_role_arn: credentials.aws_role_arn,
instance_id: credentials.instance_id,
az: credentials.az,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export interface RDSPayload extends CommonRDSAzurePayload {
replication_set: string;
aws_access_key: string;
aws_secret_key: string;
aws_role_arn: string;
rds_exporter: boolean;
qan_mysql_perfschema: boolean;
disable_parsing_comments: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const DISCOVERY_RDS_CANCEL_TOKEN = 'discoveryRds';
export const INITIAL_CREDENTIALS = { aws_secret_key: '', aws_access_key: '' };
export const INITIAL_CREDENTIALS = { aws_secret_key: '', aws_access_key: '', aws_role_arn: '' };
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { awsNoCredentialsError, noCredentialsError } = Messages;

class DiscoveryService {
static async discoveryRDS(
{ aws_access_key, aws_secret_key }: RDSCredentialsForm,
{ aws_access_key, aws_secret_key, aws_role_arn }: RDSCredentialsForm,
token?: CancelToken,
disableNotifications = false
) {
Expand All @@ -22,6 +22,7 @@ class DiscoveryService {
{
aws_access_key,
aws_secret_key,
aws_role_arn,
},
true,
token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export const Messages = {
name: 'aws_secret_key',
label: 'Amazon RDS secret key',
},
awsRoleArn: {
placeholder: 'arn:aws:iam::123456789012:role/PmmRdsReadOnlyRole',
name: 'aws_role_arn',
label: 'AWS IAM role ARN',
tooltipText: 'Optional. PMM Server assumes this role before discovering RDS instances.',
},
},
submitButton: 'Discover',
toMenuButton: 'Return to menu',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export const getStyles = ({ breakpoints, spacing }: GrafanaTheme) => {
width: 100%;
`,
fieldsWrapper: css`
display: flex;
flex-direction: column;
width: 100%;
`,
credentialsRow: css`
display: flex;
width: 100%;
div {
Expand All @@ -34,6 +39,9 @@ export const getStyles = ({ breakpoints, spacing }: GrafanaTheme) => {
credentialsField: css`
width: 48%;
`,
roleArnField: css`
width: 100%;
`,
credentialsSubmit: css`
margin-left: ${spacing.md};
margin-right: ${spacing.sm};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,32 @@ import { render, screen, fireEvent } from '@testing-library/react';
import Credentials from './Credentials';

describe('Credentials:: ', () => {
it('should render access and secret keys fields', () => {
it('should render access key, secret key, and role ARN fields in order', () => {
render(<Credentials discover={jest.fn()} />);

expect(screen.getByTestId('aws_access_key-text-input')).toBeInTheDocument();
expect(screen.getByTestId('aws_secret_key-password-input')).toBeInTheDocument();
const accessKeyInput = screen.getByTestId('aws_access_key-text-input');
const secretKeyInput = screen.getByTestId('aws_secret_key-password-input');
const roleArnInput = screen.getByTestId('aws_role_arn-text-input');

expect(accessKeyInput).toBeInTheDocument();
expect(secretKeyInput).toBeInTheDocument();
expect(roleArnInput).toBeInTheDocument();
expect(accessKeyInput.compareDocumentPosition(secretKeyInput)).toBe(Node.DOCUMENT_POSITION_FOLLOWING);
expect(secretKeyInput.compareDocumentPosition(roleArnInput)).toBe(Node.DOCUMENT_POSITION_FOLLOWING);
});

it('should call discover on submit', () => {
const discover = jest.fn();
render(<Credentials discover={discover} />);

const form = screen.getByTestId('credentials-form');
fireEvent.change(screen.getByTestId('aws_role_arn-text-input'), {
target: { value: 'arn:aws:iam::123456789012:role/PmmRdsReadOnlyRole' },
});
fireEvent.submit(form);

expect(discover).toHaveBeenCalled();
expect(discover).toHaveBeenCalledWith(
expect.objectContaining({ aws_role_arn: 'arn:aws:iam::123456789012:role/PmmRdsReadOnlyRole' })
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Credentials: FC<CredentialsProps> = ({ discover }) => {

const onSubmit = useCallback(
(values: RDSCredentialsForm) => {
discover(values);
discover({ aws_access_key: '', aws_secret_key: '', aws_role_arn: '', ...values });
},
[discover]
);
Expand All @@ -31,17 +31,26 @@ const Credentials: FC<CredentialsProps> = ({ discover }) => {
data-testid="credentials-form"
>
<div className={styles.fieldsWrapper}>
<div className={styles.credentialsRow}>
<TextInputField
name={Messages.form.fields.awsAccessKey.name}
placeholder={Messages.form.fields.awsAccessKey.placeholder}
label={Messages.form.fields.awsAccessKey.label}
fieldClassName={styles.credentialsField}
/>
<PasswordInputField
name={Messages.form.fields.awsSecretKey.name}
placeholder={Messages.form.fields.awsSecretKey.placeholder}
label={Messages.form.fields.awsSecretKey.label}
fieldClassName={styles.credentialsField}
/>
</div>
<TextInputField
name={Messages.form.fields.awsAccessKey.name}
placeholder={Messages.form.fields.awsAccessKey.placeholder}
label={Messages.form.fields.awsAccessKey.label}
fieldClassName={styles.credentialsField}
/>
<PasswordInputField
name={Messages.form.fields.awsSecretKey.name}
placeholder={Messages.form.fields.awsSecretKey.placeholder}
label={Messages.form.fields.awsSecretKey.label}
fieldClassName={styles.credentialsField}
name={Messages.form.fields.awsRoleArn.name}
placeholder={Messages.form.fields.awsRoleArn.placeholder}
label={Messages.form.fields.awsRoleArn.label}
tooltipText={Messages.form.fields.awsRoleArn.tooltipText}
fieldClassName={styles.roleArnField}
/>
</div>
</form>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface RDSCredentialsForm {
aws_access_key: string;
aws_secret_key: string;
aws_role_arn: string;
}

export interface CredentialsProps {
Expand Down
1 change: 1 addition & 0 deletions public/app/percona/add-instance/panel.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface RemoteInstanceCredentials {
region?: string;
aws_access_key?: string;
aws_secret_key?: string;
aws_role_arn?: string;
azure_client_id?: string;
azure_client_secret?: string;
azure_tenant_id?: string;
Expand Down