Class: VagrantPlugins::GSAuth::ExpandGSUrls

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-gsauth/middleware/expand_gs_urls.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, _) ⇒ ExpandGSUrls

Returns a new instance of ExpandGSUrls.



6
7
8
# File 'lib/vagrant-gsauth/middleware/expand_gs_urls.rb', line 6

def initialize(app, _)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vagrant-gsauth/middleware/expand_gs_urls.rb', line 10

def call(env)
  env[:box_urls].map! do |url_string|
    url = URI(url_string)

    if url.scheme == 'gs'
      bucket = url.host
      key = url.path[1..-1]
      raise Errors::MalformedShorthandURLError, url: url unless bucket && key
      next "https://storage.cloud.google.com/#{bucket}/#{key}"
    end

    url_string
  end

  @app.call(env)
end