Skip to content
This repository was archived by the owner on Mar 25, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apigee-cf-service-broker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ This plan uses `route-services` to redirect traffic coming into Cloud Foundry to
This plan uses `route-services` to redirect traffic coming into Cloud Foundry to the Apigee Microgateway application before being directed to the target application -- reducing the network latency that occurs in the `org` plan.
3. The `microgateway-coresident` plan: The `microgateway-coresident` plan allows a user to launch Apigee Microgateway in the same container as their target application.
This plan does not need to use `route-services` in that traffic will not need to be redirected to a separate container or cloud url. By using the `microgateway-coresident` plan, users will see the lowest latencies (as there are no extra network hops) as well as better scalability in that every new application instance will be started with Apigee Microgateway alongside it.
4. The `portal` plan: The `portal` plan allows for the use of the Apigee public or private cloud to proxy an application, creates proxy, portal, api-product in Apigee edge for the target application
This plan uses `route-services` to redirect traffic coming into Cloud Foundry to an Edge proxy in the cloud before being directed back down to the target application.

## Based on your chosen plan(s), follow the instructions below:

* For the `org` plan, follow the instructions [here](../docs/setup-org.md)
* For the `microgateway` plan, follow the instructions [here](../docs/setup-microgateway.md)
* For the `microgateway-decorator` plan, follow the instructions [here](../docs/setup-microgateway-coresident.md)
* For the `portal` plan, follow the instructions [here](../docs/setup-portal.md)
32 changes: 32 additions & 0 deletions apigee-cf-service-broker/commands/bind-route-to-app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const path = require('path')
const commandLineArgs = require('command-line-args')
const { CF_API_URL, CFBinder } = require('../lib/providers/cf-binder')
const Apps = require(path.resolve('./lib/providers/cf-nodejs-client/model/cloudcontroller/Apps'))

const optionDefinitions = [
{ name: 'src', alias: 's', type: String },
{ name: 'dst', alias: 'd', type: String },
];

const options = commandLineArgs(optionDefinitions);

const run = async () => {
const client = new CFBinder()
await client.login()

const apps = await client.getApps({
space: { metadata: { guid: '15ecd7cf-42b0-439d-a009-57df23b9c400' } }
})
const app = apps.resources.find(r => r.entity.name = options.src)

const route = await client.getRoute({ target_app_route: options.dst } )

const appsService = new Apps(CF_API_URL)
appsService.setToken(client.loginResponse)

const mappedResult = await appsService.associateRoute(app.metadata.guid, route.metadata.guid)

console.info('new route', JSON.stringify(app, null, 2), route, mappedResult)
}

run()
15 changes: 15 additions & 0 deletions apigee-cf-service-broker/commands/run-cf-app-route-binding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { CFBinder } = require('../lib/providers/cf-binder')

const run = async () => {
const client = new CFBinder()
await client.login()
const result = await client.runBinding({
"target_app_port": 80,
"target_app_route": "sample",
"target_app_space_name": "dev"
})
console.info('RES', result)
// console.info('new route', client.getAppInternalFullHostname())
}

run()
12 changes: 12 additions & 0 deletions apigee-cf-service-broker/commands/service-plans.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const ServicePlans = require('../lib/providers/service-plans')

const plan = new ServicePlans()
const microc2c = plan.getProvider('micro_c2c')
const microc2c = plan.getProvider('micro')

console.info('microc2c.getUrlFromProxyToApp', microc2c.getUrlFromProxyToApp({}))
console.info('microc2c.deriveParams', microc2c.deriveParams({
target_app_port: 20,
target_app_route: 'dev',
target_app_space_name: 'space'
}))
23 changes: 23 additions & 0 deletions apigee-cf-service-broker/config/environment/development.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const path = require('path');
require('dotenv').config();

