esp_sdk 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/CHANGELOG.md +6 -1
  4. data/Gemfile.lock +11 -1
  5. data/README.md +287 -28
  6. data/bin/esp +15 -0
  7. data/esp_sdk.gemspec +2 -0
  8. data/lib/esp/aws_clients.rb +60 -0
  9. data/lib/esp/commands/add_external_account.rb +57 -0
  10. data/lib/esp/commands/commands_tasks.rb +106 -0
  11. data/lib/esp/commands/console.rb +68 -0
  12. data/lib/esp/extensions/active_resource/formats/json_api_format.rb +12 -4
  13. data/lib/esp/extensions/active_resource/paginated_collection.rb +5 -5
  14. data/lib/esp/extensions/active_resource/validations.rb +1 -1
  15. data/lib/esp/external_account_creator.rb +77 -0
  16. data/lib/esp/resources/alert.rb +30 -34
  17. data/lib/esp/resources/cloud_trail_event.rb +5 -0
  18. data/lib/esp/resources/contact_request.rb +6 -5
  19. data/lib/esp/resources/custom_signature.rb +32 -56
  20. data/lib/esp/resources/dashboard.rb +8 -1
  21. data/lib/esp/resources/external_account.rb +27 -19
  22. data/lib/esp/resources/organization.rb +27 -3
  23. data/lib/esp/resources/region.rb +15 -3
  24. data/lib/esp/resources/report.rb +28 -24
  25. data/lib/esp/resources/resource.rb +26 -10
  26. data/lib/esp/resources/service.rb +5 -0
  27. data/lib/esp/resources/signature.rb +28 -12
  28. data/lib/esp/resources/stat.rb +21 -2
  29. data/lib/esp/resources/stat_custom_signature.rb +30 -4
  30. data/lib/esp/resources/stat_region.rb +29 -3
  31. data/lib/esp/resources/stat_service.rb +29 -3
  32. data/lib/esp/resources/stat_signature.rb +29 -3
  33. data/lib/esp/resources/sub_organization.rb +27 -3
  34. data/lib/esp/resources/suppression/region.rb +14 -32
  35. data/lib/esp/resources/suppression/signature.rb +14 -40
  36. data/lib/esp/resources/suppression/unique_identifier.rb +8 -6
  37. data/lib/esp/resources/suppression.rb +43 -5
  38. data/lib/esp/resources/tag.rb +5 -0
  39. data/lib/esp/resources/team.rb +33 -9
  40. data/lib/esp/resources/user.rb +29 -3
  41. data/lib/esp/version.rb +1 -1
  42. data/lib/esp.rb +25 -5
  43. data/test/esp/aws_clients_test.rb +101 -0
  44. data/test/esp/extensions/active_resource/formats/json_api_format_test.rb +26 -12
  45. data/test/esp/extensions/active_resource/paginated_collection_test.rb +93 -72
  46. data/test/esp/extensions/active_resource/validations_test.rb +2 -12
  47. data/test/esp/external_account_creator_test.rb +153 -0
  48. data/test/esp/resources/alert_test.rb +71 -33
  49. data/test/esp/resources/cloud_trail_event_test.rb +9 -1
  50. data/test/esp/resources/contact_request_test.rb +8 -0
  51. data/test/esp/resources/custom_signature_test.rb +8 -0
  52. data/test/esp/resources/dashboard_test.rb +8 -0
  53. data/test/esp/resources/external_account_test.rb +8 -0
  54. data/test/esp/resources/metadata_test.rb +1 -1
  55. data/test/esp/resources/organization_test.rb +8 -0
  56. data/test/esp/resources/region_test.rb +12 -4
  57. data/test/esp/resources/report_test.rb +13 -4
  58. data/test/esp/resources/resource_test.rb +208 -64
  59. data/test/esp/resources/service_test.rb +8 -0
  60. data/test/esp/resources/signature_test.rb +15 -9
  61. data/test/esp/resources/stat_custom_signature_test.rb +9 -1
  62. data/test/esp/resources/stat_region_test.rb +23 -1
  63. data/test/esp/resources/stat_service_test.rb +23 -1
  64. data/test/esp/resources/stat_signature_test.rb +23 -1
  65. data/test/esp/resources/stat_test.rb +52 -8
  66. data/test/esp/resources/sub_organization_test.rb +8 -0
  67. data/test/esp/resources/suppression/region_test.rb +10 -2
  68. data/test/esp/resources/suppression/signature_test.rb +10 -2
  69. data/test/esp/resources/suppression/unique_identifier_test.rb +10 -2
  70. data/test/esp/resources/suppression_test.rb +74 -14
  71. data/test/esp/resources/tag_test.rb +9 -1
  72. data/test/esp/resources/team_test.rb +8 -0
  73. data/test/esp/resources/user_test.rb +49 -19
  74. data/test/esp_test.rb +19 -1
  75. data/test/factories/alerts.rb +70 -0
  76. data/test/factories/organizations.rb +2 -2
  77. data/test/factories/regions.rb +1 -1
  78. data/test/factories/sub_organizations.rb +1 -1
  79. data/test/factories/suppressions.rb +109 -3
  80. data/test/factories/users.rb +65 -2
  81. data/test/test_helper.rb +9 -8
  82. metadata +41 -69
  83. data/bin/esp_console +0 -67
  84. data/rdoc/ActiveResource/Formats.html +0 -178
  85. data/rdoc/ActiveResource/PaginatedCollection.html +0 -912
  86. data/rdoc/ActiveResource.html +0 -182
  87. data/rdoc/ESP/Alert.html +0 -808
  88. data/rdoc/ESP/CloudTrailEvent.html +0 -377
  89. data/rdoc/ESP/ContactRequest.html +0 -368
  90. data/rdoc/ESP/CustomSignature.html +0 -748
  91. data/rdoc/ESP/Dashboard.html +0 -357
  92. data/rdoc/ESP/ExternalAccount.html +0 -567
  93. data/rdoc/ESP/Metadata.html +0 -411
  94. data/rdoc/ESP/Organization.html +0 -592
  95. data/rdoc/ESP/Region.html +0 -401
  96. data/rdoc/ESP/Report.html +0 -624
  97. data/rdoc/ESP/Service.html +0 -382
  98. data/rdoc/ESP/Signature.html +0 -557
  99. data/rdoc/ESP/Stat.html +0 -1780
  100. data/rdoc/ESP/StatCustomSignature.html +0 -1601
  101. data/rdoc/ESP/StatRegion.html +0 -1600
  102. data/rdoc/ESP/StatService.html +0 -1600
  103. data/rdoc/ESP/StatSignature.html +0 -1600
  104. data/rdoc/ESP/SubOrganization.html +0 -542
  105. data/rdoc/ESP/Suppression/Region.html +0 -456
  106. data/rdoc/ESP/Suppression/Signature.html +0 -472
  107. data/rdoc/ESP/Suppression/UniqueIdentifier.html +0 -419
  108. data/rdoc/ESP/Suppression.html +0 -651
  109. data/rdoc/ESP/Tag.html +0 -373
  110. data/rdoc/ESP/Team.html +0 -586
  111. data/rdoc/ESP/User.html +0 -485
  112. data/rdoc/ESP.html +0 -549
  113. data/rdoc/README_md.html +0 -503
  114. data/rdoc/created.rid +0 -31
  115. data/rdoc/images/add.png +0 -0
  116. data/rdoc/images/arrow_up.png +0 -0
  117. data/rdoc/images/brick.png +0 -0
  118. data/rdoc/images/brick_link.png +0 -0
  119. data/rdoc/images/bug.png +0 -0
  120. data/rdoc/images/bullet_black.png +0 -0
  121. data/rdoc/images/bullet_toggle_minus.png +0 -0
  122. data/rdoc/images/bullet_toggle_plus.png +0 -0
  123. data/rdoc/images/date.png +0 -0
  124. data/rdoc/images/delete.png +0 -0
  125. data/rdoc/images/find.png +0 -0
  126. data/rdoc/images/loadingAnimation.gif +0 -0
  127. data/rdoc/images/macFFBgHack.png +0 -0
  128. data/rdoc/images/package.png +0 -0
  129. data/rdoc/images/page_green.png +0 -0
  130. data/rdoc/images/page_white_text.png +0 -0
  131. data/rdoc/images/page_white_width.png +0 -0
  132. data/rdoc/images/plugin.png +0 -0
  133. data/rdoc/images/ruby.png +0 -0
  134. data/rdoc/images/tag_blue.png +0 -0
  135. data/rdoc/images/tag_green.png +0 -0
  136. data/rdoc/images/transparent.png +0 -0
  137. data/rdoc/images/wrench.png +0 -0
  138. data/rdoc/images/wrench_orange.png +0 -0
  139. data/rdoc/images/zoom.png +0 -0
  140. data/rdoc/index.html +0 -136
  141. data/rdoc/js/darkfish.js +0 -155
  142. data/rdoc/js/jquery.js +0 -4
  143. data/rdoc/js/navigation.js +0 -142
  144. data/rdoc/js/search.js +0 -94
  145. data/rdoc/js/search_index.js +0 -1
  146. data/rdoc/js/searcher.js +0 -228
  147. data/rdoc/rdoc.css +0 -595
  148. data/rdoc/table_of_contents.html +0 -942
