awspec 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37bdea5e957ae058dcbe8cd39b0aea104eb7b351
4
- data.tar.gz: 7aeaef96ed3d595a3b767d36375d5f2ffa7ba61c
3
+ metadata.gz: 7b82928f9ac3ba086bd8057f29a2d29d924b6173
4
+ data.tar.gz: 46a33e636b743394115ecc99d5b3db3418716041
5
5
  SHA512:
6
- metadata.gz: e3c16ac71245320c4be9b6007e924bee29843cdebcfa6c5a41438b89ad4d4d8553dc1d1b49ce8df807d2bad614c5f7fa4ee417d04d13200a6122c9a0757f9b48
7
- data.tar.gz: a83b4e57e8630d812cad45aaa94584cbea73a0b630a7ef103fe7363e9154274d313a10762bb2aff86295b89988f93c9ebf1e7bf278a3edd923c5869e338420cc
6
+ metadata.gz: 898a43391065b7f8f4cae1bec98f4b68e8c4328db0acf23e4356e40bbed8782930f7d371ca037396a6c48bb5a1f8918d90515a25921b7305e4474a0c96d55495
7
+ data.tar.gz: d4490f55c1e4f4ebf2f85a081ca7235f1c3d6236c598145bf30f62e04cae818da4dfc9d210be8e1a40849511ca6393f3d4833e183210c93305bca9d3ad7fae05
data/.tachikoma.yml ADDED
@@ -0,0 +1 @@
1
+ strategy: 'bundler'
data/README.md CHANGED
@@ -92,13 +92,16 @@ $ awspec generate ec2 vpc-ab123cde >> spec/ec2_spec.rb
92
92
  - [x] EBS Volume (`ebs`)
93
93
  - [x] ELB (`elb`)
94
94
  - [x] Lambda (`lambda`)
95
+ - IAM
96
+ - [x] IAM User (`iam_user`)
97
+ - [ ] IAM Group
98
+ - [ ] IAM Role
99
+ - [ ] IAM Policy
95
100
 
96
101
  [Resource Types more infomation here](doc/resource_types.md)
97
102
 
98
103
  ### Next..
99
104
 
100
- - IAM
101
- - [ ] IAM User
102
105
  - ...
103
106
 
104
107
  ## Contributing
