<commit_before># Cloud Foundry Services Connector (Node.js)
---

## About

This library provides a broker implementation to develop any custom service on
top of any Cloud Foundry based system.

The connector was written with the ideology of being super portable, lightweight,
simple to use, and to take advantage of the node.js module ecosystem. It allows 
for any service to be written in pure Node.js with minimal external
dependencies and memory footprint.

It's super portable, and doesn't need to be running inside a Stackato or
Cloud Foundry instance - it only needs Node.js installed.

## Installation

Either `git clone` this repo as the base service skeleton, or: `npm install cf-services-connector` in your new service.

## Usage

There is an "echo service" demonstrating full use of the broker in
`example/echo-service` that should provide a good reference point to get
started writing your own service.

Once you are in the example/echo-service directory:

  node server.js

The recommended way is to use the connector API directly, for example:

### Broker (coffeescript):
```coffeescript
    Broker = require 'cf-services-connector'
    
    config = require 'config/custom-service' # JSON config file
    
    broker = new Broker(config)
    
    broker.start  (err) ->
        broker.log.error(err)
      
    broker.on 'error', (err) ->
        broker.log.error(err)
    
    broker.on 'provision', (req, next) ->
        # Do custom provisioning action / generate credentials
        # The API allows 'dashboard_url' to be returned here, i.e.:
        # next({dashboard_url: "http://example/instance1" }) 
        next();

    broker.on 'unprovision', (req, next) ->
        # Delete service instance
        # req.params.id
        next()
    
    broker.on 'bind', (req, next) ->
        # Take any action for binding
        reply =
            credentials =
                host: '192.168.100.200'
                port: 9999
                user: 'demo'
                pass: '<PASSWORD>'

        next(credentials)
    
    broker.on 'unbind', (service, cb) ->
        # Undo instance binding
        # here we tell the CC this instance does not exist
        reply =
            doesNotExist: true
        next(reply)
    
```

## Register the broker with the CC

Once you have the service setup, simply run the following against the
Cloud Foundry instance you wish to install the service to (requires admin):

    stackato create-service-broker demo-service --url http://<ip>:5001 --user demo --password <PASSWORD>

or using the `cf` client:

    cf add-service-broker demo-service --url http://<ip>:5001 --username demo --password<commit_msg>State where the service broker credentials are stored<commit_after># Cloud Foundry Services Connector (Node.js)
---

## About

This library provides a broker implementation to develop any custom service on
top of any Cloud Foundry based system.

The connector was written with the ideology of being super portable, lightweight,
simple to use, and to take advantage of the node.js module ecosystem. It allows 
for any service to be written in pure Node.js with minimal external
dependencies and memory footprint.

It's super portable, and doesn't need to be running inside a Stackato or
Cloud Foundry instance - it only needs Node.js installed.

## Installation

Either `git clone` this repo as the base service skeleton, or: `npm install cf-services-connector` in your new service.

## Usage

There is an "echo service" demonstrating full use of the broker in
`example/echo-service` that should provide a good reference point to get
started writing your own service.

Once you are in the example/echo-service directory:

  node server.js

The recommended way is to use the connector API directly, for example:

### Broker (coffeescript):
```coffeescript
    Broker = require 'cf-services-connector'
    
    config = require 'config/custom-service' # JSON config file
    
    broker = new Broker(config)
    
    broker.start  (err) ->
        broker.log.error(err)
      
    broker.on 'error', (err) ->
        broker.log.error(err)
    
    broker.on 'provision', (req, next) ->
        # Do custom provisioning action / generate credentials
        # The API allows 'dashboard_url' to be returned here, i.e.:
        # next({dashboard_url: "http://example/instance1" }) 
        next();

    broker.on 'unprovision', (req, next) ->
        # Delete service instance
        # req.params.id
        next()
    
    broker.on 'bind', (req, next) ->
        # Take any action for binding
        reply =
            credentials =
                host: '192.168.100.200'
                port: 9999
                user: 'demo'
                pass: '<PASSWORD>'

        next(credentials)
    
    broker.on 'unbind', (service, cb) ->
        # Undo instance binding
        # here we tell the CC this instance does not exist
        reply =
            doesNotExist: true
        next(reply)
    
```

## Register the broker with the CC

Once you have the service setup, simply run the following against the
Cloud Foundry instance you wish to install the service to (requires admin):

    stackato create-service-broker demo-service --url http://<ip>:5001 --user demouser --password <PASSWORD>

or using the `cf` client:

    cf add-service-broker demo-service --url http://<ip>:5001 --username demouser --password <PASSWORD>

The username and password are defined in echo-service/config/echo-service.json
{'fraction_non_alphanumeric': 0.08602739726027397, 'fraction_numerical': 0.0091324200913242, 'mean_word_length': 2.6776359973136334, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '691047', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1469, 'n_words': 621}