@@ -2,6 +2,12 @@ module ESP
2
2
  class Suppression
3
3
  class Region < ESP::Resource
4
4
  self.prefix += "suppressions/"
5
+ # Not Implemented. You cannot search for Suppression::Region.
6
+ #
7
+ # Regular ARELlike methods are disabled. Use the ESP::Suppression object to search suppressions.
8
+ def self.where(*)
9
+ fail ESP::NotImplementedError, 'Regular ARELlike methods are disabled. Use the ESP::Suppression object to search suppressions'
10
+ end
5
11
 
6
12
  # Not Implemented. You cannot search for Suppression::Region.
7
13
  #
@@ -44,26 +50,14 @@ module ESP
44
50
  #
45
51
  # +attributes+ | Required | A hash of region suppression attributes
46
52
  #
47
- # ===== Valid Attributes When Not Creating for Alert
53
+ # ===== Valid Attributes
48
54
  #
49
- # +regions+ | Required | An array of region names to suppress.
55
+ # See {API documentation}[http://api-docs.evident.io?ruby#suppression-region-create] for valid arguments
50
56
  #
51
- # +external_account_ids+ | Required | An Array of the external accounts identified by +external_account_id+ to suppress the signature or custom signature on.
52
- #
53
- # +resource+ | Not Required | The resource string this suppression will suppress alerts for.
54
- #
55
- # +reason+ | Required | The reason for creating the suppression.
56
- #
57
- # ==== Example
57
+ # ==== Example When Not Creating for Alert
58
58
  # create(regions: ['us_east_1'], external_account_ids: [5], reason: 'My very good reason for creating this suppression')
