pact_broker 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/CONTRIBUTING.md +6 -0
- data/README.md +12 -8
- data/lib/pact_broker/api.rb +27 -27
- data/lib/pact_broker/api/renderers/html_pact_renderer.rb +6 -1
- data/lib/pact_broker/api/resources/base_resource.rb +9 -1
- data/lib/pact_broker/app.rb +57 -24
- data/lib/pact_broker/configuration.rb +26 -0
- data/lib/pact_broker/diagnostic/app.rb +2 -2
- data/lib/pact_broker/diagnostic/resources/base_resource.rb +17 -0
- data/lib/pact_broker/diagnostic/resources/dependencies.rb +2 -2
- data/lib/pact_broker/diagnostic/resources/heartbeat.rb +2 -2
- data/lib/pact_broker/ui/app.rb +2 -49
- data/lib/pact_broker/ui/controllers/relationships.rb +1 -1
- data/lib/pact_broker/ui/views/groups/show.html.erb +1 -0
- data/lib/pact_broker/ui/views/layouts/main.haml +5 -1
- data/lib/pact_broker/ui/views/relationships/show.haml +1 -4
- data/lib/pact_broker/version.rb +1 -1
- data/lib/rack/pact_broker/accepts_html_filter.rb +31 -0
- data/public/images/favicon.ico +0 -0
- data/spec/integration/app_spec.rb +9 -3
- data/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb +1 -0
- data/spec/lib/pact_broker/api/resources/latest_pact_spec.rb +1 -1
- data/spec/lib/pact_broker/api/resources/tag_spec.rb +2 -2
- data/spec/lib/pact_broker/app_spec.rb +35 -2
- data/spec/spec_helper.rb +4 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b8b4752ea480c1accb24a8ac99986695d2927e1
|
4
|
+
data.tar.gz: d6cd4104ef81b44b089ee51f37d28d46de6edc11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3369dc3103dc71184db705883000d0ac6a522ca1f7450bf9635ae0976be70eff8a655be909d002c3157a5d7955ab991f3ccd348fc2eedf4960d04548eb43184
|
7
|
+
data.tar.gz: 7d863d3a17c5d4aa0dcf05fcbe7584a085792894263e1486db6d90570e5aa8d6341eea39e6f06d6b622332363c03c02f84d5f3c497f116bc8c9ed15d0632009f
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
Do this to generate your change history
|
2
2
|
|
3
|
-
$ git log --pretty=format:' * %h - %s (%an, %ad)'
|
3
|
+
$ git log --pretty=format:' * %h - %s (%an, %ad)'
|
4
|
+
|
5
|
+
#### 2.0.4 (2017-06-02)
|
6
|
+
* 99e1c25 - Turn off http_origin checking for https://github.com/pact-foundation/pact_broker/issues/108 (Beth Skurrie, Fri Jun 2 16:27:38 2017 +1000)
|
7
|
+
* e58f609 - Add favicon.ico (Beth Skurrie, Mon May 29 15:02:22 2017 +1000)
|
8
|
+
* 2780f0a - Add pull request guidelines. (Beth Skurrie, Mon May 29 11:45:04 2017 +1000)
|
4
9
|
|
5
10
|
#### 2.0.3 (2017-05-17)
|
6
11
|
* c03b871 - Make specs pass for sqlite, postgres and mysql. At the same time. Amazing. (Beth Skurrie, Sun May 28 10:22:20 2017 +1000)
|
data/CONTRIBUTING.md
CHANGED
@@ -10,6 +10,12 @@ Please provide the following information with your issue to enable us to respond
|
|
10
10
|
* An executable code example where possible. You can use the [pact-ruby-e2e-example] codebase to quickly recreate your issue.
|
11
11
|
* Where you are using a pact broker deployed on third party infrastructure, please include the relevant details.
|
12
12
|
|
13
|
+
# Pull requests
|
14
|
+
* Write tests for any changes
|
15
|
+
* Follow existing code style and conventions
|
16
|
+
* Separate unrelated changes into multiple pull requests
|
17
|
+
* For bigger changes, make sure you start a discussion first by creating an issue and explaining the intended change
|
18
|
+
|
13
19
|
[wiki]: https://github.com/pact-foundation/pact_broker/wiki
|
14
20
|
[stackoverflow]: https://stackoverflow.com/questions/tagged/pact-broker
|
15
21
|
[pact-ruby-e2e-example]: https://github.com/pact-foundation/pact-ruby-e2e-example
|
data/README.md
CHANGED
@@ -90,20 +90,23 @@ Use the HAL browser to view documentation as you browse.
|
|
90
90
|
* Click on the HAL Browser link to have a poke around the API.
|
91
91
|
* Click on the book icon under "docs" to view documentation related to a given relation.
|
92
92
|
|
93
|
-
###
|
93
|
+
### For reals
|
94
94
|
|
95
|
-
|
96
|
-
the [Hosted Pact Broker](https://pact.dius.com.au/?utm_source=github&utm_campaign=GITHUB_BROKER&utm_medium=github) - it's fast, it's secure and it's free!
|
95
|
+
#### Hosted
|
97
96
|
|
98
|
-
|
97
|
+
In a hurry? Hate having to run your own infrastructure? Check out the [Hosted Pact Broker][hosted] - it's fast, it's secure and it's free!
|
98
|
+
|
99
|
+
#### Container solutions
|
100
|
+
|
101
|
+
You can use the [Pact Broker Docker container][docker] or [Terraform on AWS][terraform]
|
99
102
|
|
100
|
-
|
103
|
+
#### Rolling your own
|
101
104
|
|
102
|
-
* Create a
|
103
|
-
* __Note:__ It is recommended to use __PostgreSQL__ as it will support JSON search features that are planned in
|
105
|
+
* Create a PostgreSQL (recommended) or MySQL (not recommended, see following note) database.
|
106
|
+
* __Note:__ It is recommended to use __PostgreSQL__ as it will support JSON search features that are planned in the future, however MySQL the other [semi supported](https://github.com/pact-foundation/pact_broker/issues/33) database.
|
104
107
|
* Install ruby 2.2.0 or later and bundler >= 1.12.0
|
105
108
|
* Copy the [example](/example) directory to the location you want to install the application.
|
106
|
-
* Modify the config.ru and Gemfile as desired (eg. choose database driver gem, set your database credentials. Use the "pg" gem if using Postgres
|
109
|
+
* Modify the config.ru and Gemfile as desired (eg. choose database driver gem, set your database credentials. Use the "pg" gem if using Postgres and the "mysql2" gem if using MySQL)
|
107
110
|
* Please ensure you use `encoding: 'utf8'` in your Sequel options to avoid encoding issues.
|
108
111
|
* For production usage, use a web application server like [Phusion Passenger](https://www.phusionpassenger.com) or [Nginx](http://nginx.org/) to serve the Pact Broker application.
|
109
112
|
* Deploy to your location of choice.
|
@@ -114,3 +117,4 @@ You can use the [Pact Broker Docker container][docker] or [Terraform on AWS][ter
|
|
114
117
|
[different-teams]: https://github.com/realestate-com-au/pact/wiki/Using-pact-where-the-consumer-team-is-different-from-the-provider-team
|
115
118
|
[docker]: https://hub.docker.com/r/dius/pact-broker
|
116
119
|
[terraform]: https://github.com/nadnerb/terraform-pact-broker
|
120
|
+
[hosted]: https://pact.dius.com.au/?utm_source=github&utm_campaign=GITHUB_BROKER&utm_medium=github
|
data/lib/pact_broker/api.rb
CHANGED
@@ -36,47 +36,47 @@ module PactBroker
|
|
36
36
|
app.routes do
|
37
37
|
add(['trace', :*], Webmachine::Trace::TraceResource) unless ENV['RACK_ENV'] == 'production'
|
38
38
|
|
39
|
-
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'versions'], Api::Resources::PactVersions
|
40
|
-
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'versions', :consumer_version_number], Api::Resources::Pact # Not the standard URL, but keep for backwards compatibility
|
39
|
+
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'versions'], Api::Resources::PactVersions, {resource_name: "pact_publications"}
|
40
|
+
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'versions', :consumer_version_number], Api::Resources::Pact, {resource_name: "pact_publication", deprecated: true} # Not the standard URL, but keep for backwards compatibility
|
41
41
|
|
42
42
|
# Pacts
|
43
|
-
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number], Api::Resources::Pact
|
44
|
-
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number, 'previous-distinct'], Api::Resources::PreviousDistinctPactVersion
|
45
|
-
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number, 'diff', 'previous-distinct'], Api::Resources::PactContentDiff
|
43
|
+
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number], Api::Resources::Pact, {resource_name: "pact_publication"}
|
44
|
+
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number, 'previous-distinct'], Api::Resources::PreviousDistinctPactVersion, {resource_name: "previous_distinct_pact_version"}
|
45
|
+
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number, 'diff', 'previous-distinct'], Api::Resources::PactContentDiff, {resource_name: "previous_distinct_pact_version_diff"}
|
46
46
|
|
47
47
|
# Verifications
|
48
|
-
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'pact-version', :pact_version_sha, 'verification-results'], Api::Resources::Verifications
|
49
|
-
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'pact-version', :pact_version_sha, 'verification-results', :verification_number], Api::Resources::Verification
|
50
|
-
add ['verification-results', 'consumer', :consumer_name, 'version', :consumer_version_number,'latest'], Api::Resources::LatestVerificationsForConsumerVersion
|
48
|
+
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'pact-version', :pact_version_sha, 'verification-results'], Api::Resources::Verifications, {resource_name: "verification_results"}
|
49
|
+
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'pact-version', :pact_version_sha, 'verification-results', :verification_number], Api::Resources::Verification, {resource_name: "verification_result"}
|
50
|
+
add ['verification-results', 'consumer', :consumer_name, 'version', :consumer_version_number,'latest'], Api::Resources::LatestVerificationsForConsumerVersion, {resource_name: "verification_results_for_consumer_version"}
|
51
51
|
|
52
52
|
# Latest pacts
|
53
|
-
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'latest'], Api::Resources::LatestPact
|
54
|
-
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'latest', :tag], Api::Resources::LatestPact
|
55
|
-
add ['pacts', 'provider', :provider_name, 'latest'], Api::Resources::LatestProviderPacts
|
56
|
-
add ['pacts', 'provider', :provider_name, 'latest', :tag], Api::Resources::LatestProviderPacts
|
57
|
-
add ['pacts', 'latest'], Api::Resources::LatestPacts
|
53
|
+
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'latest'], Api::Resources::LatestPact, {resource_name: "latest_pact_publication"}
|
54
|
+
add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'latest', :tag], Api::Resources::LatestPact, {resource_name: "latest_tagged_pact_publication"}
|
55
|
+
add ['pacts', 'provider', :provider_name, 'latest'], Api::Resources::LatestProviderPacts, {resource_name: "latest_provider_pact_publications"}
|
56
|
+
add ['pacts', 'provider', :provider_name, 'latest', :tag], Api::Resources::LatestProviderPacts, {resource_name: "latest_tagged_provider_pact_publications"}
|
57
|
+
add ['pacts', 'latest'], Api::Resources::LatestPacts, {resource_name: "latest_pacts"}
|
58
58
|
|
59
59
|
# Deprecated pact
|
60
|
-
add ['pact', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number], Api::Resources::Pact # Deprecate, singular /pact
|
61
|
-
add ['pact', 'provider', :provider_name, 'consumer', :consumer_name, 'latest'], Api::Resources::LatestPact
|
60
|
+
add ['pact', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number], Api::Resources::Pact, {resource_name: "pact_publications", deprecated: "true"} # Deprecate, singular /pact
|
61
|
+
add ['pact', 'provider', :provider_name, 'consumer', :consumer_name, 'latest'], Api::Resources::LatestPact, {resource_name: "latest_pact_publications", deprecated: "true"}
|
62
62
|
|
63
63
|
# Pacticipants
|
64
|
-
add ['pacticipants'], Api::Resources::Pacticipants
|
65
|
-
add ['pacticipants', :name], Api::Resources::Pacticipant
|
66
|
-
add ['pacticipants', :pacticipant_name, 'versions'], Api::Resources::Versions
|
67
|
-
add ['pacticipants', :pacticipant_name, 'versions', :pacticipant_version_number], Api::Resources::Version
|
68
|
-
add ['pacticipants', :pacticipant_name, 'versions', :pacticipant_version_number, 'tags', :tag_name], Api::Resources::Tag
|
64
|
+
add ['pacticipants'], Api::Resources::Pacticipants, {resource_name: "pacticipants"}
|
65
|
+
add ['pacticipants', :name], Api::Resources::Pacticipant, {resource_name: "pacticipant"}
|
66
|
+
add ['pacticipants', :pacticipant_name, 'versions'], Api::Resources::Versions, {resource_name: "pacticipant_versions"}
|
67
|
+
add ['pacticipants', :pacticipant_name, 'versions', :pacticipant_version_number], Api::Resources::Version, {resource_name: "pacticipant_version"}
|
68
|
+
add ['pacticipants', :pacticipant_name, 'versions', :pacticipant_version_number, 'tags', :tag_name], Api::Resources::Tag, {resource_name: "pacticipant_version_tag"}
|
69
69
|
|
70
70
|
# Webhooks
|
71
|
-
add ['webhooks', 'provider', :provider_name, 'consumer', :consumer_name ], Api::Resources::PactWebhooks
|
72
|
-
add ['webhooks', :uuid ], Api::Resources::Webhook
|
73
|
-
add ['webhooks', :uuid, 'execute' ], Api::Resources::WebhookExecution
|
74
|
-
add ['webhooks'], Api::Resources::Webhooks
|
71
|
+
add ['webhooks', 'provider', :provider_name, 'consumer', :consumer_name ], Api::Resources::PactWebhooks, {resource_name: "pact_webhooks"}
|
72
|
+
add ['webhooks', :uuid ], Api::Resources::Webhook, {resource_name: "webhook"}
|
73
|
+
add ['webhooks', :uuid, 'execute' ], Api::Resources::WebhookExecution, {resource_name: "execute_webhook"}
|
74
|
+
add ['webhooks'], Api::Resources::Webhooks, {resource_name: "webhooks"}
|
75
75
|
|
76
|
-
add ['relationships'], Api::Resources::Relationships
|
77
|
-
add ['groups', :pacticipant_name], Api::Resources::Group
|
76
|
+
add ['relationships'], Api::Resources::Relationships, {resource_name: "relationships"}
|
77
|
+
add ['groups', :pacticipant_name], Api::Resources::Group, {resource_name: "group"}
|
78
78
|
|
79
|
-
add [], Api::Resources::Index
|
79
|
+
add [], Api::Resources::Index, {resource_name: "index"}
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -35,7 +35,8 @@ module PactBroker
|
|
35
35
|
private
|
36
36
|
|
37
37
|
def head
|
38
|
-
"<
|
38
|
+
"<title>#{title}</title>
|
39
|
+
<link rel='stylesheet' type='text/css' href='/stylesheets/github.css'>
|
39
40
|
<link rel='stylesheet' type='text/css' href='/stylesheets/pact.css'>
|
40
41
|
<link rel='stylesheet' type='text/css' href='/stylesheets/github-json.css'>
|
41
42
|
<script src='/javascripts/highlight.pack.js'></script>
|
@@ -60,6 +61,10 @@ module PactBroker
|
|
60
61
|
</div>"
|
61
62
|
end
|
62
63
|
|
64
|
+
def title
|
65
|
+
"Pact between #{@pact.consumer.name} and #{@pact.provider.name}"
|
66
|
+
end
|
67
|
+
|
63
68
|
def published_date
|
64
69
|
@pact.created_at.to_time.localtime.to_datetime.strftime("%a %d %b %Y, %l:%M%P %:z")
|
65
70
|
end
|
@@ -31,9 +31,17 @@ module PactBroker
|
|
31
31
|
include PactBroker::Api::PactBrokerUrls
|
32
32
|
include PactBroker::Logging
|
33
33
|
|
34
|
+
def initialize
|
35
|
+
PactBroker.configuration.before_resource.call(self)
|
36
|
+
end
|
37
|
+
|
38
|
+
def finish_request
|
39
|
+
PactBroker.configuration.after_resource.call(self)
|
40
|
+
end
|
41
|
+
|
34
42
|
def identifier_from_path
|
35
43
|
request.path_info.each_with_object({}) do | pair, hash|
|
36
|
-
hash[pair.first] = URI.decode(pair.last)
|
44
|
+
hash[pair.first] = pair.last === String ? URI.decode(pair.last) : pair.last
|
37
45
|
end
|
38
46
|
end
|
39
47
|
|
data/lib/pact_broker/app.rb
CHANGED
@@ -7,6 +7,7 @@ require 'rack/pact_broker/add_pact_broker_version_header'
|
|
7
7
|
require 'rack/pact_broker/convert_file_extension_to_accept_header'
|
8
8
|
require 'rack/pact_broker/database_transaction'
|
9
9
|
require 'rack/pact_broker/invalid_uri_protection'
|
10
|
+
require 'rack/pact_broker/accepts_html_filter'
|
10
11
|
require 'sucker_punch'
|
11
12
|
|
12
13
|
module PactBroker
|
@@ -16,14 +17,21 @@ module PactBroker
|
|
16
17
|
attr_accessor :configuration
|
17
18
|
|
18
19
|
def initialize &block
|
20
|
+
@app_builder = ::Rack::Builder.new
|
21
|
+
@cascade_apps = []
|
19
22
|
@configuration = PactBroker.configuration
|
20
23
|
yield configuration
|
21
24
|
post_configure
|
22
|
-
|
25
|
+
migrate_database
|
26
|
+
prepare_app
|
27
|
+
end
|
28
|
+
|
29
|
+
def use *args, &block
|
30
|
+
@app_builder.use *args, &block
|
23
31
|
end
|
24
32
|
|
25
33
|
def call env
|
26
|
-
|
34
|
+
running_app.call env
|
27
35
|
end
|
28
36
|
|
29
37
|
private
|
@@ -36,7 +44,9 @@ module PactBroker
|
|
36
44
|
PactBroker.logger = configuration.logger
|
37
45
|
SuckerPunch.logger = configuration.logger
|
38
46
|
configure_database_connection
|
47
|
+
end
|
39
48
|
|
49
|
+
def migrate_database
|
40
50
|
if configuration.auto_migrate_db
|
41
51
|
logger.info "Migrating database"
|
42
52
|
PactBroker::DB.run_migrations configuration.database_connection
|
@@ -55,44 +65,67 @@ module PactBroker
|
|
55
65
|
Sequel.typecast_timezone = :utc # If no timezone specified on dates going into the database, assume they are UTC
|
56
66
|
end
|
57
67
|
|
58
|
-
def
|
59
|
-
|
68
|
+
def prepare_app
|
69
|
+
configure_middleware
|
60
70
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
@
|
71
|
+
if configuration.enable_diagnostic_endpoints
|
72
|
+
@cascade_apps << build_diagnostic
|
73
|
+
end
|
74
|
+
|
75
|
+
@cascade_apps << build_ui
|
76
|
+
@cascade_apps << build_api
|
77
|
+
end
|
78
|
+
|
79
|
+
def configure_middleware
|
80
|
+
@app_builder.use Rack::Protection, except: [:remote_token, :session_hijacking, :http_origin]
|
81
|
+
@app_builder.use Rack::PactBroker::InvalidUriProtection
|
82
|
+
@app_builder.use Rack::PactBroker::AddPactBrokerVersionHeader
|
83
|
+
@app_builder.use Rack::Static, :urls => ["/stylesheets", "/css", "/fonts", "/js", "/javascripts", "/images"], :root => PactBroker.project_root.join("public")
|
84
|
+
@app_builder.use Rack::Static, :urls => ["/favicon.ico"], :root => PactBroker.project_root.join("public/images"), header_rules: [[:all, {'Content-Type' => 'image/x-icon'}]]
|
85
|
+
@app_builder.use Rack::PactBroker::ConvertFileExtensionToAcceptHeader
|
66
86
|
|
67
87
|
if configuration.use_hal_browser
|
68
88
|
logger.info "Mounting HAL browser"
|
69
|
-
@
|
89
|
+
@app_builder.use Rack::HalBrowser::Redirect
|
70
90
|
else
|
71
91
|
logger.info "Not mounting HAL browser"
|
72
92
|
end
|
93
|
+
end
|
73
94
|
|
95
|
+
def build_ui
|
74
96
|
logger.info "Mounting UI"
|
75
97
|
require 'pact_broker/ui'
|
98
|
+
builder = ::Rack::Builder.new
|
99
|
+
builder.use Rack::PactBroker::AcceptsHtmlFilter
|
100
|
+
builder.run PactBroker::UI::App.new
|
101
|
+
builder
|
102
|
+
end
|
76
103
|
|
104
|
+
def build_api
|
77
105
|
logger.info "Mounting PactBroker::API"
|
78
106
|
require 'pact_broker/api'
|
107
|
+
builder = ::Rack::Builder.new
|
108
|
+
builder.use Rack::PactBroker::DatabaseTransaction, configuration.database_connection
|
109
|
+
builder.run PactBroker::API
|
110
|
+
builder
|
111
|
+
end
|
79
112
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
apps << PactBroker::UI::App.new
|
88
|
-
apps << Rack::PactBroker::DatabaseTransaction.new(PactBroker::API, configuration.database_connection)
|
113
|
+
def build_diagnostic
|
114
|
+
require 'pact_broker/diagnostic/app'
|
115
|
+
builder = ::Rack::Builder.new
|
116
|
+
builder.run PactBroker::Diagnostic::App.new
|
117
|
+
builder
|
118
|
+
end
|
89
119
|
|
90
|
-
|
91
|
-
|
120
|
+
def running_app
|
121
|
+
@running_app ||= begin
|
122
|
+
apps = @cascade_apps
|
123
|
+
@app_builder.map "/" do
|
124
|
+
run Rack::Cascade.new(apps)
|
125
|
+
end
|
126
|
+
@app_builder
|
92
127
|
end
|
93
|
-
|
94
128
|
end
|
95
129
|
|
96
130
|
end
|
97
|
-
|
98
|
-
end
|
131
|
+
end
|
@@ -4,6 +4,11 @@ module PactBroker
|
|
4
4
|
@@configuration ||= Configuration.default_configuration
|
5
5
|
end
|
6
6
|
|
7
|
+
# @private, for testing only
|
8
|
+
def self.reset_configuration
|
9
|
+
@@configuration = Configuration.default_configuration
|
10
|
+
end
|
11
|
+
|
7
12
|
class Configuration
|
8
13
|
|
9
14
|
SAVABLE_SETTING_NAMES = [:order_versions_by_date, :use_case_sensitive_resource_names]
|
@@ -14,6 +19,11 @@ module PactBroker
|
|
14
19
|
attr_accessor :semver_formats
|
15
20
|
attr_writer :logger
|
16
21
|
|
22
|
+
def initialize
|
23
|
+
@before_resource_hook = ->(resource){}
|
24
|
+
@after_resource_hook = ->(resource){}
|
25
|
+
end
|
26
|
+
|
17
27
|
def logger
|
18
28
|
@logger ||= create_logger log_path
|
19
29
|
end
|
@@ -43,6 +53,22 @@ module PactBroker
|
|
43
53
|
}
|
44
54
|
end
|
45
55
|
|
56
|
+
def before_resource &block
|
57
|
+
if block_given?
|
58
|
+
@before_resource_hook = block
|
59
|
+
else
|
60
|
+
@before_resource_hook
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def after_resource &block
|
65
|
+
if block_given?
|
66
|
+
@after_resource_hook = block
|
67
|
+
else
|
68
|
+
@after_resource_hook
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
46
72
|
def save_to_database
|
47
73
|
# Can't require a Sequel::Model class before the connection has been set
|
48
74
|
require 'pact_broker/config/save'
|
@@ -21,8 +21,8 @@ module PactBroker
|
|
21
21
|
def build_diagnostic_app
|
22
22
|
app = Webmachine::Application.new do |app|
|
23
23
|
app.routes do
|
24
|
-
add ['diagnostic','status','heartbeat'], Diagnostic::Resources::Heartbeat
|
25
|
-
add ['diagnostic','status','dependencies'], Diagnostic::Resources::Dependencies
|
24
|
+
add ['diagnostic','status','heartbeat'], Diagnostic::Resources::Heartbeat, {resource_name: 'diagnostic_heartbeat'}
|
25
|
+
add ['diagnostic','status','dependencies'], Diagnostic::Resources::Dependencies, {resource_name: 'diagnostic_dependencies'}
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'webmachine'
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module Diagnostic
|
5
|
+
module Resources
|
6
|
+
class BaseResource < Webmachine::Resource
|
7
|
+
def initialize
|
8
|
+
PactBroker.configuration.before_resource.call(self)
|
9
|
+
end
|
10
|
+
|
11
|
+
def finish_request
|
12
|
+
PactBroker.configuration.after_resource.call(self)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'pact_broker/diagnostic/resources/base_resource'
|
2
2
|
require 'pact_broker/db'
|
3
3
|
require 'pact_broker/logging'
|
4
4
|
|
5
5
|
module PactBroker
|
6
6
|
module Diagnostic
|
7
7
|
module Resources
|
8
|
-
class Dependencies <
|
8
|
+
class Dependencies < BaseResource
|
9
9
|
|
10
10
|
include Logging
|
11
11
|
|
data/lib/pact_broker/ui/app.rb
CHANGED
@@ -9,8 +9,6 @@ module PactBroker
|
|
9
9
|
def initialize
|
10
10
|
@app = ::Rack::Builder.new {
|
11
11
|
|
12
|
-
use HtmlFilter
|
13
|
-
|
14
12
|
map "/ui/relationships" do
|
15
13
|
run PactBroker::UI::Controllers::Relationships
|
16
14
|
end
|
@@ -24,7 +22,7 @@ module PactBroker
|
|
24
22
|
end
|
25
23
|
|
26
24
|
map "/" do
|
27
|
-
run
|
25
|
+
run PactBroker::UI::Controllers::Relationships
|
28
26
|
end
|
29
27
|
}
|
30
28
|
end
|
@@ -32,51 +30,6 @@ module PactBroker
|
|
32
30
|
def call env
|
33
31
|
@app.call(env)
|
34
32
|
end
|
35
|
-
|
36
|
-
class RedirectRootToRelationships
|
37
|
-
|
38
|
-
def self.call env
|
39
|
-
# A request for the root path in the browser (not the json index) should
|
40
|
-
# redirect to ui/relationships
|
41
|
-
if (env['PATH_INFO'].chomp("/") == "")
|
42
|
-
[303, {'Location' => "#{env['SCRIPT_NAME']}/ui/relationships"},[]]
|
43
|
-
else
|
44
|
-
[404, {},[]]
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
class HtmlFilter
|
51
|
-
|
52
|
-
def initialize app
|
53
|
-
@app = app
|
54
|
-
end
|
55
|
-
|
56
|
-
def call env
|
57
|
-
if accepts_html_and_not_json_or_csv env
|
58
|
-
@app.call(env)
|
59
|
-
else
|
60
|
-
[404, {},[]]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def accepts_html_and_not_json_or_csv env
|
65
|
-
accept = env['HTTP_ACCEPT'] || ''
|
66
|
-
accepts_html(accept) && !accepts_json_or_csv(accept)
|
67
|
-
end
|
68
|
-
|
69
|
-
def accepts_html(accept)
|
70
|
-
accept.include?("html")
|
71
|
-
end
|
72
|
-
|
73
|
-
def accepts_json_or_csv accept
|
74
|
-
accept.include?("json") || accept.include?("csv")
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
33
|
end
|
80
34
|
end
|
81
|
-
|
82
|
-
end
|
35
|
+
end
|
@@ -12,7 +12,7 @@ module PactBroker
|
|
12
12
|
get "/" do
|
13
13
|
view_model = ViewDomain::Relationships.new(pacticipant_service.find_relationships)
|
14
14
|
|
15
|
-
haml :'relationships/show', {locals: {relationships: view_model}
|
15
|
+
haml :'relationships/show', {locals: {relationships: view_model, title: "Pacts"}, layout: :'layouts/main'}
|
16
16
|
end
|
17
17
|
|
18
18
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
<head>
|
4
4
|
<meta charset="utf-8">
|
5
5
|
<title>Network Graph</title>
|
6
|
+
<link rel='shortcut icon' href='/favicon.ico' type='image/x-icon'/>
|
6
7
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7
8
|
<meta name="description" content="">
|
8
9
|
<meta name="author" content="Duncan Alexander">
|
@@ -1,12 +1,9 @@
|
|
1
|
-
%
|
2
|
-
%title
|
3
|
-
Pacts
|
1
|
+
%body
|
4
2
|
%link{rel: 'stylesheet', href: '/css/bootstrap.min.css'}
|
5
3
|
%link{rel: 'stylesheet', href: '/stylesheets/relationships.css'}
|
6
4
|
%script{type: 'text/javascript', src:'/javascripts/jquery-2.1.1.min.js'}
|
7
5
|
%script{type: 'text/javascript', src:'/javascripts/jquery.tablesorter.min.js'}
|
8
6
|
%script{type: 'text/javascript', src:'/js/bootstrap.min.js'}
|
9
|
-
%body
|
10
7
|
%nav.navbase-default.navbar-right{role: "navigation"}
|
11
8
|
.container
|
12
9
|
%ul
|
data/lib/pact_broker/version.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Rack
|
2
|
+
module PactBroker
|
3
|
+
class AcceptsHtmlFilter
|
4
|
+
|
5
|
+
def initialize app
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call env
|
10
|
+
if accepts_html_and_not_json_or_csv env
|
11
|
+
@app.call(env)
|
12
|
+
else
|
13
|
+
[404, {},[]]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def accepts_html_and_not_json_or_csv env
|
18
|
+
accept = env['HTTP_ACCEPT'] || ''
|
19
|
+
accepts_html(accept) && !accepts_json_or_csv(accept)
|
20
|
+
end
|
21
|
+
|
22
|
+
def accepts_html(accept)
|
23
|
+
accept.include?("html")
|
24
|
+
end
|
25
|
+
|
26
|
+
def accepts_json_or_csv accept
|
27
|
+
accept.include?("json") || accept.include?("csv")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
Binary file
|
@@ -23,6 +23,11 @@ module PactBroker
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
it "exposes a favicon.ico file" do
|
27
|
+
get "/favicon.ico"
|
28
|
+
expect(last_response.headers['Content-Type']).to eq "image/x-icon"
|
29
|
+
end
|
30
|
+
|
26
31
|
context "when Accept includes text/html" do
|
27
32
|
let(:env) { {'HTTP_ACCEPT' => 'text/html'} }
|
28
33
|
|
@@ -32,9 +37,10 @@ module PactBroker
|
|
32
37
|
|
33
38
|
let(:path) { '/' }
|
34
39
|
|
35
|
-
it "
|
36
|
-
expect(subject.status).to eq
|
37
|
-
expect(subject.headers['
|
40
|
+
it "returns the relationships page" do
|
41
|
+
expect(subject.status).to eq 200
|
42
|
+
expect(subject.headers['Content-Type']).to include 'text/html'
|
43
|
+
expect(subject.body).to include 'Pacts'
|
38
44
|
end
|
39
45
|
|
40
46
|
end
|
@@ -40,6 +40,7 @@ module PactBroker
|
|
40
40
|
expect(subject).to match /<h\d>.*Some Provider/
|
41
41
|
expect(subject).to include("Date published:")
|
42
42
|
expect(subject).to include("Thu 27 Feb 2014, 11:00am +11:00")
|
43
|
+
expect(subject).to match /title.*Pact between Consumer and Provider/
|
43
44
|
end
|
44
45
|
|
45
46
|
context "when the content is not a valid pact, but is still JSON" do
|
@@ -29,7 +29,7 @@ module PactBroker::Api
|
|
29
29
|
subject { get "/pacts/provider/provider_name/consumer/consumer_name/latest",{}, {'HTTP_ACCEPT' => "text/html"} }
|
30
30
|
|
31
31
|
it "find the pact" do
|
32
|
-
expect(PactBroker::Pacts::Service).to receive(:find_latest_pact).with(pact_id_params)
|
32
|
+
expect(PactBroker::Pacts::Service).to receive(:find_latest_pact).with(hash_including(pact_id_params))
|
33
33
|
subject
|
34
34
|
end
|
35
35
|
|
@@ -29,7 +29,7 @@ module PactBroker
|
|
29
29
|
|
30
30
|
context "when the tag exists" do
|
31
31
|
it "deletes the tag by name" do
|
32
|
-
expect(Tags::Service).to receive(:delete) .with(tag_attributes)
|
32
|
+
expect(Tags::Service).to receive(:delete) .with(hash_including(tag_attributes))
|
33
33
|
subject
|
34
34
|
end
|
35
35
|
|
@@ -145,7 +145,7 @@ module PactBroker
|
|
145
145
|
|
146
146
|
|
147
147
|
it "creates the tag" do
|
148
|
-
expect(Tags::Service).to receive(:create).with(tag_attributes)
|
148
|
+
expect(Tags::Service).to receive(:create).with(hash_including(tag_attributes))
|
149
149
|
subject
|
150
150
|
end
|
151
151
|
|
@@ -9,7 +9,7 @@ module PactBroker
|
|
9
9
|
# do nothing
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def migrate_database
|
13
13
|
# do nothing
|
14
14
|
end
|
15
15
|
|
@@ -18,7 +18,6 @@ module PactBroker
|
|
18
18
|
let(:app) do
|
19
19
|
TestApp.new do | configuration |
|
20
20
|
configuration.database_connection = PactBroker::DB.connection
|
21
|
-
configuration.auto_migrate_db = false
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
@@ -27,6 +26,40 @@ module PactBroker
|
|
27
26
|
expect(last_response.headers['X-Pact-Broker-Version']).to match /\d/
|
28
27
|
end
|
29
28
|
|
29
|
+
class Middleware
|
30
|
+
|
31
|
+
def initialize app
|
32
|
+
@app = app
|
33
|
+
end
|
34
|
+
|
35
|
+
def call env
|
36
|
+
self.class.calls << env
|
37
|
+
@app.call(env)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.calls
|
41
|
+
@calls ||= []
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "acts like a ::Rack::Builder" do
|
46
|
+
app.use Middleware
|
47
|
+
expect { get "/" }.to change { Middleware.calls.count }.by(1)
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "before_resource and after_resource" do
|
51
|
+
CALLBACKS = []
|
52
|
+
before do
|
53
|
+
PactBroker.configuration.before_resource { | resource | CALLBACKS << "before" }
|
54
|
+
PactBroker.configuration.after_resource { | resource | CALLBACKS << "after" }
|
55
|
+
end
|
56
|
+
|
57
|
+
it "executes the callbacks" do
|
58
|
+
get "/"
|
59
|
+
expect(CALLBACKS).to eq ["before", "after"]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
30
63
|
describe "transactions", no_db_clean: true do
|
31
64
|
let(:pact_content) { load_fixture('a_consumer-a_provider.json') }
|
32
65
|
let(:path) { "/pacts/provider/A%20Provider/consumer/A%20Consumer/versions/1.2.3" }
|
data/spec/spec_helper.rb
CHANGED
@@ -18,6 +18,10 @@ RSpec.configure do | config |
|
|
18
18
|
PactBroker::DB.connection = PactBroker::Database.database = DB::PACT_BROKER_DB
|
19
19
|
end
|
20
20
|
|
21
|
+
config.before :each do
|
22
|
+
PactBroker.reset_configuration
|
23
|
+
end
|
24
|
+
|
21
25
|
config.include Rack::Test::Methods
|
22
26
|
config.mock_with :rspec do |mocks|
|
23
27
|
mocks.verify_partial_doubles = true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact_broker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bethany Skurrie
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-06-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httparty
|
@@ -534,6 +534,7 @@ files:
|
|
534
534
|
- lib/pact_broker/db.rb
|
535
535
|
- lib/pact_broker/db/validate_encoding.rb
|
536
536
|
- lib/pact_broker/diagnostic/app.rb
|
537
|
+
- lib/pact_broker/diagnostic/resources/base_resource.rb
|
537
538
|
- lib/pact_broker/diagnostic/resources/dependencies.rb
|
538
539
|
- lib/pact_broker/diagnostic/resources/heartbeat.rb
|
539
540
|
- lib/pact_broker/doc/controllers/app.rb
|
@@ -626,6 +627,7 @@ files:
|
|
626
627
|
- lib/pact_broker/webhooks/webhook.rb
|
627
628
|
- lib/rack/hal_browser.rb
|
628
629
|
- lib/rack/hal_browser/redirect.rb
|
630
|
+
- lib/rack/pact_broker/accepts_html_filter.rb
|
629
631
|
- lib/rack/pact_broker/add_pact_broker_version_header.rb
|
630
632
|
- lib/rack/pact_broker/convert_file_extension_to_accept_header.rb
|
631
633
|
- lib/rack/pact_broker/database_transaction.rb
|
@@ -645,6 +647,7 @@ files:
|
|
645
647
|
- public/fonts/glyphicons-halflings-regular.ttf
|
646
648
|
- public/fonts/glyphicons-halflings-regular.woff
|
647
649
|
- public/images/doc-text.svg
|
650
|
+
- public/images/favicon.ico
|
648
651
|
- public/javascripts/d3.v3.js.pagespeed.ce.dFNRrGTALe.js
|
649
652
|
- public/javascripts/highlight.pack.js
|
650
653
|
- public/javascripts/jquery-2.1.1.min.js
|