IBM/sample-resource-service-brokers

Name: sample-resource-service-brokers

Owner: International Business Machines

Description: This repository provides sample Open Service Broker (OSB) service brokers for providers to use when integrating services with IBM Cloud.

Created: 2018-04-03 00:58:36.0

Updated: 2018-04-24 13:43:53.0

Pushed: 2018-04-24 13:43:52.0

Homepage:

Size: 1507

Language: Java

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Sample Resource Service Brokers

This repository provides sample Open Service Broker (OSB) service brokers for providers to use when integrating services with IBM Cloud. These samples conform to the OSB specification (https://github.com/openservicebrokerapi/servicebroker/blob/v2.12/spec.md). The samples are to be used with the IBM Cloud Resource Management Console (https://console.bluemix.net/onboarding).

These samples include OSB logic for catalog (GET), provision (PUT), bind (PUT), unbind (DELETE), unprovision (DELETE), update service (PATCH) and get service last operation (GET). These samples also include logic for the IBM Cloud extensions of enable (PUT) and state (GET).

Basic Authentication

Each call into the service broker implementation has an http authorization header. Each call should verify the value. The user and password for this verification correspond to the values provided to the IBM Cloud Resource Management Console.

Errors

In order to expose error text from a service broker for the provision, bind, unbind, unprovision, update and get service last operation entry points, return a JSON object with a description entry. This error text will be displayed in the IBM Cloud console when invoked due to an action in the IBM Cloud console.

Sample JSON

"description" : "Service failed due to invalid authorization"

Get Catalog

This REST API will be called to retrieve the list of service offerings and their service plans.

URL

The URL path for the GET invoked within the service broker implementation is /v2/catalog.

Get Catalog Result
Result

A status code of 200 is the expected successful value.

The fields returned from a catalog GET within the JSON result are as follows:

Successful Sample JSON

"services" :
[
    {
        "bindable"         : true,
        "description"      : "Test Node Resource Service Broker Description",
        "id"               : "service-guid-here",
        "metadata"         : 
        {
          "displayName           : "Test Node Resource Service Broker Display Name",
          "documentationUrl"     : "http://10.0.1.2/documentation.html,
          "imageUrl"             : "http://10.0.1.2/servicesample.png",
          "instructionsUrl"      : "http://10.0.1.2/servicesample.md",
          "longDescription"      : "Test Node Resource Service Broker Plan Long Description",
          "providerDisplayName"  : "Some Company",
          "supportUrl"           : "http://10.0.1.2/support.html",
          "termsUrl"             : "http://10.0.1.2/terms.html"
        },
        "name"             : "testnoderesourceservicebrokername",
        "plan_updateable"  : true,
        "tags"             : [ "lite", "tag1a", "tag1b" ],
        "plans"            :
        [
            {
                "description" : "Test Node Resource Service Broker Plan Description",
                "free"        : true,
                "id"          : "plan-guid-here",
                "metadata"    :
                {
                  "bullets"     : [ "Test bullet 1", "Test bullet 2" ],
                  "displayName" : "Lite"
                },
                "name"        : "lite"
            }
        ]
    }
]

Get Catalog Test
 -X GET -H "Accept:application/json" -H "X-Broker-Api-Version:2.12" -u "TestServiceBrokerUser:TestServiceBrokerPassword" http://localhost:3000/v2/catalog
Provision
URL

The URL path for the PUT invoked within the service broker implementation is /v2/service_instances/:instance_id where :instance_id is the id generated by IBM Cloud for the service instance.

Query Parameters

The fields passed into a provision PUT as query parameters are as follows:

Content

The fields passed into a provision PUT within the JSON body are as follows:

Sample JSON

"context"      :
{
    "account_id"        : "account-id-here",
    "crn"               : "crn-here",
    "platform"          : "ibmcloud",
    "resource_group_crn : "resource-group-crn-here",
    "target_crn"        : "target-crn-here"
},
"plan_id"      : "plan-guid-here",
"service_id"   : "service-guid-here"

Provision Result
Result

"error"       : "AsyncRequired",
"description" : "This service plan requires support for asynchronous service operations."

Successful Response Body

The fields returned from a successful provision PUT within the JSON result are as follows for a 200/201/202

Successful Sample JSON

"dashboard_url" : "http://www.ibm.com",
"description"   : "Your service is being created asynchronously.",
"operation"     : "Provision_45"

Provision Test
 -X PUT -H "Accept:application/json" -H "Content-Type:application/json" -H "X-Broker-Api-Version:2.12" -H "X-Broker-Api-Originating-Identity:ibmcloud eyJpYW1faWQiOiJJQk1pZC0zMTAwMDJNNEpGIiwic3ViIjoiYmx1ZW1peF91aV9zb3Rlc3RAbWFpbGluYXRvci5jb20ifQ==" -u "TestServiceBrokerUser:TestServiceBrokerPassword" -d "{\"context\":{\"account_id\":\"499b176abb3e1c9727df87ae48b27c7b\",\"crn\":\"crn:v1:bluemix:public:testjavaresourceservicebrokername:us-south:a\/499b176abb3e1c9727df87ae48b27c7b:7f0d2b93-fd4a-4ce9-8675-978d20b1e0b7::\",\"platform\":\"ibmcloud\",\"resource_group_crn\":\"crn:v1:bluemix:public:resource-controller::a\/499b176abb3e1c9727df87ae48b27c7b::resource-group:2a5f74056b254efbaab5e9e28a711141\",\"target_crn\":\"crn:v1:bluemix:public:resource-catalog::a\/e97a8c01ac694e308ef3ad7795c7cdb3::deployment:e62e2c19-0c3b-41e3-b8b3-c71762ecd489%3Aus-south38399\"}, \"parameters\":{\"parameter1\":1, \"parameter2\":\"value\"}, \"plan_id\":\"e62e2c19-0c3b-41e3-b8b3-c71762ecd489\", \"service_id\":\"cb55391b-3416-4943-a6a6-a541778c1924\"}" http://localhost:3000/v2/service_instances/crn%3Av1%3Abluemix%3Apublic%3Atestjavaresourceservicebrokername%3Aus-south%3Aa%2F499b176abb3e1c9727df87ae48b27c7b%3A7f0d2b93-fd4a-4ce9-8675-978d20b1e0b7%3A%3A?accepts_incomplete=true
Bind
URL

The URL path for the PUT invoked within the service broker implementation is /v2/service_instances/:instance_id/service_bindings/:binding_id where :instance_id is the id generated by IBM Cloud for the service instance and :binding_id is the id generated by IBM Cloud for the service/app binding.

Content

The fields passed into a bind PUT within the JSON body are as follows:

Sample JSON

"bind_resource :
{
   "app_guid" : "80e0caaa-4145-4f2a-9bf8-1ab00fff1766"
},
"plan_id"      : "plan-guid-here",
"service_id"   : "service-guid-here"

Bind Result
Result

"error"       : "RequiresApp",
"description" : "This service does not support service keys."

Successful Response Body

The fields returned from a bind PUT within the JSON result are as follows for a 200/201:

Successful Sample JSON

"credentials"   :
{
    "url"      : "http://10.0.1.2:12345",
    "userid"   : "8401a824-1da7-4114-8664-2460db21661a",
    "password" : "b98e9690-c5e7-405f-9ef6-d6fa36afbaba"
}

Bind Test
 -X PUT -H "Accept:application/json" -H "Content-Type:application/json" -H "X-Broker-Api-Version:2.12" -H "X-Broker-Api-Originating-Identity:ibmcloud eyJpYW1faWQiOiJJQk1pZC0zMTAwMDJNNEpGIiwic3ViIjoiYmx1ZW1peF91aV9zb3Rlc3RAbWFpbGluYXRvci5jb20ifQ==" -u "TestServiceBrokerUser:TestServiceBrokerPassword" -d "{\"bind_resource\":{\"app_guid\":\"d3f16a48-8bd1-4aab-a7de-e2a22ad38292\"}, \"parameters\":{\"parameter1\":1, \"parameter2\":\"value\"}, \"plan_id\":\"e62e2c19-0c3b-41e3-b8b3-c71762ecd489\", \"service_id\":\"cb55391b-3416-4943-a6a6-a541778c1924\"}" http://localhost:3000/v2/service_instances/crn%3Av1%3Abluemix%3Apublic%3Atestjavaresourceservicebrokername%3Aus-south%3Aa%2F499b176abb3e1c9727df87ae48b27c7b%3A7f0d2b93-fd4a-4ce9-8675-978d20b1e0b7%3A%3A/service_bindings/crn%3Av1%3Abluemix%3Apublic%3Atestjavaresourceservicebrokername%3Aus-south%3Aa%2F499b176abb3e1c9727df87ae48b27c7b%3A7f0d2b93-fd4a-4ce9-8675-978d20b1e0b7%3Aresource-key%3A92dba2e9-86e7-4bb6-8e9f-b14294a41cbd
Unbind
URL

The URL path for the DELETE invoked within the service broker implementation is /v2/service_instances/:instance_id/service_bindings/:binding_id where :instance_id is the id generated by IBM Cloud for the service instance and :binding_id is the id generated by IBM Cloud for the service/app binding.

Query Parameters

The fields passed into an unbind DELETE as query parameters are as follows:

Unbind Result
Result
Successful Sample JSON


Unbind Test
 -X DELETE -H "Accept:application/json" -H "X-Broker-Api-Version:2.12" -H "X-Broker-Api-Originating-Identity:ibmcloud eyJpYW1faWQiOiJJQk1pZC0zMTAwMDJNNEpGIiwic3ViIjoiYmx1ZW1peF91aV9zb3Rlc3RAbWFpbGluYXRvci5jb20ifQ==" -u "TestServiceBrokerUser:TestServiceBrokerPassword" "http://localhost:3000/v2/service_instances/crn%3Av1%3Abluemix%3Apublic%3Atestjavaresourceservicebrokername%3Aus-south%3Aa%2F499b176abb3e1c9727df87ae48b27c7b%3A7f0d2b93-fd4a-4ce9-8675-978d20b1e0b7%3A%3A/service_bindings/crn%3Av1%3Abluemix%3Apublic%3Atestjavaresourceservicebrokername%3Aus-south%3Aa%2F499b176abb3e1c9727df87ae48b27c7b%3A7f0d2b93-fd4a-4ce9-8675-978d20b1e0b7%3Aresource-key%3A92dba2e9-86e7-4bb6-8e9f-b14294a41cbd?plan_id=e62e2c19-0c3b-41e3-b8b3-c71762ecd489&service_id=cb55391b-3416-4943-a6a6-a541778c1924"
Unprovision
URL

The URL path for the DELETE invoked within the service broker implementation is /v2/service_instances/:instance_id where :instance_id is the id generated by IBM Cloud for the service instance.

Query Parameters

The fields passed into an unprovision DELETE as query parameters are as follows:

Unprovision Result
Result

"error"       : "AsyncRequired",
"description" : "This service plan requires support for asynchronous service operations."

Successful Response Body

The fields returned from a successful unprovision DELETE within the JSON result are as follows for a 200/202/410

Successful Sample JSON

"description" : "Your service instance is being deleted asynchronously.",
"operation"   : "Unprovision_45"

Unprovision Test
 -X DELETE -H "Accept:application/json" -H "X-Broker-Api-Version:2.12" -H "X-Broker-Api-Originating-Identity:ibmcloud eyJpYW1faWQiOiJJQk1pZC0zMTAwMDJNNEpGIiwic3ViIjoiYmx1ZW1peF91aV9zb3Rlc3RAbWFpbGluYXRvci5jb20ifQ==" -u "TestServiceBrokerUser:TestServiceBrokerPassword" "http://localhost:3000/v2/service_instances/crn%3Av1%3Abluemix%3Apublic%3Atestjavaresourceservicebrokername%3Aus-south%3Aa%2F499b176abb3e1c9727df87ae48b27c7b%3A7f0d2b93-fd4a-4ce9-8675-978d20b1e0b7%3A%3A?accepts_incomplete=true&plan_id=e62e2c19-0c3b-41e3-b8b3-c71762ecd489&service_id=cb55391b-3416-4943-a6a6-a541778c1924"
Update Service
URL

The URL path for the PATCH invoked within the service broker implementation is /v2/service_instances/:instance_id where :instance_id is the id generated by IBM Cloud for the service instance.

Query Parameters

The fields passed into an update PATCH as query parameters are as follows:

Content

The fields passed into an update-service PATCH within the JSON body are as follows:

Sample JSON

"context"         :
{
    "account_id"        : "account-id-here",
    "crn"               : "crn-here",
    "platform"          : "ibmcloud",
    "resource_group_crn : "resource-group-crn-here",
    "target_crn"        : "target-crn-here"
},
"plan_id"         : "new-plan-guid-here",
"previous_values" :
{
    "plan_id"         : "plan-guid-here",
    "service_id"      : "service-guid-here"
}

Update Service Result
Result

"error"       : "AsyncRequired",
"description" : "This service plan requires support for asynchronous service operations."

Successful Response Body

The fields returned from a successful update PATCH within the JSON result are as follows for a 200/202

Sample Succesful JSON

"description" : "Your service instance is being updated asynchronously.",
"operation"   : "Update_45"

Update Service Test
 -X PATCH -H "Accept:application/json" -H "Content-Type:application/json" -H "X-Broker-Api-Version:2.12" -H "X-Broker-Api-Originating-Identity:ibmcloud eyJpYW1faWQiOiJJQk1pZC0zMTAwMDJNNEpGIiwic3ViIjoiYmx1ZW1peF91aV9zb3Rlc3RAbWFpbGluYXRvci5jb20ifQ==" -u "TestServiceBrokerUser:TestServiceBrokerPassword" -d "{\"context\":{\"account_id\":\"499b176abb3e1c9727df87ae48b27c7b\",\"crn\":\"crn:v1:bluemix:public:testjavaresourceservicebrokername:us-south:a\/499b176abb3e1c9727df87ae48b27c7b:7f0d2b93-fd4a-4ce9-8675-978d20b1e0b7::\",\"platform\":\"ibmcloud\",\"resource_group_crn\":\"crn:v1:bluemix:public:resource-controller::a\/499b176abb3e1c9727df87ae48b27c7b::resource-group:2a5f74056b254efbaab5e9e28a7111414\",\"target_crn\":\"crn:v1:bluemix:public:resource-catalog::a\/e97a8c01ac694e308ef3ad7795c7cdb3::deployment:e62e2c19-0c3b-41e3-b8b3-c71762ecd489%3Aus-south38399\"}, \"parameters\":{\"parameter1\":1, \"parameter2\":\"value\"}, \"plan_id\":\"e1031579-4b42-4169-b7cf-f7793c616fdc\", \"previous_values\":{\"plan_id\":\"e62e2c19-0c3b-41e3-b8b3-c71762ecd489\", \"service_id\":\"cb55391b-3416-4943-a6a6-a541778c1924\"}, \"service_id\":\"cb55391b-3416-4943-a6a6-a541778c1924\"}" http://localhost:3000/v2/service_instances/crn%3Av1%3Abluemix%3Apublic%3Atestjavaresourceservicebrokername%3Aus-south%3Aa%2F499b176abb3e1c9727df87ae48b27c7b%3A7f0d2b93-fd4a-4ce9-8675-978d20b1e0b7%3A%3A?accepts_incomplete=true
Get Service Instance Last Operation

This REST API will be called intermittently to refresh the current state of an asynchronous service instance operation. This includes provision, unprovision and update.

URL

The URL path for the GET invoked within the service broker implementation is /v2/service_instances/:instance_id/last_operation where :instance_id is the id generated by IBM Cloud for the service instance.

Query Parameters

The fields passed into a GET last operation as query parameters are as follows:

Get Service Instance Last Operation Result
Result

A status code of 200 is the expected successful value handled by IBM Cloud code.

The fields returned from a catalog GET within the JSON result are as follows:

Successful Sample JSON

"state"       : "succeeded",
"description" : "The asynchronous creation of your service instance succeeded."

Get Service Instance Last Operation Test
 -X GET -H "Accept:application/json" -H "X-Broker-Api-Version:2.12" -u "TestServiceBrokerUser:TestServiceBrokerPassword" "http://localhost:3000/v2/service_instances/crn%3Av1%3Abluemix%3Apublic%3Atestjavaresourceservicebrokername%3Aus-south%3Aa%2F499b176abb3e1c9727df87ae48b27c7b%3A7f0d2b93-fd4a-4ce9-8675-978d20b1e0b7%3A%3A/last_operation?operation=Provision_45&plan_id=e62e2c19-0c3b-41e3-b8b3-c71762ecd489&service_id=cb55391b-3416-4943-a6a6-a541778c1924"
Enablement Extension Enable

This extension supports enablement/disablement of a service instance.

URL

The URL path for the PUT for the service broker implementation is /bluemix_v1/service_instances/:instance_id where :instance_id is the id generated by IBM Cloud for the service instance.

Content

The fields passed into an enable PUT within the JSON body are as follows:

Sample JSON

"enabled"      : true,
"initiator_id" : "the ID of the initiator",
"reason_code"  : "the reason code"

Enablement Extension Enable Result
Result

A status code of 204 is the expected successful value

Enable Extension Enable Test
 -X PUT -H "Content-Type:application/json" -u "TestServiceBrokerUser:TestServiceBrokerPassword" -d "{\"enabled\":true, \"initiator_id\":\"some id\", \"reason_code\":\"some reason code\"}" http://localhost:3000/bluemix_v1/service_instances/crn%3Av1%3Abluemix%3Apublic%3Atestjavaresourceservicebrokername%3Aus-south%3Aa%2F499b176abb3e1c9727df87ae48b27c7b%3A7f0d2b93-fd4a-4ce9-8675-978d20b1e0b7%3A%3A
Enablement Extension State

This extension supports retrieving the current state of a service instance.

URL

The URL path for the GET for the service broker implementation is /bluemix_v1/service_instances/:instance_id where :instance_id is the id generated by IBM Cloud for the service instance.

Enablement Extension State Result
Result

A status code of 200 is the expected successful value.

The fields returned from a state GET within the JSON result are as follows:

Successful Sample JSON

"enabled"    : true,
"active"     : false,
"last_active : 1234567890000

Enable Extension State Test
 -X GET -H "Accept:application/json" -u "TestServiceBrokerUser:TestServiceBrokerPassword" http://localhost:3000/bluemix_v1/service_instances/crn%3Av1%3Abluemix%3Apublic%3Atestjavaresourceservicebrokername%3Aus-south%3Aa%2F499b176abb3e1c9727df87ae48b27c7b%3A7f0d2b93-fd4a-4ce9-8675-978d20b1e0b7%3A%3A

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.