Skip to content

Commit

Permalink
Merge pull request #491 from kgaikwad/exclude_project_option
Browse files Browse the repository at this point in the history
adds exclude_projects option to exclude any global project
  • Loading branch information
Temikus authored Mar 26, 2020
2 parents 46d1bee + 5a59e4d commit 220eef2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/fog/compute/google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Google < Fog::Service
:google_client,
:google_client_options,
:google_extra_global_projects,
:google_exclude_projects,
:google_key_location,
:google_key_string,
:google_json_key_location,
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/compute/google/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ module Compute
class Google
class Mock
include Fog::Google::Shared
attr_reader :extra_global_projects
attr_reader :extra_global_projects, :exclude_projects

def initialize(options)
shared_initialize(options[:google_project], GOOGLE_COMPUTE_API_VERSION, GOOGLE_COMPUTE_BASE_URL)
@extra_global_projects = options.fetch(:google_extra_global_projects, [])
@exclude_projects = options.fetch(:google_exclude_projects, [])
end

def self.data(api_version)
Expand Down
6 changes: 5 additions & 1 deletion lib/fog/compute/google/models/images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ def get_from_family(family, project = nil)

def all_projects
# Search own project before global projects
[service.project] + GLOBAL_PROJECTS + service.extra_global_projects
project_list = [service.project] + GLOBAL_PROJECTS + service.extra_global_projects
unless service.exclude_projects.empty?
project_list.delete_if { |project| service.exclude_projects.include?(project) }
end
project_list
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/compute/google/real.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Real
include Fog::Google::Shared

attr_accessor :client
attr_reader :compute, :extra_global_projects
attr_reader :compute, :extra_global_projects, :exclude_projects

def initialize(options)
shared_initialize(options[:google_project], GOOGLE_COMPUTE_API_VERSION, GOOGLE_COMPUTE_BASE_URL)
Expand All @@ -16,6 +16,7 @@ def initialize(options)
apply_client_options(@compute, options)

@extra_global_projects = options[:google_extra_global_projects] || []
@exclude_projects = options[:google_exclude_projects] || []
end
end
end
Expand Down

0 comments on commit 220eef2

Please sign in to comment.