pact_broker 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pact_broker (0.0.1)
4
+ pact_broker (0.0.2)
5
5
  httparty
6
6
  json
7
+ roar
7
8
  sequel
8
9
  sinatra
9
10
  sinatra-contrib
@@ -49,8 +50,11 @@ GEM
49
50
  multi_xml (>= 0.5.2)
50
51
  json (1.8.1)
51
52
  method_source (0.8.2)
53
+ mini_portile (0.5.1)
52
54
  multi_json (1.8.2)
53
55
  multi_xml (0.5.5)
56
+ nokogiri (1.6.0)
57
+ mini_portile (~> 0.5.0)
54
58
  pry (0.9.12.2)
55
59
  coderay (~> 1.0.5)
56
60
  method_source (~> 0.8)
@@ -62,6 +66,11 @@ GEM
62
66
  rack (>= 1.0)
63
67
  rake (10.0.4)
64
68
  randexp (0.1.7)
69
+ representable (1.6.1)
70
+ multi_json
71
+ nokogiri
72
+ roar (0.12.0)
73
+ representable (~> 1.6.0)
65
74
  rspec (2.14.1)
66
75
  rspec-core (~> 2.14.0)
67
76
  rspec-expectations (~> 2.14.0)
data/README.md CHANGED
@@ -1,94 +1,3 @@
1
- # PactBroker
1
+ # Pact Broker
2
2
 
