Cloudwatch: Upgrade aws-sdk and display external ids for temporary credentials (#72821)

(under a feature toggle, not yet ready for public testing)
This commit is contained in:
Sarah Zinger
2023-08-14 13:42:30 -04:00
committed by GitHub
parent c2aeb9882d
commit 09d5483c6c
9 changed files with 92 additions and 6 deletions

View File

@@ -36,6 +36,10 @@ jest.mock('@grafana/runtime', () => ({
get: getMock,
}),
getAppEvents: () => mockAppEvents,
config: {
...jest.requireActual('@grafana/runtime').config,
awsAssumeRoleEnabled: true,
},
}));
const props: Props = {

View File

@@ -57,6 +57,15 @@ export const ConfigEditor = (props: Props) => {
failSubscription.unsubscribe();
};
}, [options.jsonData.authType, report]);
const [externalId, setExternalId] = useState('');
useEffect(() => {
if (!externalId && datasource) {
datasource.resources
.getExternalId()
.then(setExternalId)
.catch(() => setExternalId('Unable to fetch externalId'));
}
}, [datasource, externalId]);
return (
<>
@@ -76,6 +85,7 @@ export const ConfigEditor = (props: Props) => {
);
})
}
externalId={externalId}
>
<InlineField label="Namespaces of Custom Metrics" labelWidth={29} tooltip="Namespaces of Custom Metrics.">
<Input

View File

@@ -35,6 +35,10 @@ export class ResourcesAPI extends CloudWatchRequest {
return getBackendSrv().get(`/api/datasources/${this.instanceSettings.id}/resources/${subtype}`, parameters);
}
async getExternalId(): Promise<string> {
return await this.memoizedGetRequest<{ externalId: string }>('external-id').then(({ externalId }) => externalId);
}
getAccounts({ region }: ResourceRequest): Promise<Account[]> {
return this.memoizedGetRequest<Array<ResourceResponse<Account>>>('accounts', {
region: this.templateSrv.replace(this.getActualRegion(region)),