Class: Berkshelf::Config

Inherits:
Buff::Config::JSON
  • Object
show all
Defined in:
lib/berkshelf/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = self.class.path, options = {}) ⇒ Config

Returns a new instance of Config.

Parameters:

  • path (String) (defaults to: self.class.path)
  • options (Hash) (defaults to: {})

    @see Buff::Config::JSON



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/berkshelf/config.rb', line 76

def initialize(path = self.class.path, options = {})
  super(path, options).tap do
    # Deprecation
    if !self.vagrant.omnibus.enabled.nil?
      Berkshelf.ui.warn "`vagrant.omnibus.enabled' is deprecated and " \
        "will be removed in a future release. Please remove the " \
        "`enabled' attribute from your Berkshelf config."
    end
    if !self.vagrant.vm.box_url.nil?
      Berkshelf.ui.warn "`vagrant.vm.box_url' is deprecated and " \
        "will be removed in a future release. Please remove the " \
        "`box_url' attribute from your Berkshelf config."
    end
  end
end

Class Method Details

.coerce_sslConfig

force proper X509 types from any configuration strings

Returns:



64
65
66
67
68
69
70
# File 'lib/berkshelf/config.rb', line 64

def coerce_ssl
  ssl = @instance.ssl
  ssl[:ca_cert] = OpenSSL::X509::Certificate.new(File.read(ssl[:ca_cert])) if ssl[:ca_cert] && ssl[:ca_cert].is_a?(String)
  ssl[:client_cert] = OpenSSL::X509::Certificate.new(File.read(ssl[:client_cert])) if ssl[:client_cert] && ssl[:client_cert].is_a?(String)
  ssl[:client_key] = OpenSSL::PKey::RSA.new(File.read(ssl[:client_key])) if ssl[:client_key] && ssl[:client_key].is_a?(String)
  @instance
end

.fileString?

Returns the contents of the file.

Returns:

  • (String, nil)

    the contents of the file



35
36
37
# File 'lib/berkshelf/config.rb', line 35

def file
  File.read(path) if File.exists?(path)
end

.instanceConfig

Instantiate and return or just return the currently instantiated Berkshelf configuration

Returns:



43
44
45
46
47
48
49
50
51
# File 'lib/berkshelf/config.rb', line 43

def instance
  @instance ||=
    if file
      from_json file
    else
      new
    end
  coerce_ssl
end

.local_locationString

Returns:



13
14
15
# File 'lib/berkshelf/config.rb', line 13

def local_location
  ENV["BERKSHELF_CONFIG"] || File.join(".", ".berkshelf", "config.json")
end

.pathString

Returns:



18
19
20
21
# File 'lib/berkshelf/config.rb', line 18

def path
  path = File.exists?(local_location) ? local_location : store_location
  File.expand_path(path)
end

.reloadConfig

Reload the currently instantiated Berkshelf configuration

Returns:



56
57
58
59
# File 'lib/berkshelf/config.rb', line 56

def reload
  @instance = nil
  self.instance
end

.set_config(config) ⇒ Object

Parameters:



24
25
26
# File 'lib/berkshelf/config.rb', line 24

def set_config(config)
  @instance = config
end

.set_path(new_path) ⇒ Object

Parameters:



29
30
31
# File 'lib/berkshelf/config.rb', line 29

def set_path(new_path)
  @instance = nil
end

.store_locationString

Returns:



8
9
10
# File 'lib/berkshelf/config.rb', line 8

def store_location
  File.join(Berkshelf.berkshelf_path, "config.json")
end