Sha256: 6ceda183e9ec28212fc2c8b8a609b5b4ebad341be26a675794fb8e0769b62bda

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

require 'rhcl'

# prototype for the individual hierarchy paths
class Vault::Provision::Prototype
  class InvalidProvisioningFileError < RuntimeError; end

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

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

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

  def repo_files
    Find.find(repo_path).select { |rf| rf.end_with?('.json') }
  end

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

  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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vault-provision-0.1.7 lib/vault/provision/prototype.rb
vault-provision-0.1.6 lib/vault/provision/prototype.rb
vault-provision-0.1.5 lib/vault/provision/prototype.rb
vault-provision-0.1.4 lib/vault/provision/prototype.rb