Class: Bosh::Cli::Release

Inherits:
Object show all
Defined in:
lib/cli/release.rb

Overview

This class encapsulates the details of handling dev and final releases: also it partitions release metadata between final config (which is under version control) and user dev config.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Release

Returns a new instance of Release.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cli/release.rb', line 10

def initialize(dir)
  @dir = dir
  config_dir = File.join(dir, "config")
  @final_config_file = File.join(config_dir, "final.yml")
  @dev_config_file = File.join(config_dir, "dev.yml")

  @private_config_file = File.join(config_dir, "private.yml")

  unless File.directory?(dir)
    err("Cannot find release directory `#{dir}'")
  end

  unless File.directory?(config_dir)
    err("Cannot find release config directory `#{config_dir}'")
  end

  @final_config = load_config(@final_config_file)
  @dev_config = load_config(@dev_config_file)
  @private_config = load_config(@private_config_file)

  migrate_legacy_configs
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



8
9
10
# File 'lib/cli/release.rb', line 8

def dir
  @dir
end

Instance Method Details

#blobstoreBosh::Blobstore::Client

Picks blobstore client to use with current release.

Returns:

  • (Bosh::Blobstore::Client)

    blobstore client



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/cli/release.rb', line 65

def blobstore
  return @blobstore if @blobstore
  blobstore_config = Marshal.load(Marshal.dump(@final_config["blobstore"]))

  if blobstore_config.nil?
    err("Missing blobstore configuration, please update your release")
  end

  provider = blobstore_config["provider"]
  options  = blobstore_config["options"] || {}

  if has_blobstore_secret?
    options["secret"] = @private_config["blobstore_secret"]
  end

  @blobstore = Bosh::Blobstore::Client.create(provider,
                                              symbolize_keys(options))

rescue Bosh::Blobstore::BlobstoreError => e
  err("Cannot initialize blobstore: #{e}")
end

#has_blobstore_secret?Boolean

Check if the blobstore secret is provided in the private config file

Returns:

  • (Boolean)


58
59
60
# File 'lib/cli/release.rb', line 58

def has_blobstore_secret?
  @private_config.has_key?("blobstore_secret")
end

#save_configObject



87
88
89
90
91
92
93
94
95
96
# File 'lib/cli/release.rb', line 87

def save_config
  # TODO: introduce write_yaml helper
  File.open(@dev_config_file, "w") do |f|
    YAML.dump(@dev_config, f)
  end

  File.open(@final_config_file, "w") do |f|
    YAML.dump(@final_config, f)
  end
end