Class: VagrantFogBoxStorage::Config

Inherits:
Vagrant::Config::Base
  • Object
show all
Defined in:
lib/vagrant-fog-box-storage/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.key_namesObject



10
11
12
13
14
15
16
17
18
# File 'lib/vagrant-fog-box-storage/config.rb', line 10

def self.key_names
  [
    :provider,
    :access_key_id,
    :secret_access_key,
    :bucket_name,
    :box_file_name
  ]
end

Instance Method Details

#box_directoryObject



46
47
48
49
50
51
52
# File 'lib/vagrant-fog-box-storage/config.rb', line 46

def box_directory
  directory = cloud_directories.get(self.bucket_name)

  raise CloudStorageBucketNotFound.new("#{self.bucket_name} does not exist") if !directory

  directory
end

#box_urlObject



64
65
66
67
68
69
70
# File 'lib/vagrant-fog-box-storage/config.rb', line 64

def box_url
  files = directory_files()

  url = files.get_https_url(self.box_file_name, expiry_time)

  url
end

#cloud_directoriesObject



42
43
44
# File 'lib/vagrant-fog-box-storage/config.rb', line 42

def cloud_directories
  cloud_storage.directories
end

#cloud_storageObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vagrant-fog-box-storage/config.rb', line 30

def cloud_storage
  if is_used?
    provider_name = self.provider.to_s.downcase

    @cloud_storage ||= Fog::Storage.new({
      :provider => self.provider,
      :"#{provider_name}_access_key_id" => self.access_key_id,
      :"#{provider_name}_secret_access_key" => self.secret_access_key
    })
  end
end

#directory_filesObject



54
55
56
57
58
# File 'lib/vagrant-fog-box-storage/config.rb', line 54

def directory_files
  directory = box_directory()

  directory.files
end

#expiry_timeObject



60
61
62
# File 'lib/vagrant-fog-box-storage/config.rb', line 60

def expiry_time
  Time.now + 3600
end

#is_used?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/vagrant-fog-box-storage/config.rb', line 24

def is_used?
  self.class.key_names.any? do |name|
    !self.send(name).nil?
  end
end

#validate(env, errors) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/vagrant-fog-box-storage/config.rb', line 72

def validate(env, errors)
  if is_used?
    errors.add('missing provider')          if !self.provider
    errors.add('missing access_key_id')     if !self.access_key_id
    errors.add('missing secret_access_key') if !self.secret_access_key
    errors.add('missing bucket_name')       if !self.bucket_name
    errors.add('missing box_file_name')     if !self.box_file_name
  end
end