Skip to content

Commit

Permalink
Merge pull request #1249 from SUSE/azure-ltss
Browse files Browse the repository at this point in the history
Send the instance ID in the token for Azure
  • Loading branch information
jesusbv authored Nov 26, 2024
2 parents e5e2ae8 + 7a98619 commit 27dfa84
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 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 @@ -50,6 +46,10 @@ def payg_billing_code?(iid, identifier)
return true if (identifier.casecmp('sles_sap').zero? && SLES4SAP_PRODUCT_IDENTIFIER.include?(instance_billing_info[:marketplace_code]))
end

def instance_identifier
'foo'
end

def allowed_extension?
# method to check if a product (extension) meet the criteria
# to be acivated on SCC or not, i.e. LTSS in Azure Basic VM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@
end

before do
allow(InstanceVerification::Providers::Example).to receive(:new)
.and_return(plugin_double)
allow(InstanceVerification::Providers::Example).to receive(:new).and_return(plugin_double)
allow(plugin_double).to receive(:instance_identifier).and_return('foo')
allow(plugin_double).to receive(:parse_instance_data).and_return({ InstanceId: 'foo' })
allow(plugin_double).to receive(:allowed_extension?).and_return(true)

Expand Down
25 changes: 6 additions & 19 deletions engines/scc_proxy/lib/scc_proxy/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
Net::HTTPRetriableError
].freeze

INSTANCE_ID_KEYS = {
amazon: 'instanceId',
google: 'instance_id',
microsoft: 'vmId'
}.freeze

# rubocop:disable Metrics/ModuleLength
module SccProxy
class << self
Expand All @@ -43,7 +37,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,18 +60,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']
)
instance_id_key = INSTANCE_ID_KEYS[params['hwinfo']['cloud_provider'].downcase.to_sym]
iid = verification_provider.parse_instance_data
iid[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 27dfa84

Please sign in to comment.