ruby-jss 0.9.2 → 0.10.0a1

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +13 -1
  3. data/README.md +7 -7
  4. data/bin/cgrouper +6 -6
  5. data/bin/netseg-update +1 -1
  6. data/lib/jss.rb +1 -0
  7. data/lib/jss/api_connection.rb +428 -44
  8. data/lib/jss/api_object.rb +119 -68
  9. data/lib/jss/api_object/account.rb +12 -12
  10. data/lib/jss/api_object/advanced_search.rb +12 -12
  11. data/lib/jss/api_object/categorizable.rb +4 -4
  12. data/lib/jss/api_object/category.rb +2 -2
  13. data/lib/jss/api_object/computer.rb +111 -58
  14. data/lib/jss/api_object/computer_invitation.rb +2 -2
  15. data/lib/jss/api_object/creatable.rb +19 -8
  16. data/lib/jss/api_object/criteriable/criteria.rb +8 -8
  17. data/lib/jss/api_object/distribution_point.rb +14 -48
  18. data/lib/jss/api_object/extension_attribute.rb +14 -11
  19. data/lib/jss/api_object/extension_attribute/computer_extension_attribute.rb +18 -18
  20. data/lib/jss/api_object/group.rb +7 -7
  21. data/lib/jss/api_object/ldap_server.rb +51 -60
  22. data/lib/jss/api_object/locatable.rb +2 -2
  23. data/lib/jss/api_object/matchable.rb +8 -9
  24. data/lib/jss/api_object/mobile_device.rb +61 -59
  25. data/lib/jss/api_object/mobile_device_application.rb +3 -3
  26. data/lib/jss/api_object/network_segment.rb +24 -19
  27. data/lib/jss/api_object/package.rb +6 -6
  28. data/lib/jss/api_object/peripheral.rb +5 -5
  29. data/lib/jss/api_object/policy.rb +5 -5
  30. data/lib/jss/api_object/restricted_software.rb +4 -4
  31. data/lib/jss/api_object/scopable/scope.rb +3 -3
  32. data/lib/jss/api_object/script.rb +1 -1
  33. data/lib/jss/api_object/self_servable.rb +3 -3
  34. data/lib/jss/api_object/self_servable/icon.rb +7 -2
  35. data/lib/jss/api_object/updatable.rb +2 -2
  36. data/lib/jss/api_object/uploadable.rb +1 -1
  37. data/lib/jss/api_object/user.rb +2 -2
  38. data/lib/jss/composer.rb +37 -10
  39. data/lib/jss/ruby_extensions/string.rb +51 -42
  40. data/lib/jss/server.rb +27 -6
  41. data/lib/jss/utility.rb +44 -0
  42. data/lib/jss/validate.rb +85 -0
  43. data/lib/jss/version.rb +1 -1
  44. metadata +5 -4
@@ -26,13 +26,14 @@
26
26
  ###
27
27
  module JSS
28
28
 
29
- # A class representing the currently-connected JSS Server.
29
+ # A class representing the currently-connected JSS Server in a
30
+ # JSS::APIConnection instance.
30
31
  #
31
32
  # The {JSS::APIConnection} instance has a JSS::Server instance in its #server
32
33
  # attribute. It is created fresh every time {APIConnection#connect} is called.
33
34
  #
34
35
  # That's the only time it should be instantiated, and all access should be
35
- # through {JSS.api_connection.server}
36
+ # through the #server attribute of the APIConnection instance.
36
37
  #
37
38
  class Server
38
39
 
@@ -66,6 +67,10 @@ module JSS
66
67
  # @return [String]
67
68
  attr_reader :raw_version
68
69
 
70
+ # @return [JSS::APIConnection] The APIConnection object that contains this
71
+ # instance of Server
72
+ attr_reader :api
73
+
69
74
  # Instance Methods
70
75
  #####################################
71
76
 
@@ -77,8 +82,12 @@ module JSS
77
82
  # However, it's marked as 'deprecated'. Hopefully jamf will
78
83
  # keep this basic level of info available for basic authentication
