ruby-jss 1.2.3 → 1.2.4a1
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/lib/jamf.rb +169 -0
- data/lib/jamf/api/abstract_classes/collection_resource.rb +422 -0
- data/lib/jamf/api/abstract_classes/generic_reference.rb +145 -0
- data/lib/jamf/api/abstract_classes/json_object.rb +1074 -0
- data/lib/jamf/api/abstract_classes/prestage.rb +219 -0
- data/lib/jamf/api/abstract_classes/prestage_skip_setup_items.rb +126 -0
- data/lib/jamf/api/abstract_classes/resource.rb +250 -0
- data/lib/jamf/api/abstract_classes/singleton_resource.rb +87 -0
- data/lib/jamf/api/attribute_classes/ip_address.rb +66 -0
- data/lib/jamf/api/attribute_classes/timestamp.rb +144 -0
- data/lib/jamf/api/connection.rb +734 -0
- data/lib/jamf/api/connection/api_error.rb +111 -0
- data/lib/jamf/api/connection/api_error_styleguide.rb +96 -0
- data/lib/jamf/api/connection/token.rb +220 -0
- data/lib/jamf/api/json_objects/account_prefs.rb +79 -0
- data/lib/jamf/api/json_objects/android_details.rb +139 -0
- data/lib/jamf/api/json_objects/appletv_details.rb +110 -0
- data/lib/jamf/api/json_objects/attachment.rb +68 -0
- data/lib/jamf/api/json_objects/cellular_network.rb +151 -0
- data/lib/jamf/api/json_objects/change_log_entry.rb +77 -0
- data/lib/jamf/api/json_objects/computer_prestage_skip_setup_items.rb +67 -0
- data/lib/jamf/api/json_objects/country.rb +51 -0
- data/lib/jamf/api/json_objects/extension_attribute_value.rb +128 -0
- data/lib/jamf/api/json_objects/installed_application.rb +59 -0
- data/lib/jamf/api/json_objects/installed_certificate.rb +53 -0
- data/lib/jamf/api/json_objects/installed_configuration_profile.rb +67 -0
- data/lib/jamf/api/json_objects/installed_ebook.rb +58 -0
- data/lib/jamf/api/json_objects/installed_provisioning_profile.rb +59 -0
- data/lib/jamf/api/json_objects/inventory_preload_extension_attribute.rb +52 -0
- data/lib/jamf/api/json_objects/ios_details.rb +244 -0
- data/lib/jamf/api/json_objects/location.rb +95 -0
- data/lib/jamf/api/json_objects/md_prestage_name.rb +57 -0
- data/lib/jamf/api/json_objects/md_prestage_names.rb +82 -0
- data/lib/jamf/api/json_objects/md_prestage_skip_setup_items.rb +165 -0
- data/lib/jamf/api/json_objects/mobile_device_details.rb +219 -0
- data/lib/jamf/api/json_objects/mobile_device_security.rb +101 -0
- data/lib/jamf/api/json_objects/prestage_assignment.rb +61 -0
- data/lib/jamf/api/json_objects/prestage_location.rb +104 -0
- data/lib/jamf/api/json_objects/prestage_purchasing_data.rb +132 -0
- data/lib/jamf/api/json_objects/prestage_scope.rb +54 -0
- data/lib/jamf/api/json_objects/prestage_sync_status.rb +63 -0
- data/lib/jamf/api/json_objects/purchasing_data.rb +125 -0
- data/lib/jamf/api/mixins/abstract.rb +58 -0
- data/lib/jamf/api/mixins/bulk_deletable.rb +39 -0
- data/lib/jamf/api/mixins/change_log.rb +136 -0
- data/lib/jamf/api/mixins/extendable.rb +75 -0
- data/lib/jamf/api/mixins/immutable.rb +39 -0
- data/lib/jamf/api/mixins/locatable.rb +124 -0
- data/lib/jamf/api/mixins/lockable.rb +48 -0
- data/lib/jamf/api/mixins/referable.rb +92 -0
- data/lib/jamf/api/mixins/searchable.rb +202 -0
- data/lib/jamf/api/mixins/uncreatable.rb +40 -0
- data/lib/jamf/api/mixins/undeletable.rb +40 -0
- data/lib/jamf/api/resources/collection_resources/account.rb +163 -0
- data/lib/jamf/api/resources/collection_resources/building.rb +114 -0
- data/lib/jamf/api/resources/collection_resources/category.rb +82 -0
- data/lib/jamf/api/resources/collection_resources/computer.rb +49 -0
- data/lib/jamf/api/resources/collection_resources/computer_prestage.rb +80 -0
- data/lib/jamf/api/resources/collection_resources/department.rb +79 -0
- data/lib/jamf/api/resources/collection_resources/extension_attribute.rb +45 -0
- data/lib/jamf/api/resources/collection_resources/inventory_preload_record.rb +274 -0
- data/lib/jamf/api/resources/collection_resources/md_prestage.rb +139 -0
- data/lib/jamf/api/resources/collection_resources/mobile_device.rb +315 -0
- data/lib/jamf/api/resources/collection_resources/script.rb +190 -0
- data/lib/jamf/api/resources/collection_resources/site.rb +77 -0
- data/lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb +131 -0
- data/lib/jamf/api/resources/singleton_resources/authorization.rb +88 -0
- data/lib/jamf/api/resources/singleton_resources/client_checkin_settings.rb +139 -0
- data/lib/jamf/api/resources/singleton_resources/reenrollment_settings.rb +95 -0
- data/lib/jamf/client.rb +301 -0
- data/lib/jamf/client/jamf_binary.rb +132 -0
- data/lib/jamf/client/jamf_helper.rb +298 -0
- data/lib/jamf/client/management_action.rb +114 -0
- data/lib/jamf/compatibility.rb +88 -0
- data/lib/jamf/composer.rb +190 -0
- data/lib/jamf/configuration.rb +281 -0
- data/lib/jamf/exceptions.rb +107 -0
- data/lib/jamf/ruby_extensions.rb +36 -0
- data/lib/jamf/ruby_extensions/array.rb +35 -0
- data/lib/jamf/ruby_extensions/array/predicates.rb +46 -0
- data/lib/jamf/ruby_extensions/array/utils.rb +47 -0
- data/lib/jamf/ruby_extensions/filetest.rb +32 -0
- data/lib/jamf/ruby_extensions/filetest/predicates.rb +46 -0
- data/lib/jamf/ruby_extensions/hash.rb +33 -0
- data/lib/jamf/ruby_extensions/hash/backports.rb +92 -0
- data/lib/jamf/ruby_extensions/ipaddr.rb +37 -0
- data/lib/jamf/ruby_extensions/ipaddr/utils.rb +95 -0
- data/lib/jamf/ruby_extensions/object.rb +30 -0
- data/lib/jamf/ruby_extensions/object/predicates.rb +51 -0
- data/lib/jamf/ruby_extensions/pathname.rb +39 -0
- data/lib/jamf/ruby_extensions/pathname/predicates.rb +50 -0
- data/lib/jamf/ruby_extensions/pathname/utils.rb +75 -0
- data/lib/jamf/ruby_extensions/string.rb +35 -0
- data/lib/jamf/ruby_extensions/string/backports.rb +66 -0
- data/lib/jamf/ruby_extensions/string/conversions.rb +65 -0
- data/lib/jamf/ruby_extensions/string/predicates.rb +47 -0
- data/lib/jamf/utility.rb +423 -0
- data/lib/jamf/validate.rb +224 -0
- data/lib/jamf/version.rb +32 -0
- data/lib/jpapi.rb +26 -0
- data/lib/jss/version.rb +1 -1
- metadata +104 -4
@@ -0,0 +1,111 @@
|
|
1
|
+
# Copyright 2019 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
|
+
# The module
|
26
|
+
module Jamf
|
27
|
+
|
28
|
+
class Connection
|
29
|
+
|
30
|
+
# TODO: figure out what to do with
|
31
|
+
# ConflictError, BadRequestError, APIRequestError
|
32
|
+
# and maybe AuthenticationError
|
33
|
+
class APIError < RuntimeError
|
34
|
+
|
35
|
+
RSRC_NOT_FOUND = 'Resource Not Found'.freeze
|
36
|
+
|
37
|
+
# Struct to hold the info for each individual error in an API error
|
38
|
+
# response body.
|
39
|
+
#
|
40
|
+
# Has these attributes (descriptions from developer.jamf.com):
|
41
|
+
#
|
42
|
+
# code: String
|
43
|
+
# Error-specific code that can be used to identify localization
|
44
|
+
# string, etc.
|
45
|
+
#
|
46
|
+
# field: String
|
47
|
+
# Name of the field that caused the error.
|
48
|
+
#
|
49
|
+
# description: String
|
50
|
+
# A general description of error for troubleshooting/debugging.
|
51
|
+
# Generally this text should not be displayed to a user; instead
|
52
|
+
# refer to errorCode and its localized text
|
53
|
+
#
|
54
|
+
# id: Integer
|
55
|
+
# id of object with error. 0 if not applicable
|
56
|
+
#
|
57
|
+
ErrorInfo = ImmutableStruct.new(:code, :field, :description, :id) do
|
58
|
+
def to_s
|
59
|
+
deets = "{code: #{code}"
|
60
|
+
deets << ", field: #{field}" if field
|
61
|
+
deets << ", id: #{id}" if id
|
62
|
+
deets << '}'
|
63
|
+
"#{description} #{deets}"
|
64
|
+
end
|
65
|
+
end # ErrorInfo
|
66
|
+
|
67
|
+
# @return [Faraday::Response]
|
68
|
+
attr_reader :http_response
|
69
|
+
|
70
|
+
# @return [integer]
|
71
|
+
#
|
72
|
+
attr_reader :httpStatus
|
73
|
+
alias status httpStatus
|
74
|
+
|
75
|
+
# @return [Array<ErrorInfo>] see ErrorInfo above
|
76
|
+
#
|
77
|
+
attr_reader :errors
|
78
|
+
|
79
|
+
# @return [RestClient::ExceptionWithResponse] the original RestClient error
|
80
|
+
attr_reader :rest_error
|
81
|
+
|
82
|
+
# @param rest_error [RestClient::ExceptionWithResponse]
|
83
|
+
def initialize(http_response)
|
84
|
+
@http_response = http_response
|
85
|
+
@httpStatus = http_response.status
|
86
|
+
|
87
|
+
@errors =
|
88
|
+
if @http_response.body.dig :errors
|
89
|
+
@http_response.body[:errors].map { |e| ErrorInfo.new e }
|
90
|
+
else
|
91
|
+
[]
|
92
|
+
end
|
93
|
+
|
94
|
+
if @errors.empty?
|
95
|
+
code = @httpStatus
|
96
|
+
desc = @httpStatus == 404 ? RSRC_NOT_FOUND : @http_response.reason_phrase
|
97
|
+
@errors << ErrorInfo.new(code: code, field: nil, description: desc, id: nil)
|
98
|
+
end
|
99
|
+
|
100
|
+
super
|
101
|
+
end
|
102
|
+
|
103
|
+
def to_s
|
104
|
+
@errors.map(&:to_s).join '; '
|
105
|
+
end
|
106
|
+
|
107
|
+
end # class APIError
|
108
|
+
|
109
|
+
end # class Connection
|
110
|
+
|
111
|
+
end # module JSS
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# Copyright 2019 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
|
+
|
26
|
+
# The module
|
27
|
+
module Jamf
|
28
|
+
|
29
|
+
# When the API returns an HTTP status other than 2xx or 3xx, the document body
|
30
|
+
# contains one of these.
|
31
|
+
#
|
32
|
+
class APIError < Jamf::JSONObject
|
33
|
+
|
34
|
+
OBJECT_MODEL = {
|
35
|
+
|
36
|
+
# @!attribute [r] traceId
|
37
|
+
# @return [String]
|
38
|
+
traceId: {
|
39
|
+
class: :string,
|
40
|
+
readonly: true
|
41
|
+
},
|
42
|
+
|
43
|
+
# @!attribute [r] errors
|
44
|
+
# @return [Array<Jamf::APIErrorDetail>]
|
45
|
+
errors: {
|
46
|
+
class: Jamf::APIErrorDetail,
|
47
|
+
readonly: true,
|
48
|
+
multi: true
|
49
|
+
}
|
50
|
+
|
51
|
+
}.freeze
|
52
|
+
|
53
|
+
parse_object_model
|
54
|
+
|
55
|
+
end # class APIError
|
56
|
+
|
57
|
+
# an individual error report in an APIError object
|
58
|
+
class APIErrorDetail < Jamf::JSONObject
|
59
|
+
|
60
|
+
OBJECT_MODEL = {
|
61
|
+
|
62
|
+
# @!attribute [r] objectId
|
63
|
+
# @return [String]
|
64
|
+
objectId: {
|
65
|
+
class: :string,
|
66
|
+
readonly: true
|
67
|
+
},
|
68
|
+
|
69
|
+
# @!attribute [r] reasonCode
|
70
|
+
# @return [String]
|
71
|
+
reasonCode: {
|
72
|
+
class: :string,
|
73
|
+
readonly: true
|
74
|
+
},
|
75
|
+
|
76
|
+
# @!attribute [r] field
|
77
|
+
# @return [String]
|
78
|
+
field: {
|
79
|
+
class: :string,
|
80
|
+
readonly: true
|
81
|
+
},
|
82
|
+
|
83
|
+
# @!attribute [r] description
|
84
|
+
# @return [String]
|
85
|
+
description: {
|
86
|
+
class: :string,
|
87
|
+
readonly: true
|
88
|
+
}
|
89
|
+
|
90
|
+
}.freeze
|
91
|
+
|
92
|
+
parse_object_model
|
93
|
+
|
94
|
+
end # class APIErrorDetail
|
95
|
+
|
96
|
+
end # module
|
@@ -0,0 +1,220 @@
|
|
1
|
+
# Copyright 2019 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
|
+
# The module
|
26
|
+
module Jamf
|
27
|
+
|
28
|
+
class Connection
|
29
|
+
|
30
|
+
# A token used for a JSS connection
|
31
|
+
class Token
|
32
|
+
|
33
|
+
AUTH_RSRC = 'auth'.freeze
|
34
|
+
|
35
|
+
NEW_TOKEN_RSRC = "#{AUTH_RSRC}/tokens".freeze
|
36
|
+
|
37
|
+
KEEP_ALIVE_RSRC = "#{AUTH_RSRC}/keepAlive".freeze
|
38
|
+
|
39
|
+
INVALIDATE_RSRC = "#{AUTH_RSRC}/invalidateToken".freeze
|
40
|
+
|
41
|
+
# this string is prepended to the token data when used for
|
42
|
+
# transaction authorization.
|
43
|
+
AUTH_TOKEN_PFX = 'jamf-token '.freeze
|
44
|
+
|
45
|
+
# @return [String] The user who generated this token
|
46
|
+
attr_reader :user
|
47
|
+
|
48
|
+
# @return [Jamf::Timestamp]
|
49
|
+
attr_reader :expires
|
50
|
+
alias expiration expires
|
51
|
+
|
52
|
+
# @return [String] The AUTH_TOKEN_PFX with the token data, used in the
|
53
|
+
# Authorization header of a request
|
54
|
+
attr_reader :auth_token
|
55
|
+
|
56
|
+
# @return [URI] The base API url, e.g. https://myjamf.jamfcloud.com/uapi
|
57
|
+
attr_reader :base_url
|
58
|
+
|
59
|
+
# when was this token created?
|
60
|
+
attr_reader :login_time
|
61
|
+
|
62
|
+
def initialize(**params)
|
63
|
+
@valid = false
|
64
|
+
@user = params[:user]
|
65
|
+
@base_url = params[:base_url].is_a?(String) ? URI.parse(params[:base_url]) : params[:base_url]
|
66
|
+
@timeout = params[:timeout] || Jamf::Connection::DFT_TIMEOUT
|
67
|
+
@ssl_options = params[:ssl_options] || {}
|
68
|
+
|
69
|
+
if params[:pw]
|
70
|
+
init_from_pw params[:pw]
|
71
|
+
elsif params[:token_string]
|
72
|
+
init_from_token_string params[:token_string]
|
73
|
+
else
|
74
|
+
raise ArgumentError, 'Must provide either pw: or token_string:'
|
75
|
+
end
|
76
|
+
|
77
|
+
end # init
|
78
|
+
|
79
|
+
# Initialize from password
|
80
|
+
def init_from_pw(pw)
|
81
|
+
resp = token_connection(
|
82
|
+
NEW_TOKEN_RSRC,
|
83
|
+
pw: pw,
|
84
|
+
timeout: @timeout,
|
85
|
+
ssl_opts: @ssl_options
|
86
|
+
).post
|
87
|
+
|
88
|
+
if resp.success?
|
89
|
+
parse_token_from_response resp
|
90
|
+
elsif resp.status == 401
|
91
|
+
raise Jamf::AuthenticationError, 'Incorrect name or password'
|
92
|
+
else
|
93
|
+
# TODO: better error reporting here
|
94
|
+
raise 'An error occurred while authenticating'
|
95
|
+
end
|
96
|
+
end # init_from_pw
|
97
|
+
|
98
|
+
# Initialize from token string
|
99
|
+
def init_from_token_string(str)
|
100
|
+
str = "#{AUTH_TOKEN_PFX}#{str}" unless str.start_with? AUTH_TOKEN_PFX
|
101
|
+
resp = token_connection(AUTH_RSRC, token: str).get
|
102
|
+
raise Jamf::InvalidDataError, 'Token string is not valid' unless resp.success?
|
103
|
+
|
104
|
+
@auth_token = str
|
105
|
+
@user = resp.body.dig :account, :username
|
106
|
+
# use this token to get a fresh one with a known expiration
|
107
|
+
keep_alive
|
108
|
+
end # init_from_token_string
|
109
|
+
|
110
|
+
# @return [String]
|
111
|
+
def host
|
112
|
+
@base_url.host
|
113
|
+
end
|
114
|
+
|
115
|
+
# @return [Integer]
|
116
|
+
def port
|
117
|
+
@base_url.port
|
118
|
+
end
|
119
|
+
|
120
|
+
# @return [String]
|
121
|
+
def api_version
|
122
|
+
token_connection(Jamf::Connection::SLASH, token: @auth_token ).get.body[:version]
|
123
|
+
end
|
124
|
+
|
125
|
+
# @return [Boolean]
|
126
|
+
def expired?
|
127
|
+
return unless @expires
|
128
|
+
Time.now >= @expires
|
129
|
+
end
|
130
|
+
|
131
|
+
# @return [Float]
|
132
|
+
def secs_remaining
|
133
|
+
return unless @expires
|
134
|
+
@expires - Time.now
|
135
|
+
end
|
136
|
+
|
137
|
+
# @return [String] e.g. "1 week 6 days 23 hours 49 minutes 56 seconds"
|
138
|
+
def time_remaining
|
139
|
+
return unless @expires
|
140
|
+
Jamf.humanize_secs secs_remaining
|
141
|
+
end
|
142
|
+
|
143
|
+
# @return [Boolean]
|
144
|
+
def valid?
|
145
|
+
@valid =
|
146
|
+
if expired?
|
147
|
+
false
|
148
|
+
elsif !@auth_token
|
149
|
+
false
|
150
|
+
else
|
151
|
+
token_connection(AUTH_RSRC, token: @auth_token).get.success?
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
# the Jamf::Account object assciated with this token
|
156
|
+
def account
|
157
|
+
return @account if @account
|
158
|
+
resp = token_connection(AUTH_RSRC, token: @auth_token).get
|
159
|
+
return unless resp.success?
|
160
|
+
|
161
|
+
@account = Jamf::APIAccount.new resp.body
|
162
|
+
end
|
163
|
+
|
164
|
+
# Use this token to get a fresh one
|
165
|
+
def keep_alive
|
166
|
+
raise 'Token has expired' if expired?
|
167
|
+
|
168
|
+
keep_alive_token_resp = token_connection(KEEP_ALIVE_RSRC, token: @auth_token).post
|
169
|
+
# TODO: better error reporting here
|
170
|
+
raise 'An error occurred while authenticating' unless keep_alive_token_resp.success?
|
171
|
+
|
172
|
+
parse_token_from_response keep_alive_token_resp
|
173
|
+
# parse_token_from_response keep_alive_rsrc.post('')
|
174
|
+
expires
|
175
|
+
end
|
176
|
+
alias refresh keep_alive
|
177
|
+
|
178
|
+
# Make this token invalid
|
179
|
+
def invalidate
|
180
|
+
@valid = !token_connection(INVALIDATE_RSRC, token: @auth_token).post.success?
|
181
|
+
end
|
182
|
+
alias destroy invalidate
|
183
|
+
|
184
|
+
# Private instance methods
|
185
|
+
#################################
|
186
|
+
private
|
187
|
+
|
188
|
+
# a generic, one-time Faraday connection for token
|
189
|
+
# acquision & manipulation
|
190
|
+
#
|
191
|
+
def token_connection(rsrc, token: nil, pw: nil, timeout: nil, ssl_opts: nil)
|
192
|
+
|
193
|
+
Faraday.new("#{@base_url}/#{rsrc}", ssl: ssl_opts ) do |con|
|
194
|
+
con.headers[Jamf::Connection::HTTP_ACCEPT_HEADER] = Jamf::Connection::MIME_JSON
|
195
|
+
con.response :json, parser_options: { symbolize_names: true }
|
196
|
+
con.options[:timeout] = timeout
|
197
|
+
con.options[:open_timeout] = timeout
|
198
|
+
if token
|
199
|
+
con.headers[:authorization] = token
|
200
|
+
else
|
201
|
+
con.basic_auth @user, pw
|
202
|
+
end
|
203
|
+
con.use Faraday::Adapter::NetHttp
|
204
|
+
end # Faraday.new
|
205
|
+
end # token_connection
|
206
|
+
|
207
|
+
# Parse the API token data into instance vars.
|
208
|
+
def parse_token_from_response(resp)
|
209
|
+
@token_response_body = resp.body
|
210
|
+
@auth_token = AUTH_TOKEN_PFX + @token_response_body[:token]
|
211
|
+
@expires = Jamf::Timestamp.new @token_response_body[:expires]
|
212
|
+
@login_time = Jamf::Timestamp.new Time.now
|
213
|
+
@valid = true
|
214
|
+
end
|
215
|
+
|
216
|
+
end # class Token
|
217
|
+
|
218
|
+
end # class Connection
|
219
|
+
|
220
|
+
end # module JSS
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Copyright 2019 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
|
+
|
26
|
+
# The Module
|
27
|
+
module Jamf
|
28
|
+
|
29
|
+
# Classes
|
30
|
+
#####################################
|
31
|
+
|
32
|
+
# Preferences for an administrator account in the JSS
|
33
|
+
class AccountPreferences < Jamf::JSONObject
|
34
|
+
|
35
|
+
# Object Model / Attributes
|
36
|
+
# See APIObject class documentation for details
|
37
|
+
# of how the OBJECT_MODEL hash works.
|
38
|
+
#####################################
|
39
|
+
OBJECT_MODEL = {
|
40
|
+
|
41
|
+
# @!attribute [r] language
|
42
|
+
# @return [String]
|
43
|
+
language: {
|
44
|
+
class: :string,
|
45
|
+
readonly: true
|
46
|
+
},
|
47
|
+
|
48
|
+
# @!attribute [r] dateFormat
|
49
|
+
# @return [String]
|
50
|
+
dateFormat: {
|
51
|
+
class: :string,
|
52
|
+
readonly: true
|
53
|
+
},
|
54
|
+
|
55
|
+
# @!attribute [r] region
|
56
|
+
# @return [String]
|
57
|
+
region: {
|
58
|
+
class: :string,
|
59
|
+
readonly: true
|
60
|
+
},
|
61
|
+
# @!attribute [r] timezone
|
62
|
+
# @return [String]
|
63
|
+
timezone: {
|
64
|
+
class: :string,
|
65
|
+
readonly: true
|
66
|
+
},
|
67
|
+
|
68
|
+
# @!attribute [r] isDisableRelativeDates
|
69
|
+
# @return [String]
|
70
|
+
isDisableRelativeDates: {
|
71
|
+
class: :boolean,
|
72
|
+
readonly: true
|
73
|
+
}
|
74
|
+
}.freeze
|
75
|
+
parse_object_model
|
76
|
+
|
77
|
+
end # class
|
78
|
+
|
79
|
+
end # module
|