ruby-jss 1.3.3 → 1.6.0b1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ruby-jss might be problematic. Click here for more details.

Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +142 -0
  3. data/THANKS.md +3 -2
  4. data/lib/jamf.rb +18 -17
  5. data/lib/jamf/api/base_classes/collection_resource.rb +613 -0
  6. data/lib/jamf/api/{abstract_classes → base_classes}/json_object.rb +109 -101
  7. data/lib/jamf/api/{abstract_classes → base_classes}/prestage.rb +55 -30
  8. data/lib/jamf/api/{abstract_classes → base_classes}/resource.rb +10 -6
  9. data/lib/jamf/api/{abstract_classes → base_classes}/singleton_resource.rb +4 -3
  10. data/lib/jamf/api/connection.rb +13 -9
  11. data/lib/jamf/api/connection/api_error.rb +8 -8
  12. data/lib/jamf/api/connection/token.rb +36 -15
  13. data/lib/jamf/api/json_objects/device_enrollment_device.rb +14 -7
  14. data/lib/jamf/api/json_objects/{location.rb → device_enrollment_device_sync_state.rb} +27 -41
  15. data/lib/jamf/api/json_objects/device_enrollment_sync_status.rb +1 -1
  16. data/lib/jamf/api/json_objects/{attachment.rb → locale.rb} +14 -23
  17. data/lib/jamf/api/json_objects/md_prestage_name.rb +1 -1
  18. data/lib/jamf/api/json_objects/md_prestage_names.rb +2 -2
  19. data/lib/jamf/api/json_objects/md_prestage_skip_setup_items.rb +50 -1
  20. data/lib/jamf/api/json_objects/prestage_assignment.rb +2 -2
  21. data/lib/jamf/api/json_objects/prestage_location.rb +3 -3
  22. data/lib/jamf/api/json_objects/prestage_purchasing_data.rb +7 -7
  23. data/lib/jamf/api/json_objects/prestage_scope.rb +1 -1
  24. data/lib/jamf/api/{resources/collection_resources → json_objects}/time_zone.rb +9 -23
  25. data/lib/jamf/api/mixins/{abstract.rb → base_class.rb} +34 -16
  26. data/lib/jamf/api/mixins/bulk_deletable.rb +27 -6
  27. data/lib/jamf/api/mixins/change_log.rb +201 -51
  28. data/lib/jamf/api/{resources/collection_resources/computer.rb → mixins/filterable.rb} +19 -17
  29. data/lib/jamf/api/mixins/pageable.rb +208 -0
  30. data/lib/jamf/api/{json_objects/installed_application.rb → mixins/sortable.rb} +33 -33
  31. data/lib/jamf/api/resources/collection_resources/building.rb +16 -9
  32. data/lib/jamf/api/resources/collection_resources/category.rb +5 -4
  33. data/lib/jamf/api/resources/collection_resources/computer_prestage.rb +12 -5
  34. data/lib/jamf/api/resources/collection_resources/department.rb +1 -3
  35. data/lib/jamf/api/resources/collection_resources/device_enrollment.rb +13 -13
  36. data/lib/jamf/api/resources/collection_resources/inventory_preload_record.rb +11 -3
  37. data/lib/jamf/api/resources/collection_resources/mobile_device_prestage.rb +25 -23
  38. data/lib/jamf/api/resources/collection_resources/script.rb +61 -25
  39. data/lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb +15 -5
  40. data/lib/jamf/api/resources/singleton_resources/locales.rb +155 -0
  41. data/lib/jamf/api/resources/singleton_resources/time_zones.rb +213 -0
  42. data/lib/jamf/client.rb +3 -3
  43. data/lib/jamf/client/management_action.rb +2 -3
  44. data/lib/jamf/composer.rb +2 -2
  45. data/lib/jamf/utility.rb +35 -7
  46. data/lib/jamf/validate.rb +63 -24
  47. data/lib/jamf/version.rb +1 -1
  48. data/lib/jss.rb +2 -2
  49. data/lib/jss/api_connection.rb +114 -406
  50. data/lib/jss/api_object.rb +10 -20
  51. data/lib/jss/api_object/advanced_search.rb +27 -26
  52. data/lib/jss/api_object/app_store_country_codes.rb +298 -0
  53. data/lib/jss/api_object/categorizable.rb +1 -1
  54. data/lib/jss/api_object/computer.rb +13 -0
  55. data/lib/jss/api_object/configuration_profile.rb +61 -5
  56. data/lib/jss/api_object/directory_binding_type.rb +66 -60
  57. data/lib/jss/api_object/directory_binding_type/active_directory.rb +71 -34
  58. data/lib/jss/api_object/directory_binding_type/admitmac.rb +536 -467
  59. data/lib/jss/api_object/directory_binding_type/centrify.rb +21 -7
  60. data/lib/jss/api_object/directory_binding_type/open_directory.rb +4 -4
  61. data/lib/jss/api_object/distribution_point.rb +2 -2
  62. data/lib/jss/api_object/dock_item.rb +102 -96
  63. data/lib/jss/api_object/ebook.rb +1 -2
  64. data/lib/jss/api_object/extendable.rb +1 -1
  65. data/lib/jss/api_object/extension_attribute.rb +4 -3
  66. data/lib/jss/api_object/group.rb +33 -2
  67. data/lib/jss/api_object/mac_application.rb +107 -8
  68. data/lib/jss/api_object/network_segment.rb +45 -13
  69. data/lib/jss/api_object/patch_source.rb +10 -9
  70. data/lib/jss/api_object/policy.rb +267 -28
  71. data/lib/jss/api_object/printer.rb +10 -4
  72. data/lib/jss/api_object/scopable.rb +10 -15
  73. data/lib/jss/api_object/scopable/scope.rb +389 -73
  74. data/lib/jss/api_object/script.rb +242 -352
  75. data/lib/jss/api_object/self_servable.rb +17 -9
  76. data/lib/jss/api_object/uploadable.rb +1 -1
  77. data/lib/jss/api_object/user.rb +43 -2
  78. data/lib/jss/api_object/vpp_account.rb +209 -0
  79. data/lib/jss/api_object/vppable.rb +169 -13
  80. data/lib/jss/client/management_action.rb +1 -2
  81. data/lib/jss/composer.rb +2 -2
  82. data/lib/jss/exceptions.rb +3 -0
  83. data/lib/jss/server.rb +15 -0
  84. data/lib/jss/utility.rb +213 -45
  85. data/lib/jss/validate.rb +53 -10
  86. data/lib/jss/version.rb +1 -1
  87. metadata +50 -66
  88. data/lib/jamf/api/abstract_classes/advanced_search.rb +0 -86
  89. data/lib/jamf/api/abstract_classes/collection_resource.rb +0 -433
  90. data/lib/jamf/api/abstract_classes/generic_reference.rb +0 -145
  91. data/lib/jamf/api/abstract_classes/prestage_skip_setup_items.rb +0 -126
  92. data/lib/jamf/api/json_objects/account_prefs.rb +0 -79
  93. data/lib/jamf/api/json_objects/android_details.rb +0 -139
  94. data/lib/jamf/api/json_objects/appletv_details.rb +0 -110
  95. data/lib/jamf/api/json_objects/cellular_network.rb +0 -151
  96. data/lib/jamf/api/json_objects/computer_prestage_skip_setup_items.rb +0 -67
  97. data/lib/jamf/api/json_objects/criterion.rb +0 -152
  98. data/lib/jamf/api/json_objects/extension_attribute_value.rb +0 -128
  99. data/lib/jamf/api/json_objects/installed_certificate.rb +0 -53
  100. data/lib/jamf/api/json_objects/installed_configuration_profile.rb +0 -67
  101. data/lib/jamf/api/json_objects/installed_ebook.rb +0 -58
  102. data/lib/jamf/api/json_objects/installed_provisioning_profile.rb +0 -59
  103. data/lib/jamf/api/json_objects/ios_details.rb +0 -244
  104. data/lib/jamf/api/json_objects/mobile_device_details.rb +0 -219
  105. data/lib/jamf/api/json_objects/mobile_device_security.rb +0 -101
  106. data/lib/jamf/api/json_objects/purchasing_data.rb +0 -125
  107. data/lib/jamf/api/mixins/locatable.rb +0 -124
  108. data/lib/jamf/api/mixins/referable.rb +0 -92
  109. data/lib/jamf/api/resources/collection_resources/account.rb +0 -163
  110. data/lib/jamf/api/resources/collection_resources/advanced_mobile_device_search.rb +0 -52
  111. data/lib/jamf/api/resources/collection_resources/advanced_user_search.rb +0 -52
  112. data/lib/jamf/api/resources/collection_resources/extension_attribute.rb +0 -45
  113. data/lib/jamf/api/resources/collection_resources/mobile_device.rb +0 -315
  114. data/lib/jamf/api/resources/collection_resources/site.rb +0 -77
  115. data/lib/jamf/api/resources/singleton_resources/authorization.rb +0 -88
  116. data/lib/jamf/api/resources/singleton_resources/client_checkin_settings.rb +0 -139
  117. data/lib/jamf/api/resources/singleton_resources/reenrollment_settings.rb +0 -95
