Class: Vault::Provision::Prototype

Inherits:
Object
  • Object
show all
Defined in:
lib/vault/provision/prototype.rb

Overview

prototype for the individual hierarchy paths

Defined Under Namespace

Classes: InvalidProvisioningFileError

Instance Method Summary collapse

Constructor Details

#initialize(boss) ⇒ Prototype

Returns a new instance of Prototype.



7
8
9
10
11
12
13
# File 'lib/vault/provision/prototype.rb', line 7

def initialize boss
  @vault = boss.vault
  @instance_dir = boss.instance_dir
  @intermediate_issuer = boss.intermediate_issuer
  @pki_allow_destructive = boss.pki_allow_destructive
  @aws_update_creds = boss.aws_update_creds
end

Instance Method Details

#mounts_by_type(type) ⇒ Object



29
30
31
32
# File 'lib/vault/provision/prototype.rb', line 29

def mounts_by_type type
  mounts = @vault.sys.mounts
  mounts.keys.select { |mp| mounts[mp].type == type }
end

#provision!Object



47
48
49
# File 'lib/vault/provision/prototype.rb', line 47

def provision!
  puts "#{self.class} says: Go climb a tree!"
end

#repo_filesObject



24
25
26
27
# File 'lib/vault/provision/prototype.rb', line 24

def repo_files
  return [] unless File.exist? repo_path
  Find.find(repo_path).select { |rf| rf.end_with?('.json') }
end

#repo_files_by_mount_type(type) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vault/provision/prototype.rb', line 34

def repo_files_by_mount_type type
  files = []
  mounts_by_type(type).each do |mp|
    next unless Dir.exist? "#{@instance_dir}/#{mp}"
    Find.find("#{@instance_dir}/#{mp}").each do |rf|
      next unless rf.end_with? '.json'
      files << rf
    end
  end
  files
end

#repo_pathObject



20
21
22
# File 'lib/vault/provision/prototype.rb', line 20

def repo_path
  "#{@instance_dir}/#{repo_prefix}"
end

#repo_prefixObject



15
16
17
18
# File 'lib/vault/provision/prototype.rb', line 15

def repo_prefix
  ActiveSupport::Inflector.underscore(self.class.to_s)
                          .split('/')[2..-1].join('/')
end

#validate_file!(path) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vault/provision/prototype.rb', line 51

def validate_file! path
  file_string = File.read(path)
  begin
    case File.extname(path)
    when '.json'
      JSON.parse file_string
    when '.hcl'
      Rhcl.parse file_string
    else
      raise InvalidProvisioningFileError.new("unknown filetype #{File.extname(path)}")
    end
    true
  rescue Racc::ParseError, JSON::ParserError, InvalidProvisioningFileError => e
    raise InvalidProvisioningFileError.new("Unable to parse file #{path}:\nšŸ±šŸ±šŸ±\n#{file_string}\nšŸ±šŸ±šŸ±\n#{e.class} #{e.message}")
  end
end