// Development specific configuration
// ==================================
module.exports = {
cf: {
user: process.env.CF_LOGIN,
password: process.env.CF_LOGIN_PASSWORD,
appsBaseDomain: process.env.APPS_BASE_DOMAIN,
microgatewayAppName: process.env.MICROGATEWAY_APP_NAME,
brokerAppName: process.env.BROKER_APP_NAME,

loginEndpoint: process.env.LOGIN_ENDPOINT,
apiUrl: process.env.CF_API_URL,
appsInternalDomain: process.env.APPS_INTERNAL_DOMAIN
},
auth: {
securityUserName: process.env.SECURITY_USER_NAME,
securityUserPassword: process.env.SECURITY_USER_PASSWORD,
type: 'staticauth'
}
};
90 changes: 90 additions & 0 deletions apigee-cf-service-broker/config/environment/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const path = require('path')
const nconf = require('nconf')
const _ = require('lodash')
const logger = require(path.resolve('./lib/helpers/logger'))

let vcapApplicationConfig

Object.prototype.toString.call(process.env.VCAP_APPLICATION) === '[object String]'
? vcapApplicationConfig = JSON.parse(process.env.VCAP_APPLICATION)
: vcapApplicationConfig = {
// for tests and local usage
application_name: 'cf-broker-name'
}

// All configurations will extend these options
// ============================================
const all = {
vcapApplication: vcapApplicationConfig,
env: process.env.NODE_ENV || 'development',
// Server port
port: process.env.PORT || 8888,
// Server IP
ip: process.env.IP || '0.0.0.0',
defaults: {
APIGEE_DASHBOARD_URL: 'https://enterprise.apigee.com/platform/#/',
APIGEE_MGMT_API_URL: 'https://api.enterprise.apigee.com/v1',
APIGEE_PROXY_DOMAIN: 'apigee.net',
APIGEE_PROXY_HOST_TEMPLATE: '${org}-${env}.${domain}',
APIGEE_PROXY_NAME_TEMPLATE: 'cf-${route}',
auth: 'staticauth'
}
};

// read in specific apigee configurations
all.getApigeeConfiguration = (userOrg, userEnv, callback) => {
const configString = nconf.get('APIGEE_CONFIGURATIONS')

let configurations

if (configString) {
try {
configurations = JSON.parse(configString)
} catch (e) {
logger.log.error(e)

const loggerError = logger.ERR_CONFIG_PARSE(
null,
null,
`${configString}. With ERROR message: "${e.message}". Please make sure your configuration is in the correct JSON format`
)
return callback(loggerError)
}

for (var i = 0; i < configurations.length; i++) {
if (configurations[i].org === userOrg && configurations[i].env === userEnv) {
Object.keys(configurations[i]).forEach(function (key) {
nconf.set(key.toUpperCase(), configurations[i][key])
logger.log.info('Config key: ', key.toUpperCase(), ' = ', configurations[i][key])
})
return callback(null, nconf)
}
}
const loggerError = logger.ERR_ORG_ENV_NOT_FOUND(
null,
null,
`Specified "org" = "${userOrg}" with "env" = "${userEnv}" do not exist in your Tile or Open Source Cloud Foundry configuration. Please contact your Cloud Foundry administrator for more assistance`)
return callback(loggerError)
}
const loggerError = logger.ERR_NO_CONFIGURATION()
callback(loggerError)
}

// arguments, environment vars
nconf.use('memory')
.argv()
.env()
.defaults(all.defaults)

all.default = nconf

// Export the config object based on the NODE_ENV
// ==============================================
/* eslint-disable */
const mod = require(`./${all.env.toLowerCase()}.js`) || {};
/* eslint-enable */

module.exports = _.merge(
all,
mod,
);
23 changes: 23 additions & 0 deletions apigee-cf-service-broker/config/environment/production.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const path = require('path');
require('dotenv').config();

// Development specific configuration
// ==================================
module.exports = {
cf: {
user: process.env.CF_LOGIN,
password: process.env.CF_LOGIN_PASSWORD,
appsBaseDomain: process.env.APPS_BASE_DOMAIN,
microgatewayAppName: process.env.MICROGATEWAY_APP_NAME,
brokerAppName: process.env.BROKER_APP_NAME,

loginEndpoint: process.env.LOGIN_ENDPOINT,
apiUrl: process.env.CF_API_URL,
appsInternalDomain: process.env.APPS_INTERNAL_DOMAIN
},
auth: {
securityUserName: process.env.SECURITY_USER_NAME,
securityUserPassword: process.env.SECURITY_USER_PASSWORD,
type: 'staticauth'
}
};
26 changes: 26 additions & 0 deletions apigee-cf-service-broker/config/environment/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const path = require('path')
require('dotenv').config()

