jss-api 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/CHANGES.md +4 -0
  2. data/LICENSE.txt +174 -0
  3. data/README.md +368 -0
  4. data/THANKS.md +6 -0
  5. data/lib/jss-api.rb +549 -0
  6. data/lib/jss-api/api_connection.rb +326 -0
  7. data/lib/jss-api/api_object.rb +590 -0
  8. data/lib/jss-api/api_object/advanced_search.rb +389 -0
  9. data/lib/jss-api/api_object/advanced_search/advanced_computer_search.rb +95 -0
  10. data/lib/jss-api/api_object/advanced_search/advanced_mobile_device_search.rb +96 -0
  11. data/lib/jss-api/api_object/advanced_search/advanced_user_search.rb +95 -0
  12. data/lib/jss-api/api_object/building.rb +92 -0
  13. data/lib/jss-api/api_object/category.rb +147 -0
  14. data/lib/jss-api/api_object/computer.rb +852 -0
  15. data/lib/jss-api/api_object/creatable.rb +98 -0
  16. data/lib/jss-api/api_object/criteriable.rb +189 -0
  17. data/lib/jss-api/api_object/criteriable/criteria.rb +231 -0
  18. data/lib/jss-api/api_object/criteriable/criterion.rb +228 -0
  19. data/lib/jss-api/api_object/department.rb +93 -0
  20. data/lib/jss-api/api_object/distribution_point.rb +490 -0
  21. data/lib/jss-api/api_object/extendable.rb +221 -0
  22. data/lib/jss-api/api_object/extension_attribute.rb +457 -0
  23. data/lib/jss-api/api_object/extension_attribute/computer_extension_attribute.rb +362 -0
  24. data/lib/jss-api/api_object/extension_attribute/mobile_device_extension_attribute.rb +189 -0
  25. data/lib/jss-api/api_object/extension_attribute/user_extension_attribute.rb +117 -0
  26. data/lib/jss-api/api_object/group.rb +380 -0
  27. data/lib/jss-api/api_object/group/computer_group.rb +124 -0
  28. data/lib/jss-api/api_object/group/mobile_device_group.rb +139 -0
  29. data/lib/jss-api/api_object/group/user_group.rb +139 -0
  30. data/lib/jss-api/api_object/ldap_server.rb +535 -0
  31. data/lib/jss-api/api_object/locatable.rb +268 -0
  32. data/lib/jss-api/api_object/matchable.rb +97 -0
  33. data/lib/jss-api/api_object/mobile_device.rb +556 -0
  34. data/lib/jss-api/api_object/netboot_server.rb +148 -0
  35. data/lib/jss-api/api_object/network_segment.rb +414 -0
  36. data/lib/jss-api/api_object/package.rb +760 -0
  37. data/lib/jss-api/api_object/peripheral.rb +335 -0
  38. data/lib/jss-api/api_object/peripheral_type.rb +295 -0
  39. data/lib/jss-api/api_object/policy.rb +882 -0
  40. data/lib/jss-api/api_object/purchasable.rb +316 -0
  41. data/lib/jss-api/api_object/removable_macaddr.rb +98 -0
  42. data/lib/jss-api/api_object/scopable.rb +136 -0
  43. data/lib/jss-api/api_object/scopable/scope.rb +621 -0
  44. data/lib/jss-api/api_object/script.rb +631 -0
  45. data/lib/jss-api/api_object/site.rb +93 -0
  46. data/lib/jss-api/api_object/software_update_server.rb +109 -0
  47. data/lib/jss-api/api_object/updatable.rb +117 -0
  48. data/lib/jss-api/api_object/uploadable.rb +138 -0
  49. data/lib/jss-api/api_object/user.rb +272 -0
  50. data/lib/jss-api/client.rb +500 -0
  51. data/lib/jss-api/compatibility.rb +66 -0
  52. data/lib/jss-api/composer.rb +171 -0
  53. data/lib/jss-api/configuration.rb +301 -0
  54. data/lib/jss-api/db_connection.rb +243 -0
  55. data/lib/jss-api/exceptions.rb +83 -0
  56. data/lib/jss-api/ruby_extensions.rb +35 -0
  57. data/lib/jss-api/ruby_extensions/filetest.rb +43 -0
  58. data/lib/jss-api/ruby_extensions/hash.rb +79 -0
  59. data/lib/jss-api/ruby_extensions/ipaddr.rb +91 -0
  60. data/lib/jss-api/ruby_extensions/pathname.rb +77 -0
  61. data/lib/jss-api/ruby_extensions/string.rb +43 -0
  62. data/lib/jss-api/ruby_extensions/time.rb +63 -0
  63. data/lib/jss-api/server.rb +108 -0
  64. data/lib/jss-api/version.rb +31 -0
  65. metadata +219 -0
