fog-aws 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -1
  3. data/lib/fog/aws/dns.rb +1 -1
  4. data/lib/fog/aws/iam.rb +57 -20
  5. data/lib/fog/aws/iam/default_policies.json +1574 -0
  6. data/lib/fog/aws/iam/default_policies.rb +15 -0
  7. data/lib/fog/aws/iam/default_policy_versions.json +3372 -0
  8. data/lib/fog/aws/iam/paged_collection.rb +54 -0
  9. data/lib/fog/aws/models/compute/flavors.rb +95 -35
  10. data/lib/fog/aws/models/elb/load_balancer.rb +9 -10
  11. data/lib/fog/aws/models/elb/policies.rb +24 -9
  12. data/lib/fog/aws/models/elb/policy.rb +9 -10
  13. data/lib/fog/aws/models/iam/group.rb +33 -2
  14. data/lib/fog/aws/models/iam/groups.rb +2 -22
  15. data/lib/fog/aws/models/iam/managed_policies.rb +63 -0
  16. data/lib/fog/aws/models/iam/managed_policy.rb +38 -0
  17. data/lib/fog/aws/models/iam/policies.rb +19 -15
  18. data/lib/fog/aws/models/iam/user.rb +34 -2
  19. data/lib/fog/aws/parsers/iam/list_managed_policies.rb +25 -0
  20. data/lib/fog/aws/parsers/iam/policy_version.rb +33 -0
  21. data/lib/fog/aws/region_methods.rb +1 -1
  22. data/lib/fog/aws/requests/compute/allocate_address.rb +21 -19
  23. data/lib/fog/aws/requests/iam/attach_group_policy.rb +26 -0
  24. data/lib/fog/aws/requests/iam/attach_user_policy.rb +30 -4
  25. data/lib/fog/aws/requests/iam/create_access_key.rb +6 -5
  26. data/lib/fog/aws/requests/iam/detach_group_policy.rb +26 -0
  27. data/lib/fog/aws/requests/iam/detach_user_policy.rb +26 -0
  28. data/lib/fog/aws/requests/iam/get_policy.rb +57 -0
  29. data/lib/fog/aws/requests/iam/get_policy_version.rb +59 -0
  30. data/lib/fog/aws/requests/iam/get_user.rb +7 -0
  31. data/lib/fog/aws/requests/iam/list_attached_group_policies.rb +89 -0
  32. data/lib/fog/aws/requests/iam/list_attached_user_policies.rb +89 -0
  33. data/lib/fog/aws/requests/iam/list_policies.rb +47 -2
  34. data/lib/fog/aws/signaturev4.rb +14 -12
  35. data/lib/fog/aws/version.rb +1 -1
  36. data/tests/models/iam/managed_policies_tests.rb +67 -0
  37. data/tests/models/iam/users_tests.rb +20 -0
  38. data/tests/requests/compute/address_tests.rb +33 -20
  39. data/tests/signaturev4_tests.rb +7 -0
  40. metadata +14 -2
@@ -27,6 +27,32 @@ module Fog
27
27
  )
28
28
  end
29
29
  end
30
+
31
+ class Mock
32
+ def attach_group_policy(group_name, policy_arn)
33
+ if policy_arn.nil?
34
+ raise Fog::AWS::IAM::ValidationError, "1 validation error detected: Value null at 'policyArn' failed to satisfy constraint: Member must not be null"
35
+ end
36
+
37
+ managed_policy = self.data[:managed_policies][policy_arn]
38
+
39
+ unless managed_policy
40
+ raise Fog::AWS::IAM::NotFound, "Policy #{policy_arn} does not exist."
41
+ end
42
+
43
+ unless self.data[:groups].key?(group_name)
44
+ raise Fog::AWS::IAM::NotFound.new("The group with name #{group_name} cannot be found.")
45
+ end
46
+
47
+ group = self.data[:groups][group_name]
48
+ group[:attached_policies] << policy_arn
49
+
50
+ Excon::Response.new.tap { |response|
51
+ response.status = 200
52
+ response.body = { "RequestId" => Fog::AWS::Mock.request_id }
53
+ }
54
+ end
55
+ end
30
56
  end
31
57
  end
32
58
  end
@@ -20,13 +20,39 @@ module Fog
20
20
  #
