<commit_before>require 'morpheus/cli/cli_command'

class Morpheus::Cli::CredentialsCommand
  include Morpheus::Cli::CliCommand
  include Morpheus::Cli::RestCommand

  set_command_name :'credentials'
  set_command_description "View and manage credentials."
  register_subcommands :list, :get, :add, :update, :remove

  # RestCommand settings
  register_interfaces :credentials, :credential_types
  set_rest_has_type true
  # set_rest_type :credential_types

  protected

  def render_response_for_get(json_response, options)
    render_response(json_response, options, rest_object_key) do
      record = json_response[rest_object_key]
      print_h1 rest_label, [], options
      print cyan
      print_description_list(credential_column_definitions(options, record), record, options)
      print reset,"\n"
    end
  end

  def credential_list_column_definitions(options)
    {
      "ID" => 'id',
      "Name" => 'name',
      "Type" => lambda {|it| it['type'] ? it['type']['name'] : '' },
    }
  end

  def credential_column_definitions(options, credential)
    columns = [
      {"ID" => 'id' },
      {"Name" => 'name' },
      {"Description" => 'description' },
      {"Type" => lambda {|it| it['type'] ? it['type']['name'] : '' } },
      {"Enabled" => lambda {|it| format_boolean(it['enabled']) } },
      {"Created" => lambda {|it| format_local_dt(it['dateCreated']) } },
      {"Updated" => lambda {|it| format_local_dt(it['lastUpdated']) } }
    ]
    type_code = credential['type']['code']
    if type_code == "access-key-secret"
      columns += [
        {"Access Key" => lambda {|it| it['clientId'] } },
        {"Secret Key" => lambda {|it| it['clientSecret'] } },
      ]
    elsif type_code == "client-id-secret"
      columns += [
        {"Client ID" => lambda {|it| it['clientId'] } },
        {"Client Secret" => lambda {|it| it['clientSecret'] } },
      ]
    elsif type_code == "email-private-key"
      columns += [
        {"Email" => lambda {|it| it['email'] } },
        {"Private Key" => lambda {|it| it['authKey'] ? it['authKey']['name'] : '' } },
      ]
    elsif type_code == "tenant-username-keypair"
      columns += [
        {"Tenant" => lambda {|it| it['tenant'] } },
        {"Username" => lambda {|it| it['username'] } },
        {"Private Key" => lambda {|it| it['authKey'] ? it['authKey']['name'] : '' } },
      ]
    elsif type_code == "username-api-key"
      columns += [
        {"Username" => lambda {|it| it['username'] } },
        {"API Key" => lambda {|it| it['apiKey'] } },
      ]
    elsif type_code == "username-key"
      columns += [
        {"Username" => lambda {|it| it['username'] } },
        {"Private Key" => lambda {|it| it['authKey'] ? it['authKey']['name'] : '' } },<commit_msg>credentials Secret Key display fix<commit_after>require 'morpheus/cli/cli_command'

class Morpheus::Cli::CredentialsCommand
  include Morpheus::Cli::CliCommand
  include Morpheus::Cli::RestCommand

  set_command_name :'credentials'
  set_command_description "View and manage credentials."
  register_subcommands :list, :get, :add, :update, :remove

  # RestCommand settings
  register_interfaces :credentials, :credential_types
  set_rest_has_type true
  # set_rest_type :credential_types

  protected

  def render_response_for_get(json_response, options)
    render_response(json_response, options, rest_object_key) do
      record = json_response[rest_object_key]
      print_h1 rest_label, [], options
      print cyan
      print_description_list(credential_column_definitions(options, record), record, options)
      print reset,"\n"
    end
  end

  def credential_list_column_definitions(options)
    {
      "ID" => 'id',
      "Name" => 'name',
      "Type" => lambda {|it| it['type'] ? it['type']['name'] : '' },
    }
  end

  def credential_column_definitions(options, credential)
    columns = [
      {"ID" => 'id' },
      {"Name" => 'name' },
      {"Description" => 'description' },
      {"Type" => lambda {|it| it['type'] ? it['type']['name'] : '' } },
      {"Enabled" => lambda {|it| format_boolean(it['enabled']) } },
      {"Created" => lambda {|it| format_local_dt(it['dateCreated']) } },
      {"Updated" => lambda {|it| format_local_dt(it['lastUpdated']) } }
    ]
    type_code = credential['type']['code']
    if type_code == "access-key-secret"
      columns += [
        {"Access Key" => lambda {|it| it['accessKey'] } },
        {"Secret Key" => lambda {|it| it['secretKey'] } },
      ]
    elsif type_code == "client-id-secret"
      columns += [
        {"Client ID" => lambda {|it| it['clientId'] } },
        {"Client Secret" => lambda {|it| it['clientSecret'] } },
      ]
    elsif type_code == "email-private-key"
      columns += [
        {"Email" => lambda {|it| it['email'] } },
        {"Private Key" => lambda {|it| it['authKey'] ? it['authKey']['name'] : '' } },
      ]
    elsif type_code == "tenant-username-keypair"
      columns += [
        {"Tenant" => lambda {|it| it['tenant'] } },
        {"Username" => lambda {|it| it['username'] } },
        {"Private Key" => lambda {|it| it['authKey'] ? it['authKey']['name'] : '' } },
      ]
    elsif type_code == "username-api-key"
      columns += [
        {"Username" => lambda {|it| it['username'] } },
        {"API Key" => lambda {|it| it['apiKey'] } },
      ]
    elsif type_code == "username-key"
      columns += [
        {"Username" => lambda {|it| it['username'] } },
        {"Private Key" => lambda {|it| it['authKey'] ? it['authKey']['name'] : '' } },
{'fraction_non_alphanumeric': 0.1871939053147107, 'fraction_numerical': 0.00036277888626881915, 'mean_word_length': 3.205949656750572, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2360674', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1769, 'n_words': 366}