Product
Introducing Ruby Support in Socket
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
@financial-times/cmdb.js
Advanced tools
A javascript library for interacting with the CMDB v3 (cmdb v2 is now retired).
Provides versions for the browser, and node.js.
fetch
polyfill. This is no longer the case for current versionsPull requests are welcomed.
npm install @financial-times/cmdb.js
Pass in your apikey to the library to authenticate requests:
const Cmdb = require('cmdb.js');
const cmdb = new Cmdb({
api: 'https://cmdb.in.ft.com/v3/',
apikey: process.env.APIKEY,
verbose: true,
});
If you're playing with test or development data, you should point the library to a test environment, to avoid corrupting production:
const Cmdb = require('cmdb.js');
const cmdb = new Cmdb({
api: 'https://cmdb-test.in.ft.com/v3/',
apikey: process.env.APIKEY,
});
Available as jsdoc documentation
Once you've setup the class with an apikey, you can get information about a given system by passing in the type 'system' and relevant system code into getItem
:
const systemCode = 'ft-dashing';
cmdb
.getItem(null, 'system', systemCode)
.then(result => {
console.log(result);
})
.catch(error => {
console.error('an error occured');
});
You can also create/update and delete items, using putItem
and deleteItem
in a similar fashion.
To get a list of all the systems currently listed in CMDB, pass the type 'system' into getAllItems
:
cmdb.getAllItems(null, 'systems').then(body => {
body.forEach(contact => {
console.log(contact);
});
});
Beware, calls to getAllItems can attempt to return a large amount of data - and therefore timeout. A better approach is to refine your request to focus on the actual data you require. For example:
See the Function Reference below for more details on these targeted requests.
If changes made by your system are triggered by another user or system, it is recommended that the upstream user is sent to the CMDB using the FT-Forwarded-Auth header. This allows for fine-grained reports to be created centrally, which may be necessary in the event of a security incident.
If you're using the s3o-middleware module, you can handle this automatically by passing res.locals into each call made by this library. For example:
const express = require('express');
const app = express();
const authS3O = require('s3o-middleware');
app.use(authS3O);
const Cmdb = require('cmdb.js');
const cmdb = new Cmdb({
apikey: process.env.APIKEY,
});
app.post('/contacts/:contactid', function(req, res) {
cmdb
.putItem(res.locals, 'contact', req.params.contactid, req.body)
.then(result => {
res.render('contact', result);
});
});
Via the use of optional parameters and dedicated functions it is possible to retrieve anything from a single field on a single record to all fields on all records. Selection criteria and response timeouts may also be specified. BEWARE there is an ongoing discussion re how the underlying fetch() function handles timeouts.
The criteria parameter defines the query string to use to restrict the number of records that are returned. It expects an object of name/value pairs. A blank value for a name indicates a query for records that dont include the name as an attribute. Values can include wildcard characters of * and ?
The fields parameter defines which fields are to be output for each record. It expects an array of field names. Note that dataItemID, dataTypeID and lastUpdate will always be output.
The relatedFields parameter indicates if nested related item data is to be outout. If set to false then performance is improved at the expense of detail; no related items are shown just the item itself.
All returned JSON arrays and JSON objects are native javascript
The expected node version for development is defined in .nvmrc
.
Checkout the repository, and install packages:
git clone git@github.com:Financial-Times/cmdb.js.git
npm install`
Linting and tests are ran on precommit and prepush respectively, otherwise view npm scripts using npm run
.
FAQs
A javascript library for interacting with the CMDB v3
We found that @financial-times/cmdb.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 15 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.