Skip to content

Instantly share code, notes, and snippets.

@jgoldschrafe
Created September 21, 2014 07:17
Show Gist options
  • Save jgoldschrafe/47cb72a32e5193051624 to your computer and use it in GitHub Desktop.
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
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