21
21
  def attach_user_policy(user_name, policy_arn)
22
22
  request(
23
- 'Action' => 'AttachUserPolicy',
24
- 'UserName' => user_name,
25
- 'PolicyArn' => policy_arn,
26
- :parser => Fog::Parsers::AWS::IAM::Basic.new
23
+ 'Action' => 'AttachUserPolicy',
24
+ 'UserName' => user_name,
25
+ 'PolicyArn' => policy_arn,
26
+ :parser => Fog::Parsers::AWS::IAM::Basic.new
27
27
  )
28
28
  end
29
29
  end
30
+
31
+ class Mock
32
+ def attach_user_policy(user_name, policy_arn)
33
+ if policy_arn.nil?
34
+ raise Fog::AWS::IAM::ValidationError, "1 validation error detected: Value null at 'policyArn' failed to satisfy constraint: Member must not be null"
35
+ end
36
+
37
+ managed_policy = self.data[:managed_policies][policy_arn]
38
+
39
+ unless managed_policy
40
+ raise Fog::AWS::IAM::NotFound, "Policy #{policy_arn} does not exist."
41
+ end
42
+
43
+ unless self.data[:users].key?(user_name)
44
+ raise Fog::AWS::IAM::NotFound.new("The user with name #{user_name} cannot be found.")
45
+ end
46
+
47
+ user = self.data[:users][user_name]
48
+ user[:attached_policies] << policy_arn
49
+
50
+ Excon::Response.new.tap { |response|
51
+ response.status = 200
52
+ response.body = { "RequestId" => Fog::AWS::Mock.request_id }
53
+ }
54
+ end
55
+ end
30
56
  end
31
57
  end
32
58
  end
@@ -38,16 +38,17 @@ module Fog
38
38
  if data[:users].key? user
39
39
  access_keys_data = data[:users][user][:access_keys]
40
40
  else
41
- raise Fog::AWS::IAM::NotFound.new('The user with name #{user_name} cannot be found.')
41
+ raise Fog::AWS::IAM::NotFound.new("The user with name #{user_name} cannot be found.")
42
42
  end
43
43
  else
44
44
  access_keys_data = data[:access_keys]
45
45
  end
46
46
 
47
- key = { 'SecretAccessKey' => Fog::Mock.random_base64(40),
48
- 'Status' => 'Active',
49
- 'AccessKeyId' => Fog::AWS::Mock.key_id(20),
50
- }
47
+ key = {
48
+ 'SecretAccessKey' => Fog::Mock.random_base64(40),
49
+ 'Status' => 'Active',
50
+ 'AccessKeyId' => Fog::AWS::Mock.key_id(20),
51
+ }
51
52
  if user
52
53
  key["UserName"] = user
53
54
  end
@@ -27,6 +27,32 @@ module Fog
27
27
  )
28
28
  end
29
29
  end
30
+
31
+ class Mock
32
+ def detach_group_policy(group_name, policy_arn)
33
+ if policy_arn.nil?
34
+ raise Fog::AWS::IAM::ValidationError, "1 validation error detected: Value null at 'policyArn' failed to satisfy constraint: Member must not be null"
35
+ end
36
+
37
+ managed_policy = self.data[:managed_policies][policy_arn]
38
+
39
+ unless managed_policy
40
+ raise Fog::AWS::IAM::NotFound, "Policy #{policy_arn} does not exist."
41
+ end
42
+
43
+ unless self.data[:groups].key?(group_name)
44
+ raise Fog::AWS::IAM::NotFound.new("The group with name #{group_name} cannot be found.")
45
+ end
46
+
47
+ group = self.data[:groups][group_name]
48
+ group[:attached_policies].delete(policy_arn)
49
+
50
+ Excon::Response.new.tap { |response|
51
+ response.status = 200
52
+ response.body = { "RequestId" => Fog::AWS::Mock.request_id }
53
+ }
54
+ end
55
+ end
30
56
  end
31
57
  end
32
58
  end
@@ -27,6 +27,32 @@ module Fog
27
27
  )
28
28
  end
29
29
  end
30
+
31
+ class Mock
32
+ def detach_user_policy(user_name, policy_arn)
33
+ if policy_arn.nil?
34
+ raise Fog::AWS::IAM::ValidationError, "1 validation error detected: Value null at 'policyArn' failed to satisfy constraint: Member must not be null"
35
+ end
36
+
37
+ managed_policy = self.data[:managed_policies][policy_arn]
38
+
39
+ unless managed_policy
40
+ raise Fog::AWS::IAM::NotFound, "Policy #{policy_arn} does not exist."
41
+ end
42
+
43
+ unless self.data[:users].key?(user_name)
44
+ raise Fog::AWS::IAM::NotFound.new("The user with name #{user_name} cannot be found.")
45
+ end
46
+
47
+ user = self.data[:users][user_name]
48
+ user[:attached_policies].delete(policy_arn)
49
+
50
+ Excon::Response.new.tap { |response|
51
+ response.status = 200
52
+ response.body = { "RequestId" => Fog::AWS::Mock.request_id }
53
+ }
54
+ end
55
+ end
30
56
  end
31
57
  end
32
58
  end
@@ -0,0 +1,57 @@
1
+ module Fog
2
+ module AWS
3
+ class IAM
4
+ class Real
5
+ require 'fog/aws/parsers/iam/single_policy'
6
+
7
+ # Get Policy
8
+ #
9
+ # ==== Parameters
10
+ # * 'PolicyArn'<~String>: The Amazon Resource Name (ARN). ARNs are unique identifiers for AWS resources.
11
+ #
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~Hash>:
15
+ # * Arn<~String> The Amazon Resource Name (ARN). ARNs are unique identifiers for AWS resources.
16
+ # * AttachmentCount<~Integer> The number of entities (users, groups, and roles) that the policy is attached to.
17
+ # * CreateDate<~DateTime> The date and time, in ISO 8601 date-time format, when the policy was created.
18
+ # * DefaultVersionId<~String> The identifier for the version of the policy that is set as the default version.
19
+ # * Description<~String> A friendly description of the policy.
20
+ # * IsAttachable<~Boolean> Specifies whether the policy can be attached to an IAM user, group, or role.
21
+ # * Path<~String> The path to the policy.
22
+ # * PolicyId<~String> The stable and unique string identifying the policy.
23
+ # * PolicyName<~String> The friendly name (not ARN) identifying the policy.
24
+ # * UpdateDate<~DateTime> The date and time, in ISO 8601 date-time format, when the policy was last updated.
25
+ #
26
+ # ==== See Also
27
+ # http://docs.aws.amazon.com/IAM/latest/APIReference/API_GetPolicy.html
28
+ #
29
+ def get_policy(policy_arn)
30
+ request({
31
+ 'Action' => 'GetPolicy',
32
+ 'PolicyArn' => policy_arn,
33
+ :parser => Fog::Parsers::AWS::IAM::SinglePolicy.new
34
+ })
35
+ end
36
+ end
37
+
38
+ class Mock
39
+ def get_policy(policy_arn)
40
+ managed_policy = self.data[:managed_policies][policy_arn]
41
+
42
+ unless managed_policy
43
+ raise Fog::AWS::IAM::NotFound, "Policy #{policy_arn} does not exist."
44
+ end
45
+
46
+ Excon::Response.new.tap do |response|
47
+ response.body = {
48
+ 'Policy' => managed_policy,
49
+ 'RequestId' => Fog::AWS::Mock.request_id
50
+ }
51
+ response.status = 200
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,59 @@
1
+ module Fog
2
+ module AWS
3
+ class IAM
4
+ class Real
5
+ require 'fog/aws/parsers/iam/policy_version'
6
+
7
+ # Contains information about a version of a managed policy.
8
+ #
9
+ # ==== Parameters
10
+ # * PolicyArn<~String>: The Amazon Resource Name (ARN). ARNs are unique identifiers for AWS resources.
11
+ # * VersionId<~String>: Identifies the policy version to retrieve.
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~Hash>:
15
+ # * 'RequestId'<~String> - Id of the request
16
+ # * 'PolicyVersion'<~Array>:
17
+ # * CreateDate<~DateTime> The date and time, in ISO 8601 date-time format, when the policy version was created.
18
+ # * Document<~String> The policy document. Pattern: [\u0009\u000A\u000D\u0020-\u00FF]+
19
+ # * IsDefaultVersion<~String> Specifies whether the policy version is set as the policy's default version.
20
+ # * VersionId<~String> The identifier for the policy version.
21
+ # ==== See Also
22
+ # http://docs.aws.amazon.com/IAM/latest/APIReference/API_PolicyVersion.html
23
+ #
24
+ def get_policy_version(policy_arn, version_id)
25
+ request({
26
+ 'Action' => 'GetPolicyVersion',
27
+ 'PolicyArn' => policy_arn,
28
+ 'VersionId' => version_id,
29
+ :parser => Fog::Parsers::AWS::IAM::PolicyVersion.new
30
+ })
31
+ end
32
+ end
33
+
34
+ class Mock
35
+ def get_policy_version(policy_arn, version_id)
36
+ managed_policy_versions = self.data[:managed_policy_versions][policy_arn]
37
+
38
+ unless managed_policy_versions
39
+ raise Fog::AWS::IAM::NotFound, "Policy #{policy_arn} version #{version_id} does not exist."
40
+ end
41
+
42
+ version = managed_policy_versions[version_id]
43
+
44
+ unless version
45
+ raise Fog::AWS::IAM::NotFound, "Policy #{policy_arn} version #{version_id} does not exist."
46
+ end
47
+
48
+ Excon::Response.new.tap do |response|
49
+ response.body = {
50
+ 'PolicyVersion' => version,
51
+ 'RequestId' => Fog::AWS::Mock.request_id
52
+ }
53
+ response.status = 200
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -51,6 +51,13 @@ module Fog
51
51
  'CreateDate' => user[:created_at]
