Google-cloud-ruby: When can we expect AutoML support?

Created on 27 Sep 2018  路  4Comments  路  Source: googleapis/google-cloud-ruby

I would be very interested in using AutoML translate

question

All 4 comments

@dazuma @TheRoyalTnetennba Do either of you know the answer to this question?

Is there something I can use in the meantime until AutoML is supported?

The AutoML REST API requires 'gcloud auth print-access-token' as authentication, not entirely sure how to obtain this authentication key on a rails server

This question has also been asked for Google API Client in googleapis/google-api-ruby-client#721.

I spoke with the AutoML team, and the current plan is to produce the Ruby clients during early 2019. Until then, you can talk directly to the REST API as documented here.

@echan00 For authentication from Rails, our recommendation is to create a service account. Since as you mention, the access token from gcloud auth probably isn't available on a production rails server, since you probably don't have gcloud installed and logged in with your google account there.

Some getting started info is here. The steps are:

  • Create a service account in the cloud console.
  • Grant the necessary permissions to the service account to access AutoML.
  • Download a service account key. This is a JSON file that you should treat the same way as you would a password or other secret in your deployment.
  • In your Ruby code, get an access token from the Google auth service. Use the [googleauth gem] for this. It might look like this:
require "googleauth"
scope = "https://www.googleapis.com/auth/cloud-platform"
creds = File.open "/path/to/service_account_key.json" do |io|
  Google::Auth::ServiceAccountCredentials.make_creds json_key_io: io, scope: scope
end
access_token_info = creds.fetch_access_token!
access_token = access_token_info["access_token"]
  • That access token can then be sent in the Authorization header of requests. For example, using Faraday:
conn = Faraday.new(
  url: "https://automl.googleapis.com",
  headers: {"Authorization" => "Bearer #{access_token}",
    "Content-Type" => "application/json"})
response = conn.post # etc.

Access tokens expire after a period of time. If it does, fetch a new one from the creds object by calling fetch_access_token! again.

If you are running on Google infrastructure (such as Google Compute Engine, Kubernetes Engine, or App Engine), you can also use the "default" service account associated with the server you're running on. That makes it easier to get an access token. You don't need to create your own service account or download a key. Instead, do this:

require "googleauth"
scope = "https://www.googleapis.com/auth/cloud-platform"
creds = Google::Auth.get_application_default scope
access_token_info = creds.fetch_access_token!
access_token = access_token_info["access_token"]

Then use the access token in the Authorization header as above.

Was this page helpful?
0 / 5 - 0 ratings