59
59
  #
60
- # ===== Valid Attributes When Creating for Alert
61
- #
62
- # +alert_id+ | Required | The id for the alert you want to create a suppression for.
63
- #
64
- # +reason+ | Required | The reason for creating the suppression.
65
- #
66
- # ==== Example
60
+ # ==== Example When Creating for Alert
67
61
  # create(alert_id: 5, reason: 'My very good reason for creating this suppression')
68
62
 
69
63
  # :method: save
@@ -71,27 +65,15 @@ module ESP
71
65
  #
72
66
  # If you set an +alert_id+, set the +reason+ and all other params will be ignored, and the suppression will be created based on that alert.
73
67
  #
74
- # ===== Valid Attributes When Not Creating for Alert
75
- #
76
- # +regions+ | Required | An array of region names to suppress.
77
- #
78
- # +external_account_ids+ | Required | An Array of the external accounts identified by +external_account_id+ to suppress the signature or custom signature on.
68
+ # ===== Valid Attributes
79
69
  #
80
- # +resource+ | Not Required | The resource string this suppression will suppress alerts for.
70
+ # See {API documentation}[http://api-docs.evident.io?ruby#suppression-region-create] for valid arguments
81
71
  #
82
- # +reason+ | Required | The reason for creating the suppression.
83
- #
84
- # ==== Example
72
+ # ==== Example When Not Creating for Alert
85
73
  # suppression = new(regions: ['us_east_1'], external_account_ids: [5], reason: 'My very good reason for creating this suppression')
86
74
  # suppression.save
87
75
  #
88
- # ===== Valid Attributes When Creating for Alert
89
- #
90
- # +alert_id+ | Required | The id for the alert you want to create a suppression for.
91
- #
92
- # +reason+ | Required | The reason for creating the suppression.
93
- #
94
- # ==== Example
76
+ # ==== Example When Creating for Alert
95
77
  # suppression = new(alert_id: 5, reason: 'My very good reason for creating this suppression')
96
78
  # suppression.save
97
79
  end
@@ -2,6 +2,12 @@ module ESP
2
2
  class Suppression
3
3
  class Signature < ESP::Resource
4
4
  self.prefix += "suppressions/"
