Skip to content

Commit e1616a3

Browse files
committed
Add support for latest generic extensions proposal
See cloudfoundry/servicebroker#670
1 parent 4254e64 commit e1616a3

File tree

5 files changed

+35
-34
lines changed

5 files changed

+35
-34
lines changed

app.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ function start(callback) {
6060
data.responseMode = process.env.responseMode;
6161
response.json(data);
6262
});
63-
app.get('/health', function(request, response) {
63+
app.get('/extensions/health.yaml', function(request, response) {
6464
response.sendFile('health.yaml', { root: 'extensions' });
6565
});
66-
app.get('/info', function(request, response) {
66+
app.get('/extensions/info.yaml', function(request, response) {
6767
response.sendFile('info.yaml', { root: 'extensions' });
6868
});
6969
app.get('/logs', function(request, response) {
@@ -95,9 +95,6 @@ function start(callback) {
9595
});
9696
app.use('/images', express.static('images'));
9797

98-
/* Extensions (unauthenticated) */
99-
app.get('/v2/service_instances/:instance_id/health', serviceBrokerInterface.getHealth());
100-
app.get('/v2/service_instances/:instance_id/info', serviceBrokerInterface.getInfo());
10198

10299
/* Authenticated routes (uses Basic Auth) */
103100
var users = {};
@@ -166,6 +163,10 @@ function start(callback) {
166163
app.get('/v2/service_instances/:instance_id', serviceBrokerInterface.getServiceInstance());
167164
app.get('/v2/service_instances/:instance_id/service_bindings/:binding_id', serviceBrokerInterface.getServiceBinding());
168165

166+
/* Extensions */
167+
app.get('/v2/service_instances/:instance_id/health-extension/health', serviceBrokerInterface.getHealth());
168+
app.get('/v2/service_instances/:instance_id/info-extension/info', serviceBrokerInterface.getInfo());
169+
169170
/* Listing */
170171
app.get('/v2/service_instances', function(request, response) {
171172
serviceBrokerInterface.listInstances(request, response);

extensions/health.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ info:
44
description: Fetch health information about a service instance
55
version: 0.1.0
66
paths:
7-
/info:
7+
/health:
88
get:
99
summary: Returns health information for the service instance
1010
responses:

service_broker.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,22 @@ class ServiceBroker {
9898
});
9999
}
100100

101-
// getServiceInstanceExtensionAPIs(serviceId) {
102-
// return [
103-
// {
104-
// discovery_url: '/logs',
105-
// server_url: `${cfenv.getAppEnv().url}/v2/service_instances/${serviceId}`,
106-
// adheres_to: 'http://broker.sapi.life/logs'
107-
// },
108-
// {
109-
// discovery_url: '/health',
110-
// server_url: `${cfenv.getAppEnv().url}/v2/service_instances/${serviceId}`,
111-
// adheres_to: 'http://broker.sapi.life/health'
112-
// },
113-
// {
114-
// discovery_url: '/info',
115-
// server_url: `${cfenv.getAppEnv().url}/v2/service_instances/${serviceId}`,
116-
// adheres_to: 'http://broker.sapi.life/info'
117-
// }
118-
// ]
119-
// };
101+
getServiceInstanceExtensionAPIs() {
102+
return [
103+
{
104+
"id": "urn:osbext:health:v1",
105+
"path": "/health-extension",
106+
"description": "Obtains the health of a service instance",
107+
"openapi_url": "extensions/health.yaml"
108+
},
109+
{
110+
"id": "urn:osbext:overviewbroker-info:v1",
111+
"path": "/info-extension",
112+
"description": "Gets information about the service instance",
113+
"openapi_url": "/extensions/info.yaml"
114+
}
115+
]
116+
};
120117

121118
validateParameters(schema, parameters) {
122119
var result = validate(parameters, schema);
@@ -199,7 +196,8 @@ class ServiceBroker {
199196
parameters: largePlanSchema
200197
}
201198
}
202-
}
199+
},
200+
extensions: this.getServiceInstanceExtensionAPIs()
203201
});
204202

205203
// Load example schemas if requested and generate a plan for each

tests/extensions.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('Extensions', function() {
2626

2727
it('should fetch discovery doc', function(done) {
2828
request(server)
29-
.get('/health')
29+
.get('/extensions/health.yaml')
3030
.expect(200)
3131
.then(response => {
3232
done();
@@ -36,16 +36,13 @@ describe('Extensions', function() {
3636
});
3737

3838
describe('info', function() {
39-
4039
it('should fetch discovery doc', function(done) {
4140
request(server)
42-
.get('/info')
41+
.get('/extensions/info.yaml')
4342
.expect(200)
4443
.then(response => {
4544
done();
4645
});
4746
});
48-
4947
});
50-
5148
});

tests/service_broker_interface_tests.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,21 +2107,26 @@ describe('Service Broker Interface', function() {
21072107

21082108
it('should fetch health', function(done) {
21092109
request(server)
2110-
.get(`/v2/service_instances/${instanceId}/health`)
2110+
.get(`/v2/service_instances/${instanceId}/health-extension/health`)
2111+
.auth(brokerUsername, brokerPassword)
2112+
.set('X-Broker-Api-Version', apiVersion)
21112113
.expect(200)
21122114
.then(response => {
21132115
should.exist(response.body);
21142116
response.body.should.have.property('alive');
21152117
done();
21162118
})
2117-
.catch(error => {
2119+
.catch((error, resp) => {
2120+
console.log(resp);
21182121
done(error);
21192122
});
21202123
});
21212124

21222125
it('should fetch info', function(done) {
21232126
request(server)
2124-
.get(`/v2/service_instances/${instanceId}/info`)
2127+
.get(`/v2/service_instances/${instanceId}/info-extension/info`)
2128+
.auth(brokerUsername, brokerPassword)
2129+
.set('X-Broker-Api-Version', apiVersion)
21252130
.expect(200)
21262131
.then(response => {
21272132
should.exist(response.body);

0 commit comments

Comments
 (0)