File tree 5 files changed +20
-30
lines changed
5 files changed +20
-30
lines changed Original file line number Diff line number Diff line change @@ -26,23 +26,31 @@ def initialize(app, env)
26
26
@logger = Log4r ::Logger . new ( "vagrant_google::action::connect_google" )
27
27
end
28
28
29
+ # Initialize Fog::Compute and add it to the environment
29
30
def call ( env )
30
31
provider_config = env [ :machine ] . provider_config
31
32
32
33
# Build fog config
33
34
fog_config = {
34
35
:provider => :google ,
35
36
:google_project => provider_config . google_project_id ,
36
- :google_client_email => provider_config . google_client_email
37
37
}
38
38
39
- fog_config [ :google_json_key_location ] = find_key ( provider_config . google_json_key_location , env )
39
+ unless provider_config . google_client_email . nil?
40
+ fog_config [ :google_client_email ] = provider_config . google_client_email
41
+ end
40
42
41
- @logger . info ( "Connecting to Google..." )
42
- env [ :google_compute ] = Fog ::Compute . new ( fog_config )
43
+ unless provider_config . google_json_key_location . nil?
44
+ fog_config [ :google_json_key_location ] = find_key ( provider_config . google_json_key_location , env )
45
+ end
46
+
47
+ if provider_config . google_client_email . nil? and provider_config . google_json_key_location . nil?
48
+ fog_config [ :google_application_default ] = true
49
+ end
43
50
51
+ @logger . info ( "Creating Google API client and adding to Vagrant environment" )
52
+ env [ :google_compute ] = Fog ::Compute . new ( fog_config )
44
53
@app . call ( env )
45
- @logger . info ( "...Connected!" )
46
54
end
47
55
48
56
# If the key is not found, try expanding from root location (see #159)
Original file line number Diff line number Diff line change @@ -421,13 +421,12 @@ def validate(machine)
421
421
# TODO: Check why provider-level settings are validated in the zone config
422
422
errors << I18n . t ( "vagrant_google.config.google_project_id_required" ) if \
423
423
config . google_project_id . nil?
424
- errors << I18n . t ( "vagrant_google.config.google_client_email_required" ) if \
425
- config . google_client_email . nil?
426
- errors << I18n . t ( "vagrant_google.config.google_key_location_required" ) if \
427
- config . google_json_key_location . nil?
428
- errors << I18n . t ( "vagrant_google.config.private_key_missing" ) unless \
429
- File . exist? ( File . expand_path ( config . google_json_key_location . to_s ) ) or
430
- File . exist? ( File . expand_path ( config . google_json_key_location . to_s , machine . env . root_path ) )
424
+
425
+ if config . google_json_key_location
426
+ errors << I18n . t ( "vagrant_google.config.private_key_missing" ) unless \
427
+ File . exist? ( File . expand_path ( config . google_json_key_location . to_s ) ) or
428
+ File . exist? ( File . expand_path ( config . google_json_key_location . to_s , machine . env . root_path ) )
429
+ end
431
430
432
431
if config . preemptible
433
432
errors << I18n . t ( "vagrant_google.config.auto_restart_invalid_on_preemptible" ) if \
Original file line number Diff line number Diff line change 52
52
# Translations for config validation errors
53
53
# -------------------------------------------------------------------------------
54
54
config :
55
- google_client_email_required : |-
56
- A Google Service Account client email is required via
57
- "google_client_email".
58
55
private_key_missing : |-
59
56
Private key for Google could not be found in the specified location.
60
57
zone_required : |-
63
60
An instance name must be specified via "name" option.
64
61
image_required : |-
65
62
An image must be specified via "image" or "image_family" option.
66
- google_key_location_required : |-
67
- A private key pathname is required via:
68
- "google_json_key_location" (for JSON keys)
69
63
google_project_id_required : |-
70
64
A Google Cloud Project ID is required via "google_project_id".
71
65
auto_restart_invalid_on_preemptible : |-
Original file line number Diff line number Diff line change 118
118
its ( "google_client_email" ) { should == "client_id_email" }
119
119
its ( "google_json_key_location" ) { should == "/path/to/json/key" }
120
120
end
121
-
122
- context "With none of the Google credential environment variables set" do
123
- before :each do
124
- allow ( ENV ) . to receive ( :[] ) . with ( "GOOGLE_CLIENT_EMAIL" ) . and_return ( "client_id_email" )
125
- end
126
-
127
- it "Should return no key set errors" do
128
- instance . finalize!
129
- expect ( instance . validate ( "foo" ) [ "Google Provider" ] [ 1 ] ) . to include ( "en.vagrant_google.config.google_key_location_required" )
130
- end
131
- end
132
121
end
133
122
134
123
describe "zone config" do
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
s . required_rubygems_version = ">= 1.3.6"
29
29
s . rubyforge_project = "vagrant-google"
30
30
31
- s . add_runtime_dependency "fog-google" , "~> 1.8 .1"
31
+ s . add_runtime_dependency "fog-google" , "~> 1.9 .1"
32
32
33
33
# This is a restriction to avoid errors on `failure_message_for_should`
34
34
# TODO: revise after vagrant_spec goes past >0.0.1 (at master@e623a56)
You can’t perform that action at this time.
0 commit comments