Git Product home page Git Product logo

cf-nodejs-client's Introduction

cf-client

Build Status Build status Dependency Status devDependency Status Changelog API Doc

Table of Contents

Overview

This project provides a simple client library to interact with the Cloud Foundry Architecture:

ScreenShot

Using this library, you could interact with the following platforms: PWS , Bluemix or a Local Cloud Foundry instance:

Cloud Controller UAA Logging & Metrics
Apps Users Logs
Buildpacks
Domains
Jobs
Organizations
Organizations Quotas
Routes
Services
Service Bindings
Service Instances
Service Plans
Spaces
Spaces Quotas
Stacks
User provided Services
Users

Focus

The development doesn't cover the whole CloudController API. Main areas of development are:

App life cycle:

  • Create an App
  • Upload source code in .zip or .war (Support for Static, Python, PHP, Node.js & JEE)
  • Create an User Provided Services
  • Associate Apps with an User Provided Services
  • Start | Stop an App
  • Restage Apps
  • Scale Apps
  • Simple Logs management
  • Remove Apps
  • Remove User Provided Services

PaaS Management:

  • Organization quota
  • Organization
  • Space
  • Services, Service Instances, Service Plans, User provided Services & Service Binding
  • UAA Users
  • Users

Getting Started

If you need to interact with a Cloud Foundry platform try this online tool and use this example:

"use-strict";

const endpoint = "https://api.ng.bluemix.net";
const username = "BLUEMIX_USERNAME";
const password = "BLUEMIX_PASSWORD";

const CloudController = new (require("cf-client")).CloudController(endpoint);
const UsersUAA = new (require("cf-client")).UsersUAA;
const Apps = new (require("cf-client")).Apps(endpoint);

CloudController.getInfo().then( (result) => {
    UsersUAA.setEndPoint(result.authorization_endpoint);
    return UsersUAA.login(username, password);
}).then( (result) => {
	Apps.setToken(result);
    return Apps.getApps();
}).then( (result) => {
    console.log(result);
}).catch( (reason) => {
    console.error("Error: " + reason);
});

Explore the library and if you like the features, use it on your App:

npm install cf-client --save

Testing

This project has a test suite to ensure the readability of this project. Take a look the Tests cases developed with Mocha & Chai to understand some stuff about Cloud Foundry and the usage of this client. Besides, the project has invested some amount of time in testing phase to be the code with a nice coverage level.

The development has been tested with:

Local Instance PWS Bluemix
2.25.0 2.60.0 2.54.0

Last test: 2016/01/26

Testing against Bluemix:

export BLUEMIX_CF_API_URL=https://api.ng.bluemix.net && export BLUEMIX_username=$USERNAME && export BLUEMIX_password=$PASSWORD && npm run test:bluemix

Test suite:

npm test

Code coverage:

istanbul cover node_modules/mocha/bin/_mocha -- -R spec

Issues

If you have any question or doubt, please create an issue.

License

Licensed under the Apache License, Version 2.0.

References

cf-nodejs-client's People

Contributors

adrukh avatar aeweidne avatar cphrmky avatar jabrena avatar jsloyer avatar jthomas avatar nsand avatar sedgewickmm18 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cf-nodejs-client's Issues

Events and Logs are not supported?

When I try to use getEvents(guid) or getRecentLogs(guid) I get the following error

TypeError: Cannot read property 'replace' of undefined

But I notice that Events/Logs aren't listed in the main npmjs page, but are listed in the cf-rest-client docs page. Are these endpoints not supported yet or am I doing something wrong?

protobufjs vulnerability

Hello.
Please update the protobufjs dependency to fix the protobufjs vulnerability.
cf-client3 is a root library of this package. protobufjs has a dependency of cf-client3 in the version contained within this current tree.
protobufjs version needs to update to 6.10.3,6.11.3

Node security alerts

Hi there, there are a number of errors regarding security when nsp tool analyzes this package.

I believe in most cases it is just a matter of updating the dependent package and move on, it seems to have a PR regarding updates actually, it was merged but never updated on npm, so the users are not able to benefit from.

Can I help to maintain this project somehow? I mean, obviously I can open PR's but I would need to be allowed to update it at npm as well.

Missing expected instances when using ServiceInstances method

