<commit_before>require 'json'

module Carto
  module Api
    class ApiKeyGrantsPresenter
      def initialize(api_key_grants)
        @api_key_grants = api_key_grants
      end

      def to_poro
        return [] unless @api_key_grants
        [
          {
            type: 'apis',
            apis: @api_key_grants.granted_apis
          },
          {
            type: 'database',
            tables: @api_key_grants.table_permissions.map do |p|
              {
                schema: p.schema,
                name: p.name,
                permissions: p.permissions
              }
            end
          }
        ]
      end
    end

    class ApiKeyPresenter
      def initialize(api_key)
        @api_key = api_key
      end

      def to_poro
        return {} unless @api_key
        grants_presenter = ApiKeyGrantsPresenter.new(@api_key.api_key_grants)
        {
          id: @api_key.id,
          user: { username: @api_key.user.username },
          type: @api_key.type,
          token: @api_key.token,
          grants: grants_presenter.to_poro,
          databaseConfig: {
            role: @api_key.db_role,
            password: <PASSWORD>
          },
          createdAt: @api_key.created_at.to_s,<commit_msg>Missing 'name' at api key presenter<commit_after>require 'json'

module Carto
  module Api
    class ApiKeyGrantsPresenter
      def initialize(api_key_grants)
        @api_key_grants = api_key_grants
      end

      def to_poro
        return [] unless @api_key_grants
        [
          {
            type: 'apis',
            apis: @api_key_grants.granted_apis
          },
          {
            type: 'database',
            tables: @api_key_grants.table_permissions.map do |p|
              {
                schema: p.schema,
                name: p.name,
                permissions: p.permissions
              }
            end
          }
        ]
      end
    end

    class ApiKeyPresenter
      def initialize(api_key)
        @api_key = api_key
      end

      def to_poro
        return {} unless @api_key
        grants_presenter = ApiKeyGrantsPresenter.new(@api_key.api_key_grants)
        {
          id: @api_key.id,
          user: { username: @api_key.user.username },
          type: @api_key.type,
          name: @api_key.name,
          token: @api_key.token,
          grants: grants_presenter.to_poro,
          databaseConfig: {
            role: @api_key.db_role,
            password: <PASSWORD>
          },
          createdAt: @api_key.created_at.to_s,
{'fraction_non_alphanumeric': 0.08060055314105097, 'fraction_numerical': 0.0, 'mean_word_length': 1.4511132623426912, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1076351', 'n_tokens_mistral': 784, 'n_tokens_neox': 783, 'n_words': 144}