@@ -0,0 +1,93 @@
1
+ ### Copyright 2014 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
+ #####################################
29
+ ### Module Variables
30
+ #####################################
31
+
32
+ #####################################
33
+ ### Module Methods
34
+ #####################################
35
+
36
+
37
+ #####################################
38
+ ### Classes
39
+ #####################################
40
+
41
+ ###
42
+ ### A Site in the JSS.
43
+ ###
44
+ ### These are simple, in that they only have an ID and a name.
45
+ ###
46
+ ### @see JSS::APIObject
47
+ ###
48
+ class Site < JSS::APIObject
49
+
50
+ #####################################
51
+ ### Mix-Ins
52
+ #####################################
53
+ include JSS::Creatable
54
+ include JSS::Updatable
55
+
56
+ #####################################
57
+ ### Class Methods
58
+ #####################################
59
+
60
+ #####################################
61
+ ### Class Constants
62
+ #####################################
63
+
64
+ ### The base for REST resources of this class
65
+ RSRC_BASE = "sites"
66
+
67
+ ### the hash key used for the JSON list output of all objects in the JSS
68
+ RSRC_LIST_KEY = :sites
69
+
70
+ ### The hash key used for the JSON object output.
71
+ ### It's also used in various error messages
72
+ RSRC_OBJECT_KEY = :site
73
+
74
+ ### these keys, as well as :id and :name, are present in valid API JSON data for this class
75
+ VALID_DATA_KEYS = []
76
+
77
+ #####################################
78
+ ### Attributes
79
+ #####################################
80
+
81
+ #####################################
82
+ ### Constructor
83
+ #####################################
84
+
85
+
86
+ #####################################
87
+ ### Public Instance Methods
88
+ #####################################
89
+
90
+
91
+ end # class site
92
+
93
+ end # module
@@ -0,0 +1,109 @@
1
+ ### Copyright 2014 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
+ #####################################
29
+ ### Module Variables
30
+ #####################################
31
+
32
+ #####################################
33
+ ### Module Methods
34
+ #####################################
35
+
36
+ #####################################
37
+ ### Classes
38
+ #####################################
39
+
40
+ ###
41
+ ### A Software Update Server in the JSS
42
+ ###
43
+ ### Only minimally implemented, for access to the APIObject list methods
44
+ ###
45
+ ### @see JSS::APIObject
46
+ ###
47
+ class SoftwareUpdateServer < JSS::APIObject
48
+
49
+ #####################################
50
+ ### Mix-Ins
51
+ #####################################
52
+
53
+ #####################################
54
+ ### Class Methods
55
+ #####################################
56
+
57
+ #####################################
58
+ ### Class Constants
59
+ #####################################
60
+
61
+ ### The base for REST resources of this class
62
+ RSRC_BASE = "softwareupdateservers"
63
+
64
+ ### the hash key used for the JSON list output of all objects in the JSS
65
+ RSRC_LIST_KEY = :software_update_servers
66
+
67
+ ### The hash key used for the JSON object output.
68
+ ### It's also used in various error messages
69
+ RSRC_OBJECT_KEY = :software_update_server
70
+
71
+ ### these keys, as well as :id and :name, are present in valid API JSON data for this class
72
+ VALID_DATA_KEYS = [:set_system_wide, :port]
73
+
74
+ #####################################
75
+ ### Attributes
76
+ #####################################
77
+
78
+ ### @return [String]
79
+ attr_reader :ip_address
80
+
81
+ ### @return [Integer]
82
+ attr_reader :port
83
+
84
+ ### @return [Boolean]
85
+ attr_reader :set_system_wide
86
+
87
+
88
+ #####################################
89
+ ### Constructor
90
+ #####################################
91
+
92
+ ###
93
+ ### @see SS::APIObject#initialize
94
+ ###
95
+ def initialize (args = {})
96
+ super
97
+ @ip_address = @init_data[:ip_address]
98
+ @port = @init_data[:port]
99
+ @set_system_wide = @init_data[:set_system_wide]
100
+ end
101
+
102
+ #####################################
103
+ ### Public Instance Methods
104
+ #####################################
105
+
106
+
107
+ end # class NetbootServer
108
+
109
+ end # module
@@ -0,0 +1,117 @@
1
+ ### Copyright 2014 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 mix-in module providing object-updating via the JSS API.
29
+ ###
30
+
31
+
32
+
33
+ #####################################
34
+ ### Module Variables
35
+ #####################################
36
+
37
+ #####################################
38
+ ### Module Methods
39
+ #####################################
40
+
41
+ #####################################
42
+ ### Sub-Modules
43
+ #####################################
44
+
45
+ ###
46
+ ### A mix-in module that allows objects to be updated in the JSS via the API.
47
+ ###
48
+ ### When a JSS::APIObject subclass includes this module, instances of that
49
+ ### subclass can be modified in the JSS using the {#update} or {APIObject#save} methods.
50
+ ###
51
+ ### Such classes should define setter methods for any values that they wish to
52
+ ### modify, such as the {#name=} method defined here. Those setter methods must:
53
+ ### - ensure the correctness of the data they accept.
54
+ ### - set @need_to_update to true, indicating that the local object no longer
55
+ ### matches the JSS, and the changes should be pushed to the server with {#update}
56
+ ###
57
+ ### Classes mixing this module *must* provide a #rest_xml instance method that returns the XML
58
+ ### String to be submitted to the API for object updating.
59
+ ###
60
+ ### @see APIObject#save
61
+ ###
62
+ module Updatable
63
+
64
+ #####################################
65
+ ### Constants
66
+ #####################################
67
+
68
+ UPDATABLE = true
69
+
70
+ #####################################
71
+ ### Attributes
72
+ #####################################
73
+
74
+
75
+ ### @return [Boolean] do we have unsaved changes?
76
+ attr_reader :need_to_update
77
+
78
+
79
+ #####################################
80
+ ### Mixed-in Instance Methods
81
+ #####################################
82
+
83
+ ###
84
+ ### Change the name of this item
85
+ ### Remember to #update to push changes to the server.
86
+ ###
87
+ ### @param newname[String] the new name
88
+ ###
89
+ ### @return [void]
90
+ ###
91
+ def name= (newname)
92
+ raise JSS::UnsupportedError, "Editing #{self.class::RSRC_LIST_KEY} isn't yet supported. Please use other Casper workflows." unless UPDATABLE
93
+ return nil if @name == newname
94
+ raise JSS::InvalidDataError, "Names can't be empty!" if newname.to_s.empty?
95
+ raise JSS::AlreadyExistsError, "A #{self.class::RSRC_OBJECT_KEY} named '#{newname}' already exsists in the JSS" if self.class.all_names(:refresh).include? newname
96
+ @name = newname
97
+ @rest_rsrc = "#{self.class::RSRC_BASE}/name/#{URI.escape @name}" if @rest_rsrc.include? '/name/'
98
+ @need_to_update = true
99
+ end # name=(newname)
100
+
101
+ ###
102
+ ### Save changes to the JSS
103
+ ###
104
+ ### @return [Boolean] success
105
+ ###
106
+ def update
107
+ raise JSS::UnsupportedError, "Editing #{self.class::RSRC_LIST_KEY} isn't yet supported. Please use other Casper workflows." unless UPDATABLE
108
+ return nil unless @need_to_update
109
+ raise JSS::NoSuchItemError, "Not In JSS! Use #create to create this #{self.class::RSRC_OBJECT_KEY} in the JSS before updating it." unless @in_jss
110
+ JSS::API.put_rsrc @rest_rsrc, rest_xml
111
+ @need_to_update = false
112
+ @id
113
+ end # update
114
+
115
+ end # module Creatable
116
+
117
+ end # module
@@ -0,0 +1,138 @@
1
+ ### Copyright 2014 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
+ #####################################
29
+ ### Module Variables
30
+ #####################################
31
+
32
+
33
+ #####################################
34
+ ### Module Methods
35
+ #####################################
36
+
37
+ #####################################
38
+ ### Sub-Modules
39
+ #####################################
40
+
41
+ ###
42
+ ### A mixin module providing file-upload capabilities to JSSAPIObject subclasses.
43
+ ###
44
+ ### Classes mixing in this module are required to define a constant UPLOAD_TYPES
45
+ ### which is a Hash of :type => :resource pairs, like this:
46
+ ###
47
+ ### UPLOAD_TYPES = {
48
+ ### :icon => :mobiledeviceapplicationsicon
49
+ ### :app => mobiledeviceapplicationsipa
50
+ ### :attachment => mobiledeviceapplications
51
+ ### }
52
+ ###
53
+ ### with one pair for each type of upload that the class can handle.
54
+ ### (most of them only handle one, usually :attachment)
55
+ ###
56
+ ### When the #upload method is called, one of the keys from that Hash must be specified
57
+ ###
58
+ ### Classes with only one upload type may want to redefine #upload to always call super with
59
+ ### that one type.
60
+ ###
61
+ ### ----
62
+ ###
63
+ ### Implementation Notes from
64
+ ### https://casperserver:8443/api/index.htm#!/fileuploads/uploadFiles_post
65
+ ###
66
+ ### POST ...JSSResource/fileuploads/<resource>/<idType>/<id>
67
+ ###
68
+ ### You can POST different types of files by entering parameters for <resource>, <idType>, and <id>.
69
+ ### For example /JSSResource/fileuploads/computers/id/2.
70
+ ###
71
+ ### Attachments can be uploaded by specifying computers, mobiledevices, enrollmentprofiles, or
72
+ ### peripherals as the resource.
73
+ ###
74
+ ### Icons can be uploaded by specifying policies, ebooks, or mobiledeviceapplicationsicon as the resource.
75
+ ###
76
+ ### A mobile device application can be uploaded by using mobiledeviceapplicationsipa as the resource.
77
+ ###
78
+ ### A disk encryption can be uploaded by specifying diskencryptionconfigurations as the resource.
79
+ ###
80
+ ### idTypes supported are "id" and "name", although peripheral names are not supported.
81
+ ###
82
+ ### A sample command is:
83
+ ### curl -k -u user:password https://my.jss:8443/JSSResource/fileuploads/computers/id/2 -F name=@/Users/admin/Documents/Sample.doc -X POST
84
+ ###
85
+ ###
86
+ ###
87
+ ###
88
+ module Uploadable
89
+
90
+ #####################################
91
+ ### Constants
92
+ #####################################
93
+
94
+ UPLOAD_RSRC_PREFIX = "fileuploads"
95
+
96
+ #####################################
97
+ ### Variables
98
+ #####################################
99
+
100
+
101
+ #####################################
102
+ ### Methods
103
+ #####################################
104
+
105
+ ###
106
+ ### Upload a file to the JSS via the REST Resource of the
107
+ ### object to which this module is mixed in.
108
+ ###
109
+ ### @param type[Symbol] the type of upload happening.
110
+ ### Must be one of the keys defined in the class's UPLOAD_TYPES Hash.
111
+ ###
112
+ ### @param local_file[String, Pathname] String or Pathname pointing to the
113
+ ### locally-readable file to be uploaded.
114
+ ###
115
+ ### @return [String] The xml response from the server.
116
+ ###
117
+ def upload(type, local_file)
118
+
119
+ ### the thing's gotta be in the JSS, and have an @id
120
+ raise JSS::NoSuchItemError, 'Create this #{self.class::RSRC_OBJECT_KEY} in the JSS before uploading files to it.' unless @id and @in_jss
121
+
122
+ ### the type has to be defined in the class of self.
123
+ raise JSS::InvalidDataError, "#{self.class::RSRC_LIST_KEY} only take uploads of type: :#{self.class::UPLOAD_TYPES.keys.join(', :')}." unless self.class::UPLOAD_TYPES.keys.include? type
124
+
125
+ ### figure out the resource after the UPLOAD_RSRC_PREFIX
126
+ upload_rsrc = "#{UPLOAD_RSRC_PREFIX}/#{self.class::UPLOAD_TYPES[type]}/id/#{@id}"
127
+
128
+ ### make a File object to hand to REST.
129
+ file = File.new local_file.to_s, 'rb'
130
+
131
+ ### upload it!
132
+ JSS::API.cnx[upload_rsrc].post :name => file
133
+
134
+ end # def upload file
135
+
136
+ end # module FileUpload
137
+
138
+ end # module JSS