mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudWatch: Make deeplinks work for us-gov and china regions (#64080)
This commit is contained in:
18
public/app/plugins/datasource/cloudwatch/aws_url.test.ts
Normal file
18
public/app/plugins/datasource/cloudwatch/aws_url.test.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { getLogsEndpoint } from './aws_url';
|
||||
|
||||
describe('getEndpoint', () => {
|
||||
it('should return the default url for normal regions', () => {
|
||||
const result = getLogsEndpoint('us-east-1');
|
||||
expect(result).toBe('us-east-1.console.aws.amazon.com');
|
||||
});
|
||||
|
||||
it('should return the us-gov url for us-gov regions', () => {
|
||||
const result = getLogsEndpoint('us-gov-east-1');
|
||||
expect(result).toBe('us-gov-east-1.console.amazonaws-us-gov.com');
|
||||
});
|
||||
|
||||
it('should return the china url for cn regions', () => {
|
||||
const result = getLogsEndpoint('cn-northwest-1');
|
||||
expect(result).toBe('cn-northwest-1.console.amazonaws.cn');
|
||||
});
|
||||
});
|
||||
@@ -11,8 +11,23 @@ export interface AwsUrl {
|
||||
source: string[];
|
||||
}
|
||||
|
||||
export function encodeUrl(obj: AwsUrl, region: string): string {
|
||||
return `https://${region}.console.aws.amazon.com/cloudwatch/home?region=${region}#logs-insights:queryDetail=${JSURL.stringify(
|
||||
obj
|
||||
)}`;
|
||||
const defaultURL = 'console.aws.amazon.com';
|
||||
const usGovURL = 'console.amazonaws-us-gov.com';
|
||||
const chinaURL = 'console.amazonaws.cn';
|
||||
|
||||
export function getLogsEndpoint(region: string): string {
|
||||
let url = defaultURL;
|
||||
if (region.startsWith('us-gov-')) {
|
||||
url = usGovURL;
|
||||
}
|
||||
if (region.startsWith('cn-')) {
|
||||
url = chinaURL;
|
||||
}
|
||||
return `${region}.${url}`;
|
||||
}
|
||||
|
||||
export function encodeUrl(obj: AwsUrl, region: string): string {
|
||||
return `https://${getLogsEndpoint(
|
||||
region
|
||||
)}/cloudwatch/home?region=${region}#logs-insights:queryDetail=${JSURL.stringify(obj)}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user