awspec 0.8.1 → 0.9.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: edbd8a2286e70ffc10e86c7c47f11158b3a5df0c
4
- data.tar.gz: 99c9ac752bfb8590c1d39e34e21e21434407fa59
3
+ metadata.gz: 327a5cd2ed17af3f58122c6d2d2edf1fab622bfa
4
+ data.tar.gz: 66f4220079021aaf43365b7bb013e69b78df44d5
5
5
  SHA512:
6
- metadata.gz: e320bfea9c343abe46adace0eb3568af0d00ef304720c8fc20870f7fe3ee379ae89b46098644a97e7e549ca7a868a06ffdc206ef8a6a7ee510de8da1fd4b77c4
7
- data.tar.gz: 3b40f6d0ccb4068bcd995d4c9b2b4198fe9f6b93aa00822a44f56e360f3c5ca785f99abec7c2011161331757e674e6afd4f44b61e022c6ad84af0c9e6a9b29e1
6
+ metadata.gz: 37722811763e42a9728d7e1fc8d6f22c3e6403f910c16c84411114c73f191361f807adf2afaa6c43cc5aa5133606efd4e6ad8b3e807268364464ca2231f1dc98
7
+ data.tar.gz: fc0d09164bdbf8825bac61b2cf514d19d21929bde7a61b79ba20212cbfd82d77fcf438350dd6322af19b98d76aa12233c27e0458f4fd1a9f808804db64046f40
data/README.md CHANGED
@@ -94,7 +94,7 @@ $ awspec generate ec2 vpc-ab123cde >> spec/ec2_spec.rb
94
94
  - [x] Lambda (`lambda`)
95
95
  - IAM
96
96
  - [x] IAM User (`iam_user`)
97
- - [ ] IAM Group
97
+ - [x] IAM Group (`iam_group`)
98
98
  - [ ] IAM Role
99
99
  - [ ] IAM Policy
100
100
 
