Skip to content

Commit

Permalink
Add instance_identifier method
Browse files Browse the repository at this point in the history
In order to keep RMT implementation generic add a CSP specific method in
the CSP instance verification class
  • Loading branch information
jesusbv committed Nov 25, 2024
1 parent f7c3ae5 commit ddcb893
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ def validate_instance_data(_instance_data)
end

def parse_instance_data
if @instance_data.include? '<instance_data/>'
return { 'instance_data' => 'parsed_instance_data' }
end

if @instance_data.include?('SUSE')
if @instance_data.include?('SAP')
return { 'billingProducts' => nil, 'marketplaceProductCodes' => ['6789_SUSE_SAP'] }
Expand All @@ -49,4 +45,8 @@ def payg_billing_code?(iid, identifier)
return true if (identifier.casecmp('sles').zero? && instance_billing_info[:billing_product] == SLES_PRODUCT_IDENTIFIER)
return true if (identifier.casecmp('sles_sap').zero? && SLES4SAP_PRODUCT_IDENTIFIER.include?(instance_billing_info[:marketplace_code]))
end

def instance_identifier
'foo'
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@
before do
allow(InstanceVerification::Providers::Example).to receive(:new)
.with(nil, nil, nil, instance_data).and_return(plugin_double)
allow(plugin_double).to receive(:parse_instance_data).and_return({ InstanceId: 'foo' })
allow(plugin_double).to receive(:instance_identifier).and_return('foo')

allow(InstanceVerification).to receive(:update_cache).with('127.0.0.1', system.login, product.id)
FactoryBot.create(:subscription, product_classes: product_classes)
Expand Down
20 changes: 6 additions & 14 deletions engines/scc_proxy/lib/scc_proxy/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ class << self
# rubocop:disable ThreadSafety/InstanceVariableInClassMethod
def headers(auth, params)
@instance_id = if params && params.class != String
get_instance_id(params)
InstanceVerification.provider.new(
nil,
nil,
nil,
params['instance_data']
).instance_identifier
else
# if it is not JSON, it is the system_token already
# announce system has metadata
Expand All @@ -61,19 +66,6 @@ def headers(auth, params)
end
# rubocop:enable ThreadSafety/InstanceVariableInClassMethod

def get_instance_id(params)
verification_provider = InstanceVerification.provider.new(
nil,
nil,
nil,
params['instance_data']
)
csp = params['hwinfo']['cloud_provider'].downcase
instance_id_key = INSTANCE_ID_KEYS[csp.to_sym]
instance_data = verification_provider.parse_instance_data
csp.casecmp('microsoft').zero? ? instance_data['attestedData'][instance_id_key] : instance_data[instance_id_key]
end

def prepare_scc_announce_request(uri_path, auth, params)
scc_request = Net::HTTP::Post.new(uri_path, headers(auth, params))

Expand Down

0 comments on commit ddcb893

Please sign in to comment.