We have two service instances, one in our Dev space and the other in our Prod space. Both services have the same name.

The results of ServiceInstances does not contain the instance that's in our Dev space. This happens whether we pass the space_guid for our Dev space to ServiceInstances or if we don't specify the space_guid.

The service instance in Prod is contained in the results of calling ServiceInstances if we pass the space_guid for the Prod space or if we don't specify the space_guid.

Is there a bug in cf-nodejs-client related to service instances sharing the same name in different spaces? Or perhaps a bug in Cloud Foundry itself? Please look at the attached application to see how we're calling ServiceInstances.

list-instances.zip

Add "getTokenInfo(accessToken) => TokenInfo" method to UsersUAA

Add method to decode access token into username, email, and user guid. user guid is required for management / permission calls.

from the go implementation:

type TokenInfo struct {
    Username string `json:"user_name"`
    Email    string `json:"email"`
    UserGuid string `json:"user_id"`
}

func NewTokenInfo(accessToken string) (info TokenInfo) {
    tokenJson, err := DecodeAccessToken(accessToken)
    if err != nil {
        return TokenInfo{}
    }

    info = TokenInfo{}
    err = json.Unmarshal(tokenJson, &info)
    if err != nil {
        return TokenInfo{}
    }

    return info
}

func DecodeAccessToken(accessToken string) (tokenJson []byte, err error) {
    tokenParts := strings.Split(accessToken, " ")

    if len(tokenParts) < 2 {
        return
    }

    token := tokenParts[1]
    encodedParts := strings.Split(token, ".")

    if len(encodedParts) < 3 {
        return
    }

    encodedTokenJson := encodedParts[1]
    return base64Decode(encodedTokenJson)
}

func base64Decode(encodedData string) ([]byte, error) {
    return base64.StdEncoding.DecodeString(restorePadding(encodedData))
}

func restorePadding(seg string) string {
    switch len(seg) % 4 {
    case 2:
        seg = seg + "=="
    case 3:
        seg = seg + "="
    }
    return seg
}

Bluemix - getRecent() getting app logs failing with RangeError: Illegal offset

getRecent() is failing when attempting to retrieve logs for any Bluemix application that contains recent logs. The current mocha test for logs (https://github.com/IBM-Bluemix/cf-nodejs-client/blob/master/test/lib/model/metrics/LogTests.js#L54) pass because the test app returns an empty log (i.e. there were no recent logs). I modified the test to point to a Bluemix app that had recent logs and the mocha test fails (result is below).
cc: @chambrid

  1. Cloud foundry Logs The platform returns Logs:
    AssertionError: expected [RangeError: Illegal offset: 0 <= 127 (+1) <= 53] to equal 'No App'
    at test/lib/model/metrics/LogTests.js:83:31
    at tryCatcher (node_modules/bluebird/js/release/util.js:11:23)
    at Promise._settlePromiseFromHandler (node_modules/bluebird/js/release/promise.js:489:31)
    at Promise._settlePromise (node_modules/bluebird/js/release/promise.js:546:18)
    at Promise._settlePromise0 (node_modules/bluebird/js/release/promise.js:591:10)
    at Promise._settlePromises (node_modules/bluebird/js/release/promise.js:670:18)
    at Async._drainQueue (node_modules/bluebird/js/release/async.js:129:16)
    at Async._drainQueues (node_modules/bluebird/js/release/async.js:139:10)
    at Immediate.Async.drainQueues as _onImmediate

Using it in any cloud foundry env

Does this lib is supporting just env the based on bluemix or any other CF env ?
1 .I mean I just need const endpoint = "https://api.cf.mycompany.com"; and it should work?
2. In cf the app is bounded to a spaces so how should i works with your example

CloudController.getInfo().then( (result) => {
UsersUAA.setEndPoint(result.authorization_endpoint);
return UsersUAA.login(username, password);
}).then( (result) => {
Apps.setToken(result);
return Apps.getApps();
}).then( (result) => {
console.log(result);
}).catch( (reason) => {
console.error("Error: " + reason);
});

where does the space is handled here ? since when I connect from the cli it ask me to which space I want to connect...

Btw, I try to run it against our API (until I receive your input ...) and its not working and Im not getting no error message in the console, what it can be ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.