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, final = false) ⇒ 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
32
33
# File 'lib/cli/release.rb', line 10

def initialize(dir, final = false)
  @dir = dir
  @final = final

  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



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/cli/release.rb', line 96

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 config/final.yml") if @final
    unless @user_warned
      warning("Missing blobstore configuration, please update config/final.yml before making a final release")
      @user_warned = true
    end
    return nil
  end

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

  options = merge_private_data(provider, options)

  opts = Bosh::Common.symbolize_keys(options)
  @blobstore = Bosh::Blobstore::Client.safe_create(provider, opts)

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

#has_blobstore_secret?Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cli/release.rb', line 64

def has_blobstore_secret?
  bs = @private_config["blobstore"]

  return false unless @final_config['blobstore']

  # Add special handling for local blobstore which should not need need credentials
  provider = @final_config['blobstore']['provider']
  return true if provider == 'local'

  has_legacy_secret? ||
    has_blobstore_secrets?(bs, "simple", "user", "password") ||
    has_blobstore_secrets?(bs, "dav", "user", "password") ||
    has_blobstore_secrets?(bs, "s3", "access_key_id", "secret_access_key")
end

#has_legacy_secret?Boolean

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

Returns:

  • (Boolean)


60
61
62
# File 'lib/cli/release.rb', line 60

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

#save_configObject



121
122
123
124
# File 'lib/cli/release.rb', line 121

def save_config
  write_yaml(@dev_config_file, @dev_config)
  write_yaml(@final_config_file, @final_config)
end