CloudWatch: Make deeplinks work for us-gov and china regions (#64080)

This commit is contained in:
Isabella Siu
2023-03-06 16:00:59 -05:00
committed by GitHub
parent e7cd629e79
commit 4f3d64e8b7
4 changed files with 74 additions and 6 deletions

View 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');
});
});

View File

@@ -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)}`;
}