@@ -13,6 +13,7 @@
13
13
  | [ebs](#ebs)
14
14
  | [elb](#elb)
15
15
  | [lambda](#lambda)
16
+ | [iam_user](#iam_user)
16
17
 
17
18
  ## <a name="ec2">ec2</a>
18
19
 
@@ -268,3 +269,12 @@ Lambda resource type.
268
269
  This matcher does not support Amazon S3 event sources. ( [See SDK doc](http://docs.aws.amazon.com/sdkforruby/api/Aws/Lambda/Client.html#list_event_source_mappings-instance_method) )
269
270
 
270
271
  #### its(:function_name), its(:function_arn), its(:runtime), its(:role), its(:handler), its(:code_size), its(:description), its(:timeout), its(:memory_size), its(:last_modified)
272
+ ## <a name="iam_user">iam_user</a>
273
+
274
+ IamUser resource type.
275
+
276
+ ### exist
277
+
278
+ ### have_iam_policy
279
+
280
+ #### its(:path), its(:user_name), its(:user_id), its(:arn), its(:create_date), its(:password_last_used)
@@ -0,0 +1,17 @@
1
+ module Awspec::Generator
2
+ module Doc
3
+ module Type
4
+ class IamUser < Base
5
+ def initialize
6
+ super
7
+ @type_name = 'IamUser'
8
+ @type = Awspec::Type::IamUser.new('my-iam-user')
9
+ @ret = @type.user
10
+ @matchers = []
11
+ @ignore_matchers = []
12
+ @describes = []
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -9,6 +9,7 @@ require 'awspec/helper/finder/auto_scaling'
9
9
  require 'awspec/helper/finder/ebs'
10
10
  require 'awspec/helper/finder/elb'
11
11
  require 'awspec/helper/finder/lambda'
12
+ require 'awspec/helper/finder/iam'
12
13
 
13
14
  module Awspec::Helper
14
15
  module Finder
@@ -23,6 +24,7 @@ module Awspec::Helper
23
24
  include Awspec::Helper::Finder::Ebs
24
25
  include Awspec::Helper::Finder::Elb
25
26
  include Awspec::Helper::Finder::Lambda
27
+ include Awspec::Helper::Finder::Iam
26
28
 
27
29
  # rubocop:disable all
28
30
  def initialize(id = nil)
@@ -33,6 +35,7 @@ module Awspec::Helper
33
35
  @auto_scaling_client = Aws::AutoScaling::Client.new
34
36
  @elb_client = Aws::ElasticLoadBalancing::Client.new
35
37
  @lambda_client = Aws::Lambda::Client.new
38
+ @iam_client = Aws::IAM::Client.new
36
39
  end
37
40
  end
38
41
  end
@@ -0,0 +1,36 @@
1
+ module Awspec::Helper
2
+ module Finder
3
+ module Iam
4
+ def find_iam_user(id)
5
+ users = []
6
+ marker = nil
7
+ loop do
8
+ res = @iam_client.list_users(
9
+ marker: marker
10
+ )
11
+ marker = res.marker
12
+ break if res.users.empty?
13
+ res.users.each do |user|
14
+ users.push(user) if user.user_name == id || user.user_id == id
15
+ end
16
+ break unless marker
17
+ end
18
+ return users[0] if users.count == 1
19
+ end
20
+
21
+ def select_iam_group_by_user_name(user_name)
22
+ res = @iam_client.list_groups_for_user({
23
+ user_name: user_name
24
+ })
25
+ res.groups
26
+ end
27
+
28
+ def select_iam_policy_by_user_name(user_name)
29
+ res = @iam_client.list_attached_user_policies({
30
+ user_name: user_name
31
+ })
32
+ res.attached_policies
33
+ end
34
+ end
35
+ end
36
+ 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
7
+ route_table ebs elb lambda iam_user
8
8
  )
9
9
 
10
10
  TYPES.each do |type|
@@ -13,3 +13,6 @@ require 'awspec/matcher/have_record_set'
13
13
 
14
14
  # RouteTable
15
15
  require 'awspec/matcher/have_route'
16
+
17
+ # IAM User
18
+ require 'awspec/matcher/belong_to_iam_group'
@@ -0,0 +1,8 @@
1
+ RSpec::Matchers.define :belong_to_iam_group do |group_id|
2
+ match do |resource|
3
+ groups = resource.select_iam_group_by_user_name(resource.user[:user_name])
4
+ groups.find do |group|
5
+ group.group_id == group_id || group.group_name == group_id
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,34 @@
1
+ Aws.config[:iam] = {
2
+ stub_responses: {
3
+ list_users: {
4
+ users: [
5
+ path: '/',
6
+ user_name: 'my-iam-user',
7
+ user_id: 'ABCDEFGHI1234556890',
8
+ arn: 'arn:aws:iam::123456789012:user/my-iam-user',
9
+ create_date: Time.local(2015)
10
+ ]
11
+ },
12
+ list_groups_for_user: {
13
+ groups: [
14
+ {
15
+ path: '/',
16
+ group_name: 'my-iam-group',
17
+ group_id: 'GABCDEFGHI123455689',
18
+ arn: 'arn:aws:iam::123456789012:group/my-iam-group',
19
+ create_date: Time.local(2015)
20
+ }
21
+ ]
22
+ },
23
+ list_attached_user_policies: {
24
+ attached_policies: [
25
+ {
26
+ policy_arn: 'arn:aws:iam::aws:policy/ReadOnlyAccess',
27
+ policy_name: 'ReadOnlyAccess'
28
+ }
29
+ ],
30
+ is_truncated: false,
31
+ maker: nil
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,27 @@
1
+ module Awspec::Type
2
+ class IamUser < Base
3
+ attr_reader :user
4
+
5
+ def initialize(id)
6
+ super
7
+ @user = find_iam_user(id)
8
+ @id = @user[:user_id] if @user
9
+ end
10
+
11
+ def method_missing(name)
12
+ describe = name.to_sym
13
+ if @user.members.include?(describe)
14
+ @user[describe]
15
+ else
16
+ super
17
+ end
18
+ end
19
+
20
+ def has_iam_policy?(policy_id)
21
+ policies = select_iam_policy_by_user_name(@user[:user_name])
22
+ policies.find do |policy|
23
+ policy.policy_arn == policy_id || policy.policy_name == policy_id
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.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.7.0
4
+ version: 0.8.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-08-27 00:00:00.000000000 Z
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -133,6 +133,7 @@ files:
133
133
  - ".editorconfig"
134
134
  - ".gitignore"
135
135
  - ".rubocop.yml"
136
+ - ".tachikoma.yml"
136
137
  - ".travis.yml"
137
138
  - Gemfile
138
139
  - LICENSE.txt
@@ -160,6 +161,7 @@ files:
160
161
  - lib/awspec/generator/doc/type/ebs.rb
161
162
  - lib/awspec/generator/doc/type/ec2.rb
162
163
  - lib/awspec/generator/doc/type/elb.rb
164
+ - lib/awspec/generator/doc/type/iam_user.rb
163
165
  - lib/awspec/generator/doc/type/lambda.rb
164
166
  - lib/awspec/generator/doc/type/rds.rb
165
167
  - lib/awspec/generator/doc/type/rds_db_parameter_group.rb
@@ -182,6 +184,7 @@ files:
182
184
  - lib/awspec/helper/finder/ebs.rb
183
185
  - lib/awspec/helper/finder/ec2.rb
184
186
  - lib/awspec/helper/finder/elb.rb
187
+ - lib/awspec/helper/finder/iam.rb
185
188
  - lib/awspec/helper/finder/lambda.rb
186
189
  - lib/awspec/helper/finder/rds.rb
187
190
  - lib/awspec/helper/finder/route53.rb
@@ -192,6 +195,7 @@ files:
192
195
  - lib/awspec/matcher.rb
193
196
  - lib/awspec/matcher/be_opened.rb
194
197
  - lib/awspec/matcher/belong_to_db_subnet_group.rb
198
+ - lib/awspec/matcher/belong_to_iam_group.rb
195
199
  - lib/awspec/matcher/belong_to_subnet.rb
196
200
  - lib/awspec/matcher/belong_to_vpc.rb
197
201
  - lib/awspec/matcher/have_record_set.rb
@@ -202,6 +206,7 @@ files:
202
206
  - lib/awspec/stub/ebs.rb
203
207
  - lib/awspec/stub/ec2.rb
204
208
  - lib/awspec/stub/elb.rb
209
+ - lib/awspec/stub/iam_user.rb
205
210
  - lib/awspec/stub/lambda.rb
206
211
  - lib/awspec/stub/rds.rb
207
212
  - lib/awspec/stub/rds_db_parameter_group.rb
@@ -217,6 +222,7 @@ files:
217
222
  - lib/awspec/type/ebs.rb
218
223
  - lib/awspec/type/ec2.rb
219
224
  - lib/awspec/type/elb.rb
225
+ - lib/awspec/type/iam_user.rb
220
226
  - lib/awspec/type/lambda.rb
221
227
  - lib/awspec/type/rds.rb
222
228
  - lib/awspec/type/rds_db_parameter_group.rb