ruby-jss 2.0.0b3 → 2.0.0b5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +1 -0
- data/README-2.0.0.md +68 -57
- data/README.md +227 -172
- data/lib/jamf/api/classic/api_objects/distribution_point.rb +12 -50
- data/lib/jamf/api/classic/api_objects/patch_title.rb +14 -9
- data/lib/jamf/api/classic/base_classes/api_object.rb +68 -9
- data/lib/jamf/api/classic/base_classes/patch_source.rb +10 -5
- data/lib/jamf/api/connection.rb +1 -1
- data/lib/jamf/api/jamf_pro/mixins/collection_resource.rb +8 -12
- data/lib/jamf/version.rb +1 -1
- data/lib/jamf/zeitwerk_config.rb +217 -0
- data/lib/jamf.rb +7 -39
- metadata +4 -4
- data/lib/zeitwerk_config.rb +0 -168
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b224082c515d1c12d50736092c859f7f21f1acbb8d6d3d98b861221362a64f7d
|
4
|
+
data.tar.gz: 7c10c43a7842be9fee1819bcc9a92457e1dce0d338e97f6a00eeb27d1f75416b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32378337e65ccc32c836217434cdfa7fe060d400268848174a675fcbb163157e0d0965e4141fbbe35eef60bd042cca58777189db18d641e1dd1d6ab7ed4d2f37
|
7
|
+
data.tar.gz: d24ca66815d7e4f0b5bc4a212463e985e490fe499c0b299b6df41f12f6943f156f2681ebf5696198a66853e593cbfe9fdd248948e02e4d2c67ccd910cccc900f
|
data/CHANGES.md
CHANGED
@@ -26,6 +26,7 @@ Here are the high-level changes and there are many many others. For more details
|
|
26
26
|
- Base classes for JamfPro API objects are automatically generated from the OAPI3 Schema available at https://your.jamf.server/api/schema. This make it much simpler for ruby-jss to implement and update new and changed objects and endpoints in the Jamf Pro API.
|
27
27
|
- Code is auto-loaded from disk
|
28
28
|
- Because the auto-generated classes add hundreds of files to the gem, ruby-jss now uses [Zeitwerk](https://github.com/fxn/zeitwerk) to auto-load only the files it needs when they are needed.
|
29
|
+
- Support for Ruby 3.x
|
29
30
|
|
30
31
|
|
31
32
|
## \[1.6.7] - 2022-02-22
|
data/README-2.0.0.md
CHANGED
@@ -2,44 +2,43 @@
|
|
2
2
|
|
3
3
|
Version 2.0.0 is a major refactoring of ruby-jss. While attempting to provide as much backward compatibility as possible, there are some significant changes under the hood. **_PLEASE TEST YOUR CODE EXTENSIVELY_**
|
4
4
|
|
5
|
-
This document discusses the high-level changes, listing the
|
5
|
+
This document discusses the high-level changes, listing the changes that have already happened, as well as planned changes and deprecations. It also provides some discussion and background around all of this. It is a work-in-progress at the moment, and will probably remain so well after initial release. Hopefully this document will prompt discussion and decision-making in the #ruby-jss channel of MacAdmins Slack (Please join us!)
|
6
6
|
|
7
|
-
These changes have been in mind for some time, but the
|
7
|
+
These changes have been in mind for some time, but the requirement in late 2022 for the Classic API to authenticate with Bearer Tokens from the Jamf Pro API means that the time has come, so here we are!
|
8
8
|
|
9
9
|
**CONTENTS**
|
10
10
|
|
11
11
|
<!-- TOC -->
|
12
12
|
|
13
|
-
- [
|
14
|
-
|
15
|
-
- [
|
16
|
-
|
17
|
-
- [
|
18
|
-
- [
|
19
|
-
- [
|
20
|
-
|
21
|
-
- [
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
- [
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
- [
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
- [Contact](#contact)
|
13
|
+
- [Requirements](#requirements)
|
14
|
+
- [High level changes](#high-level-changes)
|
15
|
+
- [Ruby 3.x support](#ruby-3x-support)
|
16
|
+
- [Combined API access](#combined-api-access)
|
17
|
+
- [A single Connection class](#a-single-connection-class)
|
18
|
+
- [Connecting to the API](#connecting-to-the-api)
|
19
|
+
- [The default connection](#the-default-connection)
|
20
|
+
- [A single namespace Jamf](#a-single-namespace-jamf)
|
21
|
+
- [Inherant differences between the APIs](#inherant-differences-between-the-apis)
|
22
|
+
- [Which API does an object come from?](#which-api-does-an-object-come-from)
|
23
|
+
- [Automatic code generation](#automatic-code-generation)
|
24
|
+
- [Autoloading with Zeitwerk](#autoloading-with-zeitwerk)
|
25
|
+
- [Notable changes from ruby-jss 1.x](#notable-changes-from-ruby-jss-1x)
|
26
|
+
- [Paged queries to the Jamf Pro API](#paged-queries-to-the-jamf-pro-api)
|
27
|
+
- [API data are no longer cached ?](#api-data-are-no-longer-cached-)
|
28
|
+
- [No Attribute aliases for Jamf Pro API objects](#no-attribute-aliases-for-jamf-pro-api-objects)
|
29
|
+
- [Class/Mixin hierarchy for Jamf Pro API objects](#classmixin-hierarchy-for-jamf-pro-api-objects)
|
30
|
+
- [Support for 'Sticky Sessions' in Jamf Cloud](#support-for-sticky-sessions-in-jamf-cloud)
|
31
|
+
- [Planned deprecations](#planned-deprecations)
|
32
|
+
- [Use of the term 'api' in method names, parameter names, and attributes](#use-of-the-term-api-in-method-names-parameter-names-and-attributes)
|
33
|
+
- [.map_all_ids_to method for Classic API collection classes](#map_all_ids_to-method-for-classic-api-collection-classes)
|
34
|
+
- [Using .make, #create, and #update for Classic API objects](#using-make-create-and-update-for-classic-api-objects)
|
35
|
+
- [JSS::CONFIG](#jssconfig)
|
36
|
+
- [Jamf::Connection instance methods #next_refresh, #secs_to_refresh, & #time_to_refresh](#jamfconnection-instance-methods-next_refresh-secs_to_refresh---time_to_refresh)
|
37
|
+
- [Cross-object validation in setters](#cross-object-validation-in-setters)
|
38
|
+
- [fetch :random](#fetch-random)
|
39
|
+
- [Documentation](#documentation)
|
40
|
+
- [How to install for testing](#how-to-install-for-testing)
|
41
|
+
- [Contact](#contact)
|
43
42
|
|
44
43
|
<!-- /TOC -->
|
45
44
|
|
@@ -57,15 +56,15 @@ The plan is for ruby-jss 2.0+ to be compatible with ruby 2.6.3 and higher, inclu
|
|
57
56
|
|
58
57
|
As of this writing, basic access to the API seems to be working in ruby 3, but much much more testing is needed.
|
59
58
|
|
60
|
-
It looks like the biggest changes have been dealing with keyword arguments as Hashs. Methods defined with `def methodname([...] foo = {}` need to be changed to `def methodname([...] **foo` and calls to those methods, even in your own code, need to be changed to `methodname([...] **foo)` when `foo` is a hash of keyword args.
|
59
|
+
It looks like the biggest changes have been dealing with keyword arguments as Hashs. Methods defined with `def methodname([...] foo = {})` need to be changed to `def methodname([...] **foo)` and calls to those methods, even in your own code, need to be changed to `methodname([...] **foo)` when `foo` is a hash of keyword args.
|
61
60
|
|
62
|
-
**IMPORTANT**: do not pass raw hashes as 'keyword' args. Instead use the double-splat: `methodname(**hash)` which should be compatible with ruby 3.x and 2.
|
61
|
+
**IMPORTANT**: do not pass raw hashes as 'keyword' args. Instead use the double-splat: `methodname(**hash)` which should be compatible with ruby 3.x and 2.6.x
|
63
62
|
|
64
63
|
for more info see [Separation of positional and keyword arguments in Ruby 3.0](https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/)
|
65
64
|
|
66
65
|
### Combined API access
|
67
66
|
|
68
|
-
ruby-jss
|
67
|
+
Previous versions of ruby-jss used the `JSS` module to encapsulate all access to the Classic API. When the Jamf Pro API became a thing, it was a vary different beast, so the `Jamf` module was created as the way to interact with that API as it grew and developed.
|
69
68
|
|
70
69
|
Even though the latest Jamf Pro release notes say the Jamf Pro API is still officially "open for user testing", it has stablized enough that it is used by many folks for production work.
|
71
70
|
|
@@ -77,23 +76,24 @@ There is now one `Jamf::Connection` class, instances of which are connections to
|
|
77
76
|
|
78
77
|
##### Connecting to the API
|
79
78
|
|
80
|
-
Most of the previous methods and parameters for making
|
79
|
+
Most of the previous methods and parameters for making connections to either API should still work, including using a URL rather than individual connection parameters. So both of these are valid and identical:
|
81
80
|
|
82
81
|
```ruby
|
83
82
|
a_connection = Jamf::Connection.new 'https://apiuser@my.jamf.server:8443/', pw: :prompt
|
84
83
|
|
85
84
|
another_connection = Jamf::Connection.new host: 'my.jamf.server', port: 8443, user: 'apiuser', pw: :prompt
|
86
85
|
```
|
87
|
-
|
88
86
|
Other connection parameters can be passed in as normal.
|
89
87
|
|
90
88
|
###### The default connection
|
91
89
|
|
92
|
-
The top-level module methods for accessing the 'default' connection are still available and are now synonyms: `Jamf.cnx` and `JSS.api` both return the current default Jamf::Connection instance. There is also a top-level methods`Jamf.connect` which is the same as `Jamf.cnx.connect`. The top-level methods for changing the default connection are still there.
|
90
|
+
The top-level module methods for accessing the 'default' connection are still available and are now synonyms: `Jamf.cnx` and `JSS.api` both return the current default Jamf::Connection instance. There is also a top-level methods`Jamf.connect` which is the same as `Jamf.cnx.connect`. The top-level methods for changing the default connection are still there.
|
91
|
+
|
92
|
+
NOTE: The use of `JSS::API` has been deprecated for years now, and still is (see below).
|
93
93
|
|
94
94
|
#### A single namespace `Jamf`
|
95
95
|
|
96
|
-
Version 2.0.0 combines the `JSS` module and the `Jamf` module into a single `Jamf` module, with `JSS` aliased to it. This means you can use
|
96
|
+
Version 2.0.0 combines the `JSS` module and the `Jamf` module into a single `Jamf` module, with `JSS` aliased to it. This means you can use the names interchangably to refer to the Jamf module, and existing code that used either should still work. The module name no longer indicates which API you're working with.
|
97
97
|
|
98
98
|
For example, the `JSS::Computer` class, from the Classic API, is still a thing, but now just points to the `Jamf::Computer` class, still from the Classic API. The `Jamf::InventoryPreloadRecord` class, from the Jamf Pro API remains as is, but can also be referred to as `JSS::InventoryPreloadRecord`
|
99
99
|
|
@@ -103,9 +103,9 @@ In theory, you shouldn't need to worry about which classes and objects come from
|
|
103
103
|
|
104
104
|
However, in reality the two APIs have different functionality, some of which must be reflected in the ruby classes that represent objects in those APIs.
|
105
105
|
|
106
|
-
Take, for example, the classes for 'Collection Resources' - API endpoints that let you deal with collections of objects like Computers, or Inventory Preload Records. These classes implement a `.all` class method, which retrieves
|
106
|
+
Take, for example, the classes for 'Collection Resources' - API endpoints that let you deal with collections of objects like Computers, or Inventory Preload Records. These classes implement a `.all` class method, which retrieves an Array of some data about all members of the collection.
|
107
107
|
|
108
|
-
Not only is the data returned in such
|
108
|
+
Not only is the data returned in such Arrays very different between the APIs, but in the Jamf Pro API, you can ask the server to return the list already sorted, possibly filtered, or 'paged' in groups of some number of items. None of that is possible in the Classic API.
|
109
109
|
|
110
110
|
The `.all` method, and its relatives like `.all_ids`, `.all_names`, etc. exist for Collection Resources in both APIs, but the methods take different parameters, e.g. to deal with sorting and filtering. Jamf Pro API classes have a `.pager` method which returns an object from which you can retrieve the 'pages' of your query.
|
111
111
|
|
@@ -121,9 +121,11 @@ The API documentation you see at your own Jamf Pro server at https://your.jamf.s
|
|
121
121
|
|
122
122
|
In ruby-jss 2.0 and up, the OAPI spec is used to automatically generate hundreds of 'base' classes in ruby-jss, each with automatically generated attribute getters, setters, validators, and other useful methods. These base classes can then be used as the superclasses of the Jamt Pro API objects we implement for direct use in ruby-jss - and the majority of the coding is already done! The subclasses implementing objects in ruby-jss can then be expanded and customized beyond the simple, auto-generated superclass.
|
123
123
|
|
124
|
-
Not only does this make it fast and simple to implement new objects in ruby-jss, but allows fast and simple updates to existing objects, when new functionality is introduced to the API.
|
124
|
+
Not only does this make it fast and simple to implement new objects in ruby-jss, but allows fast and simple updates to existing objects, when new functionality is introduced to the API.
|
125
|
+
|
126
|
+
Hopefully it will also allow a single version of ruby-jss to work with a wide range of Jamf Pro versions, as API endpoint versions are added and deprecated (details of how that'll work are TBD)
|
125
127
|
|
126
|
-
If you develop ruby-jss, please see (documentation link
|
128
|
+
If you develop ruby-jss, please see (documentation link will go here) for more info about how to use the auto-generated classes, or reach out to us. (See [Contact](#contact), below)
|
127
129
|
|
128
130
|
### Autoloading with Zeitwerk
|
129
131
|
|
@@ -150,26 +152,32 @@ The `.all` method will never deliver paged results, however if you give it a `fi
|
|
150
152
|
|
151
153
|
### API data are no longer cached (?)
|
152
154
|
|
153
|
-
**NOTE:** As of this writing, caching has been removed for the objects from the Jamf Pro API, but caching remains in the Classic API. Its removal, or the re-instatement of caching for JP API objects, are pending discussion with users of ruby-jss.
|
155
|
+
**NOTE:** As of this writing, caching has been removed for the objects from the Jamf Pro API, but caching remains in the Classic API. Its removal, or the re-instatement of caching for JP API objects, are pending discussion with other users of ruby-jss.
|
154
156
|
|
155
157
|
Pre-2.0, methods that would fetch large datasets from the server would always cache that data in the Connection object, and by default use the cache in future calls unless a `refresh` parameter is given. These datasets included:
|
156
158
|
|
157
159
|
- collection lists, used by `.all` and friends, like `.all_ids` and `.valid_id`
|
158
|
-
- Extension Attribute
|
160
|
+
- Extension Attribute definitions, used for validating Extension Attribute values
|
159
161
|
|
160
162
|
In 2.0+, that caching has been removed for objects from them Jamf Pro API.
|
161
163
|
|
162
|
-
|
164
|
+
If you want to avoid repeated GET requests to the server when you aren't worried that the resulting data may have changed, you can store the results of `.all` in a variable, and either use it yourself, or pass it in to other methods via the `cached_list:` parameter. Passing in a cached_list wil prevent those methods from calling `.all` and reaching out to the server again.
|
163
165
|
|
164
|
-
**WARNING**:
|
166
|
+
**WARNING**: Caching a list yourself and using it with `cached_list` can cause all kinds of problems if you don't ensure these points:
|
167
|
+
- the cached_list contains the correct data structure for the class
|
168
|
+
- i.e. pass in the results of `.all` for that class, not `.all_ids` or other sub-lists.
|
169
|
+
- the cached_list came from the correct Connection instance
|
170
|
+
- the cached_list is sufficiently up to date.
|
165
171
|
|
166
172
|
### No Attribute aliases for Jamf Pro API objects
|
167
173
|
|
168
174
|
Objects from the Jamf Pro API will no longer define aliases for the attribute names that come from the API itself. This means, e.g., to get the name of a ComputerPrestage or MobileDevicePrestage, you have to ask for its `displayName` not its `name`, since the property comes from the API as `displayName`. To see a list of all the names, you must use `.all_displayNames` not `.all_names`. For objects with a 'name' property (most of them) then you can use `.name` and `.all_names`.
|
169
175
|
|
170
|
-
The reason behind this is twofold:
|
176
|
+
The reason behind this is twofold:
|
177
|
+
1) to simplify ruby-jss's code and automate as much as possible
|
178
|
+
2) to reflect what Jamf actually gives us in the APIs
|
171
179
|
|
172
|
-
This is a breaking change from earlier ruby-jss versions, for which Jamf Pro API objects had the potential for aliases of their attribute names.
|
180
|
+
**IMPORTANT** This is a breaking change from earlier ruby-jss versions, for which Jamf Pro API objects had the potential for aliases of their attribute names.
|
173
181
|
|
174
182
|
### Class/Mixin hierarchy for Jamf Pro API objects
|
175
183
|
|
@@ -177,7 +185,7 @@ If you contribute to ruby-jss, be aware that the structure of superclasses, subc
|
|
177
185
|
|
178
186
|
There's a lot to document about these changes, and much of the current documentation is out of date, referring to how things were done when the Jamf module was separate and only talked to the Jamf Pro API.
|
179
187
|
|
180
|
-
Give us time and we'll get everything updated. In the meantime, feel free to reach out
|
188
|
+
Give us time and we'll get everything updated. In the meantime, feel free to reach out for assistance or questions. (See [Contact](#contact), below)
|
181
189
|
|
182
190
|
### Support for 'Sticky Sessions' in Jamf Cloud
|
183
191
|
|
@@ -189,7 +197,6 @@ For details about Sticky Sessions see [Sticky Sessions for Jamf Cloud](https://d
|
|
189
197
|
|
190
198
|
**WARNING:** Jamf recommends NOT using sticky sessions unless they are needed. Using them inappropriately may negatively impact performance, especially for large automated processes.
|
191
199
|
|
192
|
-
|
193
200
|
## Planned deprecations
|
194
201
|
|
195
202
|
### Use of the term 'api' in method names, parameter names, and attributes
|
@@ -214,11 +221,15 @@ comp = JSS::Computer.fetch id: 12, cnx: my_connection
|
|
214
221
|
comp.cnx # => my_connection
|
215
222
|
```
|
216
223
|
|
217
|
-
In ruby-jss < 2.0, the term `api` is used with the Classic API in method names, method parameters, instance variables, attributes, and constants. It is used to pass, access, or hold instances of JSS::APIConnnection, e.g. so a method that talks to the server would use the passed connection rather than the module-wide default connection.
|
224
|
+
In ruby-jss < 2.0, the term `api` is used with the Classic API in method names, method parameters, instance variables, attributes, and constants. It is used to pass, access, refer to, or hold instances of JSS::APIConnnection, e.g. so a method that talks to the server would use the passed connection rather than the module-wide default connection.
|
225
|
+
|
226
|
+
But, the thing being passed is a 'connection' not an 'API', and now that there are actually two APIs at play, that usage is even less appropriate.
|
227
|
+
|
228
|
+
The original Jamf module, which accessed only the Jamf Pro API, has always used the better-suited abbreviation `cnx` for this, and now that is standard everywhere.
|
218
229
|
|
219
|
-
|
230
|
+
For now `api` should continue to work, but it will be removed 'eventually', so please start changing your code now.
|
220
231
|
|
221
|
-
Accordingly, `JSS::API` (which should never have been a constant to begin with) is also deprecated. To access the default connection, use `Jamf.cnx`
|
232
|
+
Accordingly, `JSS::API` (which should never have been a constant to begin with) has been deprecated for years in favor of `JSS.api`, which is now also deprecated. To access the default connection, use `Jamf.cnx`
|
222
233
|
|
223
234
|
### `.map_all_ids_to` method for Classic API collection classes
|
224
235
|
|
@@ -230,7 +241,7 @@ For now `map_all_ids_to` still works, however it's just a wrapper for `map_all`.
|
|
230
241
|
|
231
242
|
Use `.create` and `#save` instead, as with the Jamf Pro API objects
|
232
243
|
|
233
|
-
|
244
|
+
All versions of ruby-jss have avoided the use of the ruby-standard `.new` on Collection Resource classes, because the word 'new' in this context is ambiguous: are you creating a new instance of the class in ruby (which might already exist on the server), or are you creating a new object in Jamf Pro that doesn't yet exist on the server?
|
234
245
|
|
235
246
|
In v2.0.0 we are standardizing on the behavior of the previous Jamf module:
|
236
247
|
|
@@ -286,7 +297,7 @@ existing_policy.save
|
|
286
297
|
|
287
298
|
### JSS::CONFIG
|
288
299
|
|
289
|
-
This
|
300
|
+
This should never have been a constant. Use Jamf.config. JSS::CONFIG will go away eventually.
|
290
301
|
|
291
302
|
### Jamf::Connection instance methods `#next_refresh`, `#secs_to_refresh`, & `#time_to_refresh`
|
292
303
|
|
@@ -320,7 +331,7 @@ You can still fetch random objects from a collection, but use `.fetch random: tr
|
|
320
331
|
|
321
332
|
The YARD documentation for v2.0.0 is available before release in the [github.io site for ruby-jss](http://pixaranimationstudios.github.io/ruby-jss/docs/v2.x/index.html).
|
322
333
|
|
323
|
-
All the documentation for ruby-jss is in need of updating, from the top-level README to the auto-generated YARD docs.
|
334
|
+
All the documentation for ruby-jss is in serious need of updating, from the top-level README to the auto-generated YARD docs. Forgive us while we slowly get it up to snuff. If you have questions that aren't answered there, please reach out (see [Contact](#contact), below)
|
324
335
|
|
325
336
|
## How to install for testing
|
326
337
|
|