Sha256: 78dd6189e83a9af600fa276c223d2a4c0d8a85b6a11c2562a3cec5db213bca4e
Contents?: true
Size: 1.97 KB
Versions: 9
Compression:
Stored size: 1.97 KB
Contents
# Copyright 2013 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require "fog/google" require "log4r" module VagrantPlugins module Google module Action # This action connects to Google, verifies credentials work, and # puts the Google connection object into the `:google_compute` key # in the environment. class ConnectGoogle def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant_google::action::connect_google") end def call(env) provider_config = env[:machine].provider_config # Build fog config fog_config = { :provider => :google, :google_project => provider_config.google_project_id, :google_client_email => provider_config.google_client_email } fog_config[:google_json_key_location] = find_key(provider_config.google_json_key_location, env) @logger.info("Connecting to Google...") env[:google_compute] = Fog::Compute.new(fog_config) @app.call(env) @logger.info("...Connected!") end # If the key is not found, try expanding from root location (see #159) def find_key(location, env) if File.file?(File.expand_path(location)) return File.expand_path(location) else return File.expand_path(location, env[:root_path]) end end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems