Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for current google-api-client (0.9) #172

Closed
jeremywadsack opened this issue Oct 31, 2016 · 11 comments
Closed

Support for current google-api-client (0.9) #172

jeremywadsack opened this issue Oct 31, 2016 · 11 comments

Comments

@jeremywadsack
Copy link

I've tried to integrate this with our system that already uses google-api-client 0.9.x, but it doesn't seem to work:

connection = Fog::Compute::Google.new(connection_args)
[fog][WARNING] Please install the google-api-client gem before using this provider
LoadError: cannot load such file -- google/api_client
	from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
	from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
	from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
	from ~/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
	from ~/.rvm/gems/ruby-2.3.1/gems/fog-google-0.4.2/lib/fog/google/shared.rb:37:in `initialize_google_client'
	from ~/.rvm/gems/ruby-2.3.1/gems/fog-google-0.4.2/lib/fog/compute/google/real.rb:14:in `initialize'
	from ~/.rvm/gems/ruby-2.3.1/gems/fog-core-1.43.0/lib/fog/core/service.rb:115:in `new'
	from ~/.rvm/gems/ruby-2.3.1/gems/fog-core-1.43.0/lib/fog/core/service.rb:115:in `new'
	from (irb):10

We have the client gem installed:

$ bundle show google-api-client
~/.rvm/gems/ruby-2.3.1/gems/google-api-client-0.9.19

Looking at the code, I see that you've written this for the old 0.8-style client API.

0.8 branch was last updated on April 14, 2015, more than 18 months ago.

To change to the new code you would require 'google/apis/compute_v1' and update the client calls as described in the MIGRATING doc.

I can take a stab at an overhaul PR, but have two questions:

  1. Am I missing something?
  2. Do you want to retain google-api-client 0.8.6 compatibility?
@icco
Copy link
Member

icco commented Nov 1, 2016

As we mention in the readme, we don't support 0.9 yet. Mainly because of time. We accept pull requests to upgrade us to 0.9 support, but currently do not support it.

@jeremywadsack
Copy link
Author

Thanks for the quick response.

I see that now.

gem 'google-api-client', '~> 0.8.6'

I guess I didn't realize on initial read this meant that it doesn't support 0.9, but that is what it says.

I will need to look at our requirements and whether we can use fog-google or if the direct API access is a better fit.

It looks like you were willing to drop older google-api-client support in a previous release (0.3.0). If I were to make this change would you be ok with making the forward path only compatible with google-api-client 0.9-series?

@icco
Copy link
Member

icco commented Nov 3, 2016

Oh totally, we'd love to make that a thing. I started #100 forever ago, but due to my work, I've been unable to touch it. If you'd like to send us a PR to get us there, we'd love to move forward.

@icco
Copy link
Member

icco commented Nov 3, 2016

Also, I'll update the readme to be more explicit.

@jeremywadsack
Copy link
Author

Ok, I'll take a look at it. I took a stab at getting our code to work directly with the API and it's not pretty. Would be nice to hide that inside of a Fog::Compute.new call.

      instance = Google::Apis::ComputeV1::Instance.new(
          :name          => "#{prefix}-#{SecureRandom.uuid}",
          :machine_type  => "zones/#{zone}/machineTypes/#{machine_type}",
          :zone          => zone,
          :disks         => [
              Google::Apis::ComputeV1::AttachedDisk.new(
                  boot: true,
                  auto_delete: true,
                  initialize_params: Google::Apis::ComputeV1::AttachedDiskInitializeParams.new(
                      source_image: "projects/google-containers/global/images/family/gci-stable"
                  )
              )
          ],
          :network_interfaces => [
              Google::Apis::ComputeV1::NetworkInterface.new(
                  network: "global/networks/default",
                  access_configs:[
                      Google::Apis::ComputeV1::AccessConfig.new(name: "External NAT", type: "ONE_TO_ONE_NAT")
                  ]
              )
          ],
          :metadata           => Google::Apis::ComputeV1::Metadata.new(
              items: [Google::Apis::ComputeV1::Metadata::Item.new(key: "user-data", value: cloud_config(config_variables(args)))]
          ),
          :service_accounts   => [Google::Apis::ComputeV1::ServiceAccount.new(
              email:  "default",
              scopes: [
                  "https://www.googleapis.com/auth/cloud.useraccounts.readonly",
                  "https://www.googleapis.com/auth/devstorage.read_only",
                  "https://www.googleapis.com/auth/service.management.readonly",
                  "https://www.googleapis.com/auth/servicecontrol",
              ]
          )],
          :scheduling         => Google::Apis::ComputeV1::Scheduling.new(preemptible: true)
      )

      service.insert_instance(
          Settings.google_api.cloud.project,
          zone,
          instance
      )

For my part, I'm not a fan of all the auto-generated classes for JSON objects, that could be more succinctly handled as Hashes.

@selmanj
Copy link
Contributor

selmanj commented Nov 4, 2016

@jeremywadsack +1 when referring to the classes vs just using plain hashes.

I'm working on adding coverage to the compute api for tests (the existing tests are flaky); hopefully I can send that PR soon so you'll be able to leverage it to feel more confident about your change.

@JanStevens
Copy link

Could we also use this client instead? https://github.com/GoogleCloudPlatform/google-cloud-ruby#storage it's a real API client (not an auto generated one). And supports the latest stuff on google cloud storage

@Temikus
Copy link
Member

Temikus commented Nov 24, 2016

@JanStevens While I do agree that it's nicer to use, it's still based on google-api-client, so it'll add yet another abstraction layer to wrangle with. Additionally, it doesn't support certain critical API's like compute.

If the library ever replaces google-api-client entirely - I will be the first one considering to replace it, believe me.

@selmanj
Copy link
Contributor

selmanj commented Nov 25, 2016

@JanStevens I'm curious which pieces are missing for Google cloud Storage that you'd like to use? Is it related to the JSON API?

@Temikus
Copy link
Member

Temikus commented Nov 25, 2016

Good point @selmanj!
@JanStevens - what are you missing? We'll add it.

@JanStevens
Copy link

@selmanj @Temikus After some research and digging in the code, yea it is based on google-api-client (didn't knew that before) so it doesn't really matter.

Originally I was looking for the signed urls from google, I'm using carrierwave with fog-google and couldn't find how to do this. Thats why I posted the issue since I did found it in the google-cloud-ruby storage API. Now I found out you can use authenticate_url.

So thanks for everything nvm my comment 🍡

@icco icco closed this as completed Nov 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants