<commit_before>#
#   Copyright 2011 Red Hat, Inc.
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#

class ProvidersController < ApplicationController
  before_filter :require_user
  before_filter :load_providers, :only => [:index, :show, :new, :edit, :create, :update]
  before_filter :load_providers_types, :only => [:new, :edit, :update, :create]
  before_filter :parse_provider_type, :only => [:create, :update]

  def index
    @from_date = params[:from_date].nil? ? Date.today - 7.days :
      Date.civil(params[:from_date][:year].to_i,
                 params[:from_date][:month].to_i,
                 params[:from_date][:day].to_i)
    @to_date = params[:to_date].nil? ? Date.today :
      Date.civil(params[:to_date][:year].to_i,
                 params[:to_date][:month].to_i,
                 params[:to_date][:day].to_i)

    if @to_date < @from_date
      flash[:error] = t('logs.flash.error.date_range')
    end

    load_headers
    statistics

    respond_to do |format|
      format.html
      format.js { render :partial => 'list' }
      format.xml { render :partial => 'list.xml' , :locals => { :with_data => false }}
    end
  end

  def filter
    redirect_to_original({ "from_date" => params[:from_date],
                           "to_date" => params[:to_date] })
  end

  def new
    require_privilege(Privilege::CREATE, Provider)
    @provider = Provider.new
    @provider.url = Provider::DEFAULT_DELTACLOUD_URL
    @provider.provider_type = ProviderType.find_by_deltacloud_driver('ec2')
    @title = t("providers.new.new_provider")
  end

  def edit
    @provider = Provider.find(params[:id])
    @title = t 'cloud_providers'
    session[:current_provider_id] = @provider.id
    # requiring VIEW rather than MODIFY since edit doubles as the 'show' page
    # here -- actions must be hidden explicitly in template
    require_privilege(Privilege::VIEW, @provider)

    @alerts = provider_alerts(@provider)

    if params.delete :test_provider
      test_connection(@provider)<commit_msg>Return full provider API output if 'with_data' is supplied<commit_after>#
#   Copyright 2011 Red Hat, Inc.
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#

class ProvidersController < ApplicationController
  before_filter :require_user
  before_filter :load_providers, :only => [:index, :show, :new, :edit, :create, :update]
  before_filter :load_providers_types, :only => [:new, :edit, :update, :create]
  before_filter :parse_provider_type, :only => [:create, :update]

  def index
    @from_date = params[:from_date].nil? ? Date.today - 7.days :
      Date.civil(params[:from_date][:year].to_i,
                 params[:from_date][:month].to_i,
                 params[:from_date][:day].to_i)
    @to_date = params[:to_date].nil? ? Date.today :
      Date.civil(params[:to_date][:year].to_i,
                 params[:to_date][:month].to_i,
                 params[:to_date][:day].to_i)

    if @to_date < @from_date
      flash[:error] = t('logs.flash.error.date_range')
    end

    load_headers
    statistics

    respond_to do |format|
      format.html
      format.js { render :partial => 'list' }
      format.xml { render :partial => 'list.xml' , :locals => { :with_data => params[:with_data] }}
    end
  end

  def filter
    redirect_to_original({ "from_date" => params[:from_date],
                           "to_date" => params[:to_date] })
  end

  def new
    require_privilege(Privilege::CREATE, Provider)
    @provider = Provider.new
    @provider.url = Provider::DEFAULT_DELTACLOUD_URL
    @provider.provider_type = ProviderType.find_by_deltacloud_driver('ec2')
    @title = t("providers.new.new_provider")
  end

  def edit
    @provider = Provider.find(params[:id])
    @title = t 'cloud_providers'
    session[:current_provider_id] = @provider.id
    # requiring VIEW rather than MODIFY since edit doubles as the 'show' page
    # here -- actions must be hidden explicitly in template
    require_privilege(Privilege::VIEW, @provider)

    @alerts = provider_alerts(@provider)

    if params.delete :test_provider
      test_connection(@provider)
{'fraction_non_alphanumeric': 0.11547479484173505, 'fraction_numerical': 0.003907776475185619, 'mean_word_length': 3.3491928632115546, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, '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': '1550661', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1564, 'n_words': 423}