Class: ManifestManager
- Inherits:
-
FileManager
- Object
- FileManager
- ManifestManager
- Defined in:
- lib/team-secrets/manifest_manager.rb
Instance Attribute Summary
Attributes inherited from FileManager
Instance Method Summary collapse
-
#initialize(master_key) ⇒ ManifestManager
constructor
A new instance of ManifestManager.
- #update ⇒ Object
- #validate ⇒ Object
Methods inherited from FileManager
Constructor Details
#initialize(master_key) ⇒ ManifestManager
Returns a new instance of ManifestManager.
5 6 7 8 9 10 11 12 13 |
# File 'lib/team-secrets/manifest_manager.rb', line 5 def initialize(master_key) unless (master_key.decrypted.is_a? String) && master_key.decrypted.length raise 'Master key must be decrypted' end @@working_dir = Dir.pwd @master_key = master_key @data = @data || {} end |
Instance Method Details
#update ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/team-secrets/manifest_manager.rb', line 53 def update ['users', 'secrets'].each do |file| file_name = file +'.yaml' absolute = @@working_dir +'/'+ file_name unless File.exists?(absolute) raise "#{file_name}.yaml does not exist, cannot update manifest" end signature = @master_key.sign File.read(absolute) @data[(file + '_file').to_sym] = { path: file_name, signature: signature } end end |
#validate ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/team-secrets/manifest_manager.rb', line 15 def validate unless File.exists?(@@working_dir +'/manifest.yaml') raise 'Required manifest.yaml does not exist' end loadFile(@@working_dir +'/manifest.yaml') unless @data.is_a? Object raise 'No valid data in manifest.yaml' end if @data[:secrets_file].nil? || @data[:users_file].nil? raise 'Manifest.yaml must list a secrets_file and users_file' end @data.each do |key, value| unless value.is_a? Object raise "#{key} does not have required data" end unless File.exists?(value[:path]) raise "#{key} does not exist" end file_string = File.read @data[key][:path] signature = @master_key.sign file_string unless signature == value[:signature] raise "#{key} signature does not match" end end true end |