ruby-jss 1.4.1 → 1.5.1

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 (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +38 -0
  3. data/lib/jamf.rb +10 -3
  4. data/lib/jamf/api/abstract_classes/collection_resource.rb +329 -150
  5. data/lib/jamf/api/abstract_classes/generic_reference.rb +9 -1
  6. data/lib/jamf/api/abstract_classes/json_object.rb +106 -82
  7. data/lib/jamf/api/abstract_classes/prestage.rb +54 -29
  8. data/lib/jamf/api/abstract_classes/prestage_skip_setup_items.rb +21 -0
  9. data/lib/jamf/api/abstract_classes/resource.rb +4 -4
  10. data/lib/jamf/api/abstract_classes/singleton_resource.rb +1 -1
  11. data/lib/jamf/api/connection.rb +13 -9
  12. data/lib/jamf/api/connection/api_error.rb +8 -8
  13. data/lib/jamf/api/connection/token.rb +16 -15
  14. data/lib/jamf/api/json_objects/computer_prestage_skip_setup_items.rb +14 -1
  15. data/lib/jamf/api/json_objects/device_enrollment_device.rb +14 -7
  16. data/lib/jamf/api/json_objects/device_enrollment_device_sync_state.rb +81 -0
  17. data/lib/jamf/api/json_objects/locale.rb +59 -0
  18. data/lib/jamf/api/json_objects/md_prestage_skip_setup_items.rb +50 -1
  19. data/lib/jamf/api/json_objects/prestage_location.rb +3 -3
  20. data/lib/jamf/api/json_objects/prestage_purchasing_data.rb +7 -7
  21. data/lib/jamf/api/json_objects/prestage_scope.rb +1 -1
  22. data/lib/jamf/api/{resources/collection_resources → json_objects}/time_zone.rb +9 -23
  23. data/lib/jamf/api/mixins/bulk_deletable.rb +27 -6
  24. data/lib/jamf/api/mixins/change_log.rb +201 -51
  25. data/lib/jamf/api/mixins/filterable.rb +51 -0
  26. data/lib/jamf/api/mixins/pageable.rb +208 -0
  27. data/lib/jamf/api/mixins/sortable.rb +59 -0
  28. data/lib/jamf/api/resources/collection_resources/building.rb +19 -8
  29. data/lib/jamf/api/resources/collection_resources/category.rb +5 -3
  30. data/lib/jamf/api/resources/collection_resources/computer_prestage.rb +11 -4
  31. data/lib/jamf/api/resources/collection_resources/device_enrollment.rb +10 -10
  32. data/lib/jamf/api/resources/collection_resources/inventory_preload_record.rb +11 -3
  33. data/lib/jamf/api/resources/collection_resources/mobile_device_prestage.rb +24 -22
  34. data/lib/jamf/api/resources/collection_resources/script.rb +61 -25
  35. data/lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb +15 -5
  36. data/lib/jamf/api/resources/singleton_resources/client_checkin_settings.rb +14 -14
  37. data/lib/jamf/api/resources/singleton_resources/locales.rb +155 -0
  38. data/lib/jamf/api/resources/singleton_resources/time_zones.rb +213 -0
  39. data/lib/jamf/validate.rb +63 -24
  40. data/lib/jamf/version.rb +1 -1
  41. data/lib/jss.rb +2 -1
  42. data/lib/jss/api_connection.rb +110 -370
  43. data/lib/jss/api_object.rb +3 -19
  44. data/lib/jss/api_object/categorizable.rb +1 -1
  45. data/lib/jss/api_object/configuration_profile.rb +34 -3
  46. data/lib/jss/api_object/directory_binding_type.rb +66 -60
  47. data/lib/jss/api_object/directory_binding_type/active_directory.rb +71 -34
  48. data/lib/jss/api_object/directory_binding_type/admitmac.rb +536 -467
  49. data/lib/jss/api_object/directory_binding_type/centrify.rb +21 -7
  50. data/lib/jss/api_object/directory_binding_type/open_directory.rb +4 -4
  51. data/lib/jss/api_object/distribution_point.rb +2 -2
  52. data/lib/jss/api_object/dock_item.rb +102 -96
  53. data/lib/jss/api_object/extendable.rb +1 -1
  54. data/lib/jss/api_object/group.rb +33 -2
  55. data/lib/jss/api_object/network_segment.rb +43 -12
  56. data/lib/jss/api_object/patch_source.rb +10 -9
  57. data/lib/jss/api_object/printer.rb +10 -4
  58. data/lib/jss/api_object/scopable.rb +10 -15
  59. data/lib/jss/exceptions.rb +3 -0
  60. data/lib/jss/server.rb +15 -0
  61. data/lib/jss/version.rb +1 -1
  62. metadata +37 -22
@@ -0,0 +1,51 @@
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
+ # process filter strings for resources with filter request parameters
28
+ module Filterable
29
+
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
39
+
40
+ private
41
+
42
+ # generate the RSQL filter to put into the url
43
+ def parse_collection_filter(filter)
44
+ return if filter.nil?
45
+
46
+ "&filter=#{CGI.escape filter}"
47
+ end
48
+
49
+ end # Filterable
50
+
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
@@ -0,0 +1,59 @@
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
+ # 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,7 +35,11 @@ module Jamf
35
35
  # Mix-Ins
36
36
  #####################################
37
37
 
38
+ extend Jamf::BulkDeletable
38
39
  include Jamf::ChangeLog
40
+ # TODO: this prob isn't needed anymore
41
+ # or should be updated - according to the specs, all
42
+ # references are just ids - integers-in-strings.
39
43
  include Jamf::Referable
40
44
 
41
45
  # Constants
@@ -54,7 +58,7 @@ module Jamf
54
58
  # @!attribute [r] id
55
59
  # @return [Integer]
56
60
  id: {
57
- class: :integer,
61
+ class: :j_id,
58
62
  identifier: :primary,
59
63
  readonly: true
60
64
  },
@@ -65,45 +69,52 @@ module Jamf
65
69
  class: :string,
66
70
  identifier: true,
67
71
  validator: :non_empty_string,
68
- required: true
72
+ required: true,
73
+ filter_key: true
69
74
  },