@@ -1,5 +1,4 @@
1
1
  # Copyright 2020 Pixar
2
-
3
2
  #
4
3
  # Licensed under the Apache License, Version 2.0 (the "Apache License")
5
4
  # with the following modification; you may not use this file except in
@@ -23,27 +22,30 @@
23
22
  #
24
23
  #
25
24
 
26
- # The Module
27
25
  module Jamf
28
26
 
29
- # Classes
30
- #####################################
31
-
32
- # A building defined in the JSS
33
- class Computer < Jamf::CollectionResource
27
+ # process filter strings for resources with filter request parameters
28
+ module Filterable
34
29
 
35
- # Mix-Ins
36
- #####################################
37
- include Jamf::Referable
30
+ # # When this is included
31
+ # def self.included(klass)
32
+ # puts "Filterable was included by #{klass}"
33
+ # end
34
+ #
35
+ # # When this is exdended
36
+ # def self.extended(klass)
37
+ # puts "Filterable was extended by #{klass}"
38
+ # end
38
39
 
39
- # Constants
40
- #####################################
40
+ private
41
41
 
42
- RSRC_PATH = 'inventory/obj/computer'.freeze
42
+ # generate the RSQL filter to put into the url
43
+ def parse_collection_filter(filter)
44
+ return if filter.nil?
43
45
 
