From 6a08c9122730e7656ff4cfbbde4c6e23ebbbe7fe Mon Sep 17 00:00:00 2001 From: Jesus Bermudez Velazquez Date: Wed, 6 Mar 2024 09:44:50 +0000 Subject: [PATCH] Add longer expiration date for BYOS systems - Update tests - Rubocop compliant - Update changelog to keep track of public cloud changes --- .../lib/instance_verification/engine.rb | 7 ++++--- .../connect/v3/systems/products_controller_spec.rb | 13 ++++--------- engines/scc_proxy/lib/scc_proxy/engine.rb | 2 +- .../connect/v3/systems/products_controller_spec.rb | 5 ++++- engines/zypper_auth/lib/zypper_auth/engine.rb | 4 ++-- package/obs/rmt-server.changes | 8 ++++++++ 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/engines/instance_verification/lib/instance_verification/engine.rb b/engines/instance_verification/lib/instance_verification/engine.rb index d836d6c74..827302fd7 100644 --- a/engines/instance_verification/lib/instance_verification/engine.rb +++ b/engines/instance_verification/lib/instance_verification/engine.rb @@ -1,8 +1,9 @@ module InstanceVerification - def self.update_cache(remote_ip, system_login, product_id) + def self.update_cache(remote_ip, system_login, product_id, is_byos) cache_key = [remote_ip, system_login, product_id].join('-') # caches verification result to be used by zypper auth plugin - Rails.cache.write(cache_key, true, expires_in: 20.minutes) + expire_cache_time = is_byos ? 24.hours : 20.minutes + Rails.cache.write(cache_key, true, expires_in: expire_cache_time) end class Engine < ::Rails::Engine @@ -94,7 +95,7 @@ def verify_base_product_activation(product) ) raise 'Unspecified error' unless verification_provider.instance_valid? - InstanceVerification.update_cache(request.remote_ip, @system.login, product.id) + InstanceVerification.update_cache(request.remote_ip, @system.login, product.id, @system.proxy_byos) end # Verify that the base product doesn't change in the offline migration diff --git a/engines/instance_verification/spec/requests/api/connect/v3/systems/products_controller_spec.rb b/engines/instance_verification/spec/requests/api/connect/v3/systems/products_controller_spec.rb index 4f8da18a7..b08746e59 100644 --- a/engines/instance_verification/spec/requests/api/connect/v3/systems/products_controller_spec.rb +++ b/engines/instance_verification/spec/requests/api/connect/v3/systems/products_controller_spec.rb @@ -16,15 +16,6 @@ arch: product.arch } end - let(:payload_byos) do - { - identifier: product.identifier, - version: product.version, - arch: product.arch, - email: 'foo', - token: 'bar' - } - end describe '#activate' do let(:plugin_double) { instance_double('InstanceVerification::Providers::Example') } @@ -119,6 +110,10 @@ before do expect(InstanceVerification::Providers::Example).to receive(:new) .with(be_a(ActiveSupport::Logger), be_a(ActionDispatch::Request), payload_sap, instance_data).and_call_original + + expect(Rails.cache).to receive(:write).with( + ['127.0.0.1', system.login, product_sap.id].join('-'), true, expires_in: 20.minutes + ) post url, params: payload_sap, headers: headers end diff --git a/engines/scc_proxy/lib/scc_proxy/engine.rb b/engines/scc_proxy/lib/scc_proxy/engine.rb index a12dca5ca..4d162122c 100644 --- a/engines/scc_proxy/lib/scc_proxy/engine.rb +++ b/engines/scc_proxy/lib/scc_proxy/engine.rb @@ -274,7 +274,7 @@ def scc_activate_product raise ActionController::TranslatedError.new(error['error']) end logger.info "Product #{@product.product_string} successfully activated with SCC" - InstanceVerification.update_cache(request.remote_ip, @system.login, @product.id) + InstanceVerification.update_cache(request.remote_ip, @system.login, @product.id, @system.proxy_byos) end end end diff --git a/engines/scc_proxy/spec/requests/api/connect/v3/systems/products_controller_spec.rb b/engines/scc_proxy/spec/requests/api/connect/v3/systems/products_controller_spec.rb index 39af8d352..d6197522b 100644 --- a/engines/scc_proxy/spec/requests/api/connect/v3/systems/products_controller_spec.rb +++ b/engines/scc_proxy/spec/requests/api/connect/v3/systems/products_controller_spec.rb @@ -110,10 +110,13 @@ body: '{"id": "bar"}', headers: {} ) - post url, params: payload_byos, headers: headers end it 'renders service JSON' do + expect(Rails.cache).to receive(:write).twice.with( + ['127.0.0.1', system.login, product.id].join('-'), true, expires_in: 24.hours + ) + post url, params: payload_byos, headers: headers expect(response.body).to eq(serialized_service_json) end end diff --git a/engines/zypper_auth/lib/zypper_auth/engine.rb b/engines/zypper_auth/lib/zypper_auth/engine.rb index 170315274..277885ac7 100644 --- a/engines/zypper_auth/lib/zypper_auth/engine.rb +++ b/engines/zypper_auth/lib/zypper_auth/engine.rb @@ -24,14 +24,14 @@ def verify_instance(request, logger, system) ) is_valid = verification_provider.instance_valid? - InstanceVerification.update_cache(request.remote_ip, system.login, base_product.id) + InstanceVerification.update_cache(request.remote_ip, system.login, base_product.id, system.proxy_byos) is_valid rescue InstanceVerification::Exception => e message = '' if system.proxy_byos result = SccProxy.scc_check_subscription_expiration(request.headers, system.login, system.system_token, logger) if result[:is_active] - InstanceVerification.update_cache(request.remote_ip, system.login, base_product.id) + InstanceVerification.update_cache(request.remote_ip, system.login, base_product.id, system.proxy_byos) return true end diff --git a/package/obs/rmt-server.changes b/package/obs/rmt-server.changes index 8939204b7..19a39e312 100644 --- a/package/obs/rmt-server.changes +++ b/package/obs/rmt-server.changes @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Wed Mar 6 13:17:01 UTC 2024 - Jesús Bermúdez Velázquez + +- rmt-server-pubcloud: + Extend cache expiration time for BYOS systems + PAYG -> 20 min cache + BYOS -> 24 hours cache + ------------------------------------------------------------------- Thu Feb 20 15:36:00 UTC 2024 - Zuzana Petrova