@@ -116,13 +116,31 @@ export const validateDNSHostLabel = (label: string, options: { tlsCompatible?: b
116
116
}
117
117
} ;
118
118
119
- export const getAccessPointName = ( resource : string ) : string => {
120
- if ( resource . indexOf ( "accesspoint:" ) !== 0 && resource . indexOf ( "accesspoint/" ) !== 0 ) {
121
- throw new Error ( "Access point ARN resource should begin with 'accesspoint/'" ) ;
119
+ export const getArnResources = (
120
+ resource : string
121
+ ) : {
122
+ accesspointName : string ;
123
+ outpostId ?: string ;
124
+ } => {
125
+ const delimiter = resource . includes ( ":" ) ? ":" : "/" ;
126
+ const [ resourceType , ...rest ] = resource . split ( delimiter ) ;
127
+ if ( resourceType === "accesspoint" ) {
128
+ // Parse accesspoint ARN
129
+ if ( rest . length !== 1 || rest [ 0 ] === "" ) {
130
+ throw new Error ( "Access Point ARN should have one resource accesspoint/{accesspointname}" ) ;
131
+ }
132
+ return { accesspointName : rest [ 0 ] } ;
133
+ } else if ( resourceType === "outpost" ) {
134
+ // Parse outpost ARN
135
+ if ( ! rest [ 0 ] || rest [ 1 ] !== "accesspoint" || ! rest [ 2 ] || rest . length !== 3 ) {
136
+ throw new Error ( "Outpost ARN should have resource outpost/{outpostId}/accesspoint/{accesspointName}" ) ;
137
+ }
138
+ const [ outpostId , _ , accesspointName ] = rest ;
139
+ if ( ! / o p - [ 0 - 9 a - f A - F ] { 17 } / . test ( outpostId ) ) throw new Error ( "Outpost Id must follow pattern /op-[0-9a-fA-F]{17}/" ) ;
140
+ if ( ! / [ 0 - 9 a - z A - Z - ] { 3 , 50 } / . test ( accesspointName ) )
141
+ throw new Error ( "Accesspoint name must follow pattern /[0-9a-zA-Z-]{3,50}/" ) ;
142
+ return { outpostId, accesspointName } ;
143
+ } else {
144
+ throw new Error ( `ARN resource should begin with 'accesspoint${ delimiter } ' or 'outpost${ delimiter } '` ) ;
122
145
}
123
- const parsedResource = resource . split ( resource [ "accesspoint" . length ] ) ;
124
- if ( parsedResource . length !== 2 || parsedResource [ 1 ] === "" ) {
125
- throw new Error ( "Access Point ARN should have one resource accesspoint/{accesspointname}" ) ;
126
- }
127
- return parsedResource [ 1 ] ;
128
146
} ;
0 commit comments