<commit_before>class InstancesController < ApplicationController
  respond_to :json
  before_action :validate_params

  VOMS_PROXY_PATH = ENV['GUOCCI_VOMS_PROXY_PATH'] || '/tmp/x509up_u1000'
  CA_PATH = ENV['GUOCCI_CA_PATH'] || '/etc/grid-security/certificates'

  def index
    computes = client(params[:endpoint]).describe(Occi::Infrastructure::Compute.new.kind.type_identifier)
    computes = computes.collect { |cmpt| { id: cmpt.location, name: (cmpt.title || cmpt.hostname), state: cmpt.state, ip: first_address(cmpt) } }
    computes.compact!

    respond_with({ instances: computes }, status: 200, location: "/instances/#{params[:site_id]}/")
  end

  def show
    respond_with({ error: 'Not Implemented!' }, status: 501, location: '/test/')
  end

  def create
    compute = client(params[:endpoint]).get_resource(Occi::Infrastructure::Compute.new.kind.type_identifier)
    compute.mixins << resolve_mixin(client(params[:endpoint]), params[:size])      \
                   << resolve_mixin(client(params[:endpoint]), params[:appliance]) \
                   << context_mixin
    compute.title = compute.hostname = params[:name]
    compute.attributes['org.openstack.credentials.publickey.name'] = 'Public SSH key'
    compute.attributes['org.openstack.credentials.publickey.data'] = params[:sshkey].strip

    compute_id = client(params[:endpoint]).create compute

    respond_with({ id: compute_id }, location: "/instances/#{params[:site_id]}/new")
  end

  def destroy
    client(params[:endpoint]).delete params[:id]
    respond_with({ status: 'success' }, status: 200, location: "/instances/#{params[:site_id]}/delete")
  end

  class << self
    def voms_proxy_path
      VOMS_PROXY_PATH.strip
    end

    def ca_path
      CA_PATH.strip
    end
  end<commit_msg>Added support for proxies from REMOTE_USER<commit_after>class InstancesController < ApplicationController
  respond_to :json
  before_action :validate_params

  VOMS_PROXY_PATH = ENV['GUOCCI_VOMS_PROXY_PATH'] || '/tmp/x509up_u1000'
  CA_PATH = ENV['GUOCCI_CA_PATH'] || '/etc/grid-security/certificates'

  def index
    computes = client(params[:endpoint]).describe(Occi::Infrastructure::Compute.new.kind.type_identifier)
    computes = computes.collect { |cmpt| { id: cmpt.location, name: (cmpt.title || cmpt.hostname), state: cmpt.state, ip: first_address(cmpt) } }
    computes.compact!

    respond_with({ instances: computes }, status: 200, location: "/instances/#{params[:site_id]}/")
  end

  def show
    respond_with({ error: 'Not Implemented!' }, status: 501, location: '/test/')
  end

  def create
    compute = client(params[:endpoint]).get_resource(Occi::Infrastructure::Compute.new.kind.type_identifier)
    compute.mixins << resolve_mixin(client(params[:endpoint]), params[:size])      \
                   << resolve_mixin(client(params[:endpoint]), params[:appliance]) \
                   << context_mixin
    compute.title = compute.hostname = params[:name]
    compute.attributes['org.openstack.credentials.publickey.name'] = 'Public SSH key'
    compute.attributes['org.openstack.credentials.publickey.data'] = params[:sshkey].strip

    compute_id = client(params[:endpoint]).create compute

    respond_with({ id: compute_id }, location: "/instances/#{params[:site_id]}/new")
  end

  def destroy
    client(params[:endpoint]).delete params[:id]
    respond_with({ status: 'success' }, status: 200, location: "/instances/#{params[:site_id]}/delete")
  end

  class << self
    def voms_proxy_path
      remote_proxy || VOMS_PROXY_PATH.strip
    end

    def ca_path
      CA_PATH.strip
    end

    def remote_proxy
      return nil if ENV['REMOTE_USER'].blank?
      path = "/tmp/x509_#{ENV['REMOTE_USER']}"
      return nil unless File.readable?(path)

      path
    end
  end
{'fraction_non_alphanumeric': 0.1380587146257604, 'fraction_numerical': 0.009256810367627611, 'mean_word_length': 4.062918340026774, 'pattern_counts': {'":': 0, '<': 21, '<?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': '2963863', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1184, 'n_words': 219}