@@ -19,9 +19,12 @@ import { HostInfo } from "../host_info";
1919import { AwsCredentialsManager } from "../authentication/aws_credentials_manager" ;
2020import { DescribeGlobalClustersCommand , GlobalCluster , GlobalClusterMember , RDSClient } from "@aws-sdk/client-rds" ;
2121import { AwsCredentialIdentity , AwsCredentialIdentityProvider } from "@smithy/types/dist-types/identity/awsCredentialIdentity" ;
22+ import { logger } from "../../logutils" ;
23+ import { Messages } from "./messages" ;
24+ import { AwsWrapperError } from "./errors" ;
2225
2326export class GDBRegionUtils extends RegionUtils {
24- private static readonly GDB_CLUSTER_ARN_PATTERN = / ^ a r n : a w s : r d s : (?< region > [ ^ : \n ] * ) : ( [ ^ : \n ] * ) : ( [ ^ : / \n ] * [: / ] ) ? ( .* ) $ / ;
27+ private static readonly GDB_CLUSTER_ARN_PATTERN = / ^ a r n : a w s [ ^ : ] * : r d s : (?< region > [ ^ : \n ] * ) : ( [ ^ : \n ] * ) : ( [ ^ : / \n ] * [: / ] ) ? ( .* ) $ / ;
2528 private static readonly REGION_GROUP = "region" ;
2629 private credentialsProvider : AwsCredentialIdentity | AwsCredentialIdentityProvider | undefined ;
2730
@@ -31,14 +34,14 @@ export class GDBRegionUtils extends RegionUtils {
3134 }
3235
3336 async getRegion ( regionKey : string , hostInfo ?: HostInfo , props ?: Map < string , any > ) : Promise < string | null > {
34- if ( props . get ( regionKey ) ) {
35- return super . getRegion ( props . get ( regionKey ) , hostInfo ) ;
36- }
37-
3837 if ( ! hostInfo || ! props ) {
3938 return null ;
4039 }
4140
41+ if ( props . get ( regionKey ) ) {
42+ return this . getRegionFromRegionString ( props . get ( regionKey ) ) ;
43+ }
44+
4245 const clusterId = GDBRegionUtils . rdsUtils . getRdsClusterId ( hostInfo . host ) ;
4346 if ( ! clusterId ) {
4447 return null ;
@@ -49,7 +52,7 @@ export class GDBRegionUtils extends RegionUtils {
4952 }
5053
5154 private async findWriterClusterArn ( hostInfo : HostInfo , props : Map < string , any > , globalClusterIdentifier : string ) : Promise < string | null > {
52- if ( this . credentialsProvider != null ) {
55+ if ( ! this . credentialsProvider ) {
5356 this . credentialsProvider = AwsCredentialsManager . getProvider ( hostInfo , props ) ;
5457 }
5558
@@ -62,6 +65,11 @@ export class GDBRegionUtils extends RegionUtils {
6265
6366 const response = await rdsClient . send ( command ) ;
6467 return this . extractWriterClusterArn ( response . GlobalClusters ) ;
68+ } catch ( error ) {
69+ if ( error instanceof Error ) {
70+ logger . debug ( Messages . get ( "GDBRegionUtils.unableToRetrieveGlobalClusterARN" ) ) ;
71+ throw new AwsWrapperError ( Messages . get ( "GDBRegionUtils.unableToRetrieveGlobalClusterARN" ) ) ;
72+ }
6573 } finally {
6674 rdsClient . destroy ( ) ;
6775 }
@@ -82,6 +90,11 @@ export class GDBRegionUtils extends RegionUtils {
8290 return null ;
8391 }
8492
93+ getRegionFromClusterArn ( clusterArn : string ) : string | null {
94+ const match = clusterArn . match ( GDBRegionUtils . GDB_CLUSTER_ARN_PATTERN ) ;
95+ return match ?. groups ?. [ GDBRegionUtils . REGION_GROUP ] ?? null ;
96+ }
97+
8598 private findWriterMemberArn ( members ?: GlobalClusterMember [ ] ) : string | null {
8699 if ( ! members ) {
87100 return null ;
@@ -91,11 +104,6 @@ export class GDBRegionUtils extends RegionUtils {
91104 return writerMember ?. DBClusterArn ?? null ;
92105 }
93106
94- private getRegionFromClusterArn ( clusterArn : string ) : string | null {
95- const match = clusterArn . match ( GDBRegionUtils . GDB_CLUSTER_ARN_PATTERN ) ;
96- return match ?. groups ?. [ GDBRegionUtils . REGION_GROUP ] ?? null ;
97- }
98-
99107 private getRdsClient ( ) : RDSClient {
100108 return new RDSClient ( { credentials : this . credentialsProvider } ) ;
101109 }
0 commit comments