class Actions::SccManager::SyncProducts

def finalize

def finalize
  # this is only executed if 'run' succeeds
  SccAccount.find(input.fetch(:id)).update_scc_products(output.fetch(:data))
end

def humanized_name

def humanized_name
  _('Sync SUSE subscriptions (Products)')
end

def humanized_output

def humanized_output
  output.dup.update(data: 'Trimmed')
end

def plan(scc_account)

def plan(scc_account)
  action_subject(scc_account)
  password = encrypt_field(scc_account.password)
  plan_self(id: scc_account.id,
    base_url: scc_account.base_url,
    login: scc_account.login,
    password: password)
end

def rescue_strategy

def rescue_strategy
  Dynflow::Action::Rescue::Fail
end

def run

def run
  products = ::SccManager.get_scc_data(input.fetch(:base_url),
    '/connect/organizations/products',
    input.fetch(:login),
    decrypt_field(input.fetch(:password)))
  output[:data] = ::SccManager.sanitize_products(products).values
rescue StandardError => e
  ::Foreman::Logging.logger('foreman_scc_manager').error "Error while syncronizing SCC-Products: #{e}"
  error! e.to_s
end