5
+ # Not Implemented. You cannot search for Suppression::Signature.
6
+ #
7
+ # Regular ARELlike methods are disabled. Use the ESP::Suppression object to search suppressions.
8
+ def self.where(*)
9
+ fail ESP::NotImplementedError, 'Regular ARELlike methods are disabled. Use the ESP::Suppression object to search suppressions'
10
+ end
5
11
 
6
12
  # Not Implemented. You cannot search for Suppression::Signature.
7
13
  #
@@ -44,30 +50,14 @@ module ESP
44
50
  #
45
51
  # +attributes+ | Required | A hash of signature suppression attributes
46
52
  #
47
- # ===== Valid Attributes When Not Creating for Alert
48
- #
49
- # +signature_ids+ | Conditionally Required | An array of signatures identified by +signature_id+ to suppress. Required if +custom_signature_ids+ is blank.
53
+ # ===== Valid Attributes
50
54
  #
51
- # +custom_signature_ids+ | Conditionally Required | An array of custom signatures identified by +custom_signature_id+ to suppress. Required if +signature_ids+ is blank.
55
+ # See {API documentation}[http://api-docs.evident.io?ruby#suppression-signature-create] for valid arguments
52
56
  #
53
- # +regions+ | Required | An array of region names to suppress.
54
- #
55
- # +external_account_ids+ | Required | An Array of the external accounts identified by +external_account_id+ to suppress the signature or custom signature on.
56
- #
57
- # +resource+ | Not Required | The resource string this suppression will suppress alerts for.
58
- #
59
- # +reason+ | Required | The reason for creating the suppression.
60
- #
61
- # ==== Example
57
+ # ==== Example When Not Creating for Alert
62
58
  # create(signature_ids: [4, 2], regions: ['us_east_1'], external_account_ids: [5], reason: 'My very good reason for creating this suppression')
63
59
  #
64
- # ===== Valid Attributes When Creating for Alert
65
- #
66
- # +alert_id+ | Required | The id for the alert you want to create a suppression for.
67
- #
68
- # +reason+ | Required | The reason for creating the suppression.
69
- #
70
- # ==== Example
60
+ # ==== Example When Creating for Alert
71
61
  # create(alert_id: 5, reason: 'My very good reason for creating this suppression')
72
62
 
73
63
  # :method: save
@@ -75,31 +65,15 @@ module ESP
75
65
  #
76
66
  # If you set an +alert_id+, set the +reason+ and all other params will be ignored, and the suppression will be created based on that alert.
77
67
  #
78
- # ===== Valid Attributes When Not Creating for Alert
79
- #
80
- # +signature_ids+ | Conditionally Required | An array of signatures identified by +signature_id+ to suppress. Required if +custom_signature_ids+ is blank.
81
- #
82
- # +custom_signature_ids+ | Conditionally Required | An array of custom signatures identified by +custom_signature_id+ to suppress. Required if +signature_ids+ is blank.
83
- #
84
- # +regions+ | Required | An array of region names to suppress.
68
+ # ===== Valid Attributes
85
69
  #
86
- # +external_account_ids+ | Required | An Array of the external accounts identified by +external_account_id+ to suppress the signature or custom signature on.
70
+ # See {API documentation}[http://api-docs.evident.io?ruby#suppression-signature-create] for valid arguments
87
71
  #
88
- # +resource+ | Not Required | The resource string this suppression will suppress alerts for.
89
- #
90
- # +reason+ | Required | The reason for creating the suppression.
91
- #
92
- # ==== Example
72
+ # ==== Example When Not Creating for Alert
93
73
  # suppression = new(signature_ids: [4, 2], regions: ['us_east_1'], external_account_ids: [5], reason: 'My very good reason for creating this suppression')
94
74
  # suppression.save
95
75
  #
96
- # ===== Valid Attributes When Creating for Alert
97
- #
98
- # +alert_id+ | Required | The id for the alert you want to create a suppression for.
99
- #
100
- # +reason+ | Required | The reason for creating the suppression.
101
- #
102
- # ==== Example
76
+ # ==== Example When Creating for Alert
103
77
  # suppression = new(alert_id: 5, reason: 'My very good reason for creating this suppression')
104
78
  # suppression.save
105
79
  end
@@ -2,6 +2,12 @@ module ESP
2
2
  class Suppression
3
3
  class UniqueIdentifier < ESP::Resource
4
4
  self.prefix += "suppressions/alert/:alert_id/"
