Sha256: fb4f2c751c34a32c0bb128d292a5eda553bf0d8573faa49991f0eb07ac965025

Contents?: true

Size: 1.39 KB

Versions: 36

Compression:

Stored size: 1.39 KB

Contents

require "pact_broker/api/resources/matrix"
require "pact_broker/matrix/can_i_deploy_query_schema"
require "pact_broker/matrix/parse_can_i_deploy_query"
require "pact_broker/messages"

module PactBroker
  module Api
    module Resources
      class CanIDeploy < Matrix
        include PactBroker::Messages

        def malformed_request?
          if (errors = query_schema.call(query_params)).any?
            set_json_validation_error_messages(errors)
            true
          elsif !pacticipant
            set_json_validation_error_messages(pacticipant: [message("errors.validation.pacticipant_not_found", name: pacticipant_name)])
            true
          else
            false
          end
        end

        def policy_name
          :'matrix::can_i_deploy'
        end

        private

        def query_schema
          PactBroker::Api::Contracts::CanIDeployQuerySchema
        end

        def pacticipant
          @pacticipant ||= pacticipant_service.find_pacticipant_by_name(pacticipant_name)
        end

        def pacticipant_name
          selectors.first.pacticipant_name
        end

        def parsed_query
          @parsed_query ||= PactBroker::Matrix::ParseCanIDeployQuery.call(query_params)
        end

        def query_params
          @query_params ||= JSON.parse(Rack::Utils.parse_nested_query(request.uri.query).to_json, symbolize_names: true)
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
pact_broker-2.106.0 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.105.0 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.104.0 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.103.0 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.102.2 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.102.1 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.102.0 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.101.0 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.100.0 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.99.0 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.98.0 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.97.0 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.96.0 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.95.1 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.95.0 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.94.0 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.93.4 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.93.3 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.93.2 lib/pact_broker/api/resources/can_i_deploy.rb
pact_broker-2.93.1 lib/pact_broker/api/resources/can_i_deploy.rb