52
52
  }
53
53
 
54
+ unless @current_user_name == "root"
55
+ user_body.merge!(
56
+ 'Path' => user[:path],
57
+ 'UserName' => @current_user_name
58
+ )
59
+ end
60
+
54
61
  elsif !self.data[:users].key?(username)
55
62
  raise Fog::AWS::IAM::NotFound.new("The user with name #{username} cannot be found.")
56
63
  else
@@ -0,0 +1,89 @@
1
+ module Fog
2
+ module AWS
3
+ class IAM
4
+ class Real
5
+ require 'fog/aws/parsers/iam/list_managed_policies'
6
+
7
+ # Attaches a managed policy to a group
8
+ #
9
+ # ==== Parameters
10
+ # * group_name<~String>: name of the group
11
+ #
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~Hash>:
15
+ # * 'RequestId'<~String> - Id of the request
16
+ # * AttachedPolicies
17
+ # * 'PolicyArn'<~String> - The Amazon Resource Name (ARN). ARNs are unique identifiers for AWS resources.
18
+ # * 'PolicName'<~String> - The friendly name of the attached policy.
19
+ #
20
+ # ==== See Also
21
+ # http://docs.aws.amazon.com/IAM/latest/APIReference/API_AttachGroupPolicy.html
22
+ #
23
+ def list_attached_group_policies(group_name, options={})
24
+ request({
25
+ 'Action' => 'ListAttachedGroupPolicies',
26
+ 'GroupName' => group_name,
27
+ :parser => Fog::Parsers::AWS::IAM::ListManagedPolicies.new
28
+ }.merge(options))
29
+ end
30
+ end
31
+
32
+ class Mock
33
+ def list_attached_group_policies(group_name, options={})
34
+ unless self.data[:groups].key?(group_name)
35
+ raise Fog::AWS::IAM::NotFound.new("The group with name #{group_name} cannot be found.")
36
+ end
37
+
38
+ limit = options['MaxItems']
39
+ marker = options['Marker']
40
+ group = self.data[:groups][group_name]
41
+
42
+ if limit
43
+ if limit > 1_000
44
+ raise Fog::AWS::IAM::Error.new(
45
+ "ValidationError => 1 validation error detected: Value '#{limit}' at 'limit' failed to satisfy constraint: Member must have value less than or equal to 1000"
46
+ )
47
+ elsif limit < 1
48
+ raise Fog::AWS::IAM::Error.new(
49
+ "ValidationError => 1 validation error detected: Value '#{limit}' at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1"
50
+ )
51
+ end
52
+ end
53
+
54
+ data_set = if marker
55
+ self.data[:markers][marker] || []
56
+ else
57
+ group[:attached_policies].map { |arn|
58
+ self.data[:managed_policies].fetch(arn)
59
+ }.map { |mp|
60
+ { "PolicyName" => mp.fetch("PolicyName"), "PolicyArn" => mp.fetch("Arn") }
61
+ }
62
+ end
63
+
64
+ data = data_set.slice!(0, limit || 100)
65
+ truncated = data_set.size > 0
66
+ marker = truncated && Base64.encode64("metadata/l/#{account_id}/#{UUID.uuid}")
67
+
68
+ response = Excon::Response.new
69
+
70
+ body = {
71
+ 'Policies' => data,
72
+ 'IsTruncated' => truncated,
73
+ 'RequestId' => Fog::AWS::Mock.request_id
74
+ }
75
+
76
+ if marker
77
+ self.data[:markers][marker] = data_set
78
+ body.merge!('Marker' => marker)
79
+ end
80
+
81
+ response.body = body
82
+ response.status = 200
83
+
84
+ response
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,89 @@
1
+ module Fog
2
+ module AWS
3
+ class IAM
4
+ class Real
5
+ require 'fog/aws/parsers/iam/list_managed_policies'
6
+
7
+ # Attaches a managed policy to a user
8
+ #
9
+ # ==== Parameters
10
+ # * user_name<~String>: name of the user
11
+ #
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~Hash>:
15
+ # * 'RequestId'<~String> - Id of the request
16
+ # * AttachedPolicies
17
+ # * 'PolicyArn'<~String> - The Amazon Resource Name (ARN). ARNs are unique identifiers for AWS resources.
18
+ # * 'PolicName'<~String> - The friendly name of the attached policy.
19
+ #
20
+ # ==== See Also
21
+ # http://docs.aws.amazon.com/IAM/latest/APIReference/API_AttachUserPolicy.html
22
+ #
23
+ def list_attached_user_policies(user_name, options={})
24
+ request({
25
+ 'Action' => 'ListAttachedUserPolicies',
26
+ 'UserName' => user_name,
27
+ :parser => Fog::Parsers::AWS::IAM::ListManagedPolicies.new
28
+ }.merge(options))
29
+ end
30
+ end
31
+
32
+ class Mock
33
+ def list_attached_user_policies(user_name, options={})
34
+ unless self.data[:users].key?(user_name)
35
+ raise Fog::AWS::IAM::NotFound.new("The user with name #{user_name} cannot be found.")
36
+ end
37
+
38
+ limit = options['MaxItems']
39
+ marker = options['Marker']
40
+ user = self.data[:users][user_name]
41
+
42
+ if limit
43
+ if limit > 1_000
44
+ raise Fog::AWS::IAM::Error.new(
45
+ "ValidationError => 1 validation error detected: Value '#{limit}' at 'limit' failed to satisfy constraint: Member must have value less than or equal to 1000"
46
+ )
47
+ elsif limit < 1
48
+ raise Fog::AWS::IAM::Error.new(
49
+ "ValidationError => 1 validation error detected: Value '#{limit}' at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1"
50
+ )
51
+ end
52
+ end
53
+
54
+ data_set = if marker
55
+ self.data[:markers][marker] || []
56
+ else
57
+ user[:attached_policies].map { |arn|
58
+ self.data[:managed_policies].fetch(arn)
59
+ }.map { |mp|
60
+ { "PolicyName" => mp.fetch("PolicyName"), "PolicyArn" => mp.fetch("Arn") }
61
+ }
62
+ end
63
+
64
+ data = data_set.slice!(0, limit || 100)
65
+ truncated = data_set.size > 0
66
+ marker = truncated && Base64.encode64("metadata/l/#{account_id}/#{UUID.uuid}")
67
+
68
+ response = Excon::Response.new
69
+
70
+ body = {
71
+ 'Policies' => data,
72
+ 'IsTruncated' => truncated,
73
+ 'RequestId' => Fog::AWS::Mock.request_id
74
+ }
75
+
76
+ if marker
77
+ self.data[:markers][marker] = data_set
78
+ body.merge!('Marker' => marker)
79
+ end
80
+
81
+ response.body = body
82
+ response.status = 200
83
+
84
+ response
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end