79
84
  # and JSS version checking.
80
- def initialize(jss_data)
81
-
85
+ #
86
+ # The 'api' is a reference to the JSS::APIConnection instance
87
+ # which this JSS::Server instance is a part of.
88
+ #
89
+ def initialize(jss_data, api)
90
+ @api = api
82
91
  @license_type = jss_data[:license_type]
83
92
  @product = jss_data[:product]
84
93
  @raw_version = jss_data[:version]
@@ -91,16 +100,28 @@ module JSS
91
100
 
92
101
  # @return [String] the organization to which the server is licensed
93
102
  def organization
94
- @act_code_data ||= JSS.api_connection.get_rsrc(ACTIVATION_CODE_RSRC)[ACTIVATION_CODE_KEY]
103
+ @act_code_data ||= @api.get_rsrc(ACTIVATION_CODE_RSRC)[ACTIVATION_CODE_KEY]
95
104
  @act_code_data[:organization_name]
96
105
  end
97
106
 
98
107
  # @return [String] the activation code for the server licence
99
108
  def activation_code
100
- @act_code_data ||= JSS.api_connection.get_rsrc(ACTIVATION_CODE_RSRC)[ACTIVATION_CODE_KEY]
109
+ @act_code_data ||= @api.get_rsrc(ACTIVATION_CODE_RSRC)[ACTIVATION_CODE_KEY]
101
110
  @act_code_data[:code]
102
111
  end
103
112
 
113
+ # Remove the api object from
114
+ # the instance_variables used to create
115
+ # pretty-print (pp) output.
116
+ #
117
+ # @return [Array] the desired instance_variables
118
+ #
119
+ def pretty_print_instance_variables
120
+ vars = instance_variables.sort
121
+ vars.delete :@api
122
+ vars
123
+ end
124
+
104
125
  ##### Aliases
105
126
  alias institution organization
106
127
  alias product_name product
@@ -264,6 +264,50 @@ module JSS
264
264
  Time.at(epoch.to_i / 1000.0)
265
265
  end # parse_date
266
266
 
267
+ # Given a name, singular or plural, of a JSS::APIObject subclass as a String
268
+ # or Symbol (e.g. :computer/'computers'), return the class itself
269
+ # (e.g. JSS::Computer)
270
+ # The available names are the RSRC_LIST_KEY
271
+ # and RSRC_OBJECT_KEY values for each APIObject subclass.
272
+ #
273
+ # @seealso JSS.api_object_names
274
+ #
275
+ # @param name[String,Symbol] The name of a JSS::APIObject subclass, singluar
276
+ # or plural
277
+ #
278
+ # @return [Class] The class
279
+ #
280
+ def self.api_object_class(name)
281
+ klass = api_object_names[name.downcase.to_sym]
282
+ raise JSS::InvalidDataError, "Unknown API Object Class: #{name}" unless klass
283
+ klass
284
+ end
285
+
286
+ # APIObject subclasses have singular names, and are, of course
287
+ # capitalized, e.g. 'Computer'
288
+ # But we often want to refer to them in the plural, or lowercase,
289
+ # e.g. 'computers'
290
+ # This method returns a Hash of the RSRC_LIST_KEY (a plural symbol)
291
+ # and the RSRC_OBJECT_KEY (a singular symbol) of each APIObject
292
+ # subclass, keyed to the class itself, such that both :computer
293
+ # and :computers are keys for JSS::Computer and both :policy and
294
+ # :policies are keys for JSS::Policy, and so on.
295
+ #
296
+ # @return [Hash] APIObject subclass names to Classes
297
+ #
298
+ def self.api_object_names
299
+ return @api_object_names if @api_object_names
300
+ @api_object_names ||= {}
301
+ JSS.constants.each do |const|
302
+ klass = JSS.const_get const
303
+ next unless klass.is_a? Class
304
+ next unless klass.ancestors.include? JSS::APIObject
305
+ @api_object_names[klass.const_get(:RSRC_LIST_KEY).to_sym] = klass if klass.constants.include? :RSRC_LIST_KEY
306
+ @api_object_names[klass.const_get(:RSRC_OBJECT_KEY).to_sym] = klass if klass.constants.include? :RSRC_OBJECT_KEY
307
+ end
308
+ @api_object_names
309
+ end
310
+
267
311
  # Given a string of xml element text, escape any characters that would make XML unhappy.
