ruby-jss 0.6.6 → 0.6.7

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.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +5 -0
  3. data/README.md +13 -1
  4. data/bin/cgrouper +2 -1
  5. data/bin/subnet-update +2 -1
  6. data/lib/jss.rb +3 -1
  7. data/lib/jss/api_connection.rb +2 -1
  8. data/lib/jss/api_object.rb +4 -1
  9. data/lib/jss/api_object/account.rb +2 -1
  10. data/lib/jss/api_object/advanced_search.rb +2 -1
  11. data/lib/jss/api_object/advanced_search/advanced_computer_search.rb +2 -1
  12. data/lib/jss/api_object/advanced_search/advanced_mobile_device_search.rb +2 -1
  13. data/lib/jss/api_object/advanced_search/advanced_user_search.rb +2 -1
  14. data/lib/jss/api_object/building.rb +2 -1
  15. data/lib/jss/api_object/category.rb +2 -1
  16. data/lib/jss/api_object/computer.rb +2 -1
  17. data/lib/jss/api_object/computer_invitation.rb +2 -1
  18. data/lib/jss/api_object/creatable.rb +8 -8
  19. data/lib/jss/api_object/criteriable.rb +2 -1
  20. data/lib/jss/api_object/criteriable/criteria.rb +2 -1
  21. data/lib/jss/api_object/criteriable/criterion.rb +2 -1
  22. data/lib/jss/api_object/department.rb +2 -1
  23. data/lib/jss/api_object/distribution_point.rb +2 -1
  24. data/lib/jss/api_object/extendable.rb +2 -1
  25. data/lib/jss/api_object/extension_attribute.rb +2 -1
  26. data/lib/jss/api_object/extension_attribute/computer_extension_attribute.rb +2 -1
  27. data/lib/jss/api_object/extension_attribute/mobile_device_extension_attribute.rb +2 -1
  28. data/lib/jss/api_object/extension_attribute/user_extension_attribute.rb +2 -1
  29. data/lib/jss/api_object/group.rb +2 -1
  30. data/lib/jss/api_object/group/computer_group.rb +2 -1
  31. data/lib/jss/api_object/group/mobile_device_group.rb +2 -1
  32. data/lib/jss/api_object/group/user_group.rb +2 -1
  33. data/lib/jss/api_object/ldap_server.rb +2 -1
  34. data/lib/jss/api_object/locatable.rb +2 -1
  35. data/lib/jss/api_object/matchable.rb +2 -1
  36. data/lib/jss/api_object/mobile_device.rb +2 -1
  37. data/lib/jss/api_object/netboot_server.rb +2 -1
  38. data/lib/jss/api_object/network_segment.rb +2 -1
  39. data/lib/jss/api_object/osx_configuration_profile.rb +2 -1
  40. data/lib/jss/api_object/package.rb +2 -1
  41. data/lib/jss/api_object/peripheral.rb +2 -1
  42. data/lib/jss/api_object/peripheral_type.rb +2 -1
  43. data/lib/jss/api_object/policy.rb +2 -1
  44. data/lib/jss/api_object/purchasable.rb +2 -1
  45. data/lib/jss/api_object/removable_macaddr.rb +2 -1
  46. data/lib/jss/api_object/scopable.rb +2 -1
  47. data/lib/jss/api_object/scopable/scope.rb +2 -1
  48. data/lib/jss/api_object/script.rb +2 -1
  49. data/lib/jss/api_object/self_servable.rb +2 -1
  50. data/lib/jss/api_object/site.rb +2 -1
  51. data/lib/jss/api_object/software_update_server.rb +2 -1
  52. data/lib/jss/api_object/updatable.rb +2 -1
  53. data/lib/jss/api_object/uploadable.rb +2 -1
  54. data/lib/jss/api_object/user.rb +2 -1
  55. data/lib/jss/api_object/webhook.rb +242 -0
  56. data/lib/jss/client.rb +2 -1
  57. data/lib/jss/compatibility.rb +2 -1
  58. data/lib/jss/composer.rb +2 -1
  59. data/lib/jss/configuration.rb +2 -1
  60. data/lib/jss/db_connection.rb +2 -1
  61. data/lib/jss/exceptions.rb +2 -1
  62. data/lib/jss/ruby_extensions.rb +2 -1
  63. data/lib/jss/ruby_extensions/filetest.rb +2 -1
  64. data/lib/jss/ruby_extensions/hash.rb +2 -1
  65. data/lib/jss/ruby_extensions/ipaddr.rb +2 -1
  66. data/lib/jss/ruby_extensions/pathname.rb +2 -1
  67. data/lib/jss/ruby_extensions/string.rb +2 -1
  68. data/lib/jss/ruby_extensions/time.rb +2 -1
  69. data/lib/jss/server.rb +2 -1
  70. data/lib/jss/utility.rb +2 -1
  71. data/lib/jss/version.rb +3 -2
  72. data/lib/jss/webhooks.rb +2 -1
  73. data/lib/jss/webhooks/configuration.rb +2 -1
  74. data/lib/jss/webhooks/data/sample_handlers/RestAPIOperation-executable +2 -1
  75. data/lib/jss/webhooks/data/sample_handlers/RestAPIOperation.rb +2 -1
  76. data/lib/jss/webhooks/event.rb +2 -1
  77. data/lib/jss/webhooks/event/computer_added.rb +2 -1
  78. data/lib/jss/webhooks/event/computer_check_in.rb +2 -1
  79. data/lib/jss/webhooks/event/computer_inventory_completed.rb +2 -1
  80. data/lib/jss/webhooks/event/computer_policy_finished.rb +2 -1
  81. data/lib/jss/webhooks/event/computer_push_capability_changed.rb +2 -1
  82. data/lib/jss/webhooks/event/handlers.rb +2 -1
  83. data/lib/jss/webhooks/event/jss_shutdown.rb +2 -1
  84. data/lib/jss/webhooks/event/jss_startup.rb +2 -1
  85. data/lib/jss/webhooks/event/mobile_device_check_in.rb +2 -1
  86. data/lib/jss/webhooks/event/mobile_device_command_completed.rb +2 -1
  87. data/lib/jss/webhooks/event/mobile_device_enrolled.rb +2 -1
  88. data/lib/jss/webhooks/event/mobile_device_push_sent.rb +2 -1
  89. data/lib/jss/webhooks/event/mobile_device_unenrolled.rb +2 -1
  90. data/lib/jss/webhooks/event/patch_software_title_updated.rb +2 -1
  91. data/lib/jss/webhooks/event/push_sent.rb +2 -1
  92. data/lib/jss/webhooks/event/rest_api_operation.rb +2 -1
  93. data/lib/jss/webhooks/event/scep_challenge.rb +2 -1
  94. data/lib/jss/webhooks/event/smart_group_computer_membership_change.rb +2 -1
  95. data/lib/jss/webhooks/event/smart_group_mobile_device_membership_change.rb +2 -1
  96. data/lib/jss/webhooks/event/webhook.rb +2 -1
  97. data/lib/jss/webhooks/event_objects.rb +2 -1
  98. data/lib/jss/webhooks/event_objects/computer.rb +2 -1
  99. data/lib/jss/webhooks/event_objects/jss.rb +2 -1
  100. data/lib/jss/webhooks/event_objects/mobile_device.rb +2 -1
  101. data/lib/jss/webhooks/event_objects/patch_software_title_update.rb +2 -1
  102. data/lib/jss/webhooks/event_objects/push.rb +2 -1
  103. data/lib/jss/webhooks/event_objects/rest_api_operation.rb +2 -1
  104. data/lib/jss/webhooks/event_objects/scep_challenge.rb +2 -1
  105. data/lib/jss/webhooks/event_objects/smart_group.rb +2 -1
  106. data/lib/jss/webhooks/server_app.rb +2 -1
  107. data/lib/jss/webhooks/server_app/routes.rb +2 -1
  108. data/lib/jss/webhooks/server_app/routes/handle_webhook_event.rb +2 -1
  109. data/lib/jss/webhooks/server_app/routes/home.rb +2 -1
  110. data/lib/jss/webhooks/server_app/self_signed_cert.rb +2 -1
  111. data/lib/jss/webhooks/server_app/server.rb +2 -1
  112. data/lib/jss/webhooks/version.rb +2 -1
  113. metadata +21 -20
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -0,0 +1,242 @@
1
+ # Copyright 2017 Pixar
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ # with the following modification; you may not use this file except in
5
+ # compliance with the Apache License and the following modification to it:
6
+ # Section 6. Trademarks. is deleted and replaced with:
7
+ #
8
+ # 6. Trademarks. This License does not grant permission to use the trade
9
+ # names, trademarks, service marks, or product names of the Licensor
10
+ # and its affiliates, except as required to comply with Section 4(c) of
11
+ # the License and to reproduce the content of the NOTICE file.
12
+ #
13
+ # You may obtain a copy of the Apache License at
14
+ #
15
+ # http://www.apache.org/licenses/LICENSE-2.0
16
+ #
17
+ # Unless required by applicable law or agreed to in writing, software
18
+ # distributed under the Apache License with the above modification is
19
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ # KIND, either express or implied. See the Apache License for the specific
21
+ # language governing permissions and limitations under the Apache License.
22
+ #
23
+ #
24
+
25
+ #
26
+ module JSS
27
+
28
+ # Classes
29
+ ###################################
30
+
31
+ #
32
+ # A webhook as defined in JamfPro.
33
+ #
34
+ class WebHook < JSS::APIObject
35
+
36
+ # Mix-Ins
37
+ ###################################
38
+ include JSS::Creatable
39
+ include JSS::Updatable
40
+
41
+ # Class Methods
42
+ ###################################
43
+
44
+ # Class Constants
45
+ ###################################
46
+
47
+ # The base for REST resources of this class
48
+ RSRC_BASE = 'webhooks'.freeze
49
+
50
+ # the hash key used for the JSON list output of all objects in the JSS
51
+ RSRC_LIST_KEY = :webhooks
52
+
53
+ # The hash key used for the JSON object output.
54
+ # It's also used in various error messages
55
+ RSRC_OBJECT_KEY = :webhook
56
+
57
+ # these keys, as well as :id and :name, are present in valid API JSON data for this class
58
+ VALID_DATA_KEYS = [:event, :contact_type, :url, :enabled].freeze
59
+
60
+ # the content types available for webhooks, internally we use Symbols,
61
+ # but the API wants the proper MIME strings
62
+ CONTENT_TYPES = {
63
+ xml: 'text/xml',
64
+ json: 'application/json'
65
+ }.freeze
66
+
67
+ # The available webhook events.
68
+ EVENTS = %w(
69
+ ComputerAdded
70
+ ComputerCheckIn
71
+ ComputerInventoryCompleted
72
+ ComputerPolicyFinished
73
+ ComputerPushCapabilityChanged
74
+ JSSShutdown
75
+ JSSStartup
76
+ MobileDeviceCheckIn
77
+ MobileDeviceCommandCompleted
78
+ MobileDeviceEnrolled
79
+ MobileDevicePushSent
80
+ MobileDeviceUnEnrolled
81
+ PatchSoftwareTitleUpdated
82
+ PushSent
83
+ RestAPIOperation
84
+ SCEPChallenge
85
+ SmartGroupComputerMembershipChange
86
+ SmartGroupMobileDeviceMembershipChange
87
+ ).freeze
88
+
89
+ # Attributes
90
+ ###################################
91
+
92
+ # @return [Boolean] is this webhook enabled?
93
+ attr_reader :enabled
94
+
95
+ # @return [String] the URL accessed by this webhook
96
+ attr_reader :url
97
+
98
+ # @return [Symbols] the content_type, one of the keys of CONTENT_TYPES
99
+ attr_reader :content_type
100
+
101
+ # @return [String] the event name to which this webhook responds
102
+ attr_reader :event
103
+
104
+ # Constructor
105
+ ###################################
106
+
107
+ # See JSS::APIObject#initialize
108
+ def initialize(**args)
109
+ super
110
+
111
+ # now we have pkg_data with something in it, so fill out the instance vars
112
+ @enabled = @init_data[:enabled]
113
+ @url = @init_data[:url]
114
+ @content_type = CONTENT_TYPES.invert[@init_data[:content_type]]
115
+ @event = @init_data[:event]
116
+
117
+ # defaults
118
+ @content_type ||= :json
119
+ @enabled = false if @enabled.nil?
120
+ end # init
121
+
122
+ # Public Instance Methods
123
+ ###################################
124
+
125
+ # Setters
126
+ #########
127
+
128
+ # Set the enabled state of this webhook
129
+ #
130
+ # @param new_val[Boolean] the new state
131
+ #
132
+ # @return [void]
133
+ #
134
+ def enabled=(new_val)
135
+ return nil if new_val == @enabled
136
+ new_val = false if new_val.to_s.empty?
137
+ raise JSS::InvalidDataError, "enabled must be boolean 'true' or 'false'" unless \
138
+ JSS::TRUE_FALSE.include? new_val
139
+ @enabled = new_val
140
+ @need_to_update = true
141
+ end
142
+
143
+ # Set the URL accessed by this webhook
144
+ #
145
+ # @param new_val[String] The new URL
146
+ #
147
+ # @return [void]
148
+ #
149
+ def url=(new_val)
150
+ return nil if new_val == @url
151
+ # handy - from http://stackoverflow.com/questions/1805761/check-if-url-is-valid-ruby#1805788
152
+ url_ok = new_val =~ /\A#{URI.regexp(%w(http https))}\z/
153
+ raise JSS::InvalidDataError, 'New value is not a valid http(s) url' unless url_ok && url_ok.zero?
154
+ @url = new_val
155
+ @need_to_update = true
156
+ end
157
+
158
+ # Set the content_type sent to the url
159
+ # Must be one of the keys of CONTENT_TYPES, i.e. :xml or :json
160
+ #
161
+ # @param new_val[Symbol] The new content_type
162
+ #
163
+ # @return [void]
164
+ #
165
+ def content_type=(new_val)
166
+ return nil if new_val == @content_type
167
+ raise JSS::InvalidDataError, "content_type must be one of :#{CONTENT_TYPES.keys.join ', :'}" unless \
168
+ CONTENT_TYPES.keys.include? new_val
169
+ @content_type = new_val
170
+ @need_to_update = true
171
+ end
172
+
173
+ # Set the event handled by this webhook
174
+ # Must be a member of the EVENTS Array
175
+ #
176
+ # @param new_val[String] The event name
177
+ #
178
+ # @return [void]
179
+ #
180
+ def event=(new_val)
181
+ return nil if new_val == @event
182
+ raise JSS::InvalidDataError, 'Unknown webhook event' unless EVENTS.include? new_val
183
+ @event = new_val
184
+ @need_to_update = true
185
+ end
186
+
187
+ # Convenience Methods
188
+ #########
189
+
190
+ # Enable this webhook, saving the new state immediately
191
+ #
192
+ # @return [void]
193
+ #
194
+ def enable
195
+ raise JSS::NoSuchItemError, 'Save the webhook before enabling it' unless @in_jss
196
+ self.enabled = true
197
+ save
198
+ end
199
+
200
+ # Disable this webhook, saving the new state immediately
201
+ #
202
+ # @return [void]
203
+ #
204
+ def disable
205
+ raise JSS::NoSuchItemError, 'Save the webhook before disabling it' unless @in_jss
206
+ self.enabled = false
207
+ save
208
+ end
209
+
210
+ # Aliases
211
+ ###################################
212
+
213
+ alias enabled? enabled
214
+
215
+ # Private Instance Methods
216
+ ##############################
217
+
218
+ private
219
+
220
+ # Return the REST XML for this webhook, with the current values,
221
+ # for saving or updating
222
+ #
223
+ def rest_xml
224
+ validate_before_save
225
+ doc = REXML::Document.new APIConnection::XML_HEADER
226
+ webhook = doc.add_element 'webhook'
227
+ webhook.add_element('name').text = @name
228
+ webhook.add_element('enabled').text = @enabled
229
+ webhook.add_element('url').text = @url
230
+ webhook.add_element('content_type').text = CONTENT_TYPES[@content_type]
231
+ webhook.add_element('event').text = @event
232
+ doc.to_s
233
+ end # rest xml
234
+
235
+ def validate_before_save
236
+ raise 'url must be a valid http(s) URL String' unless @url.is_a? String
237
+ raise 'event must be a valid event name from JSS::WebHook::EVENTS' unless EVENTS.include? @event
238
+ end
239
+
240
+ end # class department
241
+
242
+ end # module
data/lib/jss/client.rb CHANGED
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
data/lib/jss/composer.rb CHANGED
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in
data/lib/jss/server.rb CHANGED
@@ -1,4 +1,5 @@
1
- ### Copyright 2016 Pixar
1
+ ### Copyright 2017 Pixar
2
+
2
3
  ###
3
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
5
  ### with the following modification; you may not use this file except in