Class: VagrantPlugins::Lightsail::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-lightsail/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vagrant-lightsail/config.rb', line 20

def initialize
  @access_key_id     = UNSET_VALUE
  @availability_zone = UNSET_VALUE
  @aws_dir           = UNSET_VALUE
  @aws_profile       = UNSET_VALUE
  @blueprint_id      = UNSET_VALUE
  @bundle_id         = UNSET_VALUE
  @endpoint          = UNSET_VALUE
  @keypair_name      = UNSET_VALUE
  @port_info         = [UNSET_VALUE]
  @region            = UNSET_VALUE
  @secret_access_key = UNSET_VALUE
  @session_token     = UNSET_VALUE
  @user_data         = UNSET_VALUE
end

Instance Attribute Details

#access_key_idObject

Returns the value of attribute access_key_id.



6
7
8
# File 'lib/vagrant-lightsail/config.rb', line 6

def access_key_id
  @access_key_id
end

#availability_zoneObject

Returns the value of attribute availability_zone.



7
8
9
# File 'lib/vagrant-lightsail/config.rb', line 7

def availability_zone
  @availability_zone
end

#aws_dirObject

Returns the value of attribute aws_dir.



8
9
10
# File 'lib/vagrant-lightsail/config.rb', line 8

def aws_dir
  @aws_dir
end

#aws_profileObject

Returns the value of attribute aws_profile.



9
10
11
# File 'lib/vagrant-lightsail/config.rb', line 9

def aws_profile
  @aws_profile
end

#blueprint_idObject

Returns the value of attribute blueprint_id.



10
11
12
# File 'lib/vagrant-lightsail/config.rb', line 10

def blueprint_id
  @blueprint_id
end

#bundle_idObject

Returns the value of attribute bundle_id.



11
12
13
# File 'lib/vagrant-lightsail/config.rb', line 11

def bundle_id
  @bundle_id
end

#endpointObject

Returns the value of attribute endpoint.



12
13
14
# File 'lib/vagrant-lightsail/config.rb', line 12

def endpoint
  @endpoint
end

#keypair_nameObject

Returns the value of attribute keypair_name.



13
14
15
# File 'lib/vagrant-lightsail/config.rb', line 13

def keypair_name
  @keypair_name
end

#port_infoObject

Returns the value of attribute port_info.



14
15
16
# File 'lib/vagrant-lightsail/config.rb', line 14

def port_info
  @port_info
end

#regionObject

Returns the value of attribute region.



15
16
17
# File 'lib/vagrant-lightsail/config.rb', line 15

def region
  @region
end

#secret_access_keyObject

Returns the value of attribute secret_access_key.



16
17
18
# File 'lib/vagrant-lightsail/config.rb', line 16

def secret_access_key
  @secret_access_key
end

#session_tokenObject

Returns the value of attribute session_token.



17
18
19
# File 'lib/vagrant-lightsail/config.rb', line 17

def session_token
  @session_token
end

#user_dataObject

Returns the value of attribute user_data.



18
19
20
# File 'lib/vagrant-lightsail/config.rb', line 18

def user_data
  @user_data
end

Instance Method Details

#finalize!Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vagrant-lightsail/config.rb', line 36

def finalize!
  if @access_key_id == UNSET_VALUE || @secret_access_key == UNSET_VALUE
    @aws_profile = 'default'                   if @aws_profile == UNSET_VALUE
    @aws_dir     = ENV['HOME'].to_s + '/.aws/' if @aws_dir == UNSET_VALUE

    @aws_region, @access_key_id, @secret_access_key, @session_token = Credentials.new.get_aws_info(@aws_profile, @aws_dir)
    @region = @aws_region if @region == UNSET_VALUE && !@aws_region.nil?
  else
    @aws_profile = nil
    @aws_dir     = nil
  end

  @blueprint_id      = 'ubuntu_16_04' if @blueprint_id      == UNSET_VALUE
  @bundle_id         = 'nano_1_0'     if @bundle_id         == UNSET_VALUE
  @endpoint          = nil            if @endpoint          == UNSET_VALUE
  @keypair_name      = 'vagrant'      if @keypair_name      == UNSET_VALUE
  @port_info         = []             if @port_info         == [UNSET_VALUE]
  @region            = 'us-east-1'    if @region            == UNSET_VALUE
  @availability_zone = "#{@region}a"  if @availability_zone == UNSET_VALUE
  @session_token     = nil            if @session_token     == UNSET_VALUE
  @user_data         = nil            if @user_data         == UNSET_VALUE
end

#validate(_) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/vagrant-lightsail/config.rb', line 59

def validate(_)
  errors = []

  if @aws_profile && (@access_key_id.nil? || @secret_access_key.nil? || @region.nil?)
    errors << I18n.t('vagrant_lightsail.config.aws_info_required',
                     profile: @aws_profile, location: @aws_dir)
  end

  errors << I18n.t('vagrant_lightsail.config.port_info_array') unless @port_info.is_a? Array

  errors << I18n.t('vagrant_lightsail.config.region_required') if @region.nil?

  { 'Lightsail Provider' => errors }
end