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.
feat: add list-environments and describe-environment
- Loading branch information
Showing
18 changed files
with
436 additions
and
183 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,6 @@ | |
|
||
* [A request for the index resource](#a_request_for_the_index_resource_given_the_pacticipant_relations_are_present) given the pacticipant relations are present | ||
|
||
* [A request for the index resource](#a_request_for_the_index_resource_given_the_pb:environments_relation_exists_in_the_index_resource) given the pb:environments relation exists in the index resource | ||
|
||
* [A request for the index resource](#a_request_for_the_index_resource_given_the_pb:latest-tagged-version_relation_exists_in_the_index_resource) given the pb:latest-tagged-version relation exists in the index resource | ||
|
||
* [A request for the index resource](#a_request_for_the_index_resource_given_the_pb:latest-version_relation_exists_in_the_index_resource) given the pb:latest-version relation exists in the index resource | ||
|
@@ -68,8 +66,6 @@ | |
|
||
* [A request to create a webhook with every possible event type](#a_request_to_create_a_webhook_with_every_possible_event_type_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker | ||
|
||
* [A request to create an environment](#a_request_to_create_an_environment) | ||
|
||
* [A request to get the Pricing Service](#a_request_to_get_the_Pricing_Service_given_the_'Pricing_Service'_already_exists_in_the_pact-broker) given the 'Pricing Service' already exists in the pact-broker | ||
|
||
* [A request to get the Pricing Service](#a_request_to_get_the_Pricing_Service_given_the_'Pricing_Service'_does_not_exist_in_the_pact-broker) given the 'Pricing Service' does not exist in the pact-broker | ||
|
@@ -606,33 +602,6 @@ Pact Broker will respond with: | |
} | ||
} | ||
``` | ||
<a name="a_request_for_the_index_resource_given_the_pb:environments_relation_exists_in_the_index_resource"></a> | ||
Given **the pb:environments relation exists in the index resource**, upon receiving **a request for the index resource** from Pact Broker Client, with | ||
```json | ||
{ | ||
"method": "GET", | ||
"path": "/", | ||
"headers": { | ||
"Accept": "application/hal+json" | ||
} | ||
} | ||
``` | ||
Pact Broker will respond with: | ||
```json | ||
{ | ||
"status": 200, | ||
"headers": { | ||
"Content-Type": "application/hal+json;charset=utf-8" | ||
}, | ||
"body": { | ||
"_links": { | ||
"pb:environments": { | ||
"href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
<a name="a_request_for_the_index_resource_given_the_pb:latest-tagged-version_relation_exists_in_the_index_resource"></a> | ||
Given **the pb:latest-tagged-version relation exists in the index resource**, upon receiving **a request for the index resource** from Pact Broker Client, with | ||
```json | ||
|
@@ -1485,54 +1454,6 @@ Pact Broker will respond with: | |
} | ||
} | ||
``` | ||
<a name="a_request_to_create_an_environment"></a> | ||
Upon receiving **a request to create an environment** from Pact Broker Client, with | ||
```json | ||
{ | ||
"method": "POST", | ||
"path": "/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Accept": "application/hal+json" | ||
}, | ||
"body": { | ||
"name": "test", | ||
"displayName": "Test", | ||
"production": false, | ||
"contacts": [ | ||
{ | ||
"name": "Foo team", | ||
"details": { | ||
"emailAddress": "[email protected]" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
Pact Broker will respond with: | ||
```json | ||
{ | ||
"status": 201, | ||
"headers": { | ||
"Content-Type": "application/hal+json;charset=utf-8" | ||
}, | ||
"body": { | ||
"name": "test", | ||
"displayName": "Test", | ||
"production": false, | ||
"contacts": [ | ||
{ | ||
"name": "Foo team", | ||
"details": { | ||
"emailAddress": "[email protected]" | ||
} | ||
} | ||
], | ||
"uuid": "ffe683ef-dcd7-4e4f-877d-f6eb3db8e86e" | ||
} | ||
} | ||
``` | ||
<a name="a_request_to_get_the_Pricing_Service_given_the_'Pricing_Service'_already_exists_in_the_pact-broker"></a> | ||
Given **the 'Pricing Service' already exists in the pact-broker**, upon receiving **a request to get the Pricing Service** from Pact Broker Client, with | ||
```json | ||
|
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,3 @@ | ||
Dir.glob(File.join(__FILE__.gsub(".rb", "/**/*.rb"))).sort.each do | path | | ||
require path | ||
end |
36 changes: 36 additions & 0 deletions
36
lib/pact_broker/client/environments/describe_environment.rb
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,36 @@ | ||
require 'pact_broker/client/environments/environment_command' | ||
require 'pact_broker/client/generate_display_name' | ||
require 'yaml' | ||
|
||
module PactBroker | ||
module Client | ||
module Environments | ||
class DescribeEnvironment < PactBroker::Client::Environments::EnvironmentCommand | ||
include PactBroker::Client::GenerateDisplayName | ||
private | ||
|
||
def do_call | ||
existing_environment_resource! | ||
PactBroker::Client::CommandResult.new(true, result_message) | ||
end | ||
|
||
def result_message | ||
if json_output? | ||
existing_environment_resource.response.raw_body | ||
else | ||
YAML.dump(displayify_keys(existing_environment_resource.response.body.except("_links"))).gsub("---\n", "") | ||
end | ||
end | ||
|
||
def displayify_keys(thing) | ||
case thing | ||
when Hash then thing.each_with_object({}) { | (key, value), new_hash | new_hash[generate_display_name(key)] = displayify_keys(value) } | ||
when Array then thing.collect{ | value | displayify_keys(value) } | ||
else | ||
thing | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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,30 @@ | ||
require 'pact_broker/client/environments/environment_command' | ||
require 'pact_broker/client/environments/text_formatter' | ||
|
||
module PactBroker | ||
module Client | ||
module Environments | ||
class ListEnvironments < PactBroker::Client::Environments::EnvironmentCommand | ||
private | ||
|
||
attr_reader :environments_resource | ||
|
||
def do_call | ||
PactBroker::Client::CommandResult.new(true, result_message) | ||
end | ||
|
||
def environments_resource | ||
@environments_resource = environments_link.get! | ||
end | ||
|
||
def result_message | ||
if json_output? | ||
environments_resource.response.raw_body | ||
else | ||
PactBroker::Client::Environments::TextFormatter.call(environments_resource._embedded["environments"]) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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,30 @@ | ||
require 'table_print' | ||
require 'ostruct' | ||
|
||
module PactBroker | ||
module Client | ||
module Environments | ||
class TextFormatter | ||
|
||
def self.call(environments) | ||
return "" if environments.size == 0 | ||
|
||
data = environments.collect do | environment | | ||
OpenStruct.new(environment) | ||
end | ||
|
||
uuid_width = data.collect(&:uuid).collect(&:size).max | ||
|
||
tp_options = [ | ||
{ uuid: { width: uuid_width } }, | ||
{ name: {} }, | ||
{ displayName: { display_name: "Display name" } }, | ||
{ production: {} } | ||
] | ||
|
||
TablePrint::Printer.new(data, tp_options).table_print | ||
end | ||
end | ||
end | ||
end | ||
end |
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,27 @@ | ||
require 'pact_broker/client/string_refinements' | ||
|
||
module PactBroker | ||
module Client | ||
module GenerateDisplayName | ||
using PactBroker::Client::StringRefinements | ||
|
||
def self.call(name) | ||
return nil if name.nil? | ||
name | ||
.to_s | ||
.gsub(/([A-Z])([A-Z])([a-z])/,'\1 \2\3') | ||
.gsub(/([a-z\d])([A-Z])(\S)/,'\1 \2\3') | ||
.gsub(/(\S)([\-_\s\.])(\S)/, '\1 \3') | ||
.gsub(/\s+/, " ") | ||
.strip | ||
.split(" ") | ||
.collect{ |word| word.camelcase(true) } | ||
.join(" ") | ||
end | ||
|
||
def generate_display_name(name) | ||
GenerateDisplayName.call(name) | ||
end | ||
end | ||
end | ||
end |
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,56 @@ | ||
module PactBroker | ||
module Client | ||
module StringRefinements | ||
refine NilClass do | ||
def blank? | ||
true | ||
end | ||
end | ||
|
||
refine String do | ||
def not_blank? | ||
!blank? | ||
end | ||
|
||
def blank? | ||
self.strip.size == 0 | ||
end | ||
|
||
# ripped from rubyworks/facets, thank you | ||
def snakecase | ||
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2') | ||
.gsub(/([a-z\d])([A-Z])/,'\1_\2') | ||
.tr('-', '_') | ||
.gsub(/\s/, '_') | ||
.gsub(/__+/, '_') | ||
.downcase | ||
end | ||
|
||
# ripped from rubyworks/facets, thank you | ||
def camelcase(*separators) | ||
case separators.first | ||
when Symbol, TrueClass, FalseClass, NilClass | ||
first_letter = separators.shift | ||
end | ||
|
||
separators = ['_', '\s'] if separators.empty? | ||
|
||
str = self.dup | ||
|
||
separators.each do |s| | ||
str = str.gsub(/(?:#{s}+)([a-z])/){ $1.upcase } | ||
end | ||
|
||
case first_letter | ||
when :upper, true | ||
str = str.gsub(/(\A|\s)([a-z])/){ $1 + $2.upcase } | ||
when :lower, false | ||
str = str.gsub(/(\A|\s)([A-Z])/){ $1 + $2.downcase } | ||
end | ||
|
||
str | ||
end | ||
end | ||
end | ||
end | ||
end |
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,7 @@ | ||
Name: existing name | ||
Display Name: existing display name | ||
Production: true | ||
Contacts: | ||
- Name: Someone | ||
Details: | ||
Email Address: [email protected] |
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 @@ | ||
UUID | NAME | DISPLAY NAME | PRODUCTION | ||
-------------------------------------|------|--------------|----------- | ||
78e85fb2-9df1-48da-817e-c9bea6294e01 | test | Test | false |
Oops, something went wrong.