70
75
 
71
76
  # @!attribute street1
72
77
  # @return [String]
73
78
  streetAddress1: {
74
- class: :string
79
+ class: :string,
80
+ filter_key: true
75
81
  },
76
82
 
77
83
  # @!attribute street2
78
84
  # @return [String]
79
85
  streetAddress2: {
80
- class: :string
86
+ class: :string,
87
+ filter_key: true
81
88
  },
82
89
 
83
90
  # @!attribute city
84
91
  # @return [String]
85
92
  city: {
86
- class: :string
93
+ class: :string,
94
+ filter_key: true
87
95
  },
88
96
 
89
97
  # @!attribute state_province
90
98
  # @return [String]
91
99
  stateProvince: {
92
100
  class: :string,
93
- aliases: %i[state province]
101
+ aliases: %i[state province],
102
+ filter_key: true
94
103
  },
95
104
 
96
105
  # @!attribute zip_postal_code
97
106
  # @return [String]
98
107
  zipPostalCode: {
99
108
  class: :string,
100
- aliases: %i[zip zipcode zip_code postal_code postalcode]
109
+ aliases: %i[zip zipcode zip_code postal_code postalcode],
110
+ filter_key: true
101
111
  },
102
112
 
103
113
  # @!attribute country
104
114
  # @return [String]
105
115
  country: {
106
- class: :string
116
+ class: :string,
117
+ filter_key: true
107
118
  }
108
119
  }.freeze
109
120
 
@@ -41,7 +41,7 @@ module Jamf
41
41
  # Constants
42
42
  #####################################
43
43
 
44
- RSRC_VERSION = 'v2'.freeze
44
+ RSRC_VERSION = 'v1'.freeze
45
45
 
46
46
  RSRC_PATH = 'categories'.freeze
47
47
 
@@ -65,13 +65,15 @@ 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 priority
72
73
  # @return [Integer]
73
74
  priority: {
74
- class: :integer
75
+ class: :integer,
76
+ filter_key: true
75
77
  }
76
78
  }.freeze
77
79
 
@@ -35,7 +35,7 @@ module Jamf
35
35
  # Constants
36
36
  #####################################
37
37
 
38
- RSRC_VERSION = 'v1'.freeze
38
+ RSRC_VERSION = 'v2'.freeze
39
39
 
40
40
  RSRC_PATH = 'computer-prestages'.freeze
41
41
 
@@ -53,23 +53,30 @@ module Jamf
53
53
 
54
54
  # @!attribute isInstallProfilesDuringSetup
55
55
  # @return [Boolean]
56
- isInstallProfilesDuringSetup: {
56
+ installProfilesDuringSetup: {
57
57
  class: :boolean
58
58
  },
59
59
 
60
60
  # @!attribute prestageInstalledProfileIds
61
61
  # @return [Array<Integer>]
62
62
  prestageInstalledProfileIds: {
63
- class: :integer,
63
+ class: :j_id,
64
64
  multi: true
65
65
  },
66
66
 
67
67
  # @!attribute customPackageIds
68
68
  # @return [Array<Integer>]
69
69
  customPackageIds: {
70
- class: :integer,
70
+ class: :j_id,
71
71
  multi: true
72
+ },
73
+
74
+ # @!attribute customPackageDistributionPointId
75
+ # @return [String]
76
+ customPackageDistributionPointId: {
77
+ class: :j_id
72
78
  }
79
+
73
80
  ).freeze
74
81
 
75
82
  parse_object_model