Skip to content

Commit

Permalink
Add support for latest generic extensions proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
Samze committed Mar 13, 2020
1 parent 4254e64 commit e1616a3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 34 deletions.
11 changes: 6 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ function start(callback) {
data.responseMode = process.env.responseMode;
response.json(data);
});
app.get('/health', function(request, response) {
app.get('/extensions/health.yaml', function(request, response) {
response.sendFile('health.yaml', { root: 'extensions' });
});
app.get('/info', function(request, response) {
app.get('/extensions/info.yaml', function(request, response) {
response.sendFile('info.yaml', { root: 'extensions' });
});
app.get('/logs', function(request, response) {
Expand Down Expand Up @@ -95,9 +95,6 @@ function start(callback) {
});
app.use('/images', express.static('images'));

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

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

/* Extensions */
app.get('/v2/service_instances/:instance_id/health-extension/health', serviceBrokerInterface.getHealth());
app.get('/v2/service_instances/:instance_id/info-extension/info', serviceBrokerInterface.getInfo());

/* Listing */
app.get('/v2/service_instances', function(request, response) {
serviceBrokerInterface.listInstances(request, response);
Expand Down
2 changes: 1 addition & 1 deletion extensions/health.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ info:
description: Fetch health information about a service instance
version: 0.1.0
paths:
/info:
/health:
get:
summary: Returns health information for the service instance
responses:
Expand Down
38 changes: 18 additions & 20 deletions service_broker.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,22 @@ class ServiceBroker {
});
}

// getServiceInstanceExtensionAPIs(serviceId) {
// return [
// {
// discovery_url: '/logs',
// server_url: `${cfenv.getAppEnv().url}/v2/service_instances/${serviceId}`,
// adheres_to: 'http://broker.sapi.life/logs'
// },
// {
// discovery_url: '/health',
// server_url: `${cfenv.getAppEnv().url}/v2/service_instances/${serviceId}`,
// adheres_to: 'http://broker.sapi.life/health'
// },
// {
// discovery_url: '/info',
// server_url: `${cfenv.getAppEnv().url}/v2/service_instances/${serviceId}`,
// adheres_to: 'http://broker.sapi.life/info'
// }
// ]
// };
getServiceInstanceExtensionAPIs() {
return [
{
"id": "urn:osbext:health:v1",
"path": "/health-extension",
"description": "Obtains the health of a service instance",
"openapi_url": "extensions/health.yaml"
},
{
"id": "urn:osbext:overviewbroker-info:v1",
"path": "/info-extension",
"description": "Gets information about the service instance",
"openapi_url": "/extensions/info.yaml"
}
]
};

validateParameters(schema, parameters) {
var result = validate(parameters, schema);
Expand Down Expand Up @@ -199,7 +196,8 @@ class ServiceBroker {
parameters: largePlanSchema
}
}
}
},
extensions: this.getServiceInstanceExtensionAPIs()
});

// Load example schemas if requested and generate a plan for each
Expand Down
7 changes: 2 additions & 5 deletions tests/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Extensions', function() {

it('should fetch discovery doc', function(done) {
request(server)
.get('/health')
.get('/extensions/health.yaml')
.expect(200)
.then(response => {
done();
Expand All @@ -36,16 +36,13 @@ describe('Extensions', function() {
});

describe('info', function() {

it('should fetch discovery doc', function(done) {
request(server)
.get('/info')
.get('/extensions/info.yaml')
.expect(200)
.then(response => {
done();
});
});

});

});
11 changes: 8 additions & 3 deletions tests/service_broker_interface_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2107,21 +2107,26 @@ describe('Service Broker Interface', function() {

it('should fetch health', function(done) {
request(server)
.get(`/v2/service_instances/${instanceId}/health`)
.get(`/v2/service_instances/${instanceId}/health-extension/health`)
.auth(brokerUsername, brokerPassword)
.set('X-Broker-Api-Version', apiVersion)
.expect(200)
.then(response => {
should.exist(response.body);
response.body.should.have.property('alive');
done();
})
.catch(error => {
.catch((error, resp) => {
console.log(resp);
done(error);
});
});

it('should fetch info', function(done) {
request(server)
.get(`/v2/service_instances/${instanceId}/info`)
.get(`/v2/service_instances/${instanceId}/info-extension/info`)
.auth(brokerUsername, brokerPassword)
.set('X-Broker-Api-Version', apiVersion)
.expect(200)
.then(response => {
should.exist(response.body);
Expand Down

0 comments on commit e1616a3

Please sign in to comment.