Skip to content

Commit

Permalink
chore: add authorization methods to OSS
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Apr 23, 2021
1 parent 17d0633 commit 532870f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/pact_broker/api/resources/authorization.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module PactBroker
module Api
module Resources
module Authorization
def action
if read_methods.include?(request.method)
:read
elsif update_methods.include?(request.method)
:update
elsif create_methods.include?(request.method)
:create
elsif delete_methods.include?(request.method)
:delete
else
raise "Cannot map #{request.method} to an action"
end
end

def read_methods
%w{GET HEAD OPTIONS}
end

def update_methods
%w{PUT PATCH}
end

def create_methods
%w{POST PUT}
end

def delete_methods
%w{DELETE}
end
end
end
end
end
7 changes: 7 additions & 0 deletions lib/pact_broker/api/resources/default_base_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'pact_broker/json'
require 'pact_broker/pacts/pact_params'
require 'pact_broker/api/resources/authentication'
require 'pact_broker/api/resources/authorization'
require 'pact_broker/errors'

module PactBroker
Expand All @@ -18,6 +19,8 @@ class DefaultBaseResource < Webmachine::Resource
include PactBroker::Services
include PactBroker::Api::PactBrokerUrls
include PactBroker::Api::Resources::Authentication
include PactBroker::Api::Resources::Authorization

include PactBroker::Logging

attr_accessor :user
Expand Down Expand Up @@ -261,6 +264,10 @@ def validation_errors_for_schema?(schema_to_use = schema, params_to_validate = p
false
end
end

def malformed_request_for_json_with_schema?(schema_to_use = schema, params_to_validate = params)
invalid_json? || validation_errors_for_schema?(schema_to_use, params_to_validate)
end
end
end
end
Expand Down

0 comments on commit 532870f

Please sign in to comment.