Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[new] Auth and listApplications examples
- Loading branch information
1 parent
10878d2
commit 3706a80
Showing
5 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
credentials.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* This example shows you how to login into a VCAP cloud, put your | ||
* credentials into credentials.json file.*/ | ||
|
||
var vcap = require('../index'); | ||
var credentials = require('./credentials'); | ||
|
||
// Create the client using the given endpoint. | ||
var client = new vcap.Client(credentials.endpoint); | ||
|
||
// Login with the given credentials | ||
client.login(credentials.user, credentials.password, function(err, token) { | ||
if(err) return console.log('Login error:', err); | ||
console.log('Auth success, token is', token); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"user": "your-email@example.com", | ||
"password": "Your - Password", | ||
"endpoint": "http://api.cloudfoundry.com" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var credentialsFilePath = path.join(__dirname, 'credentials.json'); | ||
if(!path.existsSync(credentialsFilePath)) { | ||
throw "Before running any example, be sure to put your cloud credentials in the examples/credentials.json file. Use examples/credentials-sample.json as an guide"; | ||
} | ||
var credentials = JSON.parse(fs.readFileSync(credentialsFilePath)); | ||
module.exports = credentials; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** This example shows you how to list the applications from a VCAP | ||
* cloud */ | ||
|
||
var vcap = require('../index'); | ||
var credentials = require('./credentials'); | ||
|
||
var client = new vcap.Client(credentials.endpoint); | ||
|
||
// List all my current applications | ||
client.login(credentials.user, credentials.password, function(err, token) { | ||
if(err) return console.log('Login error: ' + err); | ||
client.listApplications(function(err, apps) { | ||
if(err) return console.log('An error occurred while listing the applications: ', err); | ||
console.log(apps); | ||
}); | ||
}); |