service_params.rb 1.48 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
module ServiceParams
  extend ActiveSupport::Concern

  ALLOWED_PARAMS = [:title, :token, :type, :active, :api_key, :api_url, :api_version, :subdomain,
                    :room, :recipients, :project_url, :webhook,
                    :user_key, :device, :priority, :sound, :bamboo_url, :username, :password,
                    :build_key, :server, :teamcity_url, :drone_url, :build_type,
                    :description, :issues_url, :new_issue_url, :restrict_to_branch, :channel,
                    :colorize_messages, :channels,
                    :push_events, :issues_events, :merge_requests_events, :tag_push_events,
                    :note_events, :build_events, :wiki_page_events,
                    :notify_only_broken_builds, :add_pusher,
                    :send_from_committer_email, :disable_diffs, :external_wiki_url,
                    :notify, :color,
                    :server_host, :server_port, :default_irc_uri, :enable_ssl_verification,
                    :jira_issue_transition_id]

  # Parameters to ignore if no value is specified
  FILTER_BLANK_PARAMS = [:password]

21
  def service_params
22 23 24
    dynamic_params = []
    dynamic_params.concat(@service.event_channel_names)

25
    service_params = params.permit(:id, service: ALLOWED_PARAMS + dynamic_params)
26

27
    if service_params[:service].is_a?(Hash)
28
      FILTER_BLANK_PARAMS.each do |param|
29
        service_params[:service].delete(param) if service_params[:service][param].blank?
30 31 32
      end
    end

33
    service_params
34 35
  end
end