const yaml = require('js-yaml')
const fs = require('fs')
const fromManifest = yaml.safeLoad(fs.readFileSync(path.resolve('./manifest.yml'), 'utf8'))

// nconf.defaults(Object.assign({}, defaults, fromManifest.env))

// Development specific configuration
// ==================================
module.exports = {
defaults: fromManifest.env,
cf: {
user: 'cftester',
password: 'cftesting',
appsBaseDomain: 'cf-base-domain',
microgatewayAppName: 'c2c-mg-name',
brokerAppName: 'cf-broker-name'
},
auth: {
securityUserName: 'tester',
securityUserPassword: 'testing',
type: 'staticauth'
}
};
5 changes: 5 additions & 0 deletions apigee-cf-service-broker/env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CF_LOGIN=<userlogin-in-cloudfoundry>
CF_LOGIN_PASSWORD=<user-password-in-cloud-foundry>
MICROGATEWAY_APP_NAME=<host from command output: cf routes>
BROKER_APP_NAME=<name from command-output: cf apps>
APPS_BASE_DOMAIN=<name from command-output: cf domains>
20 changes: 20 additions & 0 deletions apigee-cf-service-broker/json-sample/service-binding-c2c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"service_id": "5E3F917B-9225-4BE4-802F-8F1491F714C0",
"plan_id": "2A7D9A35-1CB3-4E05-8085-CC0100331A96",
"bind_resource": { "route": "sample-4.apps.pcf24.apigee.xyz" },
"context": {
"platform": "cloudfoundry",
"organization_guid": "d90cc2e5-3517-4504-aa87-6e68bbd15da6",
"space_guid": "15ecd7cf-42b0-439d-a009-57df23b9c400"
},
"parameters": {
"org": "yauhenikisialiou-eval",
"env": "test",
"micro_c2c": "c2c-test-service",
"target_app_route": "sample",
"target_app_port": "8080",
"action": "bind proxy",
"protocol": "http",
"bearer": "<get_token>"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"comment": "Sample to create serivce binding - portal",
"service_id": "5E3F917B-9225-4BE4-802F-8F1491F714C0",
"plan_id": "04B7CC7F-EE5D-4BF4-A5D7-1C637651F545",
"bind_resource": {
"route": "sample-1.apps.gilroy.cf-app.com"
},
"context": {
"space_guid": "15ecd7cf-42b0-439d-a009-57df23b9c400"
},
"parameters": {
"env": "test",
"org": "yauhenikisialiou-eval",
"bearer": "<get_token>",
"action": "bind proxy",
"protocol": "http",
"target_app_route": "sample",
"target_app_port": 8080
}
}
41 changes: 41 additions & 0 deletions apigee-cf-service-broker/lib/controllers/api/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict'
/*
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Dump out version info, hosting location, etc.
* @module
*/

const path = require('path')

const config = require(path.resolve('./config/environment'))
const express = require('express')
const router = express.Router()

const auth = require(path.resolve('./lib/helpers/auth'))(config)

router.use(auth)

router.get('/', (req, res) => {
res.json({ message: 'This is the cf-apigee-broker CF Service Broker API.', configuration: 'Blocked' })
})

/**
* Router for misc API
* @type express.Router
*/
module.exports = router
46 changes: 46 additions & 0 deletions apigee-cf-service-broker/lib/controllers/api/catalog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict'
/*
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Implementation of [catalog API for CF](http://docs.cloudfoundry.org/services/api.html)
* @module
*/

const path = require('path')
const config = require(path.resolve('./config/environment'))
const express = require('express')
const router = express.Router()
const auth = require(path.resolve('./lib/helpers/auth'))(config)
const catalogData = require(path.resolve('./lib/providers/catalog_data'))

// TODO - populate services object from a data store.. CPS?
// TODO - this catalog will be different for private cloud

const services = catalogData.getServiceCatalog()

// basic auth on this
router.use(auth)

router.get('/', (req, res) => {
res.json({services: services})
})

/**
* Router for `/catalog`
* @type express.Router
*/
module.exports = router
Loading