3
- Add a detailed description of the new service here before your first commit.
4
-
5
- Information here will be consumed by the Treasure Map (via the Rumour Mill). Therefore, please retain the existing formatting on this page, importantly:
6
-
7
- * The service name at the top of the page
8
- * The location of this description text (between service name and Custodian(s)
9
- * Component Custodian(s)
10
-
11
- Other headings can be deleted if they are not relevant.
12
-
13
- **NOTE: The following is provided for convenience. Please check it carefully before your first commit.**
14
-
15
- ## Component Custodian(s)
16
-
17
- Enter Custodian(s) here
18
-
19
- ## Development
20
-
21
- Enter any developer instructions here.
22
-
23
- ### Database setup
24
-
25
- Instructions to set up the database for local testing.
26
-
27
- Then run migrations:
28
-
29
- $ bundle exec rake db:migrate
30
-
31
- ### Testing
32
-
33
- $ bundle exec rake
34
-
35
- ### Running
36
-
37
- Instructions to run the service locally.
38
-
39
- ### Debugging
40
-
41
- Any specific debugging tools built in to the service (health check is assumed so don't include that).
42
-
43
- ### Build
44
-
45
- **edit the below and add the correct endpoint**
46
-
47
- [Standalone (Bamboo)](http://master.cd.vpc.realestate.com.au/browse/YOUR_NEW_SERVICE_BUILD)
48
-
49
- ## Deployment
50
-
51
- Deployment scripts have been generated using [biq-deploy](https://git.realestate.com.au/business-systems/biq-deploy).
52
-
53
- #### EC2 environments
54
-
55
- Before deploying to EC2 environments, you may wish to check that the build you wish to deploy has been indexed.
56
-
57
- 1. Log in into the agent unix box:
58
-
59
- $ rea-ec2-ssh agent-01.biq
60
-
61
- 2. See the list of versions indexed and verify the expected version in the list:
62
-
63
- $ yum list --showduplicates --enablerepo=rea-el6-dev pact_broker
64
-
65
- You can get up an running with these scripts like so (from within the pact_broker project on your local machine):
66
-
67
- $ cd deploy
68
- $ bundle
69
- $ bundle exec bin/pact-broker-deploy-ec2 --help
70
-
71
- When deploying to an EC2 environment for the first time, you must create a node for the app:
72
-
73
- $ bundle exec bin/pact-broker-deploy-ec2 -t create -s $YOUR_SUBDOMAIN -p dev
74
-
75
- The first time the service is deployed, a database must be created. After adding the [required config values](https://git.realestate.com.au/business-systems/pact_broker/blob/master/lib/pact_broker/environment_variables.rb) to the
76
- environment's config-svc, you can run the db provision task:
77
-
78
- $ bundle exec bin/pact-broker-deploy-ec2 -t db_provision -s $YOUR_SUBDOMAIN
79
-
80
- Then you are free to migrate the db from then on:
81
-
82
- $ bundle exec bin/pact-broker-deploy-ec2 -t db_migrate -s $YOUR_SUBDOMAIN
83
-
84
- To deploy to a test environment (eg biq-qa1):
85
-
86
- $ bundle exec bin/pact-broker-deploy-ec2 -t deploy -s biq-qa1 -p dev -y
87
-
88
- #### Production
89
-
90
- Refer to the [production deployment readme](https://git.realestate.com.au/business-systems/pact_broker/blob/master/README-ProdDeploy.md).
91
-
92
- ### Architecture
93
-
94
- Any important architectural information.
3
+ The Pact Broker provides a repository for pacts created using the pact gem.
@@ -1,13 +1,31 @@
1
1
  require_relative 'base_api'
2
+ require_relative 'representors'
2
3
 
3
4
  module PactBroker
4
-
5
5
  module Api
6
6
 
7
-
8
7
  class PacticipantApi < BaseApi
9
8
 
9
+ get "/pacticipants" do
10
+ pacticipants = pacticipant_service.find_all_pacticipants
11
+ pacticipants.extend(Representors::PacticipantCollectionRepresenter)
12
+ content_type 'application/json+hal;charset=utf-8'
13
+ pacticipants.to_json
14
+ end
15
+
10
16
  namespace '/pacticipants' do
17
+
18
+ get '/:name' do
19
+ pacticipant = pacticipant_service.find_pacticipant_by_name(params[:name])
20
+ if pacticipant
21
+ pacticipant.extend(Representors::PacticipantRepresenter)
22
+ content_type 'application/json+hal;charset=utf-8'
23
+ pacticipant.to_json
24
+ else
25
+ status 404
26
+ end
27
+ end
28
+
11
29
  get '/:name/repository_url' do
12
30
  repository_url = pacticipant_service.find_pacticipant_repository_url_by_pacticipant_name(params[:name])
13
31
  if repository_url
@@ -25,7 +43,9 @@ module PactBroker
25
43
  repository_url: params[:repository_url]
26
44
  )
27
45
  created ? status(201) : status(200)
28
- json pacticipant
46
+ pacticipant.extend(Representors::PacticipantRepresenter)
47
+ content_type 'application/json+hal;charset=utf-8'
48
+ pacticipant.to_json
29
49
  end
30
50
  end
31
51
 
@@ -0,0 +1,3 @@
1
+ require 'pact_broker/api/representors/pacticipant_representor'
2
+ require 'pact_broker/api/representors/pacticipant_collection_representor'
3
+ require 'pact_broker/api/representors/version_representor'
@@ -0,0 +1,34 @@
1
+ module PactBroker
2
+ module Api
3
+ module PactBrokerUrls
4
+
5
+ def base_url
6
+ "http://localhost:1234"
7
+ end
8
+
9
+ def pacticipants_url
10
+ "#{base_url}/pacticipants"
11
+ end
12
+
13
+ def pacticipant_url pacticipant
14
+ "#{pacticipants_url}/#{url_encode(pacticipant.name)}"
15
+ end
16
+
17
+ def last_version_url pacticipant
18
+ "#{pacticipant_url(pacticipant)}/versions/last"
19
+ end
20
+
21
+ def versions_url pacticipant
22
+ "#{pacticipant_url(pacticipant)}/versions"
23
+ end
24
+
25
+ def version_url version
26
+ "#{pacticipant_url(version.pacticipant)}/versions/#{version.number}"
27
+ end
28
+
29
+ def url_encode param
30
+ ERB::Util.url_encode param
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,33 @@
1
+ require 'roar/representer/json/hal'
2
+ require_relative 'pact_broker_urls'
3
+ require_relative 'version_representor'
4
+
5
+ module PactBroker
6
+
7
+ module Api
8
+
9
+ module Representors
10
+
11
+ module PacticipantCollectionRepresenter
12
+ include Roar::Representer::JSON::HAL
13
+ include PactBroker::Api::PactBrokerUrls
14
+
15
+
16
+ collection :pacticipants, :class => PactBroker::Models::Pacticipant, :extend => PactBroker::Api::Representors::PacticipantRepresenter
17
+
18
+ def pacticipants
19
+ self
20
+ end
21
+
22
+ link :self do
23
+ pacticipants_url
24
+ end
25
+
26
+ links :pacticipants do
27
+ collect{ | pacticipant | {:href => pacticipant_url(pacticipant), :name => pacticipant.name } }
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,35 @@
1
+ require 'roar/representer/json/hal'
2
+ require_relative 'pact_broker_urls'
3
+ require_relative 'version_representor'
4
+
5
+ module PactBroker
6
+
7
+ module Api
8
+
9
+ module Representors
10
+
11
+ module PacticipantRepresenter
12
+ include Roar::Representer::JSON::HAL
13
+ include Roar::Representer::JSON::HAL::Links
14
+ include PactBroker::Api::PactBrokerUrls
15
+
16
+ property :name
17
+ property :repository_url
18
+
19
+ property :last_version, :class => PactBroker::Models::Version, :extend => PactBroker::Api::Representors::VersionRepresenter, :embedded => true
20
+
21
+ link :self do
22
+ pacticipant_url(self)
23
+ end
24
+
25
+ link :last_version do
26
+ last_version_url(self)
27
+ end
28
+
29
+ link :versions do
30
+ versions_url(self)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ require 'roar/representer/json/hal'
2
+ require_relative 'pact_broker_urls'
3
+
4
+ module PactBroker
5
+ module Api
6
+ module Representors
7
+ module VersionRepresenter
8
+ include Roar::Representer::JSON::HAL
9
+ include Roar::Representer::JSON::HAL::Links
10
+ include PactBroker::Api::PactBrokerUrls
11
+ property :number
12
+
13
+ link :self do
14
+ version_url(self)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -5,6 +5,9 @@ module PactBroker
5
5
  module Models
6
6
  class Pact < Sequel::Model
7
7
 
8
+ associate(:one_to_one, :provider, :class => "PactBroker::Models::Pacticipant", :key => :id, :primary_key => :provider_id)
9
+ associate(:one_to_one, :consumer_version, :class => "PactBroker::Models::Version", :key => :id, :primary_key => :version_id)
10
+
8
11
  #Need to work out how to do this properly!
9
12
  def consumer_version_number
10
13
  values[:consumer_version_number]
@@ -6,7 +6,12 @@ module PactBroker
6
6
 
7
7
  class Pacticipant < Sequel::Model
8
8
 
9
- one_to_many :versions
9
+ one_to_many :versions, :order => :id, :reciprocal => :pacticipant
10
+ one_to_many :pacts
11
+
12
+ def last_version
13
+ versions.last
14
+ end
10
15
 
11
16
  def to_s
12
17
  "Pacticipant: id=#{id}, name=#{name}"
@@ -7,6 +7,7 @@ module PactBroker
7
7
  class Version < Sequel::Model
8
8
 
9
9
  one_to_many :pacts
10
+ one_to_one :pacticipant
10
11
 
11
12
  def to_s
12
13
  "Version: number=#{number}, pacticipant=#{pacticipant_id}"
@@ -9,6 +9,10 @@ module PactBroker
9
9
  PactBroker::Models::Pacticipant.where(name: name).single_record
10
10
  end
11
11
 
12
+ def find_all
13
+ PactBroker::Models::Pacticipant.order(:name).all
14
+ end
15
+
12
16
  def find_by_name_or_create name
13
17
  if pacticipant = find_by_name(name)
14
18
  pacticipant
@@ -7,6 +7,14 @@ module PactBroker
7
7
 
8
8
  extend PactBroker::Repositories
9
9
 
10
+ def self.find_all_pacticipants
11
+ pacticipant_repository.find_all
12
+ end
13
+
14
+ def self.find_pacticipant_by_name name
15
+ pacticipant_repository.find_by_name(name)
16
+ end
17
+
10
18
  def self.find_pacticipant_repository_url_by_pacticipant_name name
11
19
  pacticipant = pacticipant_repository.find_by_name(name)
12
20
  if pacticipant && pacticipant.repository_url
@@ -1,3 +1,3 @@
1
1
  module PactBroker
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/pact_broker.gemspec CHANGED
@@ -7,11 +7,11 @@ require 'pact_broker/version'
7
7
  Gem::Specification.new do |gem|
8
8
  gem.name = "pact_broker"
9
9
  gem.version = PactBroker::VERSION
10
- gem.authors = ["Bethany Skurrie"]
11
- gem.email = ["bskurrie@dius.com.au"]
12
- gem.description = %q{An server that stores and returns pact files generated by the pact gem. It enables head/prod cross testing of the consumer and provider projects.}
10
+ gem.authors = ["Bethany Skurrie", "Sergei Matheson", "Warner Godfrey"]
11
+ gem.email = ["bskurrie@dius.com.au", "serge.matheson@rea-group.com", "warner@warnergodfrey.com"]
12
+ gem.description = %q{A server that stores and returns pact files generated by the pact gem. It enables head/prod cross testing of the consumer and provider projects.}
13
13
  gem.summary = %q{See description}
14
- gem.homepage = "https://github.com/bethesque/pact_broker.git"
14
+ gem.homepage = "https://github.com/DiUS/pact_broker"
15
15
 
16
16
  gem.files = `git ls-files`.split($/)
17
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -25,6 +25,7 @@ Gem::Specification.new do |gem|
25
25
  gem.add_runtime_dependency 'sinatra'
26
26
  gem.add_runtime_dependency 'sinatra-contrib'
27
27
  gem.add_runtime_dependency 'sinatra-param'
28
+ gem.add_runtime_dependency 'roar'
28
29
  gem.add_runtime_dependency 'sequel'
29
30
  gem.add_runtime_dependency 'sqlite3'
30
31
 
@@ -32,8 +32,7 @@ Pact.service_provider "Pact Broker" do
32
32
  app { PactBroker::API.new }
33
33
 
34
34
  honours_pact_with "Pact Broker Client" do
35
- pact_uri "http://localhost:9292/pacticipants/Pact%20Broker%20Client/versions/last/pacts/Pact%20Broker"
36
- # pact_uri "../pact_broker-client/spec/pacts/pact_broker_client-pact_broker.json"
35
+ pact_uri "../pact_broker-client/spec/pacts/pact_broker_client-pact_broker.json"
37
36
  end
38
37
 
39
38
  end
@@ -5,7 +5,7 @@ class ProviderStateBuilder
5
5
  include PactBroker::Repositories
6
6
 
7
7
  def create_pricing_service
8
- @pricing_service_id = pacticipant_repository.create(:name => 'Pricing Service', :repository_url => 'git@git.realestate.com.au:business-systems/condor.git').save(raise_on_save_failure: true).id
8
+ @pricing_service_id = pacticipant_repository.create(:name => 'Pricing Service', :repository_url => 'git@git.realestate.com.au:business-systems/pricing-service').save(raise_on_save_failure: true).id
9
9
  self
10
10
  end
11
11
 
@@ -19,6 +19,11 @@ class ProviderStateBuilder
19
19
  self
20
20
  end
21
21
 
22
+ def create_pricing_service_version number
23
+ @pricing_service_version_id = version_repository.create(number: number, pacticipant_id: @pricing_service_id).id
24
+ self
25
+ end
26
+
22
27
  def create_pact
23
28
  @pact_id = pact_repository.create(version_id: @condor_version_id, provider_id: @pricing_service_id, json_content: json_content).id
24
29
  self
@@ -50,7 +55,7 @@ Pact.provider_states_for "Pact Broker Client" do
50
55
 
51
56
  provider_state "the 'Pricing Service' already exists in the pact-broker" do
52
57
  set_up do
53
- ProviderStateBuilder.new.create_pricing_service
58
+ ProviderStateBuilder.new.create_pricing_service.create_pricing_service_version("1.3.0")
54
59
  end
55
60
  end
56
61
 
@@ -92,7 +97,7 @@ Pact.provider_states_for "Pact Broker Client" do
92
97
 
93
98
  provider_state "'Condor' exists in the pact-broker" do
94
99
  set_up do
95
- ProviderStateBuilder.new.create_condor
100
+ ProviderStateBuilder.new.create_condor.create_condor_version('1.3.0')
96
101
  end
97
102
  end
98
103
 
data/tasks/db.rake CHANGED
@@ -15,6 +15,7 @@ namespace :db do
15
15
  require 'yaml'
16
16
  puts "Removing database #{db_file}"
17
17
  FileUtils.rm_f db_file
18
+ FileUtils.mkdir_p File.dirname(db_file)
18
19
  end
19
20
 
20
21
  def db_file
metadata CHANGED
@@ -1,15 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact_broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bethany Skurrie
9
+ - Sergei Matheson
10
+ - Warner Godfrey
9
11
  autorequire:
10
12
  bindir: bin
11
13
  cert_chain: []
12
- date: 2013-11-03 00:00:00.000000000 Z
14
+ date: 2013-11-05 00:00:00.000000000 Z
13
15
  dependencies:
14
16
  - !ruby/object:Gem::Dependency
15
17
  name: httparty
@@ -91,6 +93,22 @@ dependencies:
91
93
  - - ! '>='
92
94
  - !ruby/object:Gem::Version
93
95
  version: '0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: roar
98
+ requirement: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
94
112
  - !ruby/object:Gem::Dependency
95
113
  name: sequel
96
114
  requirement: !ruby/object:Gem::Requirement
@@ -251,10 +269,12 @@ dependencies:
251
269
  - - ! '>='
252
270
  - !ruby/object:Gem::Version
253
271
  version: '0'
254
- description: An server that stores and returns pact files generated by the pact gem.
272
+ description: A server that stores and returns pact files generated by the pact gem.
255
273
  It enables head/prod cross testing of the consumer and provider projects.
256
274
  email:
257
275
  - bskurrie@dius.com.au
276
+ - serge.matheson@rea-group.com
277
+ - warner@warnergodfrey.com
258
278
  executables: []
259
279
  extensions: []
260
280
  extra_rdoc_files: []
@@ -280,6 +300,11 @@ files:
280
300
  - lib/pact_broker/api/index_api.rb
281
301
  - lib/pact_broker/api/pact_api.rb
282
302
  - lib/pact_broker/api/pacticipant_api.rb
303
+ - lib/pact_broker/api/representors.rb
304
+ - lib/pact_broker/api/representors/pact_broker_urls.rb
305
+ - lib/pact_broker/api/representors/pacticipant_collection_representor.rb
306
+ - lib/pact_broker/api/representors/pacticipant_representor.rb
307
+ - lib/pact_broker/api/representors/version_representor.rb
283
308
  - lib/pact_broker/db.rb
284
309
  - lib/pact_broker/logging.rb
285
310
  - lib/pact_broker/models.rb
@@ -306,7 +331,7 @@ files:
306
331
  - tasks/db.rake
307
332
  - tasks/pact.rake
308
333
  - tasks/rspec.rake
309
- homepage: https://github.com/bethesque/pact_broker.git
334
+ homepage: https://github.com/DiUS/pact_broker
310
335
  licenses:
311
336
  - MIT
312
337
  post_install_message:
@@ -321,7 +346,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
321
346
  version: '0'
322
347
  segments:
323
348
  - 0
324
- hash: 3453264579603755980
349
+ hash: -4491978602397448326
325
350
  required_rubygems_version: !ruby/object:Gem::Requirement
326
351
  none: false
327
352
  requirements:
@@ -330,7 +355,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
330
355
  version: '0'
331
356
  segments:
332
357
  - 0
333
- hash: 3453264579603755980
358
+ hash: -4491978602397448326
334
359
  requirements: []
335
360
  rubyforge_project:
336
361
  rubygems_version: 1.8.23