@cloud-copilot/iam-policy
Version:
An ORM for AWS IAM policies
50 lines • 1.66 kB
JavaScript
import { isAllWildcards } from '../utils.js';
export class ResourceImpl {
constructor(rawValue, otherProps) {
this.rawValue = rawValue;
this.otherProps = otherProps;
}
path() {
return this.otherProps.path;
}
partition() {
if (!this.isArnResource()) {
throw new Error('Called partition on a resource without an ARN, use isArnResource before calling partition');
}
return this.value().split(':').at(1);
}
service() {
if (!this.isArnResource()) {
throw new Error('Called service on a resource without an ARN, use isArnResource before calling service');
}
return this.value().split(':').at(2);
}
region() {
if (!this.isArnResource()) {
throw new Error('Called region on a resource without an ARN, use isArnResource before calling region');
}
return this.value().split(':').at(3);
}
account() {
if (!this.isArnResource()) {
throw new Error('Called account on a resource without an ARN, use isArnResource before calling account');
}
return this.value().split(':').at(4);
}
resource() {
if (!this.isArnResource()) {
throw new Error('Called resource on a resource without an ARN, use isArnResource before calling resource');
}
return this.value().split(':').slice(5).join(':');
}
value() {
return this.rawValue;
}
isAllResources() {
return isAllWildcards(this.rawValue);
}
isArnResource() {
return !this.isAllResources();
}
}
//# sourceMappingURL=resource.js.map