Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit fb5c067

Browse files
authored
v3(services): expose additional service instance fields (cloudfoundry#1720)
The documentation_url and description of the service offering are available as fields via the service instance endpoints [#173447953](https://www.pivotaltracker.com/story/show/173447953)
1 parent 6c0d2c4 commit fb5c067

9 files changed

Lines changed: 91 additions & 40 deletions

File tree

app/decorators/field_service_instance_offering_decorator.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module VCAP::CloudController
22
class FieldServiceInstanceOfferingDecorator
33
def self.allowed
4-
Set['name', 'guid', 'relationships.service_broker']
4+
Set.new(%w(name guid description documentation_url relationships.service_broker))
55
end
66

77
def self.match?(fields)
@@ -24,6 +24,8 @@ def decorate(hash, service_instances)
2424
offering_view = {}
2525
offering_view[:name] = offering.name if @fields.include?('name')
2626
offering_view[:guid] = offering.guid if @fields.include?('guid')
27+
offering_view[:description] = offering.description if @fields.include?('description')
28+
offering_view[:documentation_url] = offering.documentation_url if @fields.include?('documentation_url')
2729
if @fields.include?('relationships.service_broker')
2830
offering_view[:relationships] = {
2931
service_broker: {

app/messages/service_instance_show_message.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ class ServiceInstanceShowMessage < BaseMessage
55
validates_with NoAdditionalParamsValidator
66
validates :fields, allow_nil: true, fields: {
77
allowed: {
8-
'space' => ['name', 'guid'],
9-
'space.organization' => ['name', 'guid'],
10-
'service_plan' => ['name', 'guid'],
11-
'service_plan.service_offering' => ['name', 'guid'],
12-
'service_plan.service_offering.service_broker' => ['name', 'guid']
8+
'space' => %w(name guid),
9+
'space.organization' => %w(name guid),
10+
'service_plan' => %w(name guid),
11+
'service_plan.service_offering' => %w(name guid description documentation_url),
12+
'service_plan.service_offering.service_broker' => %w(name guid)
1313
}
1414
}
1515

app/messages/service_instances_list_message.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ class ServiceInstancesListMessage < MetadataListMessage
1919
validates_with NoAdditionalParamsValidator
2020

2121
validates :type, allow_nil: true, inclusion: {
22-
in: %w(managed user-provided),
23-
message: "must be one of 'managed', 'user-provided'"
24-
}
22+
in: %w(managed user-provided),
23+
message: "must be one of 'managed', 'user-provided'"
24+
}
2525

2626
validates :fields, allow_nil: true, fields: {
2727
allowed: {
28-
'space' => ['guid', 'name', 'relationships.organization'],
29-
'space.organization' => ['name', 'guid'],
30-
'service_plan' => ['guid', 'name', 'relationships.service_offering'],
31-
'service_plan.service_offering' => ['name', 'guid', 'relationships.service_broker'],
32-
'service_plan.service_offering.service_broker' => ['name', 'guid']
28+
'space' => %w(guid name relationships.organization),
29+
'space.organization' => %w(name guid),
30+
'service_plan' => %w(guid name relationships.service_offering),
31+
'service_plan.service_offering' => %w(name guid description documentation_url relationships.service_broker),
32+
'service_plan.service_offering.service_broker' => %w(name guid)
3333
}
3434
}
3535

docs/v3/source/includes/experimental_resources/service_instances/_get.md.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Resource | Allowed Keys
5252
space | `guid`, `name`
5353
space.organization | `name`, `guid`
5454
service_plan| `name`, `guid`
55-
service_plan.service_offering| `name`, `guid`
55+
service_plan.service_offering| `name`, `guid`, `description`, `documentation_url`
5656
service_plan.service_offering.service_broker| `name`, `guid`
5757

5858
#### Permitted roles

docs/v3/source/includes/resources/service_instances/_list.md.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Resource | Allowed Keys
5050
space | `guid`, `name`, `relationships.organization`
5151
space.organization| `guid`, `name`
5252
service_plan| `guid`, `name`, `relationships.service_offering`
53-
service_plan.service_offering| `guid`, `name`, `relationships.service_broker`
53+
service_plan.service_offering| `guid`, `name`, `description`, `documentation_url`, `relationships.service_broker`
5454
service_plan.service_offering.service_broker| `guid`, `name`
5555

5656
#### Permitted roles

spec/request/service_instances_spec.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,18 @@
133133
expect({ included: parsed_response['included'] }).to match_json_response({ included: included })
134134
end
135135

136-
it 'can include the offering and broker name and guid fields' do
137-
get "/v3/service_instances/#{guid}?fields[service_plan.service_offering]=name,guid&fields[service_plan.service_offering.service_broker]=name,guid", nil, admin_headers
136+
it 'can include service offering and broker fields' do
137+
get "/v3/service_instances/#{guid}?fields[service_plan.service_offering]=name,guid,description,documentation_url&" \
138+
'fields[service_plan.service_offering.service_broker]=name,guid', nil, admin_headers
138139
expect(last_response).to have_status_code(200)
139140

140141
included = {
141142
service_offerings: [
142143
{
143144
name: instance.service_plan.service.name,
144-
guid: instance.service_plan.service.guid
145+
guid: instance.service_plan.service.guid,
146+
description: instance.service_plan.service.description,
147+
documentation_url: instance.service_plan.service.documentation_url,
145148
}
146149
],
147150
service_brokers: [
@@ -356,9 +359,9 @@ def check_filtered_instances(*instances)
356359
expect({ included: parsed_response['included'] }).to match_json_response({ included: included })
357360
end
358361

359-
it 'can include the service plan, offering and broker name and guid fields' do
362+
it 'can include the service plan, offering and broker fields' do
360363
get '/v3/service_instances?fields[service_plan]=guid,name,relationships.service_offering&' \
361-
'fields[service_plan.service_offering]=name,guid,relationships.service_broker&' \
364+
'fields[service_plan.service_offering]=name,guid,description,documentation_url,relationships.service_broker&' \
362365
'fields[service_plan.service_offering.service_broker]=name,guid', nil, admin_headers
363366

364367
expect(last_response).to have_status_code(200)
@@ -403,6 +406,8 @@ def check_filtered_instances(*instances)
403406
{
404407
name: msi_1.service_plan.service.name,
405408
guid: msi_1.service_plan.service.guid,
409+
description: msi_1.service_plan.service.description,
410+
documentation_url: msi_1.service_plan.service.documentation_url,
406411
relationships: {
407412
service_broker: {
408413
data: {
@@ -414,6 +419,8 @@ def check_filtered_instances(*instances)
414419
{
415420
name: msi_2.service_plan.service.name,
416421
guid: msi_2.service_plan.service.guid,
422+
description: msi_2.service_plan.service.description,
423+
documentation_url: msi_2.service_plan.service.documentation_url,
417424
relationships: {
418425
service_broker: {
419426
data: {
@@ -425,6 +432,8 @@ def check_filtered_instances(*instances)
425432
{
426433
name: ssi.service_plan.service.name,
427434
guid: ssi.service_plan.service.guid,
435+
description: ssi.service_plan.service.description,
436+
documentation_url: ssi.service_plan.service.documentation_url,
428437
relationships: {
429438
service_broker: {
430439
data: {
@@ -2015,7 +2024,7 @@ def check_filtered_instances(*instances)
20152024
expect(last_response).to have_status_code(422)
20162025
expect(parsed_response['errors']).to include(
20172026
include({ 'detail' => 'Cannot update parameters of a service instance that belongs to inaccessible plan' })
2018-
)
2027+
)
20192028
end
20202029
end
20212030

spec/unit/decorators/field_service_instance_offering_decorator_spec.rb

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module VCAP::CloudController
1313
let!(:service_instance_1) { ManagedServiceInstance.make(service_plan: plan1) }
1414
let!(:service_instance_2) { ManagedServiceInstance.make(service_plan: plan2) }
1515

16-
it 'decorated the given hash with offering name from service instances' do
16+
it 'can decorate with the service offering name' do
1717
undecorated_hash = { foo: 'bar', included: { monkeys: %w(zach greg) } }
1818
decorator = described_class.new({ 'service_plan.service_offering': ['name', 'foo'] })
1919

@@ -35,7 +35,7 @@ module VCAP::CloudController
3535
})
3636
end
3737

38-
it 'decorated the given hash with offering guids from service instances' do
38+
it 'can decorate with the service offering guid' do
3939
undecorated_hash = { foo: 'bar', included: { monkeys: %w(zach greg) } }
4040
decorator = described_class.new({ 'service_plan.service_offering': ['guid', 'foo'] })
4141

@@ -57,6 +57,50 @@ module VCAP::CloudController
5757
})
5858
end
5959

60+
it 'can decorate with the service offering description' do
61+
undecorated_hash = { foo: 'bar', included: { monkeys: %w(zach greg) } }
62+
decorator = described_class.new({ 'service_plan.service_offering': ['description', 'foo'] })
63+
64+
hash = decorator.decorate(undecorated_hash, [service_instance_1, service_instance_2])
65+
66+
expect(hash).to match({
67+
foo: 'bar',
68+
included: {
69+
monkeys: %w(zach greg),
70+
service_offerings: [
71+
{
72+
description: offering1.description,
73+
},
74+
{
75+
description: offering2.description,
76+
}
77+
]
78+
}
79+
})
80+
end
81+
82+
it 'can decorate with the service offering documentation' do
83+
undecorated_hash = { foo: 'bar', included: { monkeys: %w(zach greg) } }
84+
decorator = described_class.new({ 'service_plan.service_offering': ['documentation_url', 'foo'] })
85+
86+
hash = decorator.decorate(undecorated_hash, [service_instance_1, service_instance_2])
87+
88+
expect(hash).to match({
89+
foo: 'bar',
90+
included: {
91+
monkeys: %w(zach greg),
92+
service_offerings: [
93+
{
94+
documentation_url: offering1.documentation_url,
95+
},
96+
{
97+
documentation_url: offering2.documentation_url,
98+
}
99+
]
100+
}
101+
})
102+
end
103+
60104
it 'decorated the given hash with offering relationship to broker from service instances' do
61105
undecorated_hash = { foo: 'bar', included: { monkeys: %w(zach greg) } }
62106
decorator = described_class.new({ 'service_plan.service_offering': ['relationships.service_broker', 'foo'] })
@@ -116,20 +160,16 @@ module VCAP::CloudController
116160
end
117161

118162
describe '.match?' do
119-
it 'matches hashes containing key symbol `service_plan.service_offering` and value `name`' do
120-
expect(described_class.match?({ 'service_plan.service_offering': ['name'], other: ['bar'] })).to be_truthy
121-
end
163+
fields = %w(name guid description documentation_url relationships.service_broker)
122164

123-
it 'matches hashes containing key symbol `service_plan.service_offering` and value `guid`' do
124-
expect(described_class.match?({ 'service_plan.service_offering': ['guid'], other: ['bar'] })).to be_truthy
125-
end
126-
127-
it 'matches hashes containing key symbol `service_plan.service_offering` and value `relationships.service_broker`' do
128-
expect(described_class.match?({ 'service_plan.service_offering': ['relationships.service_broker'], other: ['bar'] })).to be_truthy
165+
fields.each do |field|
166+
it "matches value `#{field}` for key symbol `service_plan.service_offering`" do
167+
expect(described_class.match?({ 'service_plan.service_offering': [field], other: ['bar'] })).to be_truthy
168+
end
129169
end
130170

131-
it 'matches hashes containing key symbol `service_plan.service_offering` and value `name,guid,relationships.service_broker`' do
132-
expect(described_class.match?({ 'service_plan.service_offering': ['name', 'guid', 'relationships.service_broker', 'something'], other: ['bar'] })).to be_truthy
171+
it 'matches all fields together for key symbol `service_plan.service_offering`' do
172+
expect(described_class.match?({ 'service_plan.service_offering': fields, other: ['bar'] })).to be_truthy
133173
end
134174

135175
it 'does not match other values for a valid key' do

spec/unit/messages/service_instance_show_message_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module VCAP::CloudController
1010

1111
it_behaves_like 'field query parameter', 'service_plan', 'name,guid'
1212

13-
it_behaves_like 'field query parameter', 'service_plan.service_offering', 'name,guid'
13+
it_behaves_like 'field query parameter', 'service_plan.service_offering', 'name,guid,description,documentation_url'
1414

1515
it_behaves_like 'field query parameter', 'service_plan.service_offering.service_broker', 'name,guid'
1616

spec/unit/messages/service_instances_list_message_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ module VCAP::CloudController
66
RSpec.describe ServiceInstancesListMessage do
77
let(:params) do
88
{
9-
'page' => 1,
10-
'per_page' => 5,
11-
'order_by' => 'name',
9+
'page' => 1,
10+
'per_page' => 5,
11+
'order_by' => 'name',
1212
'names' => 'rabbitmq, redis,mysql',
1313
'space_guids' => 'space-1, space-2, space-3',
1414
'label_selector' => 'key=value',
@@ -83,7 +83,7 @@ module VCAP::CloudController
8383

8484
it_behaves_like 'field query parameter', 'service_plan', 'guid,name,relationships.service_offering'
8585

86-
it_behaves_like 'field query parameter', 'service_plan.service_offering', 'name,guid,relationships.service_broker'
86+
it_behaves_like 'field query parameter', 'service_plan.service_offering', 'name,guid,description,documentation_url,relationships.service_broker'
8787

8888
it_behaves_like 'field query parameter', 'service_plan.service_offering.service_broker', 'name,guid'
8989
end

0 commit comments

Comments
 (0)