What is @sap/cf-tools?
@sap/cf-tools is an npm package designed to interact with SAP Cloud Foundry environments. It provides a set of tools to manage Cloud Foundry applications, services, and spaces, making it easier to automate and script common tasks.
What are @sap/cf-tools's main functionalities?
Login to Cloud Foundry
This feature allows you to log in to a Cloud Foundry environment using your credentials and API endpoint.
const cfTools = require('@sap/cf-tools');
async function login() {
const result = await cfTools.login({
username: 'your-username',
password: 'your-password',
apiEndpoint: 'https://api.cf.example.com'
});
console.log(result);
}
login();
List Spaces
This feature retrieves a list of spaces available in the Cloud Foundry environment.
const cfTools = require('@sap/cf-tools');
async function listSpaces() {
const spaces = await cfTools.getSpaces();
console.log(spaces);
}
listSpaces();
Deploy Application
This feature allows you to deploy an application to Cloud Foundry using a manifest file.
const cfTools = require('@sap/cf-tools');
async function deployApp() {
const result = await cfTools.deploy({
manifest: 'path/to/manifest.yml'
});
console.log(result);
}
deployApp();
Other packages similar to @sap/cf-tools
cf-cli
The Cloud Foundry CLI (cf-cli) is a command-line tool for interacting with Cloud Foundry. It provides similar functionalities to @sap/cf-tools, such as logging in, managing spaces, and deploying applications. However, cf-cli is a standalone executable rather than an npm package, making it more suitable for use in shell scripts and manual command-line operations.
cf-nodejs-client
cf-nodejs-client is an npm package that provides a Node.js client for the Cloud Foundry API. It offers functionalities like managing applications, services, and spaces, similar to @sap/cf-tools. The main difference is that cf-nodejs-client is more focused on providing a low-level API client, whereas @sap/cf-tools offers higher-level abstractions and utilities.
Overview
This package provides a set of APIs to help you develop applications in Cloud Foundry. You can use these APIs to manage apps, service instances, orgs, spaces, and users in your environment. Mostly, this is a wrapper of the CF command line client, which runs a particular command and parses the output to the suitable JSON file. If an error or failure occurs, the runtime exception throws with relevant problem information.
API Reference Guide
API guide
Prerequisite
from version v1.0.0
and above:
Make sure you have installed the CF CLI v7 tool in your environment.
below version v1.0.0
:
Make sure you have installed the CF CLI v6 tool in your environment.
Examples of usage
Example 1
try {
const result = await cfLogin("https://api.cf.....com", "user", "password");
if (result === "OK") {
// successful
}
} catch (e) {
// display or/and log error
}
Example 2
try {
const spaces = await cfGetAvailableSpaces("myOrg");
for (const space of spaces) {
console.log("Space label is " + space.label + " guid is " + space.guid);
}
} catch (e) {
// display or/and log error
}
Contributing
Contributing information can be found in the CONTRIBUTING.md file.