5
+ # Not Implemented. You cannot search for Suppression::UniqueIdentifier.
6
+ #
7
+ # Regular ARELlike methods are disabled. Use the ESP::Suppression object to search suppressions.
8
+ def self.where(*)
9
+ fail ESP::NotImplementedError, 'Regular ARELlike methods are disabled. Use the ESP::Suppression object to search suppressions'
10
+ end
5
11
 
6
12
  # Not Implemented. You cannot search for Suppression::UniqueIdentifier.
7
13
  #
@@ -34,9 +40,7 @@ module ESP
34
40
  #
35
41
  # ==== Attributes
36
42
  #
37
- # +alert_id+ | Required | The id for the alert you want to create a suppression for.
38
- #
39
- # +reason+ | Required | The reason for creating the suppression.
43
+ # See {API documentation}[http://api-docs.evident.io?ruby#suppression-unique-identifier-create] for valid arguments
40
44
  #
41
45
  # ==== Example
42
46
  # create(alert_id: 5, reason: 'My very good reason for creating this suppression')
@@ -48,9 +52,7 @@ module ESP
48
52
  #
49
53
  # ==== Attributes
50
54
  #
51
- # +alert_id+ | Required | The id for the alert you want to create a suppression for.
52
- #
53
- # +reason+ | Required | The reason for creating the suppression.
55
+ # See {API documentation}[http://api-docs.evident.io?ruby#suppression-unique-identifier-create] for valid arguments
54
56
  #
55
57
  # ==== Example
56
58
  # suppression = new(alert_id: 5, reason: 'My very good reason for creating this suppression')
@@ -10,24 +10,38 @@ module ESP
10
10
 
11
11
  ##
12
12
  # The regions affected by this suppression.
13
- has_many :regions, class_name: 'ESP::Region'
13
+ def regions
14
+ # When regions come back in an include, the method still gets called, to return the object from the attributes.
15
+ return attributes['regions'] if attributes['regions'].present?
16
+ return [] unless respond_to? :region_ids
17
+ ESP::Region.where(id_in: region_ids)
18
+ end
14
19
 
15
20
  ##
16
21
  # The external accounts affected by this suppression.
17
- has_many :external_accounts, class_name: 'ESP::ExternalAccount'
22
+ def external_accounts
23
+ # When external_accounts come back in an include, the method still gets called, to return the object from the attributes.
24
+ return attributes['external_accounts'] if attributes['external_accounts'].present?
25
+ return [] unless respond_to? :external_account_ids
26
+ ESP::ExternalAccount.where(id_in: external_account_ids)
27
+ end
18
28
 
19
29
  ##
20
30
  # The signatures being suppressed.
21
31
  def signatures
32
+ # When signatures come back in an include, the method still gets called, to return the object from the attributes.
33
+ return attributes['signatures'] if attributes['signatures'].present?
22
34
  return [] unless respond_to? :signature_ids
23
- ESP::Signature.find(:all, params: { id: signature_ids })
35
+ ESP::Signature.where(id_in: signature_ids)
24
36
  end
25
37
 
26
38
  ##
27
39
  # The custom signatures being suppressed.
28
40
  def custom_signatures
41
+ # When custom_signatures come back in an include, the method still gets called, to return the object from the attributes.
42
+ return attributes['custom_signatures'] if attributes['custom_signatures'].present?
29
43
  return [] unless respond_to? :custom_signature_ids
30
- ESP::CustomSignature.find(:all, params: { id: custom_signature_ids })
44
+ ESP::CustomSignature.where(id_in: custom_signature_ids)
31
45
  end
32
46
 
33
47
  # Overriden so the correct param is sent on the has_many relationships. API needs this one to be plural.
@@ -69,6 +83,20 @@ module ESP
69
83
  false
70
84
  end
71
85
 
86
+ # :singleton-method: where
87
+ # Return a paginated Suppression list filtered by search parameters
88
+ #
89
+ # ==== Parameters
90
+ #
91
+ # +clauses+ | Hash of attributes with appended predicates to search, sort and include.
92
+ #
93
+ # ===== Valid Clauses
94
+ #
95
+ # See {API documentation}[http://api-docs.evident.io?ruby#suppression-attributes] for valid arguments
96
+ #
97
+ # :call-seq:
98
+ # where(clauses = {})
99
+
72
100
  ##
73
101
  # :singleton-method: find
74
102
  # Find a Suppression by id
@@ -77,8 +105,18 @@ module ESP
77
105
  #
78
106
  # +id+ | Required | The ID of the suppression to retrieve
79
107
  #
