@actsecurity/iam-utils 0.1.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +661 -0
- package/README.md +5 -0
- package/dist/cjs/actions.d.ts +9 -0
- package/dist/cjs/actions.d.ts.map +1 -0
- package/dist/cjs/actions.js +65 -0
- package/dist/cjs/actions.js.map +1 -0
- package/dist/cjs/arn.d.ts +48 -0
- package/dist/cjs/arn.d.ts.map +1 -0
- package/dist/cjs/arn.js +67 -0
- package/dist/cjs/arn.js.map +1 -0
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +31 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/principals.d.ts +58 -0
- package/dist/cjs/principals.d.ts.map +1 -0
- package/dist/cjs/principals.js +93 -0
- package/dist/cjs/principals.js.map +1 -0
- package/dist/cjs/resourceInfoContextKeys.d.ts +19 -0
- package/dist/cjs/resourceInfoContextKeys.d.ts.map +1 -0
- package/dist/cjs/resourceInfoContextKeys.js +54 -0
- package/dist/cjs/resourceInfoContextKeys.js.map +1 -0
- package/dist/cjs/resourcePatterns.d.ts +9 -0
- package/dist/cjs/resourcePatterns.d.ts.map +1 -0
- package/dist/cjs/resourcePatterns.js +19 -0
- package/dist/cjs/resourcePatterns.js.map +1 -0
- package/dist/cjs/resourceTypes.d.ts +30 -0
- package/dist/cjs/resourceTypes.d.ts.map +1 -0
- package/dist/cjs/resourceTypes.js +267 -0
- package/dist/cjs/resourceTypes.js.map +1 -0
- package/dist/cjs/resources.d.ts +8 -0
- package/dist/cjs/resources.d.ts.map +1 -0
- package/dist/cjs/resources.js +14 -0
- package/dist/cjs/resources.js.map +1 -0
- package/dist/cjs/s3.d.ts +15 -0
- package/dist/cjs/s3.d.ts.map +1 -0
- package/dist/cjs/s3.js +35 -0
- package/dist/cjs/s3.js.map +1 -0
- package/dist/esm/actions.d.ts +9 -0
- package/dist/esm/actions.d.ts.map +1 -0
- package/dist/esm/actions.js +62 -0
- package/dist/esm/actions.js.map +1 -0
- package/dist/esm/arn.d.ts +48 -0
- package/dist/esm/arn.d.ts.map +1 -0
- package/dist/esm/arn.js +63 -0
- package/dist/esm/arn.js.map +1 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/principals.d.ts +58 -0
- package/dist/esm/principals.d.ts.map +1 -0
- package/dist/esm/principals.js +83 -0
- package/dist/esm/principals.js.map +1 -0
- package/dist/esm/resourceInfoContextKeys.d.ts +19 -0
- package/dist/esm/resourceInfoContextKeys.d.ts.map +1 -0
- package/dist/esm/resourceInfoContextKeys.js +50 -0
- package/dist/esm/resourceInfoContextKeys.js.map +1 -0
- package/dist/esm/resourcePatterns.d.ts +9 -0
- package/dist/esm/resourcePatterns.d.ts.map +1 -0
- package/dist/esm/resourcePatterns.js +16 -0
- package/dist/esm/resourcePatterns.js.map +1 -0
- package/dist/esm/resourceTypes.d.ts +30 -0
- package/dist/esm/resourceTypes.d.ts.map +1 -0
- package/dist/esm/resourceTypes.js +263 -0
- package/dist/esm/resourceTypes.js.map +1 -0
- package/dist/esm/resources.d.ts +8 -0
- package/dist/esm/resources.d.ts.map +1 -0
- package/dist/esm/resources.js +11 -0
- package/dist/esm/resources.js.map +1 -0
- package/dist/esm/s3.d.ts +15 -0
- package/dist/esm/s3.d.ts.map +1 -0
- package/dist/esm/s3.js +31 -0
- package/dist/esm/s3.js.map +1 -0
- package/package.json +115 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform an assumed role session ARN into a role ARN
|
|
3
|
+
*
|
|
4
|
+
* @param assumedRoleArn the assumed role session ARN
|
|
5
|
+
* @returns the role ARN for the assumed role session
|
|
6
|
+
*/
|
|
7
|
+
export declare function convertAssumedRoleArnToRoleArn(assumedRoleArn: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Create an assumed role ARN from a role ARN and a session name
|
|
10
|
+
*
|
|
11
|
+
* @param roleArn the role ARN to create an assumed role ARN from
|
|
12
|
+
* @param sessionName the session name to use
|
|
13
|
+
* @returns the assumed role ARN
|
|
14
|
+
*/
|
|
15
|
+
export declare function convertRoleArnToAssumedRoleArn(roleArn: string, sessionName: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Tests if a principal string is an assumed role ARN
|
|
18
|
+
*
|
|
19
|
+
* @param principal the principal string to test
|
|
20
|
+
* @returns true if the principal is an assumed role ARN, false otherwise
|
|
21
|
+
*/
|
|
22
|
+
export declare function isAssumedRoleArn(principal: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Test if a principal string is an IAM user ARN
|
|
25
|
+
*
|
|
26
|
+
* @param principal the principal string to test
|
|
27
|
+
* @returns true if the principal is an IAM user ARN, false otherwise
|
|
28
|
+
*/
|
|
29
|
+
export declare function isIamUserArn(principal: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Test if a principal string is an IAM Role ARN
|
|
32
|
+
*
|
|
33
|
+
* @param principal the principal string to test
|
|
34
|
+
* @returns true if the principal is an IAM role ARN, false otherwise
|
|
35
|
+
*/
|
|
36
|
+
export declare function isIamRoleArn(principal: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Test if a principal string is a federated user ARN
|
|
39
|
+
*
|
|
40
|
+
* @param principal the principal string to test
|
|
41
|
+
* @returns true if the principal is a federated user ARN, false otherwise
|
|
42
|
+
*/
|
|
43
|
+
export declare function isFederatedUserArn(principal: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Test if a principal string is an ARN
|
|
46
|
+
*
|
|
47
|
+
* @param principal the principal string to test
|
|
48
|
+
* @returns true if the principal is an ARN, false otherwise
|
|
49
|
+
*/
|
|
50
|
+
export declare function isArnPrincipal(principal: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Test if a principal string is a service principal
|
|
53
|
+
*
|
|
54
|
+
* @param principal the principal string to test
|
|
55
|
+
* @returns true if the principal is a service principal, false otherwise
|
|
56
|
+
*/
|
|
57
|
+
export declare function isServicePrincipal(principal: string): boolean;
|
|
58
|
+
//# sourceMappingURL=principals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"principals.d.ts","sourceRoot":"","sources":["../../src/principals.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAI7E;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAI3F;AAID;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE3D;AAID;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEvD;AAID;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEvD;AAID;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE7D"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { splitArnParts } from './arn.js';
|
|
2
|
+
/**
|
|
3
|
+
* Transform an assumed role session ARN into a role ARN
|
|
4
|
+
*
|
|
5
|
+
* @param assumedRoleArn the assumed role session ARN
|
|
6
|
+
* @returns the role ARN for the assumed role session
|
|
7
|
+
*/
|
|
8
|
+
export function convertAssumedRoleArnToRoleArn(assumedRoleArn) {
|
|
9
|
+
const arnParts = splitArnParts(assumedRoleArn);
|
|
10
|
+
const rolePathAndName = arnParts.resourcePath?.split('/').slice(0, -1).join('/');
|
|
11
|
+
return `arn:${arnParts.partition}:iam::${arnParts.accountId}:role/${rolePathAndName}`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create an assumed role ARN from a role ARN and a session name
|
|
15
|
+
*
|
|
16
|
+
* @param roleArn the role ARN to create an assumed role ARN from
|
|
17
|
+
* @param sessionName the session name to use
|
|
18
|
+
* @returns the assumed role ARN
|
|
19
|
+
*/
|
|
20
|
+
export function convertRoleArnToAssumedRoleArn(roleArn, sessionName) {
|
|
21
|
+
const arnParts = splitArnParts(roleArn);
|
|
22
|
+
const rolePathAndName = arnParts.resourcePath;
|
|
23
|
+
return `arn:${arnParts.partition}:sts::${arnParts.accountId}:assumed-role/${rolePathAndName}/${sessionName}`;
|
|
24
|
+
}
|
|
25
|
+
const assumedRoleArnRegex = /^arn:[a-zA-Z\-]+:sts::\d{12}:assumed-role\/.*$/;
|
|
26
|
+
/**
|
|
27
|
+
* Tests if a principal string is an assumed role ARN
|
|
28
|
+
*
|
|
29
|
+
* @param principal the principal string to test
|
|
30
|
+
* @returns true if the principal is an assumed role ARN, false otherwise
|
|
31
|
+
*/
|
|
32
|
+
export function isAssumedRoleArn(principal) {
|
|
33
|
+
return assumedRoleArnRegex.test(principal);
|
|
34
|
+
}
|
|
35
|
+
const userArnRegex = /^arn:[a-zA-Z\-]+:iam::\d{12}:user\/.*$/;
|
|
36
|
+
/**
|
|
37
|
+
* Test if a principal string is an IAM user ARN
|
|
38
|
+
*
|
|
39
|
+
* @param principal the principal string to test
|
|
40
|
+
* @returns true if the principal is an IAM user ARN, false otherwise
|
|
41
|
+
*/
|
|
42
|
+
export function isIamUserArn(principal) {
|
|
43
|
+
return userArnRegex.test(principal);
|
|
44
|
+
}
|
|
45
|
+
const iamRoleArnRegex = /^arn:[a-zA-Z\-]+:iam::\d{12}:role\/.*$/;
|
|
46
|
+
/**
|
|
47
|
+
* Test if a principal string is an IAM Role ARN
|
|
48
|
+
*
|
|
49
|
+
* @param principal the principal string to test
|
|
50
|
+
* @returns true if the principal is an IAM role ARN, false otherwise
|
|
51
|
+
*/
|
|
52
|
+
export function isIamRoleArn(principal) {
|
|
53
|
+
return iamRoleArnRegex.test(principal);
|
|
54
|
+
}
|
|
55
|
+
const federatedUserArnRegex = /^arn:[a-zA-Z\-]+:sts::\d{12}:federated-user\/.*$/;
|
|
56
|
+
/**
|
|
57
|
+
* Test if a principal string is a federated user ARN
|
|
58
|
+
*
|
|
59
|
+
* @param principal the principal string to test
|
|
60
|
+
* @returns true if the principal is a federated user ARN, false otherwise
|
|
61
|
+
*/
|
|
62
|
+
export function isFederatedUserArn(principal) {
|
|
63
|
+
return federatedUserArnRegex.test(principal);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Test if a principal string is an ARN
|
|
67
|
+
*
|
|
68
|
+
* @param principal the principal string to test
|
|
69
|
+
* @returns true if the principal is an ARN, false otherwise
|
|
70
|
+
*/
|
|
71
|
+
export function isArnPrincipal(principal) {
|
|
72
|
+
return principal.startsWith('arn:');
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Test if a principal string is a service principal
|
|
76
|
+
*
|
|
77
|
+
* @param principal the principal string to test
|
|
78
|
+
* @returns true if the principal is a service principal, false otherwise
|
|
79
|
+
*/
|
|
80
|
+
export function isServicePrincipal(principal) {
|
|
81
|
+
return !isArnPrincipal(principal) && principal.endsWith('amazonaws.com');
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=principals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"principals.js","sourceRoot":"","sources":["../../src/principals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B,CAAC,cAAsB;IACnE,MAAM,QAAQ,GAAG,aAAa,CAAC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H,MAAM,UAAU,cAAc,CAAC,SAAiB;IAC9C,OAAO,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;AACrC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAiB;IAClD,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAA;AAC1E,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether an IAM action is excluded from AWS resource-information context keys.
|
|
3
|
+
*
|
|
4
|
+
* AWS does not populate `aws:ResourceAccount`, `aws:ResourceOrgID`, or
|
|
5
|
+
* `aws:ResourceOrgPaths` for every action. This predicate captures the documented
|
|
6
|
+
* excluded actions currently used by Cloud Copilot request-context generation.
|
|
7
|
+
*
|
|
8
|
+
* @param action - IAM action to inspect, such as `s3:GetObject`.
|
|
9
|
+
* @returns True when AWS resource-information context keys are not available.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isAwsResourceInfoExcludedAction(action: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Checks whether AWS resource-information context keys are available for an IAM action.
|
|
14
|
+
*
|
|
15
|
+
* @param action - IAM action to inspect, such as `s3:GetObject`.
|
|
16
|
+
* @returns True when `aws:ResourceAccount`, `aws:ResourceOrgID`, and `aws:ResourceOrgPaths` may be populated.
|
|
17
|
+
*/
|
|
18
|
+
export declare function actionSupportsAwsResourceInfoContextKeys(action: string): boolean;
|
|
19
|
+
//# sourceMappingURL=resourceInfoContextKeys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceInfoContextKeys.d.ts","sourceRoot":"","sources":["../../src/resourceInfoContextKeys.ts"],"names":[],"mappings":"AA2BA;;;;;;;;;GASG;AACH,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAGvE;AAED;;;;;GAKG;AACH,wBAAgB,wCAAwC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const awsResourceInfoExcludedActions = new Set([
|
|
2
|
+
'auditmanager:updateassessmentframeworkshare',
|
|
3
|
+
'detective:acceptinvitation',
|
|
4
|
+
'ds:acceptshareddirectory',
|
|
5
|
+
'ec2:accepttransitgatewaypeeringattachment',
|
|
6
|
+
'ec2:acceptvpcendpointconnections',
|
|
7
|
+
'ec2:acceptvpcpeeringconnection',
|
|
8
|
+
'ec2:copysnapshot',
|
|
9
|
+
'ec2:createtransitgatewaypeeringattachment',
|
|
10
|
+
'ec2:createvpcendpoint',
|
|
11
|
+
'ec2:createvpcpeeringconnection',
|
|
12
|
+
'ec2:deletetransitgatewaypeeringattachment',
|
|
13
|
+
'ec2:deletevpcpeeringconnection',
|
|
14
|
+
'ec2:rejecttransitgatewaypeeringattachment',
|
|
15
|
+
'ec2:rejectvpcendpointconnections',
|
|
16
|
+
'ec2:rejectvpcpeeringconnection',
|
|
17
|
+
'guardduty:acceptadministratorinvitation',
|
|
18
|
+
'macie2:acceptinvitation',
|
|
19
|
+
'es:acceptinboundconnection',
|
|
20
|
+
'route53:associatevpcwithhostedzone',
|
|
21
|
+
'route53:createvpcassociationauthorization',
|
|
22
|
+
'route53:deletevpcassociationauthorization',
|
|
23
|
+
'route53:disassociatevpcfromhostedzone',
|
|
24
|
+
'route53:listhostedzonesbyvpc',
|
|
25
|
+
'securityhub:acceptadministratorinvitation'
|
|
26
|
+
]);
|
|
27
|
+
/**
|
|
28
|
+
* Checks whether an IAM action is excluded from AWS resource-information context keys.
|
|
29
|
+
*
|
|
30
|
+
* AWS does not populate `aws:ResourceAccount`, `aws:ResourceOrgID`, or
|
|
31
|
+
* `aws:ResourceOrgPaths` for every action. This predicate captures the documented
|
|
32
|
+
* excluded actions currently used by Cloud Copilot request-context generation.
|
|
33
|
+
*
|
|
34
|
+
* @param action - IAM action to inspect, such as `s3:GetObject`.
|
|
35
|
+
* @returns True when AWS resource-information context keys are not available.
|
|
36
|
+
*/
|
|
37
|
+
export function isAwsResourceInfoExcludedAction(action) {
|
|
38
|
+
const lowerCaseAction = action.toLowerCase();
|
|
39
|
+
return lowerCaseAction.startsWith('ebs:') || awsResourceInfoExcludedActions.has(lowerCaseAction);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Checks whether AWS resource-information context keys are available for an IAM action.
|
|
43
|
+
*
|
|
44
|
+
* @param action - IAM action to inspect, such as `s3:GetObject`.
|
|
45
|
+
* @returns True when `aws:ResourceAccount`, `aws:ResourceOrgID`, and `aws:ResourceOrgPaths` may be populated.
|
|
46
|
+
*/
|
|
47
|
+
export function actionSupportsAwsResourceInfoContextKeys(action) {
|
|
48
|
+
return !isAwsResourceInfoExcludedAction(action);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=resourceInfoContextKeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceInfoContextKeys.js","sourceRoot":"","sources":["../../src/resourceInfoContextKeys.ts"],"names":[],"mappings":"AAAA,MAAM,8BAA8B,GAAG,IAAI,GAAG,CAAC;IAC7C,6CAA6C;IAC7C,4BAA4B;IAC5B,0BAA0B;IAC1B,2CAA2C;IAC3C,kCAAkC;IAClC,gCAAgC;IAChC,kBAAkB;IAClB,2CAA2C;IAC3C,uBAAuB;IACvB,gCAAgC;IAChC,2CAA2C;IAC3C,gCAAgC;IAChC,2CAA2C;IAC3C,kCAAkC;IAClC,gCAAgC;IAChC,yCAAyC;IACzC,yBAAyB;IACzB,4BAA4B;IAC5B,oCAAoC;IACpC,2CAA2C;IAC3C,2CAA2C;IAC3C,uCAAuC;IACvC,8BAA8B;IAC9B,2CAA2C;CAC5C,CAAC,CAAA;AAEF;;;;;;;;;GASG;AACH,MAAM,UAAU,+BAA+B,CAAC,MAAc;IAC5D,MAAM,eAAe,GAAG,MAAM,CAAC,WAAW,EAAE,CAAA;IAC5C,OAAO,eAAe,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,8BAA8B,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;AAClG,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,wCAAwC,CAAC,MAAc;IACrE,OAAO,CAAC,+BAA+B,CAAC,MAAM,CAAC,CAAA;AACjD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a resource pattern from iam-data to a regex pattern.
|
|
3
|
+
* Variables like `${BucketName}` become named capture groups.
|
|
4
|
+
*
|
|
5
|
+
* @param pattern - The IAM resource type ARN pattern (e.g. `arn:${Partition}:s3:::${BucketName}/${ObjectName}`)
|
|
6
|
+
* @returns A regex string anchored with `^...$` that matches concrete ARNs against the pattern
|
|
7
|
+
*/
|
|
8
|
+
export declare function convertResourcePatternToRegex(pattern: string): string;
|
|
9
|
+
//# sourceMappingURL=resourcePatterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourcePatterns.d.ts","sourceRoot":"","sources":["../../src/resourcePatterns.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAOrE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a resource pattern from iam-data to a regex pattern.
|
|
3
|
+
* Variables like `${BucketName}` become named capture groups.
|
|
4
|
+
*
|
|
5
|
+
* @param pattern - The IAM resource type ARN pattern (e.g. `arn:${Partition}:s3:::${BucketName}/${ObjectName}`)
|
|
6
|
+
* @returns A regex string anchored with `^...$` that matches concrete ARNs against the pattern
|
|
7
|
+
*/
|
|
8
|
+
export function convertResourcePatternToRegex(pattern) {
|
|
9
|
+
const regex = pattern.replace(/\$\{.*?\}/g, (match) => {
|
|
10
|
+
const name = match.substring(2, match.length - 1);
|
|
11
|
+
const camelName = name.at(0)?.toLowerCase() + name.substring(1);
|
|
12
|
+
return `(?<${camelName}>(.+?))`;
|
|
13
|
+
});
|
|
14
|
+
return `^${regex}$`;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=resourcePatterns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourcePatterns.js","sourceRoot":"","sources":["../../src/resourcePatterns.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,6BAA6B,CAAC,OAAe;IAC3D,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE;QACpD,MAAM,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QACjD,MAAM,SAAS,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;QAC/D,OAAO,MAAM,SAAS,SAAS,CAAA;IACjC,CAAC,CAAC,CAAA;IACF,OAAO,IAAI,KAAK,GAAG,CAAA;AACrB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether a concrete resource ARN (possibly with wildcards) matches
|
|
3
|
+
* a resource-type ARN pattern from the Service Authorization Reference.
|
|
4
|
+
*
|
|
5
|
+
* A wildcard resource string (`"*"`) always matches.
|
|
6
|
+
*
|
|
7
|
+
* This is a compatibility check: it returns true when there is at least one
|
|
8
|
+
* concrete ARN that could satisfy both the resource string and the resource
|
|
9
|
+
* type pattern. Resource type variables may span resource-component separators
|
|
10
|
+
* such as `:` and `/`.
|
|
11
|
+
*
|
|
12
|
+
* @param resourceString - A concrete resource ARN or wildcard (`"*"`)
|
|
13
|
+
* @param resourcePattern - An ARN pattern from iam-data (e.g. `arn:${Partition}:s3:::${BucketName}/${ObjectName}`)
|
|
14
|
+
* @returns Whether the resource string matches the pattern
|
|
15
|
+
*/
|
|
16
|
+
export declare function resourceStringMatchesResourceTypePattern(resourceString: string, resourcePattern: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Reduce resource type patterns to the most specific patterns that match a resource string.
|
|
19
|
+
*
|
|
20
|
+
* This helper does not know about iam-data or service-specific resource type ordering. It uses
|
|
21
|
+
* the provided pattern set as context and removes matching parent patterns when a matching child
|
|
22
|
+
* pattern has all of the parent's literal structure plus additional literal structure. Wildcard
|
|
23
|
+
* resource strings preserve all matches because the wildcard may refer to parent and child resources.
|
|
24
|
+
*
|
|
25
|
+
* @param resourceString - A concrete resource ARN or wildcard (`"*"`)
|
|
26
|
+
* @param resourcePatterns - Candidate resource type ARN patterns
|
|
27
|
+
* @returns Matching resource type patterns with less-specific parent patterns removed, in input order
|
|
28
|
+
*/
|
|
29
|
+
export declare function mostSpecificMatchingResourceTypePatterns(resourceString: string, resourcePatterns: string[]): string[];
|
|
30
|
+
//# sourceMappingURL=resourceTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceTypes.d.ts","sourceRoot":"","sources":["../../src/resourceTypes.ts"],"names":[],"mappings":"AAsCA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wCAAwC,CACtD,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,MAAM,GACtB,OAAO,CAgCT;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,wCAAwC,CACtD,cAAc,EAAE,MAAM,EACtB,gBAAgB,EAAE,MAAM,EAAE,GACzB,MAAM,EAAE,CAiBV"}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { splitArnParts } from './arn.js';
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether a concrete resource ARN (possibly with wildcards) matches
|
|
4
|
+
* a resource-type ARN pattern from the Service Authorization Reference.
|
|
5
|
+
*
|
|
6
|
+
* A wildcard resource string (`"*"`) always matches.
|
|
7
|
+
*
|
|
8
|
+
* This is a compatibility check: it returns true when there is at least one
|
|
9
|
+
* concrete ARN that could satisfy both the resource string and the resource
|
|
10
|
+
* type pattern. Resource type variables may span resource-component separators
|
|
11
|
+
* such as `:` and `/`.
|
|
12
|
+
*
|
|
13
|
+
* @param resourceString - A concrete resource ARN or wildcard (`"*"`)
|
|
14
|
+
* @param resourcePattern - An ARN pattern from iam-data (e.g. `arn:${Partition}:s3:::${BucketName}/${ObjectName}`)
|
|
15
|
+
* @returns Whether the resource string matches the pattern
|
|
16
|
+
*/
|
|
17
|
+
export function resourceStringMatchesResourceTypePattern(resourceString, resourcePattern) {
|
|
18
|
+
if (resourceString === '*') {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
const resourceParts = splitArnParts(resourceString);
|
|
22
|
+
const patternParts = splitArnParts(resourcePattern);
|
|
23
|
+
if (!resourceComponentMatchesResourceTypeComponent(resourceParts.partition, patternParts.partition)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (!resourceComponentMatchesResourceTypeComponent(resourceParts.service, patternParts.service)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (!resourceComponentMatchesResourceTypeComponent(resourceParts.region, patternParts.region)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (!resourceComponentMatchesResourceTypeComponent(resourceParts.accountId, patternParts.accountId)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return resourceComponentMatchesResourceTypeComponent(resourceParts.resource, patternParts.resource);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Reduce resource type patterns to the most specific patterns that match a resource string.
|
|
39
|
+
*
|
|
40
|
+
* This helper does not know about iam-data or service-specific resource type ordering. It uses
|
|
41
|
+
* the provided pattern set as context and removes matching parent patterns when a matching child
|
|
42
|
+
* pattern has all of the parent's literal structure plus additional literal structure. Wildcard
|
|
43
|
+
* resource strings preserve all matches because the wildcard may refer to parent and child resources.
|
|
44
|
+
*
|
|
45
|
+
* @param resourceString - A concrete resource ARN or wildcard (`"*"`)
|
|
46
|
+
* @param resourcePatterns - Candidate resource type ARN patterns
|
|
47
|
+
* @returns Matching resource type patterns with less-specific parent patterns removed, in input order
|
|
48
|
+
*/
|
|
49
|
+
export function mostSpecificMatchingResourceTypePatterns(resourceString, resourcePatterns) {
|
|
50
|
+
const matchingPatterns = resourcePatterns.filter((pattern) => resourceStringMatchesResourceTypePattern(resourceString, pattern));
|
|
51
|
+
if (resourceString.includes('*') || resourceString.includes('?')) {
|
|
52
|
+
return matchingPatterns;
|
|
53
|
+
}
|
|
54
|
+
return matchingPatterns.filter((candidatePattern, candidateIndex) => {
|
|
55
|
+
return !matchingPatterns.some((otherPattern, otherIndex) => {
|
|
56
|
+
return (otherIndex !== candidateIndex &&
|
|
57
|
+
resourceTypePatternIsMoreSpecific(otherPattern, candidatePattern));
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Check whether one resource type pattern is more specific than another.
|
|
63
|
+
*
|
|
64
|
+
* @param possibleChildPattern - The pattern that may be more specific
|
|
65
|
+
* @param possibleParentPattern - The pattern that may be less specific
|
|
66
|
+
* @returns Whether the possible child has all parent literal structure plus more literal structure
|
|
67
|
+
*/
|
|
68
|
+
function resourceTypePatternIsMoreSpecific(possibleChildPattern, possibleParentPattern) {
|
|
69
|
+
const childLiteralText = literalTextFromResourceTypePattern(possibleChildPattern);
|
|
70
|
+
const parentLiteralText = literalTextFromResourceTypePattern(possibleParentPattern);
|
|
71
|
+
return (childLiteralText.length > parentLiteralText.length &&
|
|
72
|
+
childLiteralText.startsWith(parentLiteralText));
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Extract the literal text from a resource type pattern by removing variable placeholders.
|
|
76
|
+
*
|
|
77
|
+
* @param pattern - The resource type pattern to inspect
|
|
78
|
+
* @returns Literal pattern text without `${Variable}` placeholders
|
|
79
|
+
*/
|
|
80
|
+
function literalTextFromResourceTypePattern(pattern) {
|
|
81
|
+
return tokenizeResourceTypePattern(pattern)
|
|
82
|
+
.filter((token) => token.type === 'literal')
|
|
83
|
+
.map((token) => token.value)
|
|
84
|
+
.join('');
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Check whether a resource string component is compatible with a resource type pattern component.
|
|
88
|
+
*
|
|
89
|
+
* @param resourceComponent - The component value from the concrete or wildcard ARN
|
|
90
|
+
* @param resourceTypeComponent - The component value from the resource type pattern ARN
|
|
91
|
+
* @returns Whether at least one concrete component can satisfy both component patterns
|
|
92
|
+
*/
|
|
93
|
+
function resourceComponentMatchesResourceTypeComponent(resourceComponent, resourceTypeComponent) {
|
|
94
|
+
if (resourceTypeComponent === '*') {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
if (resourceComponent === undefined || resourceTypeComponent === undefined) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
if (resourceComponent === '' || resourceTypeComponent === '') {
|
|
101
|
+
return (resourceComponent.localeCompare(resourceTypeComponent, undefined, {
|
|
102
|
+
sensitivity: 'accent'
|
|
103
|
+
}) === 0);
|
|
104
|
+
}
|
|
105
|
+
return patternsHaveIntersection(createResourceStringAutomaton(resourceComponent), createResourceTypePatternAutomaton(resourceTypeComponent));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Check whether two resource pattern automata accept at least one common string.
|
|
109
|
+
*
|
|
110
|
+
* @param first - The first pattern automaton to compare
|
|
111
|
+
* @param second - The second pattern automaton to compare
|
|
112
|
+
* @returns Whether the pattern languages have a non-empty intersection
|
|
113
|
+
*/
|
|
114
|
+
function patternsHaveIntersection(first, second) {
|
|
115
|
+
const visited = new Set();
|
|
116
|
+
const queue = [[0, 0]];
|
|
117
|
+
while (queue.length > 0) {
|
|
118
|
+
const [firstState, secondState] = queue.shift();
|
|
119
|
+
const key = `${firstState}:${secondState}`;
|
|
120
|
+
if (visited.has(key)) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
visited.add(key);
|
|
124
|
+
if (firstState === first.acceptingState && secondState === second.acceptingState) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
const firstTransitions = first.transitions(firstState);
|
|
128
|
+
const secondTransitions = second.transitions(secondState);
|
|
129
|
+
for (const transition of firstTransitions) {
|
|
130
|
+
if (!transition.consumes) {
|
|
131
|
+
queue.push([transition.nextState, secondState]);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for (const transition of secondTransitions) {
|
|
135
|
+
if (!transition.consumes) {
|
|
136
|
+
queue.push([firstState, transition.nextState]);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
for (const firstTransition of firstTransitions) {
|
|
140
|
+
if (!firstTransition.consumes) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
for (const secondTransition of secondTransitions) {
|
|
144
|
+
if (!secondTransition.consumes) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (characterMatchersIntersect(firstTransition.consumes, secondTransition.consumes)) {
|
|
148
|
+
queue.push([firstTransition.nextState, secondTransition.nextState]);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Create an automaton for a resource string that may contain IAM wildcards.
|
|
157
|
+
*
|
|
158
|
+
* @param resourceString - The resource string component to convert
|
|
159
|
+
* @returns An automaton accepting concrete strings matched by the resource string
|
|
160
|
+
*/
|
|
161
|
+
function createResourceStringAutomaton(resourceString) {
|
|
162
|
+
const chars = [...resourceString];
|
|
163
|
+
return {
|
|
164
|
+
acceptingState: chars.length,
|
|
165
|
+
transitions(state) {
|
|
166
|
+
if (state >= chars.length) {
|
|
167
|
+
return [];
|
|
168
|
+
}
|
|
169
|
+
const char = chars[state];
|
|
170
|
+
if (char === '*') {
|
|
171
|
+
return [{ nextState: state + 1 }, { nextState: state, consumes: 'any' }];
|
|
172
|
+
}
|
|
173
|
+
if (char === '?') {
|
|
174
|
+
return [{ nextState: state + 1, consumes: 'any' }];
|
|
175
|
+
}
|
|
176
|
+
return [{ nextState: state + 1, consumes: { char } }];
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Create an automaton for a Service Authorization Reference resource type component.
|
|
182
|
+
*
|
|
183
|
+
* @param resourceTypePattern - The resource type component to convert
|
|
184
|
+
* @returns An automaton accepting concrete strings matched by the resource type component
|
|
185
|
+
*/
|
|
186
|
+
function createResourceTypePatternAutomaton(resourceTypePattern) {
|
|
187
|
+
const tokens = tokenizeResourceTypePattern(resourceTypePattern);
|
|
188
|
+
return {
|
|
189
|
+
acceptingState: tokens.length,
|
|
190
|
+
transitions(state) {
|
|
191
|
+
if (state >= tokens.length) {
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
const token = tokens[state];
|
|
195
|
+
if (token.type === 'variable') {
|
|
196
|
+
return [
|
|
197
|
+
{ nextState: state, consumes: token.characterMatcher },
|
|
198
|
+
{ nextState: state + 1, consumes: token.characterMatcher }
|
|
199
|
+
];
|
|
200
|
+
}
|
|
201
|
+
return [{ nextState: state + 1, consumes: { char: token.value } }];
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Tokenize a Service Authorization Reference resource type pattern.
|
|
207
|
+
*
|
|
208
|
+
* @param pattern - The resource type pattern component to tokenize
|
|
209
|
+
* @returns Tokens representing literals and `${Variable}` placeholders
|
|
210
|
+
*/
|
|
211
|
+
function tokenizeResourceTypePattern(pattern) {
|
|
212
|
+
const tokens = [];
|
|
213
|
+
const variableMatches = [...pattern.matchAll(/\$\{[0-9a-zA-Z]+\}/g)];
|
|
214
|
+
const patternIsSingleVariable = variableMatches.length === 1 && variableMatches[0][0] === pattern;
|
|
215
|
+
for (let i = 0; i < pattern.length;) {
|
|
216
|
+
if (pattern[i] === '$' && pattern[i + 1] === '{') {
|
|
217
|
+
const endIndex = pattern.indexOf('}', i + 2);
|
|
218
|
+
if (endIndex !== -1) {
|
|
219
|
+
tokens.push({
|
|
220
|
+
type: 'variable',
|
|
221
|
+
characterMatcher: patternIsSingleVariable ? 'nonSeparator' : 'any'
|
|
222
|
+
});
|
|
223
|
+
i = endIndex + 1;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
tokens.push({ type: 'literal', value: pattern[i] });
|
|
228
|
+
i++;
|
|
229
|
+
}
|
|
230
|
+
return tokens;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Check whether two character matchers can consume the same character.
|
|
234
|
+
*
|
|
235
|
+
* @param first - The first character matcher
|
|
236
|
+
* @param second - The second character matcher
|
|
237
|
+
* @returns Whether the matchers have a non-empty intersection
|
|
238
|
+
*/
|
|
239
|
+
function characterMatchersIntersect(first, second) {
|
|
240
|
+
if (first === 'any' || second === 'any') {
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
if (first === 'nonSeparator' && second === 'nonSeparator') {
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
if (first === 'nonSeparator') {
|
|
247
|
+
return typeof second === 'object' && !isResourceComponentSeparator(second.char);
|
|
248
|
+
}
|
|
249
|
+
if (second === 'nonSeparator') {
|
|
250
|
+
return typeof first === 'object' && !isResourceComponentSeparator(first.char);
|
|
251
|
+
}
|
|
252
|
+
return first.char.localeCompare(second.char, undefined, { sensitivity: 'accent' }) === 0;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Check whether a character is a resource component separator.
|
|
256
|
+
*
|
|
257
|
+
* @param char - The character to check
|
|
258
|
+
* @returns Whether the character separates resource component segments
|
|
259
|
+
*/
|
|
260
|
+
function isResourceComponentSeparator(char) {
|
|
261
|
+
return char === ':' || char === '/';
|
|
262
|
+
}
|
|
263
|
+
//# sourceMappingURL=resourceTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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AE,CAAC;QAC1D,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,KAAK,KAAK,cAAc,EAAE,CAAC;QAC7B,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,4BAA4B,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACjF,CAAC;IAED,IAAI,MAAM,KAAK,cAAc,EAAE,CAAC;QAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,4BAA4B,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC/E,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAA;AAC1F,CAAC;AAED;;;;;GAKG;AACH,SAAS,4BAA4B,CAAC,IAAY;IAChD,OAAO,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,CAAA;AACrC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert an AWS wildcard ARN pattern (e.g. "arn:aws:s3:::bucket/*") into a RegExp.
|
|
3
|
+
*
|
|
4
|
+
* @param pattern The ARN pattern string with wildcards
|
|
5
|
+
* @returns RegExp that matches ARNs according to the wildcard pattern
|
|
6
|
+
*/
|
|
7
|
+
export declare function resourceArnWithWildcardsToRegex(pattern: string): RegExp;
|
|
8
|
+
//# sourceMappingURL=resources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../src/resources.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGvE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert an AWS wildcard ARN pattern (e.g. "arn:aws:s3:::bucket/*") into a RegExp.
|
|
3
|
+
*
|
|
4
|
+
* @param pattern The ARN pattern string with wildcards
|
|
5
|
+
* @returns RegExp that matches ARNs according to the wildcard pattern
|
|
6
|
+
*/
|
|
7
|
+
export function resourceArnWithWildcardsToRegex(pattern) {
|
|
8
|
+
const parts = pattern.split('*').map((s) => s.replace(/[-/\\^$+?.()|[\]{}]/g, '\\$&'));
|
|
9
|
+
return new RegExp('^' + parts.join('.*?') + '$');
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/resources.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,+BAA+B,CAAC,OAAe;IAC7D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC,CAAA;IACtF,OAAO,IAAI,MAAM,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAA;AAClD,CAAC"}
|
package/dist/esm/s3.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks to see if an ARN is an S3 bucket or object ARN
|
|
3
|
+
*
|
|
4
|
+
* @param arn the ARN to check
|
|
5
|
+
* @returns whether the ARN is an S3 bucket or object ARN
|
|
6
|
+
*/
|
|
7
|
+
export declare function isS3BucketOrObjectArn(arn: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Get the bucket ARN from an S3 bucket or object ARN. Does not validate the input ARN.
|
|
10
|
+
*
|
|
11
|
+
* @param bucketOrObjectArn the ARN of the S3 bucket or object
|
|
12
|
+
* @returns the ARN of the S3 bucket
|
|
13
|
+
*/
|
|
14
|
+
export declare function bucketArn(bucketOrObjectArn: string): string;
|
|
15
|
+
//# sourceMappingURL=s3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../src/s3.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAa1D;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM,CAE3D"}
|