node package manager

apiconnect-cli-util

APIC Toolkit Util - a set of utilities used by various apic clis

Installation

install the dependencies module

   %npm install

install the resources

   %gulp resources

Running Tests

   %npm test

Usage

Making rest calls to an apic management stack:

 var ApicCliUtil = require('apiconnect-cli-util);
 //a wrapper around the request npm module
 //making rest calls to a backend
 //the request takes care of setting the ssl certs when interacting with an
 //APIC Stack
 ApicCliUtil.Request.get('<someurl>', function (err, rsp, body) {} );

 var opts = ApicCliUtil.Util.requestDefaultOptions();
 opts.headers['content-type'] = 'application/vnd.ibm-apim.swagger2+json';
 opts.json = {'swagger': '2.0'};//some swagger content
 opts.method = 'POST';
 ApicCliUtil.Request.post(<someurl>, opts, function (err, rsp, body) {} );

Loading a project

 var ApicCliUtil = require('apiconnect-cli-util);
 //Load a project from a directory or by specifying a file that contains apic management specific artifacts
 //for ex: swagger api files (as yaml or json) or product file(s) (yaml|json). If a file is specified then the file
 //needs to be either a swagger or a product file.
 var prj = new ApicCliUtil.Project(<dir|file>);
 prj.load (function (err) {});
 //validate project
 //opts is an optional object: {serverValidation: true|false} - default is false
 prj.validate(opts, function (results) {
       //results is an an array of objects:
       //{name: <entry_name>, status: <valid|not_valid>, err: Error}
  });

Fetch credentials from Netrc

 var ApicCliUtil = require('apiconnect-cli-util);
 //Working with Netrc to fetch/set credentials associate to a machine/server
 var creds = ApicCliUtil.Netrc.lookup('acme.com');//return {login: <login>, password: <pass>};

Set credentials from Netrc

 var ApicCliUtil = require('apiconnect-cli-util);
 //Working with Netrc to fetch/set credentials associate to a machine/server
 ApicCliUtil.Netrc.setCredential(<machine>, <username>, <password>);//return {login: <login>, password: <pass>};

Using Context - to ovveride what's set in config

var Context = require('apiconnect-cli-util').Context;
Context.set({ username: 'foo', password: 'pass', server: 'machine' });