diff --git a/engines/scc_proxy/lib/scc_proxy/engine.rb b/engines/scc_proxy/lib/scc_proxy/engine.rb index 1e74bba4a..9539bbdd0 100644 --- a/engines/scc_proxy/lib/scc_proxy/engine.rb +++ b/engines/scc_proxy/lib/scc_proxy/engine.rb @@ -271,9 +271,10 @@ class Engine < ::Rails::Engine def announce_system auth_header = nil auth_header = request.headers['HTTP_AUTHORIZATION'] if request.headers.include?('HTTP_AUTHORIZATION') + reg_code = get_reg_code(auth_header) system_information = hwinfo_params[:hwinfo].to_json instance_data = params.fetch(:instance_data, nil) - if has_no_regcode?(auth_header) + if reg_code.empty? # no token sent to check with SCC # standard announce case @system = System.create!( @@ -293,7 +294,8 @@ def announce_system proxy_byos_mode: :byos, proxy_byos: true, system_information: system_information, - instance_data: instance_data + instance_data: instance_data, + pubcloud_reg_code: reg_code ) end logger.info("System '#{@system.hostname}' announced") @@ -312,10 +314,9 @@ def status_code(error_message) error_message[0..(error_message.index(' ') - 1)].to_i end - def has_no_regcode?(auth_header) + def get_reg_code(auth_header) auth_header ||= '=' - auth_header = auth_header[(auth_header.index('=') + 1)..-1] - auth_header.empty? + auth_header[(auth_header.index('=') + 1)..-1] end end @@ -344,7 +345,10 @@ def scc_activate_product # if the system is PAYG and the registration code is valid for the extension, # then the system is hybrid # update the system to HYBRID mode if HYBRID MODE and system not HYBRID already - @system.hybrid! if mode == 'hybrid' && @system.payg? + if mode == 'hybrid' && @system.payg? + @system.hybrid! + @system.update(pubcloud_reg_code: params[:token]) + end logger.info "Product #{@product.product_string} successfully activated with SCC" InstanceVerification.update_cache(request.remote_ip, @system.login, @product.id)