Skip to content

Commit

Permalink
Merge pull request #1106 from SUSE/longer-cache-byos
Browse files Browse the repository at this point in the history
Longer cache byos
  • Loading branch information
digitaltom authored Mar 6, 2024
2 parents 99ee5f9 + 0d411ea commit 73081ef
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 23 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 @@ -275,7 +275,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
12 changes: 5 additions & 7 deletions package/obs/rmt-server.changes
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
-------------------------------------------------------------------
Wed Mar 6 14:08:42 UTC 2024 - Jesús Bermúdez Velázquez <[email protected]>

- rmt-server-pubcloud
When checking SCC for subscription expiration
on a GET request, SCC does rotate the system token

Set the byos info on the request to fix that
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, BYOS: 24 hours)
* Include byos parameter when checking subscription validity for BYOS systems with SCC

-------------------------------------------------------------------
Thu Feb 20 15:36:00 UTC 2024 - Zuzana Petrova <[email protected]>

Expand Down

0 comments on commit 73081ef

Please sign in to comment.