44
- OBJECT_MODEL = {}.freeze
45
- parse_object_model
46
+ "&filter=#{CGI.escape filter}"
47
+ end
46
48
 
47
- end # class
49
+ end # Filterable
48
50
 
49
- end # module
51
+ end # Jamf
@@ -0,0 +1,208 @@
1
+ # Copyright 2020 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
+ module Jamf
26
+
27
+ # methods for dealing with paged collection GET requests
28
+ #
29
+ module Pageable
30
+
31
+ # # When This is included
32
+ # def self.included(klass)
33
+ # puts "Pageable was included by #{klass}"
34
+ # end
35
+ #
36
+ # # When this is exdended
37
+ # def self.extended(klass)
38
+ # puts "Pageable was extended by #{klass}"
39
+ # end
40
+
41
+ DFT_PAGE_SIZE = 100
42
+
43
+ MIN_PAGE_SIZE = 1
44
+
45
+ MAX_PAGE_SIZE = 2000
46
+
47
+ PAGE_SIZE_RANGE = (MIN_PAGE_SIZE..MAX_PAGE_SIZE).freeze
48
+
49
+ # @param rsrc [String] The collection resource GET endpoint
50
+ #
51
+ # @param cnx [Jamf::Connection] The API connection to use
52
+ #
53
+ # @return [Integer] How many items exist in this collection?
54
+ #
55
+ def collection_count(rsrc, cnx: Jamf.cnx)
56
+ # this should only be true for instances of CollectionResources
57
+ cnx = @cnx if @cnx
58
+ cnx.get("#{rsrc}?page=0&page-size=1")[:totalCount]
59
+ end
60
+
61
+ # Get a specific page of a paged collection request,
62
+ # possibly sorted & filtered.
63
+ #
64
+ # @param rsrc [String] The collection resource GET endpoint
65
+ #
66
+ # @param page [Integer] which page to get
67
+ #
68
+ # @param page_size [Integer] how many items per page
69
+ #
70
+ # @param sort [String,Array<String>] server-side sorting parameters
71
+ #
72
+ # @param filter [String] RSQL String limiting the result set
73
+ #
74
+ # @param cnx [Jamf::Connection] The API connection to use
75
+ #
76
+ # @return [Array<Object>] The parsed JSON for the requested page
77
+ #
78
+ def fetch_collection_page(rsrc, page, page_size, sort, filter, cnx: Jamf.cnx)
79
+ page_size ||= DFT_PAGE_SIZE
80
+ validate_page_params page_size, page
81
+ raw = cnx.get "#{rsrc}?page=#{page}&page-size=#{page_size}#{sort}#{filter}"
82
+
83
+ raw[:results]
84
+ end
85
+
86
+ ################### Private methods
87
+ private
88
+
89
+ # get the first page of a paged collection, and set up for
90
+ # getting later pages
91
+ #
92
+ # @param rsrc [String] The collection resource GET endpoint
93
+ #
94
+ # @param page_size [Integer] how many items per page
95
+ #
96
+ # @param sort [String,Array<String>] server-side sorting parameters
97
+ #
98
+ # @param filter [String] RSQL String limiting the result set
99
+ #
100
+ # @param cnx [Jamf::Connection] The API connection to use
101
+ #
102
+ # @return [Array<Object>] The first page of the collection for this resource
103
+ #
104
+ def first_collection_page(rsrc, page_size, sort, filter, cnx)
105
+ page_size ||= DFT_PAGE_SIZE
106
+ validate_page_params page_size
107
+
108
+ @collection_rsrc_path = rsrc
109
+ @collection_cnx = cnx
110
+ @collection_page = :first
111
+ @collection_page_size = page_size
112
+ @collection_sort = sort
113
+ @collection_filter = filter
114
+ @collection_paged_fetched_count = 0
115
+
116
+ next_collection_page
117
+ end
118
+
119
+ # Fetch the next page of a paged collection request.
120
+ #
121
+ # Returns an empty array if there's been no paged request
122
+ # or if the last one has no more pages.
123
+ #
124
+ # @return [Array<Object>] The next page of the collection for this resource
125
+ #
126
+ def next_collection_page
127
+ case @collection_page
128
+ when :first
129
+ @collection_page = 0
130
+ when Integer
131
+ @collection_page += 1
132
+ else
133
+ # if here, we haven't initiated a paged request, or
134
+ # all pages have already been delivered
135
+ return []
136
+ end
137
+
138
+ raw = @collection_cnx.get "#{@collection_rsrc_path}?page=#{@collection_page}&page-size=#{@collection_page_size}#{@collection_sort}#{@collection_filter}"
139
+
140
+ @collection_paged_fetched_count += raw[:results].size
141
+ @collection_paged_total_count = raw[:totalCount]
142
+
143
+ # did we get everything in the this page?
144
+ # if so, clear all the paging data
145
+ clear_collection_paging_data if @collection_paged_fetched_count >= @collection_paged_total_count
146
+
147
+ # return the page results
148
+ raw[:results]
149
+ end
150
+
151
+ def clear_collection_paging_data
152
+ @collection_rsrc_path = nil
153
+ @collection_cnx = nil
154
+ @collection_sort = nil
155
+ @collection_filter = nil
156
+ @collection_page = nil
157
+ @collection_page_size = nil
158
+ @collection_paged_total_count = nil
159
+ @collection_paged_fetched_count = nil
160
+ end
161
+
162
+ # ensure valid page && page_size
163
+ #
164
+ # @param page_size [Integer] the page_size to be validated, must be in range
165
+ #
166
+ # @param page [Integer] the page number requested, must be >= 0
167
+ #
168
+ # @return [void]
169
+ #
170
+ def validate_page_params(page_size, page = nil)
171
+ raise ArgumentError, "page_size must be an Integer from #{MIN_PAGE_SIZE} to #{MAX_PAGE_SIZE}" unless PAGE_SIZE_RANGE.include? page_size
172
+
173
+ # if page is nil, ignore it, one of the auto paging methods is calling us
174
+ return if page.nil?
175
+
176
+ raise ArgumentError, 'page must be an Integer zero or higher' unless page.is_a?(Integer) && page > -1
177
+ end
178
+
179
+ # Description of #fetch_all_collection_pages
180
+ #
181
+ # @param rsrc [String] The collection resource GET endpoint
182
+ #
183
+ # @param sort [String,Array<String>] server-side sorting parameters
184
+ #
185
+ # @param filter [String] RSQL String limiting the result set
186
+ #
187
+ # @param cnx [Type] describe_cnx_here
188
+ #
189
+ # @return [Type] description_of_returned_object
190
+ #
191
+ def fetch_all_collection_pages(rsrc, sort, filter, cnx)
192
+ page = 0
193
+ page_size = MAX_PAGE_SIZE
194
+
195
+ raw = cnx.get "#{rsrc}?page=#{page}&page-size=#{page_size}#{sort}#{filter}"
196
+ results = raw[:results]
197
+
198
+ until results.size >= raw[:totalCount]
199
+ page += 1
200
+ raw = cnx.get "#{rsrc}?page=#{page}&page-size=#{page_size}#{sort}#{filter}"
201
+ results += raw[:results]
202
+ end
203
+ results
204
+ end
205
+
206
+ end # Pagable
207
+
208
+ end # Jamf
@@ -1,5 +1,4 @@
1
1
  # Copyright 2020 Pixar
