class Bosh::Workspace::ProjectDeployment

Constants

STUB_WHITELIST

Attributes

director_uuid[W]
file[R]
stub[W]

Public Class Methods

new(file) click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 10
def initialize(file)
  @file = file
  err("Deployment file does not exist: #{file}") unless File.exist?(@file)
end

Public Instance Methods

director_uuid() click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 21
def director_uuid
  @director_uuid || manifest["director_uuid"]
end
manifest() click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 37
def manifest
  return @manifest unless @manifest.nil?
  @manifest = YAML.load(ERB.new(IO.read(file)).result)
  validate_stub! unless stub.empty?
  @manifest = recursive_merge(@manifest, stub) unless stub.empty?
  @manifest
end
merge_tool() click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 33
def merge_tool
  Bosh::Workspace::MergeTool.new(manifest['merge_tool'])
end
merged_file() click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 25
def merged_file
  @merged_file ||= begin
    path = File.join(file_dirname, "../.deployments", file_basename)
    FileUtils.mkpath File.dirname(path)
    File.expand_path path
  end
end
perform_validation(options = {}) click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 15
def perform_validation(options = {})
  Schemas::ProjectDeployment.new.validate manifest
rescue Membrane::SchemaValidationError => e
  errors << e.message
end
stub() click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 45
def stub
  return @stub unless @stub.nil?
  @stub = stub_file ? load_stub : {}
end

Private Instance Methods

executable_stub?() click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 68
def executable_stub?
  File.executable?(stub_file)
end
execute_stub!() click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 81
def execute_stub!
  sh(stub_file, yield: :on_false) do |result|
    execute_stub_failed!(result.command, result.output) if result.failed?
  end.output
end
execute_stub_failed!(stub, output) click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 87
def execute_stub_failed!(stub, output)
  say("An error occured while executing stub file: #{stub}")
  err("error: '#{output}'")
end
file_basename(filter = '') click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 98
def file_basename(filter = '')
  File.basename(@file, filter)
end
file_dirname() click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 102
def file_dirname
  File.dirname(@file)
end
load_stub() click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 72
def load_stub
  begin
    YAML.load(executable_stub? ? execute_stub! : IO.read(stub_file))
  rescue Psych::SyntaxError => e
    say "Error loading stub file for deployment #{file} due to invalid YAML"
    err "error: #{e.message}"
  end
end
recursive_merge(source, target) click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 106
def recursive_merge(source, target)
  source.merge(target) do |_, old_value, new_value|
    if old_value.class == Hash && new_value.class == Hash
      recursive_merge(old_value, new_value)
    else
      new_value
    end
  end
end
stub_file() click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 62
def stub_file
  [file_basename, file_basename('.*')].map do |file|
    Dir[File.join(stubs_dir, file)]
  end.flatten.compact.first
end
stubs_dir() click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 58
def stubs_dir
  File.expand_path(File.join(file_dirname, "../stubs"))
end
validate_stub!() click to toggle source
# File lib/bosh/workspace/project_deployment.rb, line 92
def validate_stub!
  return unless stub.keys.any? { |k| !STUB_WHITELIST.include?(k) }
  offending_keys = stub.keys - STUB_WHITELIST
  err "Key: '#{offending_keys.first}' not allowed in stub file"
end