268
312
  # * & => &
269
313
  # * " => "
@@ -0,0 +1,85 @@
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
+ # A collection of methods for validating values. Mostly for
29
+ # ensuring the validity of data being set as attributes of APIObject
30
+ # subclass instances.
31
+ #
32
+ # Some of these methods can take multiple input types, such as a String
33
+ # or an Array. All of them will either raise an exception
34
+ # if the value isn't valid, or will return a standardized form of the input
35
+ # (e.g. an Array, even if given a String)
36
+ #
37
+ module Validate
38
+
39
+ # The regular expression that matches a valid MAC address.
40
+ MAC_ADDR_RE = /^[a-f0-9]{2}(:[a-f0-9]{2}){5}$/i
41
+
42
+ # Validate the format and content of a MAC address
43
+ #
44
+ # @param val[String] The value to validate
45
+ #
46
+ # @return [String] The valid value
47
+ #
48
+ def self.mac_address(val)
49
+ raise JSS::InvalidDataError, "Not a valid MAC address: '#{val}'" unless val =~ MAC_ADDR_RE
50
+ val
51
+ end
52
+
53
+ # Validate the format and content of an IPv4 address
54
+ #
55
+ # @param val[String] The value to validate
56
+ #
57
+ # @return [String] The valid value
58
+ #
59
+ def self.ip_address(val)
60
+ ok = true
61
+ parts = val.strip.split '.'
62
+ ok = false unless parts.size == 4
63
+ parts.each { |p| ok = false unless p.jss_integer? && p.to_i < 256 }
64
+ raise JSS::InvalidDataError, "Not a valid IPv4 address: '#{val}'" unless ok
65
+ val
66
+ end
67
+
68
+ # Validate that a value doesn't already exist for a given identifier of a given class
69
+ #
70
+ # @param klass[JSS::APIObject] A subclass of JSS::APIObject, e.g. JSS::Computer
71
+ #
72
+ # @param identifier[Symbol] One of the keys of an Item of the class's #all Array
73
+ #
74
+ # @param val[Object] The value to check for uniqueness
75
+ #
76
+ # @return [Object] the validated unique value
77
+ #
78
+ def self.unique_identifier(klass, identifier, val)
79
+ raise JSS::AlreadyExistsError, "A #{klass} already exists with #{identifier} '#{val}'" if klass.all.map { |i| i[identifier] }.include? val
80
+ val
81
+ end
82
+
83
+ end # module validate
84
+
85
+ end # module JSS
@@ -27,6 +27,6 @@
27
27
  module JSS
28
28
 
29
29
  ### The version of the JSS ruby gem
30
- VERSION = '0.9.2'.freeze
30
+ VERSION = '0.10.0a1'.freeze
31
31
 
32
32
  end # module
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: 0.9.2
4
+ version: 0.10.0a1
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: 2017-07-25 00:00:00.000000000 Z
12
+ date: 2017-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: plist
@@ -181,6 +181,7 @@ files:
181
181
  - lib/jss/ruby_extensions/time.rb
182
182
  - lib/jss/server.rb
183
183
  - lib/jss/utility.rb
184
+ - lib/jss/validate.rb
184
185
  - lib/jss/version.rb
185
186
  - lib/ruby-jss.rb
186
187
  homepage: http://pixaranimationstudios.github.io/ruby-jss/
@@ -203,9 +204,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
203
204
  version: 1.9.3
204
205
  required_rubygems_version: !ruby/object:Gem::Requirement
205
206
  requirements:
206
- - - ">="
207
+ - - ">"
207
208
  - !ruby/object:Gem::Version
208
- version: '0'
209
+ version: 1.3.1
209
210
  requirements: []
210
211
  rubyforge_project:
211
212
  rubygems_version: 2.6.8