From 5a59e4d829ba78d2e8f8661d598021ec9c4a674c Mon Sep 17 00:00:00 2001 From: kgaikwad Date: Fri, 13 Mar 2020 17:32:26 +0000 Subject: [PATCH] adds exclude_projects option to exclude any global project --- lib/fog/compute/google.rb | 1 + lib/fog/compute/google/mock.rb | 3 ++- lib/fog/compute/google/models/images.rb | 6 +++++- lib/fog/compute/google/real.rb | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/fog/compute/google.rb b/lib/fog/compute/google.rb index 07192e890b..ff97746329 100644 --- a/lib/fog/compute/google.rb +++ b/lib/fog/compute/google.rb @@ -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, diff --git a/lib/fog/compute/google/mock.rb b/lib/fog/compute/google/mock.rb index 100d922ae2..adf17ec111 100644 --- a/lib/fog/compute/google/mock.rb +++ b/lib/fog/compute/google/mock.rb @@ -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) diff --git a/lib/fog/compute/google/models/images.rb b/lib/fog/compute/google/models/images.rb index 0785f37950..3b30894e0d 100644 --- a/lib/fog/compute/google/models/images.rb +++ b/lib/fog/compute/google/models/images.rb @@ -96,7 +96,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 diff --git a/lib/fog/compute/google/real.rb b/lib/fog/compute/google/real.rb index 040b30f2cd..46e052c342 100644 --- a/lib/fog/compute/google/real.rb +++ b/lib/fog/compute/google/real.rb @@ -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) @@ -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