Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reg code system registration #1277

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions engines/scc_proxy/lib/scc_proxy/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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")
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
Loading