@@ -23,8 +23,8 @@ export class Default {
23
23
* @param urlSuffix deprecated and ignored.
24
24
*/
25
25
public static servicePrincipal ( serviceFqn : string , region : string , urlSuffix : string ) : string {
26
- const service = extractSimpleName ( serviceFqn ) ;
27
- if ( ! service ) {
26
+ const serviceName = extractSimpleName ( serviceFqn ) ;
27
+ if ( ! serviceName ) {
28
28
// Return "service" if it does not look like any of the following:
29
29
// - s3
30
30
// - s3.amazonaws.com
@@ -34,72 +34,86 @@ export class Default {
34
34
return serviceFqn ;
35
35
}
36
36
37
- // Exceptions for Service Principals in us-iso-*
38
- const US_ISO_EXCEPTIONS = new Set ( [
39
- 'cloudhsm' ,
40
- 'config' ,
41
- 'states' ,
42
- 'workspaces' ,
43
- ] ) ;
44
-
45
- // Account for idiosyncratic Service Principals in `us-iso-*` regions
46
- if ( region . startsWith ( 'us-iso-' ) && US_ISO_EXCEPTIONS . has ( service ) ) {
47
- switch ( service ) {
48
- // Services with universal principal
49
- case ( 'states' ) :
50
- return `${ service } .amazonaws.com` ;
51
-
52
- // Services with a partitional principal
53
- default :
54
- return `${ service } .${ urlSuffix } ` ;
37
+ function determineConfiguration ( service : string ) : ( service : string , region : string , urlSuffix : string ) => string {
38
+ function universal ( s : string ) { return `${ s } .amazonaws.com` ; } ;
39
+ function partitional ( s : string , _ : string , u : string ) { return `${ s } .${ u } ` ; } ;
40
+ function regional ( s : string , r : string ) { return `${ s } .${ r } .amazonaws.com` ; } ;
41
+ function regionalPartitional ( s : string , r : string , u : string ) { return `${ s } .${ r } .${ u } ` ; } ;
42
+
43
+ // Exceptions for Service Principals in us-iso-*
44
+ const US_ISO_EXCEPTIONS = new Set ( [
45
+ 'cloudhsm' ,
46
+ 'config' ,
47
+ 'states' ,
48
+ 'workspaces' ,
49
+ ] ) ;
50
+
51
+ // Account for idiosyncratic Service Principals in `us-iso-*` regions
52
+ if ( region . startsWith ( 'us-iso-' ) && US_ISO_EXCEPTIONS . has ( service ) ) {
53
+ switch ( service ) {
54
+ // Services with universal principal
55
+ case ( 'states' ) :
56
+ return universal ;
57
+
58
+ // Services with a partitional principal
59
+ default :
60
+ return partitional ;
61
+ }
55
62
}
56
- }
57
63
58
- // Exceptions for Service Principals in us-isob-*
59
- const US_ISOB_EXCEPTIONS = new Set ( [
60
- 'dms' ,
61
- 'states' ,
62
- ] ) ;
64
+ // Exceptions for Service Principals in us-isob-*
65
+ const US_ISOB_EXCEPTIONS = new Set ( [
66
+ 'dms' ,
67
+ 'states' ,
68
+ ] ) ;
69
+
70
+ // Account for idiosyncratic Service Principals in `us-isob-*` regions
71
+ if ( region . startsWith ( 'us-isob-' ) && US_ISOB_EXCEPTIONS . has ( service ) ) {
72
+ switch ( service ) {
73
+ // Services with universal principal
74
+ case ( 'states' ) :
75
+ return universal ;
76
+
77
+ // Services with a partitional principal
78
+ default :
79
+ return partitional ;
80
+ }
81
+ }
63
82
64
- // Account for idiosyncratic Service Principals in `us-isob-*` regions
65
- if ( region . startsWith ( 'us-isob-' ) && US_ISOB_EXCEPTIONS . has ( service ) ) {
66
83
switch ( service ) {
67
- // Services with universal principal
68
- case ( 'states' ) :
69
- return `${ service } .amazonaws.com` ;
84
+ // SSM turned from global to regional at some point
85
+ case 'ssm' :
86
+ return before ( region , RULE_SSM_PRINCIPALS_ARE_REGIONAL )
87
+ ? universal
88
+ : regional ;
89
+
90
+ // CodeDeploy is regional+partitional in CN, only regional everywhere else
91
+ case 'codedeploy' :
92
+ return region . startsWith ( 'cn-' )
93
+ ? regionalPartitional
94
+ : regional ;
95
+
96
+ // Services with a regional AND partitional principal
97
+ case 'logs' :
98
+ return regionalPartitional ;
99
+
100
+ // Services with a regional principal
101
+ case 'states' :
102
+ return regional ;
70
103
71
104
// Services with a partitional principal
72
- default :
73
- return `${ service } .${ urlSuffix } ` ;
74
- }
75
- }
76
-
77
- // SSM turned from global to regional at some point
78
- if ( service === 'ssm' ) {
79
- return before ( region , RULE_SSM_PRINCIPALS_ARE_REGIONAL )
80
- ? `${ service } .amazonaws.com`
81
- : `${ service } .${ region } .amazonaws.com` ;
82
- }
83
-
84
- switch ( service ) {
85
- // Services with a regional AND partitional principal
86
- case 'codedeploy' :
87
- case 'logs' :
88
- return `${ service } .${ region } .${ urlSuffix } ` ;
89
-
90
- // Services with a regional principal
91
- case 'states' :
92
- return `${ service } .${ region } .amazonaws.com` ;
105
+ case 'ec2' :
106
+ return partitional ;
93
107
94
- // Services with a partitional principal
95
- case 'ec2' :
96
- return ` ${ service } . ${ urlSuffix } ` ;
108
+ // Services with a universal principal across all regions/partitions (the default case)
109
+ default :
110
+ return universal ;
97
111
98
- // Services with a universal principal across all regions/partitions (the default case)
99
- default :
100
- return `${ service } .amazonaws.com` ;
112
+ }
113
+ } ;
101
114
102
- }
115
+ const configuration = determineConfiguration ( serviceName ) ;
116
+ return configuration ( serviceName , region , urlSuffix ) ;
103
117
}
104
118
105
119
private constructor ( ) { }
@@ -108,4 +122,4 @@ export class Default {
108
122
function extractSimpleName ( serviceFqn : string ) {
109
123
const matches = serviceFqn . match ( / ^ ( [ ^ . ] + ) (?: (?: \. a m a z o n a w s \. c o m (?: \. c n ) ? ) | (?: \. c 2 s \. i c \. g o v ) | (?: \. s c 2 s \. s g o v \. g o v ) ) ? $ / ) ;
110
124
return matches ? matches [ 1 ] : undefined ;
111
- }
125
+ }
0 commit comments