Class: JSS::DistributionPoint
- Defined in:
- lib/jss-api/api_object/distribution_point.rb,
lib/jss-api.rb
Overview
A Distribution Point in the JSS
As well as the normal Class and Instance methods for APIObject subclasses, the DistributionPoint class provides more interaction with other parts of the API.
Beyond the standard listing methods DistributionPoint.all, .all_ids, etc, every JSS has a single “master” distribution point. The Class method DistributionPoint.master_distribution_point will return the JSS::DistributionPoint object for that master.
Also, some network segments have specific DistributionPoints assigned to them. Calling the Class method DistributionPoint.my_distribution_point will return a JSS::DistributionPoint object for your local IP address.
Once you have an instance of JSS::DistributionPoint, you can mount it (on a Mac) by calling its #mount method and unmount it with #unmount. The Package and possibly Script classes use this to upload items to the master.
Constant Summary collapse
- RSRC_BASE =
The base for REST resources of this class
"distributionpoints"
- RSRC_LIST_KEY =
the hash key used for the JSON list output of all objects in the JSS its also used in various error messages
:distribution_points
- RSRC_OBJECT_KEY =
The hash key used for the JSON object output. It’s also used in various error messages
:distribution_point
- VALID_DATA_KEYS =
these keys, as well as :id and :name, are present in valid API JSON data for this class
[:read_only_username, :ssh_username, :is_master ]
- MOUNT_OPTIONS =
what are the mount options? these are comma-separated, and are passed with -o
'nobrowse'
- EMPTY_PW_256 =
An empty SHA256 digest
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
- @@master_distribution_point =
Class Variables
nil
- @@my_distribution_point =
nil
Constants inherited from APIObject
APIObject::DEFAULT_LOOKUP_KEYS, APIObject::REQUIRED_DATA_KEYS
Instance Attribute Summary collapse
-
#certificate ⇒ String
readonly
The name of the cert.
-
#certificate_required ⇒ Boolean
readonly
Do http downloads use cert.
-
#connection_type ⇒ String
readonly
Protocol for fileservice access (e.g. AFP, SMB).
-
#context ⇒ String
readonly
The “context” for http downloads (what goes after the hostname part of the URL).
-
#enable_load_balancing ⇒ String
readonly
Load balanacing enabled?.
-
#failover_point ⇒ Integer
readonly
The id of the DP to use for failover.
-
#failover_point_url ⇒ String
readonly
The URL to use if this one doesn’t work.
-
#http_downloads_enabled ⇒ Boolean
readonly
Are http downloads available from this DP?.
-
#http_password_sha256 ⇒ String
readonly
The password for http downloads, if needed, as a SHA256 digest.
-
#http_url ⇒ String
readonly
The URL for http downloads.
-
#http_username ⇒ String
readonly
The username to use for http downloads if needed for user/pw auth.
-
#ip_address ⇒ String
(also: #hostname)
readonly
The hostname of this DP.
-
#is_master ⇒ Boolean
readonly
Is this the master DP?.
-
#local_path ⇒ String
readonly
The local path on the server to the distribution point directory.
-
#no_authentication_required ⇒ Boolean
readonly
Do http downloads work without auth?.
-
#port ⇒ Integer
readonly
The port for http access.
-
#protocol ⇒ String
readonly
The protocol to use for http downloads (http/https).
-
#read_only_password_sha256 ⇒ String
readonly
Read-only password as a SHA256 digest.
-
#read_only_username ⇒ String
readonly
Read-only username for fileservice.
-
#read_write_password_sha256 ⇒ String
readonly
The read-write password as a SHA256 digest.
-
#read_write_username ⇒ String
readonly
The read-write username for fileservice access.
-
#share_name ⇒ String
readonly
The name of the fileservice sharepoint.
-
#share_port ⇒ Integer
readonly
The port for fileservice access.
-
#ssh_password_sha256 ⇒ String
readonly
The ssh password as a SHA256 digest.
-
#ssh_username ⇒ String
readonly
Ssh username.
-
#username_password_required ⇒ Boolean
readonly
Do http downloads use user/pw auth?.
-
#workgroup_or_domain ⇒ String
readonly
Work group or domain for SMB.
Attributes inherited from APIObject
#id, #in_jss, #name, #rest_rsrc
Class Method Summary collapse
-
.master_distribution_point(refresh = false) ⇒ JSS::DistributionPoint
Get the DistributionPoint instance for the master distribution point in the JSS.
-
.my_distribution_point(refresh = false) ⇒ JSS::DistributionPoint
Get the DistributionPoint instance for the machine running this code, based on its IP address.
Instance Method Summary collapse
-
#check_pw(user, pw) ⇒ Boolean, Nil
Check the validity of a password.
-
#initialize(args) ⇒ DistributionPoint
constructor
As well as the standard :id, :name, and :data, you can instantiate this class with :id => :master, in which case you’ll get the Master Distribution Point as defined in the JSS.
-
#mount(pw = nil, access = :ro1) ⇒ Pathname
Mount this distribution point locally.
-
#mounted? ⇒ Boolean
Is this thing mounted right now?.
-
#unmount ⇒ void
(also: #umount)
Unmount the distribution point.
Methods inherited from APIObject
all, all_ids, all_names, #delete, get_name, map_all_ids_to, #save, xml_list
Constructor Details
#initialize(args) ⇒ DistributionPoint
As well as the standard :id, :name, and :data, you can instantiate this class with :id => :master, in which case you’ll get the Master Distribution Point as defined in the JSS. An error will be raised if one hasn’t been defined.
You can also do this more easily by calling JSS.master_distribution_point
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 247 def initialize(args) @init_data = nil ### looking for master? if args[:id] == :master self.class.all_ids.each do |id| @init_data = JSS::API.get_rsrc("#{RSRC_BASE}/id/#{id}")[RSRC_OBJECT_KEY] if @init_data[:is_master] @id = @init_data[:id] @name = @init_data[:name] break end # if data is master @init_data = nil end # each id end # if args is master if @init_data.nil? super(args) end @ip_address = @init_data[:ip_address] @local_path = @init_data[:local_path] @enable_load_balancing = @init_data[:enable_load_balancing] @failover_point = @init_data[:failover_point] @is_master = @init_data[:is_master] @connection_type = @init_data[:connection_type] @share_port = @init_data[:share_port] @share_name = @init_data[:share_name] @workgroup_or_domain = @init_data[:workgroup_or_domain] @read_write_username = @init_data[:read_write_username] @read_write_password_sha256 = @init_data[:read_write_password_sha256] @read_only_username = @init_data[:read_only_username] @read_only_password_sha256 = @init_data[:read_only_password_sha256] @ssh_username = @init_data[:ssh_username] @ssh_password_sha256 = @init_data[:ssh_password_sha256] @http_username = @init_data[:http_username] @http_password_sha256 = @init_data[:http_password_sha256] @http_downloads_enabled = @init_data[:http_downloads_enabled] @protocol = @init_data[:protocol] @port = @init_data[:port] @context = @init_data[:context] @no_authentication_required = @init_data[:no_authentication_required] @certificate_required = @init_data[:certificate_required] @username_password_required = @init_data[:username_password_required] @certificate = @init_data[:certificate] @http_url = @init_data[:http_url] @failover_point_url = @init_data[:failover_point_url] @port = @init_data[:ssh_password] ### Note, as of Casper 9.3: ### :management_password_md5=>"xxxxx" ### and ### :management_password_sha256=> "xxxxxxxxxx" ### Are the read/write password ### ### An empty passwd is ### MD5 = d41d8cd98f00b204e9800998ecf8427e ### SHA256 = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 ### ### Seemms the read-only pw isn't available in the API ### if we mount for fileservice, where's the mountpoint? @mountpoint = Pathname.new "/Volumes/CasperDistribution-id-#{@id}" end |
Instance Attribute Details
#certificate ⇒ String (readonly)
Returns the name of the cert. used for http cert. auth.
223 224 225 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 223 def certificate @certificate end |
#certificate_required ⇒ Boolean (readonly)
Returns do http downloads use cert. authentication?.
211 212 213 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 211 def certificate_required @certificate_required end |
#connection_type ⇒ String (readonly)
Returns Protocol for fileservice access (e.g. AFP, SMB).
170 171 172 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 170 def connection_type @connection_type end |
#context ⇒ String (readonly)
Returns the “context” for http downloads (what goes after the hostname part of the URL).
205 206 207 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 205 def context @context end |
#enable_load_balancing ⇒ String (readonly)
Returns load balanacing enabled?.
159 160 161 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 159 def enable_load_balancing @enable_load_balancing end |
#failover_point ⇒ Integer (readonly)
Returns the id of the DP to use for failover.
162 163 164 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 162 def failover_point @failover_point end |
#failover_point_url ⇒ String (readonly)
Returns the URL to use if this one doesn’t work.
229 230 231 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 229 def failover_point_url @failover_point_url end |
#http_downloads_enabled ⇒ Boolean (readonly)
Returns are http downloads available from this DP?.
196 197 198 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 196 def http_downloads_enabled @http_downloads_enabled end |
#http_password_sha256 ⇒ String (readonly)
Returns the password for http downloads, if needed, as a SHA256 digest.
220 221 222 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 220 def http_password_sha256 @http_password_sha256 end |
#http_url ⇒ String (readonly)
Returns the URL for http downloads.
226 227 228 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 226 def http_url @http_url end |
#http_username ⇒ String (readonly)
Returns the username to use for http downloads if needed for user/pw auth.
217 218 219 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 217 def http_username @http_username end |
#ip_address ⇒ String (readonly) Also known as: hostname
Returns the hostname of this DP.
153 154 155 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 153 def ip_address @ip_address end |
#is_master ⇒ Boolean (readonly)
Returns is this the master DP?.
165 166 167 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 165 def is_master @is_master end |
#local_path ⇒ String (readonly)
Returns the local path on the server to the distribution point directory.
156 157 158 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 156 def local_path @local_path end |
#no_authentication_required ⇒ Boolean (readonly)
Returns do http downloads work without auth?.
208 209 210 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 208 def no_authentication_required @no_authentication_required end |
#port ⇒ Integer (readonly)
Returns the port for http access.
202 203 204 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 202 def port @port end |
#protocol ⇒ String (readonly)
Returns the protocol to use for http downloads (http/https).
199 200 201 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 199 def protocol @protocol end |
#read_only_password_sha256 ⇒ String (readonly)
Returns read-only password as a SHA256 digest.
188 189 190 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 188 def read_only_password_sha256 @read_only_password_sha256 end |
#read_only_username ⇒ String (readonly)
Returns read-only username for fileservice.
185 186 187 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 185 def read_only_username @read_only_username end |
#read_write_password_sha256 ⇒ String (readonly)
Returns the read-write password as a SHA256 digest.
182 183 184 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 182 def read_write_password_sha256 @read_write_password_sha256 end |
#read_write_username ⇒ String (readonly)
Returns the read-write username for fileservice access.
179 180 181 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 179 def read_write_username @read_write_username end |
#share_name ⇒ String (readonly)
Returns the name of the fileservice sharepoint.
176 177 178 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 176 def share_name @share_name end |
#share_port ⇒ Integer (readonly)
Returns the port for fileservice access.
173 174 175 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 173 def share_port @share_port end |
#ssh_password_sha256 ⇒ String (readonly)
Returns the ssh password as a SHA256 digest.
237 238 239 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 237 def ssh_password_sha256 @ssh_password_sha256 end |
#ssh_username ⇒ String (readonly)
Returns ssh username.
234 235 236 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 234 def ssh_username @ssh_username end |
#username_password_required ⇒ Boolean (readonly)
Returns do http downloads use user/pw auth?.
214 215 216 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 214 def username_password_required @username_password_required end |
#workgroup_or_domain ⇒ String (readonly)
Returns work group or domain for SMB.
191 192 193 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 191 def workgroup_or_domain @workgroup_or_domain end |
Class Method Details
.master_distribution_point(refresh = false) ⇒ JSS::DistributionPoint
Get the DistributionPoint instance for the master distribution point in the JSS. If there’s only one in the JSS, return it even if not marked as master.
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 113 def self.master_distribution_point(refresh = false) @@master_distribution_point = nil if refresh return @@master_distribution_point if @@master_distribution_point case self.all.count when 0 raise JSS::NoSuchItemError, "No distribution points defined" when 1 self.new :id => self.all_ids[0] else self.new :master end end |
.my_distribution_point(refresh = false) ⇒ JSS::DistributionPoint
Get the DistributionPoint instance for the machine running this code, based on its IP address. If none is defined for this IP address, use the result of master_distribution_point
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 135 def self.my_distribution_point(refresh = false) @@my_distribution_point = nil if refresh return @@my_distribution_point if @@my_distribution_point my_net_seg = JSS::NetworkSegment.my_network_segment[0] specific = if my_net_seg JSS::NetworkSegment.new(:id => my_net_seg).distribution_point else nil end return specific ? self.new(:name => specific) : self.master_distribution_point end |
Instance Method Details
#check_pw(user, pw) ⇒ Boolean, Nil
Check the validity of a password.
332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 332 def check_pw(user, pw) raise JSS::InvalidDataError, "The first parameter must be one of :ro, :rw, :ssh, :http" unless [:ro, :rw, :ssh, :http].include? user sha256 = case user when :rw then @read_write_password_sha256 when :ro then @read_only_password_sha256 when :http then @http_password_sha256 when :ssh then @ssh_password_sha256 end # case return nil if sha256 == EMPTY_PW_256 sha256 == Digest::SHA2.new(256).update(pw).to_s end |
#mount(pw = nil, access = :ro1) ⇒ Pathname
Mount this distribution point locally.
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 362 def mount(pw = nil, access = :ro1) return @mountpoint if mounted? access = :rw unless access == :ro password = if pw == :prompt JSS.prompt_for_password "Enter the password for the #{access} user '#{access == :ro ? @read_only_username : @read_write_username }':" elsif pw.is_a?(Symbol) and pw.to_s.start_with?('stdin') pw.to_s =~ /^stdin(\d+)$/ line = $1 line ||= 2 JSS.stdin line else pw end pwok = check_pw(access, password) unless pwok msg = pwok.nil? ? "No #{access} password set in the JSS" : "Incorrect password for #{access} account" raise JSS::InvalidDataError, msg end username = access == :ro ? @read_only_username : @read_write_username safe_pw = URI.escape password, /[^a-zA-Z\d]/ @mount_url = "#{@connection_type.downcase}://#{username}:#{safe_pw}@#{@ip_address}/#{@share_name}" @mnt_cmd = case @connection_type.downcase when 'smb' then '/sbin/mount_smbfs' when 'afp' then '/sbin/mount_afp' else raise "Can't mount distribution point #{@name}: no known connection type." end @mountpoint.mkpath #if system "#{@mnt_cmd} -o '#{MOUNT_OPTIONS}' '#{@mount_url}' '#{@mountpoint}'" if system @mnt_cmd.to_s, *['-o', MOUNT_OPTIONS, @mount_url, @mountpoint.to_s] @mounted = access else @mountpoint.rmdir if @mountpoint.directory? @mounted = nil raise JSS::FileServiceError, "There was a problem mounting #{@ip_address}" end return @mountpoint end |
#mounted? ⇒ Boolean
Is this thing mounted right now?
431 432 433 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 431 def mounted? @mountpoint.directory? and @mountpoint.mountpoint? end |
#unmount ⇒ void Also known as: umount
This method returns an undefined value.
Unmount the distribution point.
Does nothing if it wasn’t mounted with #mount.
414 415 416 417 418 419 420 421 422 423 |
# File 'lib/jss-api/api_object/distribution_point.rb', line 414 def unmount return nil unless mounted? if system "umount '#{@mountpoint}'" @mountpoint.rmdir if @mountpoint.directory? and (not @mountpoint.mountpoint?) @mounted = false else raise JSS::FileServiceError ,"There was a problem unmounting #{@mountpoint}" end nil end |