- NodeJS
v8.x
tov12.x
(tested) - This library requires the
needle
andform-data
node modules
npm install @on-prem/on-prem-meta
or
git clone https://github.com/on-prem/on-prem-meta-node
cd on-prem-meta-node
npm install
Required environment variables:
export ON_PREM_META_HOST=meta.yourdomain.com:443
export ON_PREM_META_APITOKEN=yourtoken
Optional environment variables:
If you're using a self-signed certificate:
export ON_PREM_META_INSECURE=true
To manage the Admin API instead of the Meta API:
export ON_PREM_META_PREFIX=admin
To obtain an On-Prem Meta OVA, please visit https://on-premises.com
The following functions are exported:
makeSHA256()
to generate an SHA256 stringmakeHMAC()
to generate an SHA256 HMAC from a string and keybuildRequest()
to generate a request object to be sent to theapiCall()
functionapiCall()
to send the actual request data to the Meta API
The following helper functions are exported:
getVersion()
to get the version of the Meta or Admin appliancebuildOVA()
to build an OVA through the Meta APIgetStatus()
to obtain the status of an OVA buildpollStatus()
to poll the status of an OVA build (every 5 seconds)getDownloads()
to obtain the list of download files for an OVA buildcancelBuild()
to cancel a running OVA build
See the usage docs below.
meta = require 'on-prem-meta'
or
meta = require './src/on-prem-meta'
apiParams =
method: 'GET'
endpoint: 'settings/license'
meta.buildRequest apiParams, (error, result) =>
unless error
meta.apiCall result, (err, res, data) ->
console.log "ERROR:", err
console.log "RESULT:", res
console.log "DATA:", data
apiParams =
method: 'GET'
endpoint: 'audit'
query:
time: 'day'
meta.buildRequest apiParams, (error, result) =>
unless error
meta.apiCall result, (err, res, data) ->
console.log data
coffee> {
logs: [
{
logdate: '1574834282.732987162',
id: '287e10307425d845',
location: 'web',
user: 'admin',
action: 'builds.create',
data: '1574834281.966265128'
}
],
num: 1
}
apiParams =
method: 'POST'
endpoint: 'settings/license'
files:
settings:
filename: 'license.asc'
data: fs.readFileSync('./path/to/license.asc')
query:
id: 1
meta.buildRequest apiParams, (error, result) =>
unless error
meta.apiCall result, (err, res, data) ->
console.log data
coffee> { Status: '200 OK' }
meta.options.agent = new https.Agent { family: 6 }
meta.buildRequest undefined, (error, result) =>
unless error
meta.apiCall result, (err, res, data) ->
console.log data
The following helper functions are designed to simplify API calls and return simple string results
apiParams =
repo_name: 'your-appliance'
ova_type: 'server'
export_disks: 'raw,qcow2'
meta.buildOVA "/path/to/your/app.tcz", apiParams, (err, res) ->
if err
console.error err
process.exit 1
else
console.log res
coffee> 1574834281.966265128
meta.pollStatus '1574834281.966265128', undefined, (err, res) ->
if err
console.error err
process.exit 1
else
console.log res
coffee> success
meta.getDownloads '1574834281.966265128', (err, res) ->
if err
console.error err
process.exit 1
else
console.log res
coffee> https://yourdomain.com:443/downloads/build-1574834281.966265128/your-appliance-v1.2.3-release.ova
meta.cancelBuild '1574834281.966265128', (err, res) ->
if err
console.error err
process.exit 1
else
console.log res
coffee> OK
meta = require('on-prem-meta');
or
meta = require('./lib/on-prem-meta');
var apiParams = { method: 'GET', endpoint: 'settings/license' };
meta.buildRequest(apiParams, (error, result) => {
if (!error) {
return meta.apiCall(result, function(err, res, data) {
console.log("ERROR:", err);
console.log("RESULT:", res);
return console.log("DATA:", data);
});
}
});
apiParams = {
method: 'GET',
endpoint: 'audit',
query: {
time: 'day'
}
};
meta.buildRequest(apiParams, (error, result) => {
if (!error) {
return meta.apiCall(result, function(err, res, data) {
return console.log(data);
});
}
});
apiParams = {
method: 'POST',
endpoint: 'settings/license',
files: {
settings: {
filename: 'license.asc',
data: fs.readFileSync('./path/to/license.asc')
}
},
query: { id: 1 }
};
meta.buildRequest(apiParams, (error, result) => {
if (!error) {
return meta.apiCall(result, function(err, res, data) {
return console.log(data);
});
}
});
meta.options.agent = new https.Agent({ family: 6 });
meta.buildRequest(void 0, (error, result) => {
if (!error) {
return meta.apiCall(result, function(err, res, data) {
return console.log(data);
});
}
});
The following helper functions are designed to simplify API calls and return simple string results
apiParams = {
repo_name: 'your-appliance',
ova_type: 'server',
export_disks: 'raw,qcow2'
};
meta.buildOVA("/path/to/your/app.tcz", apiParams, function(err, res) {
if (err) {
console.error(err);
return process.exit(1);
} else {
return console.log(res);
}
});
meta.pollStatus('1574834281.966265128', void 0, function(err, res) {
if (err) {
console.error(err);
return process.exit(1);
} else {
return console.log(res);
}
});
meta.getDownloads('1574834281.966265128', function(err, res) {
if (err) {
console.error(err);
return process.exit(1);
} else {
return console.log(res);
}
});
meta.cancelBuild('1574941961.314614280', function(err, res) {
if (err) {
console.error(err);
return process.exit(1);
} else {
return console.log(res);
}
});
To run the tests, type:
npm test
Copyright (c) 2019 Alexander Williams, Unscramble [email protected]