ruby-jss 1.0.3b4 → 1.0.3b5
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 +15 -1
- data/lib/jss.rb +1 -0
- data/lib/jss/api_object/mdm.rb +1 -1
- data/lib/jss/api_object/package.rb +171 -2
- 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: 4484b1e28fa48b3359c0fa3e1f946f516e1606ba3e699f16226d98fd83a4d87f
|
4
|
+
data.tar.gz: 70e69a2e1e38c7f2106661ee58eced3cd60d132c7c11b22449a4b5cfca210277
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2075c974cf726e611d170ba82eafd202b5d3028201359ef57648654ca3c71df31f8237046891891d362f28bbeb8202d11a89c0e28a71eea6b1928d3a54824a8e
|
7
|
+
data.tar.gz: c134e904917e2b0557134d856db08a38cbc3a60aed6ceac7ace77144b070155b8771e00dd0fb33d484d4b96d80567991eab53ef8862d372b47be98d70e6d2c0b
|
data/CHANGES.md
CHANGED
@@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
12
12
|
|
13
13
|
- LDAPServer.server_for_user and .server_for_group class methods, return the id of the first LDAP server containing the given user or group
|
14
14
|
|
15
|
-
- Client.
|
15
|
+
- Client.homedir(user) and Client.do_not_disturb?(user)
|
16
16
|
|
17
17
|
- Package.all_filenames, .orphaned_files, and .missing_files class methods. WARNING - these are very slow since they must instantiate every package.
|
18
18
|
|
@@ -25,6 +25,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
25
25
|
`JSS.api.connect server: 'myjss.myserver.edu', server_path: 'dev_mgmt/jssweb', port: 8443 [...]`
|
26
26
|
(Thanks @christopher.kemp!)
|
27
27
|
|
28
|
+
- Packages in Jamf Pro 10.10 and higher now include checksum data (`hash_type` and `hash_value` in the raw data) via the classic API. This has been integrated into JSS::Package via the following methods:
|
29
|
+
- New Class Method `JSS::Package.calculate_checksum(filepath, type)` calcuates an MD5 or SHA_512 hash for an arbtrary file.
|
30
|
+
- New Instance Methods:
|
31
|
+
- `JSS::Package#checksum` returns the checksum value
|
32
|
+
- `JSS::Package#checksum_type` returns the string 'MD5' or 'SHA_512' ('SHA_512' if no checksum is set)
|
33
|
+
- `JSS::Package#caluclate_checksum(type: nil, local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true )` recalculates and returns the checksum from a local file or the master dist. point. Doesn't change the Package instance
|
34
|
+
- `JSS::Package#checksum_valid?(local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true)` recalculates the checksum from a local file or the master dist. point, and returns Boolean true if it matches the stored one, false if not. Always false if there is no stored checksum. Doesn't change the Package instance
|
35
|
+
- `JSS::Package#reset_checksum(type: nil, local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true)` recalculates and resets the checksum from a local file or the master dist. point. The instance must be saved back to the server for the new checksum to stick,
|
36
|
+
- Modified Instance Method `JSS::Package#upload_master_file` now takes a `cksum:` parameter, 'MD5' or 'SHA_512' ('SHA_512' by default) Any other value means 'don't use a checksum on this package'
|
37
|
+
|
38
|
+
NOTE: Checksum calculation can be slow.
|
39
|
+
WARNING: when using a local file to calculate checksums, BE 100% SURE it is identical to the file on the master distribution point, or you will get an invalid checksum.
|
40
|
+
|
41
|
+
|
28
42
|
### Fixed
|
29
43
|
- JSS::MobileDevice.update now returns the device's jss id, as advertised.
|
30
44
|
|
data/lib/jss.rb
CHANGED
data/lib/jss/api_object/mdm.rb
CHANGED
@@ -453,7 +453,7 @@ module JSS
|
|
453
453
|
|
454
454
|
# make sure all of them are managed, or else the API will raise a 400
|
455
455
|
# 'Bad Request' when sending the command to an unmanaged target
|
456
|
-
all_mgd = self.map_all_ids_to(:managed).select { |_id, mgd| mgd }.keys
|
456
|
+
all_mgd = self.map_all_ids_to(:managed, api: api).select { |_id, mgd| mgd }.keys
|
457
457
|
|
458
458
|
targets.each do |target_id|
|
459
459
|
raise JSS::UnmanagedError, "#{self} with id #{target_id} is not managed. Cannot send command." unless all_mgd.include? target_id
|
@@ -23,6 +23,9 @@
|
|
23
23
|
#
|
24
24
|
#
|
25
25
|
|
26
|
+
# TEMPPORARY
|
27
|
+
require 'digest'
|
28
|
+
|
26
29
|
module JSS
|
27
30
|
|
28
31
|
# Classes
|
@@ -82,6 +85,21 @@ module JSS
|
|
82
85
|
# The table in the database for this object
|
83
86
|
DB_TABLE = 'packages'.freeze
|
84
87
|
|
88
|
+
# The hash_type value in the API for md5
|
89
|
+
CHECKSUM_HASH_TYPE_MD5 = 'MD5'.freeze
|
90
|
+
|
91
|
+
# The hash_type value in the API for sha512
|
92
|
+
CHECKSUM_HASH_TYPE_SHA512 = 'SHA_512'.freeze
|
93
|
+
|
94
|
+
# Mapping of the hash types to the maching Digest modules
|
95
|
+
# See {#calculate_checksum}
|
96
|
+
CHECKSUM_HASH_TYPES = {
|
97
|
+
CHECKSUM_HASH_TYPE_MD5 => Digest::MD5,
|
98
|
+
CHECKSUM_HASH_TYPE_SHA512 => Digest::SHA512
|
99
|
+
}.freeze
|
100
|
+
|
101
|
+
DEFAULT_CHECKSUM_HASH_TYPE = CHECKSUM_HASH_TYPE_SHA512
|
102
|
+
|
85
103
|
# the object type for this object in
|
86
104
|
# the object history table.
|
87
105
|
# See {APIObject#add_object_history_entry}
|
@@ -159,6 +177,21 @@ module JSS
|
|
159
177
|
all_filenames(api: api) - files_on_mdp
|
160
178
|
end
|
161
179
|
|
180
|
+
# Given a file path, and hash type, generate the checksum for an arbitrary
|
181
|
+
# file.
|
182
|
+
#
|
183
|
+
# @param filepath [String, Pathname] The file to checksum
|
184
|
+
#
|
185
|
+
# @param type [String ] One of the keys of CHECKSUM_HASH_TYPES, either
|
186
|
+
# CHECKSUM_HASH_TYPE_MD5 or CHECKSUM_HASH_TYPE_SHA512
|
187
|
+
#
|
188
|
+
# @return [String] The checksum of the file
|
189
|
+
#
|
190
|
+
def self.calculate_checksum(filepath, type = DEFAULT_CHECKSUM_HASH_TYPE )
|
191
|
+
raise ArgumentError, 'Unknown checksum hash type' unless CHECKSUM_HASH_TYPES.key? type
|
192
|
+
CHECKSUM_HASH_TYPES[type].file(filepath).hexdigest
|
193
|
+
end
|
194
|
+
|
162
195
|
# Attributes
|
163
196
|
#####################################
|
164
197
|
|
@@ -207,6 +240,14 @@ module JSS
|
|
207
240
|
# @return [Boolean] does this pkg cause a notification to be sent on self-heal?
|
208
241
|
attr_reader :send_notification
|
209
242
|
|
243
|
+
# @ @return [Symbol] The checksum hash type used to generate the checksum value,
|
244
|
+
# either :md5 or :sha512, defaults to :sha512 if there is no checksum yet.
|
245
|
+
attr_reader :checksum_type
|
246
|
+
|
247
|
+
# @return [String, nil] the checksum value for the package file on the
|
248
|
+
# dist. point, if it's been calculated.
|
249
|
+
attr_reader :checksum
|
250
|
+
|
210
251
|
# @see JSS::APIObject#initialize
|
211
252
|
#
|
212
253
|
def initialize(args = {})
|
@@ -231,6 +272,10 @@ module JSS
|
|
231
272
|
@send_notification = @init_data[:send_notification]
|
232
273
|
@switch_with_package = @init_data[:switch_with_package] || DO_NOT_INSTALL
|
233
274
|
|
275
|
+
@checksum = @init_data[:hash_value] #ill be nil if no checksum
|
276
|
+
@checksum_type = @checksum ? @init_data[:hash_type] : DEFAULT_CHECKSUM_HASH_TYPE
|
277
|
+
|
278
|
+
|
234
279
|
# the receipt is the filename with any .zip extension removed.
|
235
280
|
@receipt = @filename ? (JSS::Client::RECEIPTS_FOLDER + @filename.to_s.sub(/.zip$/, '')) : nil
|
236
281
|
end # init
|
@@ -516,9 +561,12 @@ module JSS
|
|
516
561
|
#
|
517
562
|
# @param unmount[Boolean] whether or not ot unount the distribution point when finished.
|
518
563
|
#
|
564
|
+
# @param chksum [String] the constants CHECKSUM_HASH_TYPE_SHA512 or
|
565
|
+
# CHECKSUM_HASH_TYPE_MD5. Anything else means don't calc.
|
566
|
+
#
|
519
567
|
# @return [void]
|
520
568
|
#
|
521
|
-
def upload_master_file(local_file_path, rw_pw, unmount = true)
|
569
|
+
def upload_master_file(local_file_path, rw_pw, unmount = true, chksum: DEFAULT_CHECKSUM_HASH_TYPE )
|
522
570
|
raise JSS::NoSuchItemError, 'Please create this package in the JSS before uploading it.' unless @in_jss
|
523
571
|
|
524
572
|
mdp = JSS::DistributionPoint.master_distribution_point api: @api
|
@@ -557,14 +605,126 @@ module JSS
|
|
557
605
|
destination = destination.to_s + '.zip'
|
558
606
|
@filename = zipfile.basename.to_s
|
559
607
|
@need_to_update = true
|
560
|
-
update
|
561
608
|
end # if directory
|
562
609
|
|
563
610
|
FileUtils.copy_entry local_path, destination
|
564
611
|
|
612
|
+
if CHECKSUM_HASH_TYPES.keys.include? chksum
|
613
|
+
@checksum_type = chksum
|
614
|
+
@checksum = calculate_checksum local_path, chksum
|
615
|
+
@need_to_update = true
|
616
|
+
end
|
617
|
+
|
618
|
+
update if @need_to_update
|
619
|
+
|
565
620
|
mdp.unmount if unmount
|
566
621
|
end # upload
|
567
622
|
|
623
|
+
# Using either a local file, or the file on the master dist. point,
|
624
|
+
# re-set the checksum for this package. Call #update to save the
|
625
|
+
# new one to the JSS.
|
626
|
+
#
|
627
|
+
# BE VERY CAREFUL if using a local copy of the file - make sure its
|
628
|
+
# identical to the one on the dist point.
|
629
|
+
#
|
630
|
+
# This can be used to change the checksum type, and by default will use
|
631
|
+
# DEFAULT_CHECKSUM_HASH_TYPE ('SHA_512')
|
632
|
+
#
|
633
|
+
# @param @see calculate_checksum
|
634
|
+
#
|
635
|
+
# @return [void]
|
636
|
+
#
|
637
|
+
def reset_checksum(type: nil, local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true)
|
638
|
+
type ||= DEFAULT_CHECKSUM_HASH_TYPE
|
639
|
+
|
640
|
+
new_checksum = calculate_checksum(
|
641
|
+
type: type,
|
642
|
+
local_file: local_file,
|
643
|
+
rw_pw: rw_pw,
|
644
|
+
ro_pw: ro_pw,
|
645
|
+
unmount: unmount
|
646
|
+
)
|
647
|
+
return if @checksum == new_checksum
|
648
|
+
|
649
|
+
@checksum_type = type
|
650
|
+
@checksum = new_checksum
|
651
|
+
@need_to_update = true
|
652
|
+
end
|
653
|
+
|
654
|
+
# Caclulate and return the checksum hash for a given local file, or the file
|
655
|
+
# on the master dist point if no local file is given.
|
656
|
+
#
|
657
|
+
# @param type [String] The checksum hash type, one of the keys of
|
658
|
+
# CHECKSUM_HASH_TYPES
|
659
|
+
#
|
660
|
+
# @param local_file [String, Pathname] A local copy of the pkg file. BE SURE
|
661
|
+
# it's identical to the one on the server. If omitted, the master dist.
|
662
|
+
# point will be mounted and the file read from there.
|
663
|
+
#
|
664
|
+
# @param rw_pw [String] The read-write password for mounting the master dist
|
665
|
+
# point. Either this or the ro_pw must be provided if no local_file
|
666
|
+
#
|
667
|
+
# @param ro_pw [String] The read-onlypassword for mounting the master dist
|
668
|
+
# point. Either this or the rw_pw must be provided if no local_file
|
669
|
+
#
|
670
|
+
# @param unmount [Boolean] Unmount the master dist point after using it.
|
671
|
+
# Only used if the dist point is mounted. default: true
|
672
|
+
#
|
673
|
+
# @return [String] The calculated checksum
|
674
|
+
#
|
675
|
+
def calculate_checksum(type: nil, local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true )
|
676
|
+
type ||= DEFAULT_CHECKSUM_HASH_TYPE
|
677
|
+
mdp = JSS::DistributionPoint.master_distribution_point api: @api
|
678
|
+
|
679
|
+
if local_file
|
680
|
+
file_to_calc = local_file
|
681
|
+
else
|
682
|
+
if rw_pw
|
683
|
+
dppw = rw_pw
|
684
|
+
mnt = :rw
|
685
|
+
elsif ro_pw
|
686
|
+
dppw = ro_pw
|
687
|
+
mnt = :ro
|
688
|
+
else
|
689
|
+
raise ArgumentError, 'Either rw_pw: or ro_pw: must be provided'
|
690
|
+
end
|
691
|
+
file_to_calc = mdp.mount(dppw, mnt) + "#{DIST_POINT_PKGS_FOLDER}/#{@filename}"
|
692
|
+
end
|
693
|
+
new_checksum = self.class.calculate_checksum(file_to_calc, type)
|
694
|
+
mdp.unmount if unmount && mdp.mounted?
|
695
|
+
new_checksum
|
696
|
+
end
|
697
|
+
|
698
|
+
# Is the checksum for this pkg is valid?
|
699
|
+
#
|
700
|
+
# @param local_file [String, Pathname] A local copy of the pkg file. BE SURE
|
701
|
+
# it's identical to the one on the server. If omitted, the master dist.
|
702
|
+
# point will be mounted and the file read from there.
|
703
|
+
#
|
704
|
+
# @param rw_pw [String] The read-write password for mounting the master dist
|
705
|
+
# point. Either this or the ro_pw must be provided if no local_file
|
706
|
+
#
|
707
|
+
# @param ro_pw [String] The read-onlypassword for mounting the master dist
|
708
|
+
# point. Either this or the rw_pw must be provided if no local_file
|
709
|
+
#
|
710
|
+
# @param unmount [Boolean] Unmount the master dist point after using it.
|
711
|
+
# Only used if the dist point is mounted. default: true
|
712
|
+
#
|
713
|
+
# @return [Boolean] false if there is no checksum for this pkg, otherwise,
|
714
|
+
# does the calculated checksum match the one stored for the pkg?
|
715
|
+
#
|
716
|
+
def checksum_valid?(local_file: nil, rw_pw: nil, ro_pw: nil, unmount: true)
|
717
|
+
return false unless @checksum
|
718
|
+
new_checksum = calculate_checksum(
|
719
|
+
type: @checksum_type,
|
720
|
+
local_file: local_file,
|
721
|
+
rw_pw: rw_pw,
|
722
|
+
ro_pw: ro_pw,
|
723
|
+
unmount: unmount
|
724
|
+
)
|
725
|
+
new_checksum == @checksum
|
726
|
+
end
|
727
|
+
|
568
728
|
# Change the name of a package file on the master distribution point.
|
569
729
|
#
|
570
730
|
# @param new_file_name[String]
|
@@ -595,6 +755,8 @@ module JSS
|
|
595
755
|
nil
|
596
756
|
end # update_master_filename
|
597
757
|
|
758
|
+
|
759
|
+
|
598
760
|
# Delete the filename from the master distribution point, if it exists.
|
599
761
|
#
|
600
762
|
# If you'll be uploading several files you can specify unmount as false, and do it manually when all
|
@@ -856,6 +1018,13 @@ module JSS
|
|
856
1018
|
pkg.add_element('required_processor').text = @required_processor.to_s.empty? ? 'None' : @required_processor
|
857
1019
|
pkg.add_element('send_notification').text = @send_notification
|
858
1020
|
pkg.add_element('switch_with_package').text = @switch_with_package
|
1021
|
+
# if there's no checksum value for this pkg, don't even include the
|
1022
|
+
# hash_type and hash_value in the XML, they'll stay whatever
|
1023
|
+
# the JSS already has (which is usuall type=MD5, and value='')
|
1024
|
+
if @checksum
|
1025
|
+
pkg.add_element('hash_type').text = @checksum_type
|
1026
|
+
pkg.add_element('hash_value').text = @checksum
|
1027
|
+
end
|
859
1028
|
add_category_to_xml(doc)
|
860
1029
|
doc.to_s
|
861
1030
|
end # rest xml
|
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.3b5
|
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: 2019-
|
12
|
+
date: 2019-05-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: plist
|