Skip to content

Commit

Permalink
Add longer expiration date for BYOS systems
Browse files Browse the repository at this point in the history
- Update tests
- Rubocop compliant
- Update changelog to keep track of public cloud changes
  • Loading branch information
jesusbv committed Mar 6, 2024
1 parent 8626219 commit 6a08c91
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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') }
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion engines/scc_proxy/lib/scc_proxy/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions engines/zypper_auth/lib/zypper_auth/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions package/obs/rmt-server.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Wed Mar 6 13:17:01 UTC 2024 - Jesús Bermúdez Velázquez <[email protected]>

- 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 <[email protected]>

Expand Down

0 comments on commit 6a08c91

Please sign in to comment.