<commit_before>module V3
  class CloudProviders < Grape::API
    helpers V3::Helpers

    version 'v3'
    format :json
    formatter :json, Grape::Formatter::ActiveModelSerializers

    resource :cloud_providers do
      before do
        api_enabled!
        authenticate!
        set_papertrail
      end

      desc "Return a list of cloud providers, possibly filtered"
      get do
        can_read!

        query = CloudProvider.all
        params.delete("idb_api_token")
        params.each do |key, value|
          keysym = key.to_sym
          query = query.merge(CloudProvider.where(CloudProvider.arel_table[keysym].eq(value)))
        end

        begin
          query.any?
        rescue ActiveRecord::StatementInvalid
          error!("Bad Request", 400)
        end

        query
      end

      desc 'Create a new cloud provider'
      post do
        can_write!
        p = params.reject { |k| !CloudProvider.attribute_method?(k) }
        c = CloudProvider.create(p)
        c
      end

      desc "Get cloud provider by name"
      get ':name', requirements: {number: /[a-zA-Z0-9.]+/ } do
        can_read!
        c = CloudProvider.find_by_name params[:name]
        error!("Not found", 404) unless c

        c
      end

      desc "Update a single cloud provider"
      put ':name', requirements: {name: /[a-zA-Z0-9.]+/ } do
        can_write!
        c = CloudProvider.find_by_inventory_number params[:name]
        error!("Not found", 404) unless c

        p = params.reject { |k| !CloudProvider.attribute_method?(k) }

        c.update_attributes(p)

        c
      end
    end
  end
end<commit_msg>use route parameter in cloud providers<commit_after>module V3
  class CloudProviders < Grape::API
    helpers V3::Helpers

    version 'v3'
    format :json
    formatter :json, Grape::Formatter::ActiveModelSerializers

    resource :cloud_providers do
      before do
        api_enabled!
        authenticate!
        set_papertrail
      end

      route_param :name, type: String, requirements: {name: /[a-zA-Z0-9.]+/ } do
        desc "Get cloud provider by name"
        get do
          can_read!
          c = CloudProvider.find_by_name params[:name]
          error!("Not found", 404) unless c

          c
        end

        desc "Update a single cloud provider"
        put do
          can_write!
          c = CloudProvider.find_by_inventory_number params[:name]
          error!("Not found", 404) unless c

          p = params.reject { |k| !CloudProvider.attribute_method?(k) }

          c.update_attributes(p)

          c
        end

        desc "Delete cloud provider by name"
        get do
          can_write!
          c = CloudProvider.find_by_name params[:name]
          error!("Not found", 404) unless c

          c.destroy!
        end
      end

      desc "Return a list of cloud providers, possibly filtered"
      get do
        can_read!

        query = CloudProvider.all
        params.delete("idb_api_token")
        params.each do |key, value|
          keysym = key.to_sym
          query = query.merge(CloudProvider.where(CloudProvider.arel_table[keysym].eq(value)))
        end

        begin
          query.any?
        rescue ActiveRecord::StatementInvalid
          error!("Bad Request", 400)
        end

        query
      end

      desc 'Create a new cloud provider'
      post do
        can_write!
        p = params.reject { |k| !CloudProvider.attribute_method?(k) }
        c = CloudProvider.create(p)
        c
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08699348257296685, 'fraction_numerical': 0.009351090960612072, 'mean_word_length': 1.8934426229508197, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2858830', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1012, 'n_words': 280}