2
-
3
2
  #
4
3
  # Licensed under the Apache License, Version 2.0 (the "Apache License")
5
4
  # with the following modification; you may not use this file except in
@@ -23,37 +22,38 @@
23
22
  #
24
23
  #
25
24
 
26
- # The module
27
25
  module Jamf
28
26
 
29
- # An installed application on a device
30
- class InstalledApplication < Jamf::JSONObject
31
-
32
- OBJECT_MODEL = {
33
-
34
- # @!attribute [r] identifier
35
- # @return [String]
36
- identifier: {
37
- class: :string,
38
- readonly: true
39
- },
40
-
41
- # @!attribute [r] name
42
- # @return [String]
43
- name: {
44
- class: :string,
45
- readonly: true
46
- },
47
-
48
- # @!attribute [r] version
49
- # @return [String]
50
- version: {
51
- class: :string,
52
- readonly: true
53
- }
54
- }.freeze
55
- parse_object_model
56
-
57
- end # class Mobile Device security
58
-
59
- end # module
27
+ # parse the sort params for collection GET requests
28
+ module Sortable
29
+
30
+ # # When this is included
31
+ # def self.included(klass)
32
+ # puts "Sortable was included by #{klass}"
33
+ # end
34
+ #
35
+ # # When this is exdended
36
+ # def self.extended(klass)
37
+ # puts "Sortable was extended by #{klass}"
38
+ # end
39
+
40
+ private
41
+
42
+ # generate the sort params for the url
43
+ #
44
+ def parse_collection_sort(sort)
45
+ case sort
46
+ when nil
47
+ sort
48
+ when String
49
+ "&sort=#{CGI.escape sort}"
50
+ when Array
51
+ "&sort=#{CGI.escape sort.join(',')}"
52
+ else
53
+ raise ArgumentError, 'sort criteria must be a String or Array of Strings'
54
+ end
55
+ end
56
+
57
+ end # Sortable
58
+
59
+ end # Jamf
@@ -35,8 +35,8 @@ module Jamf
35
35
  # Mix-Ins
