Skip to content

Commit 8ae3509

Browse files
authored
Merge pull request #98 from monk-io/sqs-client-auth
Sqs client auth
2 parents 2dbc769 + ba1c6c9 commit 8ae3509

20 files changed

+3127
-48
lines changed

dist/aws-iam/MANIFEST

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
REPO aws-iam
2-
VERSION_HASH 827128c5086a
3-
LOAD iam-policy.yaml iam-role.yaml base.yaml common.yaml
4-
RESOURCES common.js iam-role-sync.js base.js iam-policy-sync.js
2+
VERSION_HASH beb0ea564843
3+
LOAD iam-policy.yaml base.yaml common.yaml iam-role.yaml iam-user.yaml
4+
RESOURCES common.js iam-user-sync.js iam-policy-sync.js iam-role-sync.js base.js

dist/aws-iam/base.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ namespace: aws-iam
33
base:
44
defines: module
55
metadata:
6-
version-hash: 827128c5086a
6+
version-hash: beb0ea564843
77
source: <<< base.js

dist/aws-iam/common.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ namespace: aws-iam
33
common:
44
defines: module
55
metadata:
6-
version-hash: 827128c5086a
6+
version-hash: beb0ea564843
77
source: <<< common.js

dist/aws-iam/iam-policy-sync.js

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
88
// input/aws-iam/policy.ts
99
const base = require("aws-iam/base");
1010
const AWSIAMEntity = base.AWSIAMEntity;
11+
const common = require("aws-iam/common");
12+
const IAM_ACTIONS = common.IAM_ACTIONS;
1113
const cli = require("cli");
1214
var _IAMPolicy = class _IAMPolicy extends AWSIAMEntity {
1315
getPolicyName() {
@@ -84,7 +86,7 @@ var _IAMPolicy = class _IAMPolicy extends AWSIAMEntity {
8486
}
8587
}
8688
try {
87-
const response = this.makeAWSRequest("POST", "CreatePolicy", params);
89+
const response = this.makeAWSRequest("POST", IAM_ACTIONS.CREATE_POLICY, params);
8890
if (response.Policy) {
8991
this.state = {
9092
policy_arn: response.Policy.Arn,
@@ -112,7 +114,7 @@ var _IAMPolicy = class _IAMPolicy extends AWSIAMEntity {
112114
SetAsDefault: true
113115
};
114116
try {
115-
const response = this.makeAWSRequest("POST", "CreatePolicyVersion", params);
117+
const response = this.makeAWSRequest("POST", IAM_ACTIONS.CREATE_POLICY_VERSION, params);
116118
if (response.PolicyVersion) {
117119
this.state.default_version_id = response.PolicyVersion.VersionId;
118120
this.state.update_date = response.PolicyVersion.CreateDate;
@@ -127,26 +129,87 @@ var _IAMPolicy = class _IAMPolicy extends AWSIAMEntity {
127129
if (!this.state.policy_arn) {
128130
return;
129131
}
132+
if (this.state.existing) {
133+
return;
134+
}
130135
try {
131-
if (this.state.attachment_count && this.state.attachment_count > 0) {
132-
cli.output(`Warning: Policy has ${this.state.attachment_count} attachments. You may need to detach it first.`);
133-
}
136+
this.detachPolicyFromAllEntities();
134137
this.deleteNonDefaultVersions();
135138
this.deletePolicy(this.state.policy_arn, this.definition.policy_name);
136139
} catch (error) {
137140
throw new Error(`Failed to delete IAM Policy ${this.definition.policy_name}: ${error instanceof Error ? error.message : "Unknown error"}`);
138141
}
139142
}
143+
detachPolicyFromAllEntities() {
144+
if (!this.state.policy_arn) {
145+
return;
146+
}
147+
try {
148+
const response = this.makeAWSRequest("POST", IAM_ACTIONS.LIST_ENTITIES_FOR_POLICY, {
149+
PolicyArn: this.state.policy_arn
150+
});
151+
if (response.PolicyUsers) {
152+
const users = Array.isArray(response.PolicyUsers) ? response.PolicyUsers : [response.PolicyUsers];
153+
for (const user of users) {
154+
const userName = typeof user === "string" ? user : user.UserName;
155+
if (userName) {
156+
try {
157+
this.makeAWSRequest("POST", IAM_ACTIONS.DETACH_USER_POLICY, {
158+
UserName: userName,
159+
PolicyArn: this.state.policy_arn
160+
});
161+
} catch (error) {
162+
cli.output(`Warning: Failed to detach policy from user ${userName}: ${error instanceof Error ? error.message : "Unknown error"}`);
163+
}
164+
}
165+
}
166+
}
167+
if (response.PolicyRoles) {
168+
const roles = Array.isArray(response.PolicyRoles) ? response.PolicyRoles : [response.PolicyRoles];
169+
for (const role of roles) {
170+
const roleName = typeof role === "string" ? role : role.RoleName;
171+
if (roleName) {
172+
try {
173+
this.makeAWSRequest("POST", IAM_ACTIONS.DETACH_ROLE_POLICY, {
174+
RoleName: roleName,
175+
PolicyArn: this.state.policy_arn
176+
});
177+
} catch (error) {
178+
cli.output(`Warning: Failed to detach policy from role ${roleName}: ${error instanceof Error ? error.message : "Unknown error"}`);
179+
}
180+
}
181+
}
182+
}
183+
if (response.PolicyGroups) {
184+
const groups = Array.isArray(response.PolicyGroups) ? response.PolicyGroups : [response.PolicyGroups];
185+
for (const group of groups) {
186+
const groupName = typeof group === "string" ? group : group.GroupName;
187+
if (groupName) {
188+
try {
189+
this.makeAWSRequest("POST", IAM_ACTIONS.DETACH_GROUP_POLICY, {
190+
GroupName: groupName,
191+
PolicyArn: this.state.policy_arn
192+
});
193+
} catch (error) {
194+
cli.output(`Warning: Failed to detach policy from group ${groupName}: ${error instanceof Error ? error.message : "Unknown error"}`);
195+
}
196+
}
197+
}
198+
}
199+
} catch (error) {
200+
cli.output(`Warning: Failed to list policy attachments: ${error instanceof Error ? error.message : "Unknown error"}`);
201+
}
202+
}
140203
deleteNonDefaultVersions() {
141204
try {
142-
const response = this.makeAWSRequest("POST", "ListPolicyVersions", {
205+
const response = this.makeAWSRequest("POST", IAM_ACTIONS.LIST_POLICY_VERSIONS, {
143206
PolicyArn: this.state.policy_arn
144207
});
145208
if (response.Versions) {
146209
const nonDefaultVersions = response.Versions.filter((v) => !v.IsDefaultVersion);
147210
for (const version of nonDefaultVersions) {
148211
try {
149-
this.makeAWSRequest("POST", "DeletePolicyVersion", {
212+
this.makeAWSRequest("POST", IAM_ACTIONS.DELETE_POLICY_VERSION, {
150213
PolicyArn: this.state.policy_arn,
151214
VersionId: version.VersionId
152215
});

dist/aws-iam/iam-policy.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ iam-policy:
33
defines: entity
44
metadata:
55
name: IAMPolicy
6-
version-hash: 827128c5086a
6+
version-hash: beb0ea564843
77
schema:
88
region:
99
type: string
@@ -54,4 +54,5 @@ iam-policy:
5454
sync: <<< iam-policy-sync.js
5555
requires:
5656
- aws-iam/base
57+
- aws-iam/common
5758
- cli

dist/aws-iam/iam-role.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ iam-role:
33
defines: entity
44
metadata:
55
name: IAMRole
6-
version-hash: 827128c5086a
6+
version-hash: beb0ea564843
77
schema:
88
region:
99
type: string

0 commit comments

Comments
 (0)