108
+ # +options+ | Optional | A hash of options
109
+ #
110
+ # ===== Valid Options
111
+ #
112
+ # +include+ | The list of associated objects to return on the initial request.
113
+ #
114
+ # ===== Valid Includable Associations
115
+ #
116
+ # See {API documentation}[http://api-docs.evident.io?ruby#suppression-attributes] for valid arguments
117
+ #
80
118
  # :call-seq:
81
- # find(id)
119
+ # find(id, options = {})
82
120
 
83
121
  # :singleton-method: all
84
122
  # Return a paginated Suppression list
@@ -10,6 +10,11 @@ module ESP
10
10
  fail ESP::NotImplementedError
11
11
  end
12
12
 
13
+ # Not Implemented. You cannot search for a Tag.
14
+ def self.where(*)
15
+ fail ESP::NotImplementedError
16
+ end
17
+
13
18
  # Returns a paginated collection of tags for the given alert_id
14
19
  # Convenience method to use instead of ::find since an alert_id is required to return tags.
15
20
  #
@@ -26,6 +26,20 @@ module ESP
26
26
  Report.create_for_team(id)
27
27
  end
28
28
 
29
+ # :singleton-method: where
30
+ # Return a paginated Team list filtered by search parameters
31
+ #
32
+ # ==== Parameters
33
+ #
34
+ # +clauses+ | Hash of attributes with appended predicates to search, sort and include.
35
+ #
36
+ # ===== Valid Clauses
37
+ #
38
+ # See {API documentation}[http://api-docs.evident.io?ruby#team-attributes] for valid arguments
39
+ #
40
+ # :call-seq:
41
+ # where(clauses = {})
42
+
29
43
  ##
30
44
  # :singleton-method: find
31
45
  # Find a Team by id
@@ -34,8 +48,18 @@ module ESP
34
48
  #
35
49
  # +id+ | Required | The ID of the team to retrieve
36
50
  #
51
+ # +options+ | Optional | A hash of options
52
+ #
53
+ # ===== Valid Options
54
+ #
55
+ # +include+ | The list of associated objects to return on the initial request.
56
+ #
57
+ # ===== Valid Includable Associations
58
+ #
59
+ # See {API documentation}[http://api-docs.evident.io?ruby#team-attributes] for valid arguments
60
+ #
37
61
  # :call-seq:
38
- # find(id)
62
+ # find(id, options = {})
39
63
 
40
64
  # :singleton-method: all
41
65
  # Return a paginated Team list
@@ -49,24 +73,24 @@ module ESP
49
73
  #
50
74
  # +attributes+ | Required | A hash of team attributes
51
75
  #
52
- # ==== Valid Attributes
76
+ # ===== Valid Attributes
53
77
  #
54
- # +sub_organization_id+ | Required | The ID of the sub organization to attach this team to
78
+ # See {API documentation}[http://api-docs.evident.io?ruby#team-create] for valid arguments
55
79
  #
56
- # +name+ | Required | The name of the team
80
+ # ==== Example
81
+ #
82
+ # team = ESP::Team.create(name: "Team Name", sub_organization_id: 9)
57
83
 
58
84
  # :method: save
59
85
  # Create and update a Team.
60
86
  #
61
- # ==== Valid Attributes when updating
87
+ # ===== Valid Attributes when updating
62
88
  #
63
89
  # +name+ | Required | The new name of the team
64
90
  #
65
- # ==== Valid Attributes when creating
66
- #
67
- # +sub_organization_id+ | Required | The ID of the sub organization to attach this team to
91
+ # ===== Valid Attributes when creating
68
92
  #
69
- # +name+ | Required | The name of the team
93
+ # See {API documentation}[http://api-docs.evident.io?ruby#team-create] for valid arguments
70
94
  #
71
95
  # ==== Example
72
96
  #
@@ -17,15 +17,31 @@ module ESP
17
17
  ##
18
18
  # The collection of sub organizations that belong to the user.
19
19
  def sub_organizations
20
- SubOrganization.find(:all, params: { id: sub_organization_ids })
20
+ return attributes['sub_organizations'] if attributes['sub_organizations'].present?
21
+ SubOrganization.where(id_in: sub_organization_ids)
21
22
  end
22
23
 
23
24
  ##
24
25
  # The collection of teams that belong to the user.
25
26
  def teams
26
- Team.find(:all, params: { id: team_ids })
27
+ return attributes['teams'] if attributes['teams'].present?
28
+ Team.where(id_in: team_ids)
27
29
  end