36
36
  #####################################
37
37
 
38
+ extend Jamf::BulkDeletable
38
39
  include Jamf::ChangeLog
39
- include Jamf::Referable
40
40
 
41
41
  # Constants
42
42
  #####################################
@@ -54,7 +54,7 @@ module Jamf
54
54
  # @!attribute [r] id
55
55
  # @return [Integer]
56
56
  id: {
57
- class: :integer,
57
+ class: :j_id,
58
58
  identifier: :primary,
59
59
  readonly: true
60
60
  },
@@ -65,45 +65,52 @@ module Jamf
65
65
  class: :string,
66
66
  identifier: true,
67
67
  validator: :non_empty_string,
68
- required: true
68
+ required: true,
69
+ filter_key: true
69
70
  },
70
71
 
71
72
  # @!attribute street1
72
73
  # @return [String]
73
74
  streetAddress1: {
74
- class: :string
75
+ class: :string,
76
+ filter_key: true
75
77
  },
76
78
 
77
79
  # @!attribute street2
78
80
  # @return [String]
79
81
  streetAddress2: {
80
- class: :string
82
+ class: :string,
83
+ filter_key: true
81
84
  },
82
85
 
83
86
  # @!attribute city
84
87
  # @return [String]
85
88
  city: {
86
- class: :string
89
+ class: :string,
90
+ filter_key: true
87
91
  },
