/**
* External Module dependencies.
*/
var express = require('express'),
http = require('http'),
path = require('path'),
bodyParser = require("body-parser"),
validate = require("express-validation");
/**
* Internal module dependencies.
*/
var serviceBrokerRoute = require('./routes/route');
/**
* Application configuration
*/
var app = express();
app.use(bodyParser.urlencoded({
extended : true
}));
app.use(bodyParser.json());
/**
* Route registration
*/
app.use("/v2", serviceBrokerRoute);
/**
* error handler
*/
app.use(function(err, req, res, next) {
if (err instanceof validate.ValidationError)
return res.status(err.status).json(err);
return res.status(500);
});
/**
* start server
*/
http.createServer(app).listen(process.env.PORT || 3000, function() {
console.log('Express server listening on port ' + process.env.PORT || 3000);
});
{
"name": "service-broker-node-implementation",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "~4.13.4",
"body-parser": "1.18.1",
"express-basic-auth": "~1.1.2",
"express-validation": "~1.0.2",
"joi": "~10.6.0"
}
}
/**
* Middleware for authorization check
*/
router.use(basicAuth({
users: { 'admin': 'supersecret' },
challenge: true,
realm: 'Imb4T3st4pp'
}));
/**
* end point for service catalog
*/
router.get('/catalog', function(req,res){
res.send(catalogJSON);
});
{
"services": [{
"name": "fake-service",
"id": "acb56d7c-XXXX-XXXX-XXXX-feb140a59a66",
"description": "fake service",
"tags": ["no-sql", "relational"],
"requires": ["route_forwarding"],
"bindable": true,
"metadata": {
"provider": {
"name": "The name"
},
"listing": {
"imageUrl": "http://example.com/cat.gif",
"blurb": "Add a blurb here",
"longDescription": "A long time ago, in a galaxy far far away..."
},
"displayName": "The Fake Broker"
},
"dashboard_client": {
"id": "398e2f8e-XXXX-XXXX-XXXX-19a71ecbcf64",
"secret": "277cabb0-XXXX-XXXX-XXXX-7822c0a90e5d",
"redirect_uri": "http://localhost:1234"
},
"plan_updateable": true,
"plans": [{
"name": "fake-plan-1",
"id": "d3031751-XXXX-XXXX-XXXX-a42377d3320e",
"description": "Shared fake Server, 5tb persistent disk, 40 max concurrent connections",
"max_storage_tb": 5,
"metadata": {
"costs":[
{
"amount":{
"usd":99.0
},
"unit":"MONTHLY"
},
{
"amount":{
"usd":0.99
},
"unit":"1GB of messages over 20GB"
}
],
"bullets": [
"Shared fake server",
"5 TB storage",
"40 concurrent connections"
]
}
}, {
"name": "fake-plan-2",
"id": "0f4008b5-XXXX-XXXX-XXXX-dace631cd648",
"description": "Shared fake Server, 5tb persistent disk, 40 max concurrent connections. 100 async",
"max_storage_tb": 5,
"metadata": {
"costs":[
{
"amount":{
"usd":199.0
},
"unit":"MONTHLY"
},
{
"amount":{
"usd":0.99
},
"unit":"1GB of messages over 20GB"
}
],
"bullets": [
"40 concurrent connections"
]
}
}]
}]
}
/**
* end point for service instance create
*/
router.put('/service_instances/:instance_id',validate(validator.serviceInstanceCreateRequestValidator), function(req,res){
res.status(201).send({});
});
/**
* end point for service instance update
*/
router.patch('/service_instances/:instance_id',validate(validator.serviceInstanceUpdateRequestValidator), function(req,res){
res.status(200).send({});
});
/**
* end point for service instance delete
*/
router.delete('/service_instances/:instance_id',validate(validator.deleteRequestValidator), function(req,res){
res.status(200).send({});
});
/**
* end point for service instance binding
*/
router.put('/service_instances/:instance_id/service_bindings/:binding_id',validate(validator.bindServiceInstanceRequestValidator), function(req,res){
res.status(201).send({});
});
/**
* end point for service instance unbinding
*/
router.delete('/service_instances/:instance_id/service_bindings/:binding_id',validate(validator.deleteRequestValidator), function(req,res){
res.status(200).send({});
});
accepts_incomplete=true
to the request. Then the cloud controller will keep polling at regular interval of time via below endpoint:/**
* end point for operation status polling
*/
router.get('/service_instances/:instance_id/last_operation', function(req,res){
res.status(200).send({});
});
var joi = require('joi');
this.serviceInstanceCreateRequestValidator={
body: {
service_id: joi.required(),
plan_id: joi.required(),
space_guid: joi.required()
}
};
this.serviceInstanceUpdateRequestValidator={
body: {
service_id: joi.required()
}
};
this.deleteRequestValidator={
query: {
service_id: joi.required(),
plan_id: joi.required()
}
};
this.bindServiceInstanceRequestValidator={
body: {
service_id: joi.required(),
plan_id: joi.required()
}
};
module.exports = this;
cf push cloud-foundry-service-broker-node-implementation
cf create-service-broker custom-service-broker admin supersecret https://cloud-foundry-service-broker-node-implementation.cfapps.eu10.hana.ondemand.com --space-scoped
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
9 | |
9 | |
7 | |
7 | |
7 | |
6 | |
6 | |
5 |