UNPKG

aws-iam-policy-tool

Version:
46 lines (45 loc) 1.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const operation_1 = require("./operation"); class RoleNode { constructor(RoleName, Path, AssumeRolePolicyDocument) { this.RoleName = RoleName; this.Path = Path; this.AssumeRolePolicyDocument = AssumeRolePolicyDocument; } get isEc2Role() { if (this.AssumeRolePolicyDocument) { return (this.AssumeRolePolicyDocument.Statement[0].Principal.Service === 'ec2.amazonaws.com'); } else { return false; } } toCreateRoleParams() { return { RoleName: this.RoleName, Path: this.Path, AssumeRolePolicyDocument: JSON.stringify(this.AssumeRolePolicyDocument, null, 4), }; } static async findRole(roleName) { const role = await operation_1.getRole(roleName); return this.fromIAMRole(role); } static fromIAMRole(role) { return new RoleNode(role.RoleName, role.Path, role.AssumeRolePolicyDocument ? JSON.parse(decodeURIComponent(role.AssumeRolePolicyDocument)) : undefined); } } exports.RoleNode = RoleNode; class RoleEntry { constructor(name, document) { this.name = name; const { RoleName, Path, AssumeRolePolicyDocument } = document.Role; this.Role = new RoleNode(RoleName, Path, AssumeRolePolicyDocument); this.AttachedPolicies = document.AttachedPolicies; } } exports.RoleEntry = RoleEntry;