88
92
 
89
93
  # @!attribute state_province
90
94
  # @return [String]
91
95
  stateProvince: {
92
96
  class: :string,
93
- aliases: %i[state province]
97
+ aliases: %i[state province],
98
+ filter_key: true
94
99
  },
95
100
 
96
101
  # @!attribute zip_postal_code
97
102
  # @return [String]
98
103
  zipPostalCode: {
99
104
  class: :string,
100
- aliases: %i[zip zipcode zip_code postal_code postalcode]
105
+ aliases: %i[zip zipcode zip_code postal_code postalcode],
106
+ filter_key: true
101
107
  },
102
108
 
103
109
  # @!attribute country
104
110
  # @return [String]
105
111
  country: {
106
- class: :string
112
+ class: :string,
113
+ filter_key: true
107
114
  }
108
115
  }.freeze
109
116
 
@@ -36,12 +36,11 @@ module Jamf
36
36
  #####################################
37
37
 
38
38
  include Jamf::ChangeLog
39
- include Jamf::Referable
40
39
 
41
40
  # Constants
42
41
  #####################################
43
42
 
44
- RSRC_VERSION = 'v2'.freeze
43
+ RSRC_VERSION = 'v1'.freeze
45
44
 
46
45
  RSRC_PATH = 'categories'.freeze
47
46
 
@@ -65,13 +64,15 @@ module Jamf
65
64
  class: :string,
66
65
  identifier: true,
67
66
  validator: :non_empty_string,
68
- required: true
67
+ required: true,
68
+ filter_key: true
69
69
  },
70
70
 
71
71
  # @!attribute priority
72
72
  # @return [Integer]
73
73
  priority: {
74
- class: :integer
74
+ class: :integer,
75
+ filter_key: true
75
76
  }
76
77
  }.freeze
77
78