Skip to content

Commit

Permalink
Use system object
Browse files Browse the repository at this point in the history
Instead of passing system attributes, send system itself
and use its attributes inside
  • Loading branch information
jesusbv committed Nov 5, 2024
1 parent 8be136b commit 6a47425
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 37 deletions.
2 changes: 1 addition & 1 deletion engines/registry/app/models/access_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def allowed_paths(system = nil)
}
allowed_non_free_product_classes.each do |non_free_prod_class|
activation_state = SccProxy.scc_check_subscription_expiration(
auth_header, system.login, system.system_token, system.proxy_byos_mode, non_free_prod_class
auth_header, system, non_free_prod_class
)
unless activation_state[:is_active]
Rails.logger.info(
Expand Down
10 changes: 2 additions & 8 deletions engines/registry/spec/app/models/access_scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,15 @@
allow(SccProxy).to receive(:scc_check_subscription_expiration)
.with(
header_expected,
system.login,
system.system_token,
system.proxy_byos_mode,
system,
'SLES15-SP4-LTSS-X86'
).and_return(scc_response)
end

# rubocop:disable RSpec/ExampleLength
it 'returns no actions allowed' do
expect(SccProxy).to receive(:scc_check_subscription_expiration).with(
header_expected,
system.login,
system.system_token,
system.proxy_byos_mode,
system,
'SLES15-SP4-LTSS-X86'
)
yaml_string = access_policy_content
Expand All @@ -248,7 +243,6 @@
}
)
end
# rubocop:enable RSpec/ExampleLength
end
end

Expand Down
18 changes: 7 additions & 11 deletions engines/scc_proxy/lib/scc_proxy/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,16 @@ def parse_error(error_message, token = nil, email = nil)
error_message
end

def get_scc_activations(headers, system_token, mode, login)
def get_scc_activations(headers, system)
auth = headers['HTTP_AUTHORIZATION'] if headers && headers.include?('HTTP_AUTHORIZATION')
uri = URI.parse(SYSTEMS_ACTIVATIONS_URL)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
uri.query = URI.encode_www_form({ byos_mode: mode })
scc_request = Net::HTTP::Get.new(uri.path, headers(auth, system_token))
uri.query = URI.encode_www_form({ byos_mode: system.proxy_byos_mode })
scc_request = Net::HTTP::Get.new(uri.path, headers(auth, system.system_token))
response = http.request(scc_request)
unless response.code_type == Net::HTTPOK
Rails.logger.info "Could not get the system (#{login}) activations, error: #{response.message} #{response.code}"
Rails.logger.info "Could not get the system (#{system.login}) activations, error: #{response.message} #{response.code}"
raise ActionController::TranslatedError.new(response.body)
end
JSON.parse(response.body)
Expand Down Expand Up @@ -271,10 +271,8 @@ def activations_fail_state(scc_systems_activations, headers, product = nil)
end
end

def scc_check_subscription_expiration(headers, login, system_token, mode, product = nil)
scc_systems_activations = SccProxy.get_scc_activations(
headers, system_token, mode, login
)
def scc_check_subscription_expiration(headers, system, product = nil)
scc_systems_activations = SccProxy.get_scc_activations(headers, system)
return { is_active: false, message: 'No activations.' } if scc_systems_activations.empty?

no_status_products_ids = scc_systems_activations.map do |act|
Expand Down Expand Up @@ -443,9 +441,7 @@ def scc_deactivate_product
elsif @system.hybrid? && @product.extension?
# check if product is on SCC and
# if it is -> de-activate it
scc_hybrid_system_activations = SccProxy.get_scc_activations(
headers, @system.system_token, @system.proxy_byos_mode, @system.login
)
scc_hybrid_system_activations = SccProxy.get_scc_activations(headers, @system)
if scc_hybrid_system_activations.map { |act| act['service']['product']['id'] == @product.id }.present?
# if product is found on SCC, regardless of the state
# it is OK to remove it from SCC
Expand Down
4 changes: 1 addition & 3 deletions engines/zypper_auth/lib/zypper_auth/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def verify_instance(request, logger, system)
end

def handle_scc_subscription(request, system, verification_provider)
result = SccProxy.scc_check_subscription_expiration(
request.headers, system.login, system.system_token, system.proxy_byos_mode
)
result = SccProxy.scc_check_subscription_expiration(request.headers, system)
return true if result[:is_active]

ZypperAuth.zypper_auth_message(request, system, verification_provider, result[:message])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,16 @@

before do
stub_request(:get, scc_systems_activations_url).to_return(status: 200, body: [body_active].to_json, headers: {})
# allow(SccProxy).to receive(:get_scc_activations).and_return(status: 200, body: [body_active].to_json, headers: {})
expect(URI).to receive(:encode_www_form).with({ byos_mode: 'hybrid' })
allow(File).to receive(:directory?).and_return(true)
allow(Dir).to receive(:mkdir)
allow(FileUtils).to receive(:touch)
# get '/api/auth/check', headers: headers
end

it 'returns true' do
result = SccProxy.scc_check_subscription_expiration(
headers,
system_hybrid.login,
system_hybrid.system_token,
system_hybrid.proxy_byos_mode,
system_hybrid,
system_hybrid.activations.first.product.product_class + '-LTSS'
)
expect(result[:is_active]).to be(true)
Expand Down Expand Up @@ -297,9 +293,7 @@
it 'returns false, expired' do
result = SccProxy.scc_check_subscription_expiration(
headers,
system_hybrid.login,
system_hybrid.system_token,
system_hybrid.proxy_byos_mode,
system_hybrid,
system_hybrid.activations.first.product.product_class + '-LTSS'
)
expect(result[:is_active]).to eq(false)
Expand Down Expand Up @@ -339,9 +333,7 @@
it 'returns product not activated' do
result = SccProxy.scc_check_subscription_expiration(
headers,
system_hybrid.login,
system_hybrid.system_token,
system_hybrid.proxy_byos_mode,
system_hybrid,
system_hybrid.activations.first.product.product_class + '-LTSS'
)
expect(result[:is_active]).to eq(false)
Expand Down Expand Up @@ -381,9 +373,7 @@
it 'returns unexpected error' do
result = SccProxy.scc_check_subscription_expiration(
headers,
system_hybrid.login,
system_hybrid.system_token,
system_hybrid.proxy_byos_mode,
system_hybrid,
system_hybrid.activations.first.product.product_class + '-LTSS'
)
expect(result[:is_active]).to eq(false)
Expand Down

0 comments on commit 6a47425

Please sign in to comment.