ruby-jss 1.0.1 → 1.0.2
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.
- checksums.yaml +4 -4
- data/CHANGES.md +6 -0
- data/README.md +2 -2
- data/lib/jss/api_object/criteriable.rb +157 -156
- data/lib/jss/api_object/criteriable/criterion.rb +176 -146
- data/lib/jss/api_object/extension_attribute.rb +2 -2
- data/lib/jss/client.rb +1 -1
- data/lib/jss/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0196bdb655afca3d5ed45a3a3843664581141d379b5549814945d1868ed51fa4'
|
4
|
+
data.tar.gz: f818199e33219b7c21b1353874b4d3c5c2f92943acbd01e2a9b332fc868628a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b90fb35e0f5f132edf4b396d0608225f30722322fc9cbea5826c127b2b2e77fa2bce69345952b4440454be3a3ce110530c54b349ea472220bc5d4ad1e83f32d2
|
7
|
+
data.tar.gz: d2952cb9ff7f44b3617946f93d522fba7d990f98754542f1413ccd1736ea33fed85e4e4fc24b96dc347aa32907793888dacf6b26cfd068366d63f5b460d3b6d4
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Change History
|
2
2
|
|
3
|
+
## v 1.0.2 2018-10-16
|
4
|
+
|
5
|
+
- add: Support for parentheses (opening_paren and closing_paren) in JSS::Criteriable::Criterion objects
|
6
|
+
- add: Support for patch-related criterion comparisons "greater than", "less than", "greater than or equal", "less than or equal"
|
7
|
+
- fix: a couple lingering calls to `.new` on APIObject classes, now `.fetch`
|
8
|
+
|
3
9
|
## v 1.0.1, 2018-08-27
|
4
10
|
|
5
11
|
- add: `JSS::MobileDeviceApplication#version=` and `#bundle_id=` These two attributes are now settable and will be saved to the server if the application is hosted externally. Thanks to [ctaintor](https://github.com/ctaintor) for providing this patch.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# ruby-jss: Working with the Jamf Pro API in Ruby
|
1
|
+
# ruby-jss: Working with the Jamf Pro Classic API in Ruby
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/ruby-jss.svg)](http://badge.fury.io/rb/ruby-jss)
|
3
3
|
|
4
4
|
### Table of contents
|
@@ -354,7 +354,7 @@ JSS.api.connect pw: password # other arguments used from the config settings
|
|
354
354
|
|
355
355
|
## BEYOND THE API
|
356
356
|
|
357
|
-
While the Jamf Pro API provides access to object data in the JSS, this gem tries to use that data to provide more than just information exchange. Here are some examples of how we use the API data to provide functionality found in various Casper tools:
|
357
|
+
While the Jamf Pro Classic API provides access to object data in the JSS, this gem tries to use that data to provide more than just information exchange. Here are some examples of how we use the API data to provide functionality found in various Casper tools:
|
358
358
|
|
359
359
|
* Client Machine Access
|
360
360
|
* The {JSS::Client} module provides the ability to run jamf binary commands, and access the local cache of package receipts
|
@@ -1,189 +1,190 @@
|
|
1
|
-
|
1
|
+
# Copyright 2018 Pixar
|
2
|
+
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "Apache License")
|
5
|
+
# with the following modification; you may not use this file except in
|
6
|
+
# compliance with the Apache License and the following modification to it:
|
7
|
+
# Section 6. Trademarks. is deleted and replaced with:
|
8
|
+
#
|
9
|
+
# 6. Trademarks. This License does not grant permission to use the trade
|
10
|
+
# names, trademarks, service marks, or product names of the Licensor
|
11
|
+
# and its affiliates, except as required to comply with Section 4(c) of
|
12
|
+
# the License and to reproduce the content of the NOTICE file.
|
13
|
+
#
|
14
|
+
# You may obtain a copy of the Apache License at
|
15
|
+
#
|
16
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
17
|
+
#
|
18
|
+
# Unless required by applicable law or agreed to in writing, software
|
19
|
+
# distributed under the Apache License with the above modification is
|
20
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
21
|
+
# KIND, either express or implied. See the Apache License for the specific
|
22
|
+
# language governing permissions and limitations under the Apache License.
|
23
|
+
#
|
24
|
+
#
|
2
25
|
|
3
|
-
###
|
4
|
-
### Licensed under the Apache License, Version 2.0 (the "Apache License")
|
5
|
-
### with the following modification; you may not use this file except in
|
6
|
-
### compliance with the Apache License and the following modification to it:
|
7
|
-
### Section 6. Trademarks. is deleted and replaced with:
|
8
|
-
###
|
9
|
-
### 6. Trademarks. This License does not grant permission to use the trade
|
10
|
-
### names, trademarks, service marks, or product names of the Licensor
|
11
|
-
### and its affiliates, except as required to comply with Section 4(c) of
|
12
|
-
### the License and to reproduce the content of the NOTICE file.
|
13
|
-
###
|
14
|
-
### You may obtain a copy of the Apache License at
|
15
|
-
###
|
16
|
-
### http://www.apache.org/licenses/LICENSE-2.0
|
17
|
-
###
|
18
|
-
### Unless required by applicable law or agreed to in writing, software
|
19
|
-
### distributed under the Apache License with the above modification is
|
20
|
-
### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
21
|
-
### KIND, either express or implied. See the Apache License for the specific
|
22
|
-
### language governing permissions and limitations under the Apache License.
|
23
|
-
###
|
24
|
-
###
|
25
|
-
|
26
|
-
###
|
27
26
|
module JSS
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
28
|
+
# A mix-in module that allows objects to handle standardized search Criteria.
|
29
|
+
#
|
30
|
+
# Some objects in the JSS, such as Advanced Searches and Smart Groups,
|
31
|
+
# include a set of Criteria. (i.e conditions which, when met, signify inclusion
|
32
|
+
# in a result set.)
|
33
|
+
#
|
34
|
+
# A {JSS::Criteriable::Criteria} instance is a container for one or more
|
35
|
+
# {JSS::Criteriable::Criterion} instances and provides methods for dealing with
|
36
|
+
# them easily.
|
37
|
+
#
|
38
|
+
# When a {JSS::APIObject} subclass includes this module, that subclass
|
39
|
+
# will have a :criteria attribute, which holds a {JSS::Criteriable::Criteria}
|
40
|
+
# object and can be used to manipulate the Criterion objects inside.
|
41
|
+
#
|
42
|
+
# The including subclass also gains some instance methods:
|
43
|
+
# * #parse_critera - sets up the :criteria attribute during initialization
|
44
|
+
# * #criteria= - allows the wholesale replacement of the criteria
|
45
|
+
# * #need_to_update - allows the {JSS::Criteriable::Criteria} instance to
|
46
|
+
# inform the subclass instance that it has changed and needs an #update
|
47
|
+
#
|
48
|
+
# Classes mixing in this module *must*
|
49
|
+
# * If they are Updatable or Creatable, they must insert
|
50
|
+
# self.criteria.rest_xml into their own xml output.
|
51
|
+
#
|
52
|
+
#
|
53
|
+
# @example Working with the criteria of an advanced computer search
|
54
|
+
# # create three Criterion instances (split over multiple lines for clarity)
|
55
|
+
# #
|
56
|
+
# # These find all of jeauxbleaux's computers that have either
|
57
|
+
# # Excel or Word installed
|
58
|
+
#
|
59
|
+
# crtn_0 = JSS::Criteriable::Criterion.new(
|
60
|
+
# and_or: :and, # NOTE: the and_or value of the first criterion is ignored
|
61
|
+
# name: 'Username',
|
62
|
+
# search_type: 'is',
|
63
|
+
# value: 'jeauxbleaux'
|
64
|
+
# )
|
65
|
+
#
|
66
|
+
# crtn_1 = JSS::Criteriable::Criterion.new(
|
67
|
+
# and_or: :and,
|
68
|
+
# paren: :opening,
|
69
|
+
# name: 'Application Title',
|
70
|
+
# search_type: 'has',
|
71
|
+
# value: 'Microsoft Excel.app'
|
72
|
+
# )
|
73
|
+
#
|
74
|
+
# crtn_2 = JSS::Criteriable::Criterion.new(
|
75
|
+
# and_or: :or,
|
76
|
+
# name: 'Application Title',
|
77
|
+
# search_type: 'has',
|
78
|
+
# value: 'Microsoft Word.app',
|
79
|
+
# paren: :closing
|
80
|
+
# )
|
81
|
+
#
|
82
|
+
# # use them to create a Criteria instance
|
83
|
+
# crta = JSS::Criteriable::Criteria.new [crtn_0, crtn_1, crtn_2]
|
84
|
+
#
|
85
|
+
# # create a new Advanced Search
|
86
|
+
# srch = JSS::AdvancedComputerSearch.make, :name => "my computer search"
|
87
|
+
# srch.display_fields = ["Computer Name"]
|
88
|
+
#
|
89
|
+
# # add our Criteria to it
|
90
|
+
# srch.criteria = crta
|
91
|
+
#
|
92
|
+
# # create it in the JSS
|
93
|
+
# srch.create # srch.search_results now contains the matching computers
|
94
|
+
#
|
95
|
+
# # append a new criterion to the criteria, limiting the search results farther
|
96
|
+
# # to those computers that have done a recon in the past week
|
97
|
+
# srch.criteria.append_criterion JSS::Criteriable::Criterion.new(
|
98
|
+
# and_or: :or,
|
99
|
+
# name: "Last Inventory Update",
|
100
|
+
# search_type: "less than x days ago",
|
101
|
+
# value: 8
|
102
|
+
# )
|
103
|
+
#
|
104
|
+
# # save the change to the JSS
|
105
|
+
# srch.save
|
106
|
+
#
|
107
|
+
# # fetch the new results
|
108
|
+
# srch.requery_search_results
|
109
|
+
#
|
110
|
+
# # oops - that last one should have been :and, not :or
|
111
|
+
# # so replace the last criterion with a correct one
|
112
|
+
# srch.criteria.set_criterion 3, JSS::Criteriable::Criterion.new(
|
113
|
+
# and_or: :and,
|
114
|
+
# name: "Last Inventory Update",
|
115
|
+
# search_type: "less than x days ago",
|
116
|
+
# value: 8
|
117
|
+
# )
|
118
|
+
#
|
119
|
+
# # save the change to the JSS
|
120
|
+
# # providing a non-false parameter to #update will automatically
|
121
|
+
# # perform the requery after the update.
|
122
|
+
# srch.update :requery
|
123
|
+
#
|
124
|
+
# @see JSS::Criteriable::Criteria
|
125
|
+
# @see JSS::Criteriable::Criterion
|
126
|
+
#
|
111
127
|
module Criteriable
|
112
128
|
|
113
|
-
|
114
|
-
### Constants
|
129
|
+
# Constants
|
115
130
|
#####################################
|
116
131
|
|
117
132
|
CRITERIABLE = true
|
118
133
|
|
119
|
-
|
120
|
-
#####################################
|
121
|
-
### Variables
|
134
|
+
# Variables
|
122
135
|
#####################################
|
123
136
|
|
124
|
-
|
125
|
-
### Mixed-in Attributes
|
137
|
+
# Mixed-in Attributes
|
126
138
|
#####################################
|
127
139
|
|
128
|
-
|
140
|
+
# @return [JSS::Criteriable::Criteria] the criteria for the instance into which we're mixed.
|
129
141
|
attr_reader :criteria
|
130
142
|
|
131
|
-
|
132
|
-
### Mixed-in Instance Methods
|
143
|
+
# Mixed-in Instance Methods
|
133
144
|
#####################################
|
134
145
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
146
|
+
#
|
147
|
+
# During initialization, convert the @init_data[:criteria] Hash into
|
148
|
+
# a JSS::Criteriable::Criteria instance stored in @criteria
|
149
|
+
#
|
150
|
+
# Classes mixing in this module must call this in #initialize
|
151
|
+
#
|
152
|
+
# @return [void]
|
153
|
+
#
|
143
154
|
def parse_criteria
|
144
|
-
@criteria = if @init_data[:criteria]
|
145
|
-
JSS::Criteriable::Criteria.new @init_data[:criteria].map{|c| JSS::Criteriable::Criterion.new c}
|
146
|
-
else
|
147
|
-
nil
|
148
|
-
end
|
155
|
+
@criteria = (JSS::Criteriable::Criteria.new @init_data[:criteria].map { |c| JSS::Criteriable::Criterion.new c } if @init_data[:criteria])
|
149
156
|
@criteria.container = self if @criteria
|
150
157
|
end
|
151
158
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
def criteria=
|
160
|
-
raise JSS::InvalidDataError,
|
159
|
+
#
|
160
|
+
# Change the criteria, it must be a JSS::Criteriable::Criteria instance
|
161
|
+
#
|
162
|
+
# @param new_criteria[JSS::Criteriable::Criteria] the new criteria
|
163
|
+
#
|
164
|
+
# @return [void]
|
165
|
+
#
|
166
|
+
def criteria=(new_criteria)
|
167
|
+
raise JSS::InvalidDataError, 'JSS::Criteriable::Criteria instance required' unless new_criteria.is_a?(JSS::Criteriable::Criteria)
|
161
168
|
@criteria = new_criteria
|
162
169
|
@criteria.container = self
|
163
170
|
@need_to_update = true
|
164
171
|
end
|
165
172
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
173
|
+
#
|
174
|
+
#
|
175
|
+
# @api private
|
176
|
+
# Allow our Criteria to tell us when there's been a change that needs
|
177
|
+
# to be updated.
|
178
|
+
#
|
179
|
+
# @return [void]
|
180
|
+
#
|
174
181
|
def should_update
|
175
182
|
@need_to_update = true if @in_jss
|
176
183
|
end
|
177
184
|
|
178
|
-
|
179
|
-
### Mixed-in Class Methods
|
180
|
-
#####################################
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
end # module Criteriable
|
185
|
+
end # module Criteriable
|
185
186
|
|
186
187
|
end # module JSS
|
187
188
|
|
188
|
-
require
|
189
|
-
require
|
189
|
+
require 'jss/api_object/criteriable/criterion'
|
190
|
+
require 'jss/api_object/criteriable/criteria'
|
@@ -1,128 +1,129 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
###
|
1
|
+
# Copyright 2018 Pixar
|
2
|
+
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "Apache License")
|
5
|
+
# with the following modification; you may not use this file except in
|
6
|
+
# compliance with the Apache License and the following modification to it:
|
7
|
+
# Section 6. Trademarks. is deleted and replaced with:
|
8
|
+
#
|
9
|
+
# 6. Trademarks. This License does not grant permission to use the trade
|
10
|
+
# names, trademarks, service marks, or product names of the Licensor
|
11
|
+
# and its affiliates, except as required to comply with Section 4(c) of
|
12
|
+
# the License and to reproduce the content of the NOTICE file.
|
13
|
+
#
|
14
|
+
# You may obtain a copy of the Apache License at
|
15
|
+
#
|
16
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
17
|
+
#
|
18
|
+
# Unless required by applicable law or agreed to in writing, software
|
19
|
+
# distributed under the Apache License with the above modification is
|
20
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
21
|
+
# KIND, either express or implied. See the Apache License for the specific
|
22
|
+
# language governing permissions and limitations under the Apache License.
|
23
|
+
#
|
24
|
+
#
|
25
|
+
|
27
26
|
module JSS
|
28
27
|
|
29
28
|
module Criteriable
|
30
29
|
|
31
|
-
|
32
|
-
### Module Variables
|
30
|
+
# Module Variables
|
33
31
|
#####################################
|
34
32
|
|
35
|
-
|
36
|
-
### Module Methods
|
33
|
+
# Module Methods
|
37
34
|
#####################################
|
38
35
|
|
39
|
-
|
40
|
-
### Classes
|
36
|
+
# Classes
|
41
37
|
#####################################
|
42
38
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
39
|
+
# This class defines a single criterion used in advanced searches and
|
40
|
+
# smart groups throughout the JSS module.
|
41
|
+
#
|
42
|
+
# They are used within {JSS::Criteriable::Criteria} instances which store an
|
43
|
+
# array of these objects and provides methods for working with them as a group.
|
44
|
+
#
|
45
|
+
# The classes that mix-in {JSS::Criteriable} each have a :criteria attribute which
|
46
|
+
# holds one {JSS::Criteriable::Criteria}
|
47
|
+
#
|
48
|
+
# See {JSS::Criteriable} for examples
|
49
|
+
#
|
54
50
|
class Criterion
|
55
51
|
|
56
|
-
|
57
|
-
### Mix Ins
|
52
|
+
# Mix Ins
|
58
53
|
#####################################
|
59
54
|
|
60
|
-
include Comparable
|
55
|
+
include Comparable # this allows us compare instances using <=>
|
61
56
|
|
62
|
-
|
63
|
-
### Class Constants
|
57
|
+
# Class Constants
|
64
58
|
#####################################
|
65
59
|
|
66
|
-
|
60
|
+
# These are the available search-types for building criteria
|
67
61
|
SEARCH_TYPES = [
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
62
|
+
'is',
|
63
|
+
'is not',
|
64
|
+
'like',
|
65
|
+
'not like',
|
66
|
+
'has',
|
67
|
+
'does not have',
|
68
|
+
'more than',
|
69
|
+
'less than',
|
70
|
+
'greater than',
|
71
|
+
'less than',
|
72
|
+
'greater than or equal',
|
73
|
+
'less than or equal',
|
74
|
+
'before (yyyy-mm-dd)',
|
75
|
+
'after (yyyy-mm-dd)',
|
76
|
+
'more than x days ago',
|
77
|
+
'less than x days ago',
|
78
|
+
'in more than x days',
|
79
|
+
'in less than x days',
|
80
|
+
'member of',
|
81
|
+
'not member of',
|
82
|
+
'current',
|
83
|
+
'not current',
|
86
84
|
'matches regex',
|
87
85
|
'does not match regex'
|
88
|
-
]
|
86
|
+
].freeze
|
89
87
|
|
90
|
-
|
91
|
-
AND_OR = [
|
88
|
+
# the acceptable symboles for and/or
|
89
|
+
AND_OR = %i[and or].freeze
|
92
90
|
|
93
|
-
|
94
|
-
### Attributes
|
91
|
+
# Attributes
|
95
92
|
#####################################
|
96
93
|
|
97
|
-
|
98
|
-
|
99
|
-
|
94
|
+
# @return [Integer] zero-based index of this criterion within an array of criteria
|
95
|
+
# used for an advanced search or smart group.
|
96
|
+
# This is maintained automaticaly by the enclosing Criteria object
|
100
97
|
attr_accessor :priority
|
101
98
|
|
102
|
-
|
99
|
+
# @return [Symbol] :and or :or - the and_or value for associating this criterion with the previous one, defaults to :and
|
103
100
|
attr_reader :and_or
|
104
101
|
|
105
|
-
|
102
|
+
# @return [String] the name of the field being searched
|
106
103
|
attr_accessor :name
|
107
104
|
|
108
|
-
|
109
|
-
|
105
|
+
# @return [String] the comparator between the field and the value, must be one of SEARCH_TYPES
|
106
|
+
# @see #criteria=
|
110
107
|
attr_reader :search_type
|
111
108
|
|
112
|
-
|
109
|
+
# @return [String] the value being searched for in the field named by :name
|
113
110
|
attr_reader :value
|
114
111
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
### @option args :value [String] the value to compare with that stored for :name
|
121
|
-
###
|
122
|
-
### @note :priority is maintained by the JSS::Criteriable::Criteria object holding this instance
|
123
|
-
###
|
124
|
-
def initialize(args = {})
|
112
|
+
# @return [Boolean] Is there an opening paren before this criterion
|
113
|
+
attr_reader :opening_paren
|
114
|
+
|
115
|
+
# @return [Boolean] Is there a closing paren after this criterion
|
116
|
+
attr_reader :closing_paren
|
125
117
|
|
118
|
+
# @param args[Hash] a hash of settings for the new criterion
|
119
|
+
# @option args :and_or [String, Symbol] :and, or :or. How should this criterion be join with its predecessor?
|
120
|
+
# @option args :name [String] the name of a Criterion as is visible in the JSS webapp.
|
121
|
+
# @option args :search_type [String] one of SEARCH_TYPES, the comparison between the stored value and :value
|
122
|
+
# @option args :value [String] the value to compare with that stored for :name
|
123
|
+
#
|
124
|
+
# @note :priority is maintained by the JSS::Criteriable::Criteria object holding this instance
|
125
|
+
#
|
126
|
+
def initialize(args = {})
|
126
127
|
@priority = args[:priority]
|
127
128
|
|
128
129
|
@and_or = (args[:and_or].downcase.to_sym if args[:and_or]) || :and
|
@@ -131,89 +132,114 @@ module JSS
|
|
131
132
|
@name = args[:name]
|
132
133
|
|
133
134
|
if args[:search_type]
|
134
|
-
raise JSS::InvalidDataError,
|
135
|
+
raise JSS::InvalidDataError, 'Invalid :search_type' unless SEARCH_TYPES.include? args[:search_type]
|
135
136
|
@search_type = args[:search_type]
|
136
137
|
end
|
137
138
|
|
139
|
+
# from the API, parens come like this
|
140
|
+
@opening_paren = args[:opening_paren]
|
141
|
+
@closing_paren = args[:closing_paren]
|
142
|
+
|
143
|
+
# but from a user, they might come as a single :paren key, which
|
144
|
+
# will be handled by the setter below
|
145
|
+
send 'paren=', args[:paren] if args.key? :paren
|
146
|
+
|
147
|
+
# default to false
|
148
|
+
@opening_paren ||= false
|
149
|
+
@closing_paren ||= false
|
150
|
+
|
138
151
|
@value = args[:value]
|
139
152
|
end # init
|
140
153
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
def and_or= (new_val)
|
154
|
+
# Set a new and_or for the criteron
|
155
|
+
#
|
156
|
+
# @param new_val[Symbol] the new and_or
|
157
|
+
#
|
158
|
+
# @return [void]
|
159
|
+
#
|
160
|
+
def and_or=(new_val)
|
149
161
|
@and_or = new_val.to_sym
|
150
162
|
raise JSS::InvalidDataError, ":and_or must be 'and' or 'or'." unless AND_OR.include? @and_or.to_sym
|
151
163
|
end
|
152
164
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
165
|
+
# set the parenthesis for the criteria
|
166
|
+
#
|
167
|
+
# @param side[Symbol] :opening, :closing, or nil to remove
|
168
|
+
#
|
169
|
+
# @return [void]
|
170
|
+
def paren=(new_val)
|
171
|
+
case new_val
|
172
|
+
when :opening
|
173
|
+
@opening_paren = true
|
174
|
+
@closing_paren = false
|
175
|
+
when :closing
|
176
|
+
@opening_paren = false
|
177
|
+
@closing_paren = true
|
178
|
+
when nil
|
179
|
+
@opening_paren = false
|
180
|
+
@closing_paren = false
|
181
|
+
else
|
182
|
+
raise JSS::InvalidDataError, 'paren must be :opening, :closing, or nil.'
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# Set a new search type for the criteron
|
187
|
+
#
|
188
|
+
# @param new_val[String] the new search type
|
189
|
+
#
|
190
|
+
# @return [void]
|
191
|
+
#
|
192
|
+
def search_type=(new_val)
|
193
|
+
raise JSS::InvalidDataError, 'Invalid :search_type' unless SEARCH_TYPES.include? new_val
|
162
194
|
@search_type = new_val
|
163
195
|
end
|
164
196
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
###
|
197
|
+
# Set a new value for the criteron
|
198
|
+
#
|
199
|
+
# @param new_val[Integer,String] the new value
|
200
|
+
#
|
201
|
+
# @return [void]
|
202
|
+
#
|
172
203
|
def value=(new_val)
|
173
204
|
case @search_type
|
174
205
|
|
175
|
-
|
176
|
-
|
206
|
+
when 'more than', 'less than', 'more than x days ago', 'less than x days ago'
|
207
|
+
raise JSS::InvalidDataError, "Value must be an integer for search type '#{new_val}'" unless new_val =~ /^\d+$/
|
177
208
|
|
178
|
-
|
179
|
-
|
209
|
+
when 'before (yyyy-mm-dd)', 'after (yyyy-mm-dd)'
|
210
|
+
raise JSS::InvalidDataError, "Value must be a a date in the format yyyy-mm-dd for search type '#{new_val}'" unless new_val =~ /^\d\d\d\d-\d\d-\d\d$/
|
180
211
|
|
181
212
|
end # case
|
182
213
|
|
183
214
|
@value = new_val
|
184
|
-
|
185
215
|
end
|
186
216
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
###
|
217
|
+
# @return [String] All our values except priority joined together
|
218
|
+
# for comparing this Criterion to another for equality and order
|
219
|
+
#
|
220
|
+
# @see #<=>
|
221
|
+
#
|
193
222
|
def signature
|
194
|
-
[@and_or, @name, @search_type, @value].join
|
223
|
+
[@and_or, @name, @search_type, @value].join ','
|
195
224
|
end
|
196
225
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
### @see Comparable
|
204
|
-
###
|
226
|
+
# Comparison - allows the Comparable module to do its work
|
227
|
+
#
|
228
|
+
# @return [Integer] -1, 0, or 1
|
229
|
+
#
|
230
|
+
# @see Comparable
|
231
|
+
#
|
205
232
|
def <=>(other)
|
206
|
-
|
233
|
+
signature <=> other.signature
|
207
234
|
end
|
208
235
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
###
|
236
|
+
# @api private
|
237
|
+
#
|
238
|
+
# @return [REXML::Element] The xml element for the criterion, to be embeded in that of
|
239
|
+
# a Criteria instance
|
240
|
+
#
|
241
|
+
# @note For this class, rest_xml can't be a private method.
|
242
|
+
#
|
217
243
|
def rest_xml
|
218
244
|
crn = REXML::Element.new 'criterion'
|
219
245
|
crn.add_element('priority').text = @priority
|
@@ -221,9 +247,13 @@ module JSS
|
|
221
247
|
crn.add_element('name').text = @name
|
222
248
|
crn.add_element('search_type').text = @search_type
|
223
249
|
crn.add_element('value').text = @value
|
224
|
-
|
225
|
-
|
250
|
+
crn.add_element('opening_paren').text = @opening_paren ? 'true' : 'false'
|
251
|
+
crn.add_element('closing_paren').text = @closing_paren ? 'true' : 'false'
|
252
|
+
crn
|
253
|
+
end
|
226
254
|
|
227
255
|
end # class criterion
|
256
|
+
|
228
257
|
end # module Criteriable
|
258
|
+
|
229
259
|
end # module
|
@@ -290,7 +290,7 @@ module JSS
|
|
290
290
|
raise JSS::InvalidDataError, 'Invalid search_type, see JSS::Criteriable::Criterion::SEARCH_TYPES' unless JSS::Criteriable::Criterion::SEARCH_TYPES.include? search_type.to_s
|
291
291
|
begin
|
292
292
|
search_class = self.class::TARGET_CLASS::SEARCH_CLASS
|
293
|
-
acs = search_class.
|
293
|
+
acs = search_class.make api: @api, name: "ruby-jss-EA-result-search-#{Time.now.to_jss_epoch}"
|
294
294
|
acs.display_fields = [@name]
|
295
295
|
crit_list = [JSS::Criteriable::Criterion.new(and_or: 'and', name: @name, search_type: search_type.to_s, value: desired_value)]
|
296
296
|
acs.criteria = JSS::Criteriable::Criteria.new crit_list
|
@@ -308,7 +308,7 @@ module JSS
|
|
308
308
|
results << { id: i[:id], name: i[:name], value: value }
|
309
309
|
end
|
310
310
|
ensure
|
311
|
-
acs.delete
|
311
|
+
acs.delete if acs.is_a? self.class::TARGET_CLASS::SEARCH_CLASS
|
312
312
|
end
|
313
313
|
results
|
314
314
|
end # Return an Array of Hashes showing the most recent value
|
data/lib/jss/client.rb
CHANGED
data/lib/jss/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-jss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Lasell
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-10-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: plist
|