Skip to content

Support fog-core 2.5 and up #636

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

Merged
merged 9 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
22 changes: 11 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Getting Involved

New contributors are always welcome, and when in doubt please ask questions!
New contributors are always welcome, and when in doubt please ask questions!
We strive to be an open and welcoming community. Please be nice to one another.

We recommend heading over to fog's [CONTRIBUTING](https://github.com/fog/fog/blob/master/CONTRIBUTING.md)
We recommend heading over to fog's [CONTRIBUTING](https://github.com/fog/fog/blob/master/CONTRIBUTING.md)
and having a look around as well. It has information and context about the state of the `fog` project as a whole.

### Coding
Expand Down Expand Up @@ -62,7 +62,7 @@ $ rake console
### Documentation

Code should be documented using [YARDoc](https://yardoc.org/) syntax.
We use [inch](https://github.com/rrrene/inch) to keep track of overall doc
We use [inch](https://github.com/rrrene/inch) to keep track of overall doc
coverage and [inch-ci](https://inch-ci.org/) to keep track of changes over time.

You can view a doc coverage report by running:
Expand All @@ -72,19 +72,19 @@ $ inch

Or view suggestions on a specific method:
```
$ inch show Fog::Compute::Google::Server#set_metadata
$ inch show Fog::Google::Compute::Server#set_metadata
```

### Testing

This module is tested with [Minitest](https://github.com/seattlerb/minitest).
This module is tested with [Minitest](https://github.com/seattlerb/minitest).

#### Integration tests

Live integration tests can be found in `test/integration/`.
Live integration tests can be found in `test/integration/`.

Most of the library functionality is currently covered with them. To simplify things for contributors we have a
CI system that runs all integration tests in parallel against all pull requests marked with `integrate` label
CI system that runs all integration tests in parallel against all pull requests marked with `integrate` label
that anyone in `fog-google` team can set. Read [CI section](https://github.com/fog/fog-google/blob/master/CONTRIBUTING.md#continuous-integration)
for more info.

Expand Down Expand Up @@ -137,7 +137,7 @@ We're in progress of extending the library with more unit tests and contribution

#### The transition from `shindo` to Minitest

Previously, [shindo](https://github.com/geemus/shindo) was the primary testing framework.
Previously, [shindo](https://github.com/geemus/shindo) was the primary testing framework.
We've moved away from it, and to Minitest, but some artifacts may remain.

For more information on transition, read [#50](https://github.com/fog/fog-google/issues/50).
Expand All @@ -158,10 +158,10 @@ and contains the standard tests to run for all resources, (e.g. `test_lifecycle`
It also calls `cleanup` on the resource's factory during teardown, to make sure
that resources are getting destroyed before the next test run.
- The **factory**, (e.g. `ServersFactory`, in `test/integration/factories/servers_factory.rb`,)
automates the creation of resources and/or supplies parameters for explicit
automates the creation of resources and/or supplies parameters for explicit
creation of resources. For example, `ServersFactory` initializes a `DisksFactory`
to supply disks in order to create servers, and implements the `params` method
so that tests can create servers with unique names, correct zones and machine
so that tests can create servers with unique names, correct zones and machine
types, and automatically-created disks. `ServersFactory` inherits the `create`
method from `CollectionFactory`, which allows tests to create servers on-demand.
- The **main test**, (e.g. `TestServers`, in `test/integration/compute/test_servers.rb`,)
Expand All @@ -170,6 +170,6 @@ method from `CollectionFactory`, which allows tests to create servers on-demand.
it initializes a `ServersFactory`, and it includes any other tests specific to
this collection, (e.g. `test_bootstrap_ssh_destroy`).

If you want to create another resource, you should add live integration tests;
If you want to create another resource, you should add live integration tests;
all you need to do is create a factory in `test/integration/factories/my_resource_factory.rb`
and a main test in `test/integration/compute/test_my_resource.rb` that mixes in `TestCollection`.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ We're proud to be sponsored by MeisterLabs who are generously funding our CI sta

## Storage

There are two ways to access [Google Cloud Storage](https://cloud.google.com/storage/). The old S3 API and the new JSON API. `Fog::Storage::Google` will automatically direct you to the appropriate API based on the credentials you provide it.
There are two ways to access [Google Cloud Storage](https://cloud.google.com/storage/). The old S3 API and the new JSON API. `Fog::Google::Storage` will automatically direct you to the appropriate API based on the credentials you provide it.

* The [XML API](https://cloud.google.com/storage/docs/xml-api-overview/) is almost identical to S3. Use [Google's interoperability keys](https://cloud.google.com/storage/docs/migrating#keys) to access it.
* The new [JSON API](https://cloud.google.com/storage/docs/json_api/) is faster and uses auth similarly to the rest of the Google Cloud APIs using a [service account private key](https://developers.google.com/identity/protocols/OAuth2ServiceAccount).
Expand All @@ -33,7 +33,7 @@ There are two ways to access [Google Cloud Storage](https://cloud.google.com/sto

Google Compute Engine is a Virtual Machine hosting service. Currently it is built on version [v1](https://cloud.google.com/compute/docs/reference/v1/) of the GCE API.

As of 2017-12-15, we are still working on making Fog for Google Compute engine (`Fog::Compute::Google`) feature complete. If you are using Fog to interact with GCE, please keep Fog up to date and [file issues](https://github.com/fog/fog-google/issues) for any anomalies you see or features you would like.
As of 2017-12-15, we are still working on making Fog for Google Compute engine (`Fog::Google::Compute`) feature complete. If you are using Fog to interact with GCE, please keep Fog up to date and [file issues](https://github.com/fog/fog-google/issues) for any anomalies you see or features you would like.

## SQL

Expand Down Expand Up @@ -112,10 +112,10 @@ Example workflow for a GCE instance with [service account scopes](https://cloud.
defined:

```
> connection = Fog::Compute::Google.new(:google_project => "my-project", :google_application_default => true)
=> #<Fog::Compute::Google::Real:32157700...
> connection = Fog::Google::Compute.new(:google_project => "my-project", :google_application_default => true)
=> #<Fog::Google::Compute::Real:32157700...
> connection.servers
=> [ <Fog::Compute::Google::Server ... ]
=> [ <Fog::Google::Compute::Server ... ]
```

#### CarrierWave integration
Expand Down Expand Up @@ -166,9 +166,9 @@ Once you've specified your credentials, you should be good to go!
$ bundle exec pry
[1] pry(main)> require 'fog/google'
=> true
[2] pry(main)> connection = Fog::Compute::Google.new
[2] pry(main)> connection = Fog::Google::Compute.new
[3] pry(main)> connection.servers
=> [ <Fog::Compute::Google::Server
=> [ <Fog::Google::Compute::Server
name="xxxxxxx",
kind="compute#instance",
```
Expand Down
13 changes: 6 additions & 7 deletions examples/create_instance_and_attach_disk_later.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ def example

p "Attach second disk to the running server"
device_name = "fog-smoke-test-device-#{Time.now.to_i}"
# See https://github.com/fog/fog-google/blob/master/lib/fog/compute/google/models/disk.rb#L75-L107
# See https://github.com/fog/fog-google/blob/master/lib/fog/compute/google/models/server.rb#L35-L50
# See https://github.com/fog/fog-google/blob/master/lib/fog/google/compute/models/disk.rb#L75-L107
# See https://github.com/fog/fog-google/blob/master/lib/fog/google/compute/models/server.rb#L35-L50
config_hash = {
:device_name => device_name,
:source => "https://www.googleapis.com/compute/v1/projects/#{PROJECT}/zones/#{ZONE}/disks/#{attached_disk.name}"
}
raise "Could not attach second disk" unless connection.attach_disk(server.name, ZONE, config_hash)

p "Waiting for disk to be attached"
attached_disk.wait_for { ! users.nil? && users != []}
attached_disk.wait_for { !users.nil? && users != [] }

p "Detach second disk"
raise "Could not detach second disk" unless connection.detach_disk(server.name, ZONE, device_name)

p "Waiting for second disk to be detached"
attached_disk.wait_for { users.nil? || users == []}
attached_disk.wait_for { users.nil? || users == [] }

p "Deleting server"
raise "Could not delete server." unless server.destroy
Expand All @@ -74,9 +74,8 @@ def example

p "Waiting for second disk to be destroyed"
begin
rc = attached_disk.wait_for { status.nil? || status == 'DELETING' }

rescue => e
rc = attached_disk.wait_for { status.nil? || status == "DELETING" }
rescue StandardError => e
if e.message !~ /not found/ && e.message !~ /notFound/
raise e
end
Expand Down
2 changes: 1 addition & 1 deletion examples/dns/project.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def test
connection = Fog::DNS::Google.new
connection = Fog::Google::DNS.new

puts "Get the Project limits..."
puts "-------------------------"
Expand Down
2 changes: 1 addition & 1 deletion examples/dns/zones.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def test
connection = Fog::DNS::Google.new
connection = Fog::Google::DNS.new

puts "Create a Zone..."
puts "----------------"
Expand Down
2 changes: 1 addition & 1 deletion examples/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Storage -> Storage -> Settings -> "Interoperability" tab -> "Create a new key"

def test
connection = Fog::Storage::Google.new
connection = Fog::Google::Storage.new

puts "Put a bucket..."
puts "----------------"
Expand Down
2 changes: 1 addition & 1 deletion examples/storage_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Storage -> Storage -> Settings -> "Interoperability" tab -> "Create a new key"

def test
connection = Fog::Storage::Google.new
connection = Fog::Google::Storage.new

puts "Put a bucket..."
puts "----------------"
Expand Down
2 changes: 1 addition & 1 deletion fog-google.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
# As of 0.1.1
spec.required_ruby_version = ">= 2.0"

spec.add_dependency "fog-core", "< 2.5"
spec.add_dependency "fog-core", "~> 2.5"
spec.add_dependency "fog-json", "~> 1.2"
spec.add_dependency "fog-xml", "~> 0.1.0"

Expand Down
48 changes: 23 additions & 25 deletions lib/fog/bin/google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ class << self
def class_for(key)
case key
when :compute
Fog::Compute::Google
Fog::Google::Compute
when :dns
Fog::DNS::Google
Fog::Google::DNS
when :monitoring
Fog::Google::Monitoring
when :storage
Fog::Storage::Google
Fog::Google::Storage
when :storage_json
Fog::Storage::Google
Fog::Google::Storage
when :sql
Fog::Google::SQL
when :pubsub
Expand All @@ -24,25 +24,22 @@ def class_for(key)

def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Ruby LSP on VSCode reformatted this. I don't see an issue here, but I can revert this if you prefer to avoid any unnecessary changes.

when :compute
Fog::Logger.warning("Google[:compute] is not recommended, use Compute[:google] for portability")
Fog::Compute.new(:provider => "Google")
when :dns
Fog::Logger.warning("Google[:dns] is not recommended, use DNS[:google] for portability")
Fog::DNS.new(:provider => "Google")
when :monitoring
Fog::Google::Monitoring.new
when :sql
Fog::Google::SQL.new
when :pubsub
Fog::Google::Pubsub.new
when :storage
Fog::Logger.warning("Google[:storage] is not recommended, use Storage[:google] for portability")
Fog::Storage.new(:provider => "Google")
else
raise ArgumentError, "Unrecognized service: #{key.inspect}"
end
case key
when :compute
hash[key] = Fog::Compute.new(:provider => "Google")
when :dns
hash[key] = Fog::DNS.new(:provider => "Google")
when :monitoring
hash[key] = Fog::Google::Monitoring.new
when :sql
hash[key] = Fog::Google::SQL.new
when :pubsub
hash[key] = Fog::Google::Pubsub.new
when :storage
hash[key] = Fog::Storage.new(:provider => "Google")
else
hash[key] = raise ArgumentError, "Unrecognized service: #{key.inspect}"
end
end
@@connections[service]
end
Expand Down Expand Up @@ -74,7 +71,7 @@ def available?
rescue ArgumentError => e
Fog::Logger.warning(e.message)
availability = false
rescue => e
rescue StandardError => e
availability = false
end
end
Expand All @@ -83,7 +80,8 @@ def available?
services.each do |service|
class_for(service).collections.each do |collection|
next if respond_to?(collection)
class_eval <<-EOS, __FILE__, __LINE__

class_eval <<-EOS, __FILE__, __LINE__ + 1
def self.#{collection}
self[:#{service}].#{collection}
end
Expand Down
46 changes: 30 additions & 16 deletions lib/fog/google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
require "fog/google/version"

module Fog
module Compute
autoload :Google, File.expand_path("../compute/google", __FILE__)
end

module DNS
autoload :Google, File.expand_path("../dns/google", __FILE__)
end

module Google
autoload :Compute, File.expand_path("../google/compute", __FILE__)
autoload :DNS, File.expand_path("../google/dns", __FILE__)
autoload :Mock, File.expand_path("../google/mock", __FILE__)
autoload :Monitoring, File.expand_path("../google/monitoring", __FILE__)
autoload :Pubsub, File.expand_path("../google/pubsub", __FILE__)
autoload :Shared, File.expand_path("../google/shared", __FILE__)
autoload :SQL, File.expand_path("../google/sql", __FILE__)
autoload :Storage, File.expand_path("../google/storage", __FILE__)
autoload :StorageJSON, 'fog/google/storage/storage_json'
autoload :StorageXML, 'fog/google/storage/storage_xml'

extend Fog::Provider

Expand All @@ -37,17 +34,34 @@ def self.escape(str, extra_exclude_chars = "")
"%" + Regexp.last_match(1).unpack("H2" * Regexp.last_match(1).bytesize).join("%").upcase
end
end
end

module Parsers
module Storage
autoload :Google, File.expand_path("../parsers/storage/google", __FILE__)
module Parsers
autoload :Storage, 'fog/google/parsers/storage'
end
end
end

module Storage
autoload :Google, File.expand_path("../storage/google", __FILE__)
autoload :GoogleJSON, File.expand_path("../storage/google_json", __FILE__)
autoload :GoogleXML, File.expand_path("../storage/google_xml", __FILE__)
# Add shims for backward compatibility
# This allows old style references like Fog::Compute::Google to work
# by redirecting them to the new namespace Fog::Google::Compute

module Fog
# List of services from the original module
GOOGLE_SERVICES = %w[Compute DNS Monitoring Pubsub Storage SQL]

# Dynamically create shim modules for each service
GOOGLE_SERVICES.each do |service|
# Create the module namespace
const_set(service, Module.new) unless const_defined?(service)

# Get reference to the module
service_module = const_get(service)

# Define the Google submodule with the shim
service_module.const_set(:Google, Module.new)
service_module::Google.define_singleton_method(:new) do |*args|
warn "[DEPRECATION] `Fog::#{service}::Google.new` is deprecated. Please use `Fog::Google::#{service}.new` instead."
Fog::Google.const_get(service).new(*args)
end
end
end
12 changes: 6 additions & 6 deletions lib/fog/compute/google.rb → lib/fog/google/compute.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Fog
module Compute
class Google < Fog::Service
autoload :Mock, File.expand_path("../google/mock", __FILE__)
autoload :Real, File.expand_path("../google/real", __FILE__)
module Google
class Compute < Fog::Service
autoload :Mock, 'fog/google/compute/mock'
autoload :Real, 'fog/google/compute/real'

requires :google_project
recognizes(
Expand All @@ -28,7 +28,7 @@ class Google < Fog::Service
https://www.googleapis.com/auth/cloud-platform).freeze
GOOGLE_COMPUTE_DEFAULT_NETWORK = "default".freeze

request_path "fog/compute/google/requests"
request_path "fog/google/compute/requests"
request :add_backend_service_backends
request :add_instance_group_instances
request :add_server_access_config
Expand Down Expand Up @@ -212,7 +212,7 @@ class Google < Fog::Service

request :reset_windows_password

model_path "fog/compute/google/models"
model_path "fog/google/compute/models"
model :server
collection :servers

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Fog
module Compute
class Google
module Google
class Compute
class Mock
include Fog::Google::Shared
attr_reader :extra_global_projects, :exclude_projects
Expand Down
Loading