forked from pact-foundation/pact_broker-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
882 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-webhook" and add the consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-webhook. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'pact_broker/client/hal/link' | ||
require 'pact_broker/client/hal/http_client' | ||
require 'pact_broker/client/hal/entity' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require 'uri' | ||
require 'pact_broker/client/hal' | ||
require 'ostruct' | ||
require 'json' | ||
require 'pact_broker/client/command_result' | ||
|
||
module PactBroker | ||
module Client | ||
module Webhooks | ||
class Create | ||
attr_reader :params, :pact_broker_base_url, :basic_auth_options, :verbose | ||
|
||
def self.call(params, pact_broker_base_url, pact_broker_client_options) | ||
new(params, pact_broker_base_url, pact_broker_client_options).call | ||
end | ||
|
||
def initialize(params, pact_broker_base_url, pact_broker_client_options) | ||
@params = OpenStruct.new(params) | ||
@pact_broker_base_url = pact_broker_base_url | ||
@basic_auth_options = pact_broker_client_options[:basic_auth] || {} | ||
@verbose = pact_broker_client_options[:verbose] | ||
end | ||
|
||
def call | ||
request_body = JSON.parse(params.body) rescue params.body | ||
|
||
body = { | ||
events: params.events.collect{ | event | { "name" => event }}, | ||
request: { | ||
url: params.url, | ||
method: params.http_method, | ||
headers: params.headers, | ||
body: request_body, | ||
username: params.username, | ||
password: params.password | ||
} | ||
} | ||
|
||
#TODO look for relation | ||
create_webhook_url = "#{pact_broker_base_url.chomp("/")}/webhooks/provider/{provider}/consumer/{consumer}" | ||
http_client = PactBroker::Client::Hal::HttpClient.new(basic_auth_options.merge(verbose: verbose)) | ||
link = PactBroker::Client::Hal::Link.new({"href" => create_webhook_url}, http_client) | ||
entity = link.expand(consumer: params.consumer, provider: params.provider).post(body) | ||
if entity.success? | ||
CommandResult.new(true, "Webhook #{entity._link('self').title_or_name.inspect} created") | ||
else | ||
CommandResult.new(false, "Error creating webhook. response status=#{entity.response.code} body=#{entity.response.body}") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.