Created
September 21, 2014 07:17
-
-
Save jgoldschrafe/47cb72a32e5193051624 to your computer and use it in GitHub Desktop.
Fog: Authenticate to Google Compute Engine (GCE) using an instance's service account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fog' | |
require 'google/api_client' | |
APP_NAME = "my-app" | |
APP_VERSION = "1.0.0" | |
GOOGLE_PROJECT = "my-project-808" | |
client = Google::APIClient.new({ | |
application_name: APP_NAME, | |
application_version: APP_VERSION, | |
user_agent: "fog/#{Fog::VERSION}" | |
}) | |
client.authorization = Google::APIClient::ComputeServiceAccount.new | |
client.authorization.fetch_access_token! | |
options = { | |
:provider => 'google', | |
:google_project => GOOGLE_PROJECT, | |
:google_client => client | |
} | |
connection = Fog::Compute.new(options) | |
networks = connection.networks.all | |
p networks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment