This repository was archived by the owner on Jun 2, 2021. It is now read-only.
File tree Expand file tree Collapse file tree
experimental_resources/service_route_bindings Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11require 'messages/service_route_binding_create_message'
22require 'actions/service_route_binding_create'
3+ require 'presenters/v3/service_route_binding_presenter'
34
45class ServiceRouteBindingsController < ApplicationController
56 def create
@@ -17,7 +18,7 @@ def create
1718 head :not_implemented
1819 when UserProvidedServiceInstance
1920 binding = action . create ( service_instance , route )
20- render status : :created , json : { guid : binding . guid } . to_json
21+ render status : :created , json : Presenters :: V3 :: ServiceRouteBindingPresenter . new ( binding )
2122 end
2223 rescue V3 ::ServiceRouteBindingCreate ::UnprocessableCreate => e
2324 unprocessable! ( e . message )
Original file line number Diff line number Diff line change 1+ require_relative 'base_presenter'
2+
3+ module VCAP
4+ module CloudController
5+ module Presenters
6+ module V3
7+ class ServiceRouteBindingPresenter < BasePresenter
8+ def to_hash
9+ {
10+ guid : @resource . guid ,
11+ created_at : @resource . created_at ,
12+ updated_at : @resource . updated_at ,
13+ relationships : relationships ,
14+ links : links
15+ }
16+ end
17+
18+ private
19+
20+ def links
21+ {
22+ self : {
23+ href : url_builder . build_url ( path : "/v3/service_route_bindings/#{ @resource . guid } " )
24+ } ,
25+ service_instance : {
26+ href : url_builder . build_url ( path : "/v3/service_instances/#{ @resource . service_instance . guid } " )
27+ } ,
28+ route : {
29+ href : url_builder . build_url ( path : "/v3/routes/#{ @resource . route . guid } " )
30+ }
31+ }
32+ end
33+
34+ def relationships
35+ {
36+ service_instance : { data : { guid : @resource . service_instance . guid } } ,
37+ route : { data : { guid : @resource . route . guid } }
38+ }
39+ end
40+ end
41+ end
42+ end
43+ end
44+ end
Original file line number Diff line number Diff line change 1+ <% content_for :single_service_route_binding do %>
2+ {
3+ "guid": "dde5ad2a-d8f4-44dc-a56f-0452d744f1c3",
4+ "created_at": "2015-11-13T17:02:56Z",
5+ "updated_at": "2016-06-08T16:41:26Z",
6+ "relationships": {
7+ "service_instance": {
8+ "data": {
9+ "guid": "74f7c078-0934-470f-9883-4fddss5b8f13"
10+ }
11+ },
12+ "route": {
13+ "data": {
14+ "guid": "8bfe4c1b-9e18-45b1-83be-124163f31f9e"
15+ }
16+ }
17+ },
18+ "links": {
19+ "self": {
20+ "href": "https://api.example.org/v3/service_bindings/dde5ad2a-d8f4-44dc-a56f-0452d744f1c3"
21+ },
22+ "service_instance": {
23+ "href": "https://api.example.org/v3/service_instances/8bfe4c1b-9e18-45b1-83be-124163f31f9e"
24+ },
25+ "route": {
26+ "href": "https://api.example.org/v3/apps/74f7c078-0934-470f-9883-4fddss5b8f13"
27+ }
28+ }
29+ }
30+ <% end %>
Original file line number Diff line number Diff line change 1+ ### Create a service route binding
2+
3+ ```
4+ Example Request
5+ ```
6+
7+ ```shell
8+ curl "https://api.example.org/v3/service_route_bindings" \
9+ -X POST \
10+ -H "Authorization: bearer [token]" \
11+ -H "Content-type: application/json" \
12+ -d '{
13+ "relationships": {
14+ "route": {
15+ "data": {
16+ "guid": "7304bc3c-7010-11ea-8840-48bf6bec2d78"
17+ }
18+ },
19+ "service_instance": {
20+ "data": {
21+ "guid": "e0e4417c-74ee-11ea-a604-48bf6bec2d78"
22+ }
23+ }
24+ }
25+ }'
26+ ```
27+
28+ ```
29+ Example Response
30+ ```
31+
32+ ```http
33+ HTTP/1.1 201 Created
34+ Content-Type: application/json
35+
36+ <%= yield_content :single_service_route_binding %>
37+ ```
38+
39+ This endpoint creates a new route service binding. The service instance and the route
40+ must be in the same space.
41+
42+ To bind to a route to a user-provided service instance, the service instance must
43+ have the `route_service_url` property set.
44+
45+ #### Definition
46+ `POST /v3/service_route_bindings`
47+
48+ #### Required parameters
49+
50+ Name | Type | Description
51+ ---- | ---- | -----------
52+ **relationships.route** | [_to-one relationship_](#to-one-relationships) | The route to bind
53+ **relationships.service_instance** | [_to-one relationship_](#to-one-relationships) | The service instance to bind
54+
55+ #### Permitted roles
56+ |
57+ --- | ---
58+ Admin |
59+ Space Developer |
Original file line number Diff line number Diff line change 1+ ## Service Route Binding (experimental)
2+
3+ An instantiation of a service route binding.
Original file line number Diff line number Diff line change 1+ ### The service route binding object
2+
3+ ```
4+ Example Service Route Binding object
5+ ```
6+ ```json
7+ <%= yield_content :single_service_route_binding %>
8+ ```
9+
10+ Name | Type | Description
11+ ---- | ---- | -----------
12+ **guid** | _uuid_ | Unique identifier for the service credential binding
13+ **created_at** | _[timestamp](#timestamps)_ | The time with zone when the object was created
14+ **updated_at** | _[timestamp](#timestamps)_ | The time with zone when the object was last updated
15+ **relationships.service_instance** | [_to-one relationship_](#to-one-relationships) | The service instance that the route is bound to
16+ **relationships.route** | [_to-one relationship_](#to-one-relationships) | The route that the service instance is bound to
17+ **links** | [_links object_](#links) | Links to related resources
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ includes:
3232 - api_resources/service_plans
3333 - api_resources/service_plan_visibility
3434 - api_resources/service_credential_bindings
35+ - api_resources/service_route_bindings
3536 - api_resources/service_instances
3637 - api_resources/service_usage_events
3738 - api_resources/sidecars
@@ -360,6 +361,9 @@ includes:
360361 - experimental_resources/service_credential_bindings/get
361362 - experimental_resources/service_credential_bindings/list
362363 - experimental_resources/service_credential_bindings/details
364+ - experimental_resources/service_route_bindings/header
365+ - experimental_resources/service_route_bindings/object
366+ - experimental_resources/service_route_bindings/create
363367 - experimental_resources/service_instances/header
364368 - experimental_resources/service_instances/create
365369 - experimental_resources/service_instances/get
Original file line number Diff line number Diff line change 164164 api_call . call ( space_dev_headers )
165165 expect ( last_response ) . to have_status_code ( 201 )
166166
167- binding = VCAP ::CloudController ::RouteBinding . first
168- expect ( parsed_response [ 'guid' ] ) . to eq ( binding . guid )
169-
170- expect ( binding . service_instance ) . to eq ( service_instance )
171- expect ( binding . route ) . to eq ( route )
172- expect ( binding . route_service_url ) . to eq ( route_service_url )
167+ expect ( parsed_response ) . to match_json_response (
168+ expected_json (
169+ binding_guid : VCAP ::CloudController ::RouteBinding . first . guid ,
170+ service_instance_guid : service_instance . guid ,
171+ route_guid : route . guid ,
172+ )
173+ )
173174 end
174175
175176 describe 'permissions' do
278279 space . add_developer ( user )
279280 headers_for ( user )
280281 end
282+
283+ def expected_json ( binding_guid :, route_guid :, service_instance_guid :)
284+ {
285+ guid : binding_guid ,
286+ created_at : iso8601 ,
287+ updated_at : iso8601 ,
288+ relationships : {
289+ service_instance : {
290+ data : {
291+ guid : service_instance_guid
292+ }
293+ } ,
294+ route : {
295+ data : {
296+ guid : route_guid
297+ }
298+ }
299+ } ,
300+ links : {
301+ self : {
302+ href : "#{ link_prefix } /v3/service_route_bindings/#{ binding_guid } "
303+ } ,
304+ service_instance : {
305+ href : "#{ link_prefix } /v3/service_instances/#{ service_instance_guid } "
306+ } ,
307+ route : {
308+ href : "#{ link_prefix } /v3/routes/#{ route_guid } "
309+ }
310+ }
311+ }
312+ end
281313end
Original file line number Diff line number Diff line change 1+ require 'spec_helper'
2+ require 'presenters/v3/service_route_binding_presenter'
3+
4+ module VCAP
5+ module CloudController
6+ RSpec . describe Presenters ::V3 ::ServiceRouteBindingPresenter do
7+ let ( :space ) { VCAP ::CloudController ::Space . make }
8+ let ( :route_service_url ) { 'https://route_service_url.com' }
9+ let ( :service_instance ) { VCAP ::CloudController ::UserProvidedServiceInstance . make ( space : space , route_service_url : route_service_url ) }
10+ let ( :route ) { Route . make ( space : space ) }
11+ let ( :guid ) { Sham . guid }
12+ let ( :binding ) do
13+ RouteBinding . make (
14+ guid : guid ,
15+ service_instance : service_instance ,
16+ route : route ,
17+ )
18+ end
19+
20+ it 'presents the correct object' do
21+ presenter = described_class . new ( binding )
22+ expect ( presenter . to_hash ) . to match (
23+ {
24+ guid : guid ,
25+ created_at : binding . created_at ,
26+ updated_at : binding . updated_at ,
27+ relationships : {
28+ route : {
29+ data : {
30+ guid : route . guid
31+ }
32+ } ,
33+ service_instance : {
34+ data : {
35+ guid : service_instance . guid
36+ }
37+ }
38+ } ,
39+ links : {
40+ self : {
41+ href : %r{.*/v3/service_route_bindings/#{ guid } }
42+ } ,
43+ route : {
44+ href : %r{.*/v3/routes/#{ route . guid } }
45+ } ,
46+ service_instance : {
47+ href : %r{.*/v3/service_instances/#{ service_instance . guid } }
48+ }
49+ }
50+ }
51+ )
52+ end
53+ end
54+ end
55+ end
You can’t perform that action at this time.
0 commit comments