28
30
 
31
+ # :singleton-method: where
32
+ # Return a paginated User list filtered by search parameters
33
+ #
34
+ # ==== Parameters
35
+ #
36
+ # +clauses+ | Hash of attributes with appended predicates to search, sort and include.
37
+ #
38
+ # ===== Valid Clauses
39
+ #
40
+ # See {API documentation}[http://api-docs.evident.io?ruby#user-attributes] for valid arguments
41
+ #
42
+ # :call-seq:
43
+ # where(clauses = {})
44
+
29
45
  ##
30
46
  # :singleton-method: find
31
47
  # Find a User by id
@@ -34,8 +50,18 @@ module ESP
34
50
  #
35
51
  # +id+ | Required | The ID of the user to retrieve
36
52
  #
53
+ # +options+ | Optional | A hash of options
54
+ #
55
+ # ===== Valid Options
56
+ #
57
+ # +include+ | The list of associated objects to return on the initial request.
58
+ #
59
+ # ===== Valid Includable Associations
60
+ #
61
+ # See {API documentation}[http://api-docs.evident.io?ruby#user-attributes] for valid arguments
62
+ #
37
63
  # :call-seq:
38
- # find(id)
64
+ # find(id, options = {})
39
65
 
40
66
  # :singleton-method: all
41
67
  # Return a paginated User list
data/lib/esp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ESP
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  end
data/lib/esp.rb CHANGED
@@ -3,7 +3,7 @@ module ESP
3
3
  #
4
4
  # You can optionally set the `ESP_ACCESS_KEY_ID` environment variable.
5
5
  def self.access_key_id=(access_key_id)
6
- @access_key_id = access_key_id
6
+ @access_key_id = access_key_id
7
7
  ESP::Resource.hmac_access_id = access_key_id
8
8
  end
9
9
 
@@ -16,7 +16,7 @@ module ESP
16
16
  #
17
17
  # You can optionally set the `ESP_SECRET_ACCESS_KEY` environment variable.
18
18
  def self.secret_access_key=(secret_access_key)
19
- @secret_access_key = secret_access_key
19
+ @secret_access_key = secret_access_key
20
20
  ESP::Resource.hmac_secret_key = secret_access_key
21
21
  end
22
22
 
@@ -28,8 +28,8 @@ module ESP
28
28
  PATH = '/api/v2'.freeze
29
29
 
30
30
  HOST = { development: "http://localhost:3000".freeze,
31
- test: "http://localhost:3000".freeze,
32
- production: "https://api.evident.io".freeze }.freeze # :nodoc:
31
+ test: "http://localhost:3000".freeze,
32
+ production: "https://api.evident.io".freeze }.freeze # :nodoc:
33
33
 
34
34
  # Users of the Evident.io marketplace appliance application will need to set the host for their instance.
35
35
  #
@@ -37,7 +37,7 @@ module ESP
37
37
  #
38
38
  # * +host+ - The host for the installed appliance instance.
39
39
  def self.host=(host)
40
- @host = host
40
+ @host = host
41
41
  ESP::Resource.site = site
42
42
  end
43
43
 
@@ -46,6 +46,23 @@ module ESP
46
46
  "#{(@host || HOST[ESP.env.to_sym] || ENV['ESP_HOST'])}#{PATH}"
47
47
  end
48
48
 
49
+ # Manually set an http_proxy
50
+ #
51
+ # You can optionally set the `HTTP_PROXY` environment variable.
52
+ #
53
+ # ==== Attribute
54
+ #
55
+ # * +http_proxy+ - The URI of the http proxy
56
+ def self.http_proxy=(proxy)
57
+ @http_proxy = proxy
58
+ ESP::Resource.proxy = http_proxy
59
+ end
60
+
61
+ # Reads the `HTTP_PROXY` environment variable if ::http_proxy was not set manually.
62
+ def self.http_proxy
63
+ @http_proxy || ENV['http_proxy']
64
+ end
65
+
49
66
  # For use in a Rails initializer to set the ::access_key_id, ::secret_access_key and ::site.
50
67
  #
51
68
  # ==== Example
@@ -54,6 +71,7 @@ module ESP
54
71
  # config.access_key_id = <your key>
55
72
  # config.secret_access_key = <your secret key>
56
73
  # config.host = <host of your appliance instance>
74
+ # config.http_proxy = <your proxy URI>
57
75
  # end
58
76
  def self.configure
59
77
  yield self