@@ -14,6 +14,7 @@
14
14
  | [elb](#elb)
15
15
  | [lambda](#lambda)
16
16
  | [iam_user](#iam_user)
17
+ | [iam_group](#iam_group)
17
18
 
18
19
  ## <a name="ec2">ec2</a>
19
20
 
@@ -280,3 +281,14 @@ IamUser resource type.
280
281
  ### belong_to_iam_group
281
282
 
282
283
  #### its(:path), its(:user_name), its(:user_id), its(:arn), its(:create_date), its(:password_last_used)
284
+ ## <a name="iam_group">iam_group</a>
285
+
286
+ IamGroup resource type.
287
+
288
+ ### exist
289
+
290
+ ### have_iam_policy
291
+
292
+ ### have_iam_user
293
+
294
+ #### its(:path), its(:group_name), its(:group_id), its(:arn), its(:create_date)
@@ -0,0 +1,17 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ module Type
4
+ class IamGroup < Base
5
+ def initialize
6
+ super
7
+ @type_name = 'IamGroup'
8
+ @type = Awspec::Type::IamGroup.new('my-iam-group')
9
+ @ret = @type.resource
10
+ @matchers = []
11
+ @ignore_matchers = []
12
+ @describes = []
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -30,7 +30,7 @@ EOF
30
30
  path = 'lib/awspec/stub/' + @type.to_snake_case + '.rb'
31
31
  full_path = @root_path + path
32
32
  content = <<-"EOF"
33
- # Aws.config[:ec2]= {
33
+ # Aws.config[:ec2] = {
34
34
  # stub_responses: true
35
35
  # }
36
36
  EOF
@@ -18,6 +18,23 @@ module Awspec::Helper
18
18
  return users[0] if users.count == 1
19
19
  end
20
20
 
21
+ def find_iam_group(id)
22
+ groups = []
23
+ marker = nil
24
+ loop do
25
+ res = @iam_client.list_groups(
26
+ marker: marker
27
+ )
28
+ marker = res.marker
29
+ break if res.groups.empty?
30
+ res.groups.each do |group|
31
+ groups.push(group) if group.group_name == id || group.group_id == id
32
+ end
33
+ break unless marker
34
+ end
35
+ return groups[0] if groups.count == 1
36
+ end
37
+
21
38
  def select_iam_group_by_user_name(user_name)
22
39
  res = @iam_client.list_groups_for_user({
23
40
  user_name: user_name
@@ -31,6 +48,13 @@ module Awspec::Helper
31
48
  })
32
49
  res.attached_policies
33
50
  end
51
+
52
+ def select_iam_policy_by_group_name(group_name)
53
+ res = @iam_client.list_attached_group_policies({
54
+ group_name: group_name
55
+ })
56
+ res.attached_policies
57
+ end
34
58
  end
35
59
  end
36
60
  end
@@ -4,7 +4,7 @@ module Awspec
4
4
  TYPES = %w(
5
5
  base ec2 rds rds_db_parameter_group security_group
6
6
  vpc s3 route53_hosted_zone auto_scaling_group subnet
7
- route_table ebs elb lambda iam_user
7
+ route_table ebs elb lambda iam_user iam_group
8
8
  )
9
9
 
10
10
  TYPES.each do |type|
@@ -0,0 +1,43 @@
1
+ Aws.config[:iam] = {
2
+ stub_responses: {
3
+ list_groups: {
4
+ groups: [
5
+ path: '/',
6
+ group_name: 'my-iam-group',
7
+ group_id: 'GABCDEFGHI123455689',
8
+ arn: 'arn:aws:iam::123456789012:group/my-iam-group',
9
+ create_date: Time.local(2015)
10
+ ]
11
+ },
12
+ list_users: {
13
+ users: [
14
+ path: '/',
15
+ user_name: 'my-iam-user',
16
+ user_id: 'ABCDEFGHI1234556890',
17
+ arn: 'arn:aws:iam::123456789012:user/my-iam-user',
18
+ create_date: Time.local(2015)
19
+ ]
20
+ },
21
+ list_groups_for_user: {
22
+ groups: [
23
+ {
24
+ path: '/',
25
+ group_name: 'my-iam-group',
26
+ group_id: 'GABCDEFGHI123455689',
27
+ arn: 'arn:aws:iam::123456789012:group/my-iam-group',
28
+ create_date: Time.local(2015)
29
+ }
30
+ ]
31
+ },
32
+ list_attached_group_policies: {
33
+ attached_policies: [
34
+ {
35
+ policy_arn: 'arn:aws:iam::aws:policy/ReadOnlyAccess',
36
+ policy_name: 'ReadOnlyAccess'
37
+ }
38
+ ],
39
+ is_truncated: false,
40
+ maker: nil
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,26 @@
1
+ module Awspec::Type
2
+ class IamGroup < Base
3
+ def initialize(id)
4
+ super
5
+ @resource = find_iam_group(id)
6
+ @id = @resource[:group_id] if @resource
7
+ end
8
+
9
+ def has_iam_user?(user_id)
10
+ user = find_iam_user(user_id)
11
+ return false unless user
12
+ user_name = user[:user_name]
13
+ groups = select_iam_group_by_user_name(user_name)
14
+ groups.find do |group|
15
+ group.group_id == @id
16
+ end
17
+ end
18
+
19
+ def has_iam_policy?(policy_id)
20
+ policies = select_iam_policy_by_group_name(@resource[:group_name])
21
+ policies.find do |policy|
22
+ policy.policy_arn == policy_id || policy.policy_name == policy_id
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.8.1'
2
+ VERSION = '0.9.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-03 00:00:00.000000000 Z
11
+ date: 2015-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -161,6 +161,7 @@ files:
161
161
  - lib/awspec/generator/doc/type/ebs.rb
162
162
  - lib/awspec/generator/doc/type/ec2.rb
163
163
  - lib/awspec/generator/doc/type/elb.rb
164
+ - lib/awspec/generator/doc/type/iam_group.rb
164
165
  - lib/awspec/generator/doc/type/iam_user.rb
165
166
  - lib/awspec/generator/doc/type/lambda.rb
166
167
  - lib/awspec/generator/doc/type/rds.rb
@@ -206,6 +207,7 @@ files:
206
207
  - lib/awspec/stub/ebs.rb
207
208
  - lib/awspec/stub/ec2.rb
208
209
  - lib/awspec/stub/elb.rb
210
+ - lib/awspec/stub/iam_group.rb
209
211
  - lib/awspec/stub/iam_user.rb
210
212
  - lib/awspec/stub/lambda.rb
211
213
  - lib/awspec/stub/rds.rb
@@ -222,6 +224,7 @@ files:
222
224
  - lib/awspec/type/ebs.rb
223
225
  - lib/awspec/type/ec2.rb
224
226
  - lib/awspec/type/elb.rb
227
+ - lib/awspec/type/iam_group.rb
225
228
  - lib/awspec/type/iam_user.rb
226
229
  - lib/awspec/type/lambda.rb
227
230
  - lib/awspec/type/rds.rb