Class: Vagrant::Action::Builtin::BoxAdd

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-s3auth/action/box_add.rb

Instance Method Summary collapse

Instance Method Details

#call_with_s3(env) ⇒ Object Also known as: call



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vagrant-s3auth/action/box_add.rb', line 7

def call_with_s3(env)
  box_url = env[:box_url]

  # Non-iterable box_urls are Vagrant Cloud boxes, which we don't need
  # to handle.
  if box_url.respond_to?(:map!)
    box_url.map! do |url|
      if matched = VagrantPlugins::S3Auth::BOX_URL_MATCHER.match(url)
        @logger.info('Transforming S3 box URL: #{url}')
        s3_url(matched[:bucket], matched[:resource])
      else
        @logger.info("Not transforming non-S3 box: #{url}")
        url
      end
    end
  else
    @logger.debug('Box URL #{box_url.inspect} looks like a Vagrant "
      Cloud box, skipping S3 transformation...')
  end

  call_without_s3(env)
end

#s3_url(bucket, resource) ⇒ Object



30
31
32
33
34
# File 'lib/vagrant-s3auth/action/box_add.rb', line 30

def s3_url(bucket, resource)
  URI::HTTPS.build(
    host: VagrantPlugins::S3Auth::S3_HOST,
    path: File.join('/', bucket, resource)).to_s
end