@@ -93,4 +111,6 @@ module ESP
93
111
  autoload :StatSignature, File.expand_path(File.dirname(__FILE__) + '/esp/resources/stat_signature')
94
112
  autoload :StatRegion, File.expand_path(File.dirname(__FILE__) + '/esp/resources/stat_region')
95
113
  autoload :StatService, File.expand_path(File.dirname(__FILE__) + '/esp/resources/stat_service')
114
+ autoload :ExternalAccountCreator, File.expand_path(File.dirname(__FILE__) + '/../lib/esp/external_account_creator')
115
+ autoload :AWSClients, File.expand_path(File.dirname(__FILE__) + '/../lib/esp/aws_clients')
96
116
  end
@@ -0,0 +1,101 @@
1
+ require_relative '../test_helper'
2
+ require_relative '../../lib/esp/aws_clients'
3
+
4
+ module ESP
5
+ class AWSClientsTest < ActiveSupport::TestCase
6
+ context ESP::AWSClients do
7
+ context 'validations' do
8
+ should 'be 12 chars' do
9
+ aws = AWSClients.new
10
+ aws.stubs(:owner_id).returns("ABC123")
11
+
12
+ refute aws.valid?
13
+ assert_contains aws.errors.full_messages, 'Owner is the wrong length (should be 12 characters)'
14
+ end
15
+
16
+ should 'contain only numeric chars' do
17
+ aws = AWSClients.new
18
+ aws.stubs(:owner_id).returns("ABC123")
19
+
20
+ refute aws.valid?
21
+ assert_contains aws.errors.full_messages, 'Owner is not a number'
22
+ end
23
+
24
+ should 'contain 12 numeric chars' do
25
+ aws = AWSClients.new
26
+ aws.stubs(:owner_id).returns("012345678912")
27
+
28
+ assert aws.valid?
29
+ end
30
+ end
31
+
32
+ context "#create_and_attach_role" do
33
+ setup do
34
+ ENV['AWS_REGION'] = 'us-east-1'
35
+ end
36
+
37
+ teardown do
38
+ ENV['AWS_REGION'] = nil
39
+ end
40
+
41
+ should "make iam call to create_role with external account id" do
42
+ aws = AWSClients.new
43
+ iam_client = mock
44
+ iam_client.stubs(:create_role)
45
+ iam_client.stubs(:attach_role_policy)
46
+ aws.stubs(:iam).returns(iam_client)
47
+
48
+ aws.create_and_attach_role!('1234')
49
+
50
+ assert_received(iam_client, :create_role) do |expected|
51
+ expected.with do |params|
52
+ assert_equal AWSClients::AWS_ROLE_NAME, params[:role_name]
53
+ assert_equal aws.send(:trust_policy, '1234'), params[:assume_role_policy_document]
54
+ end
55
+ end
56
+ end
57
+
58
+ should "make iam call to attach_role_policy" do
59
+ aws = AWSClients.new
60
+ iam_client = mock
61
+ iam_client.stubs(:create_role)
62
+ iam_client.stubs(:attach_role_policy)
63
+ aws.stubs(:iam).returns(iam_client)
64
+
65
+ aws.create_and_attach_role!('1234')
66
+
67
+ assert_received(iam_client, :attach_role_policy) do |expected|
68
+ expected.with do |params|
69
+ assert_equal AWSClients::AWS_ROLE_NAME, params[:role_name]
70
+ assert_equal AWSClients::AWS_ROLE_POLICY_ARN, params[:policy_arn]
71
+ end
72
+ end
73
+ end
74
+
75
+ should "return the role" do
76
+ aws = AWSClients.new
77
+ iam_client = mock
78
+ iam_client.expects(:create_role).returns('the role')
79
+ iam_client.expects(:attach_role_policy)
80
+ aws.stubs(:iam).returns(iam_client)
81
+
82
+ role = aws.create_and_attach_role!('1234')
83
+
84
+ assert_equal 'the role', role
85
+ end
86
+ end
87
+
88
+ context '#trust_policy' do
89
+ should 'have the esp_owner_id and external_account_id' do
90
+ aws = AWSClients.new
91
+ ESP.stubs(:env).returns("production")
92
+
93
+ policy = aws.send(:trust_policy, '1234')
94
+
95
+ assert_match(/\"AWS\": \"arn:aws:iam::613698206329:root\"/, policy)
96
+ assert_match(/\"sts:ExternalId\": \"1234"/, policy)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end