Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const createBucket = async(orgId, // String
orgName, //String
bucketName, //String
) => {
bucketAPI = new BucketsAPI(new InfluxDB({url: __config.influx_url, token: __defaultUser.token, timeout: 20000}));
await bucketAPI.postBuckets({body: {name: bucketName, orgID: orgId}});
};
const createDashboard = async(name, orgId) => {
const dbdsAPI = new DashboardsAPI(new InfluxDB({url: __config.influx_url, token: __defaultUser.token, timeout: 20000}));
await dbdsAPI.postDashboards({body: {name: name, orgID: orgId}}).catch(async error => {
console.log('--- Error Creating dashboard ---');
console.error(error);
throw error;
});
};
const createLabel = async(userName,
labelName,
labelDescr,
labelColor ) =>{
let user = getUser(userName);
const lblAPI = new LabelsAPI(new InfluxDB({url: __config.influx_url, token: user.token, timeout: 20000}));
let lblCreateReq = {body: {name: labelName, orgID: user.orgid,
properties: { description: labelDescr, color: labelColor }}};
await lblAPI.postLabels(lblCreateReq).catch(async error => {
console.log('--- Error Creating label ---');
console.error(error);
throw error;
});
};
const setupUserRest = async(user) => {
const setupAPI = new SetupAPI(new InfluxDB(__config.influx_url));
setupAPI.getSetup().then(async ({allowed}) => {
let body = {org: user.org, bucket: user.bucket, username: user.username, password: user.password };
if(user.token){
body.token = user.token;
}
if(allowed){
await setupAPI.postSetup({
body: body,
});
console.log(`--- Setup user ${user.username} at ${__config.influx_url} success ---`)
}else{
console.error(`--- Failed to setup user ${user.username} at ${__config.influx_url} ---`);
const getDashboards = async(userName) => {
let user = getUser(userName);
const dbdsAPI = new DashboardsAPI(new InfluxDB({url: __config.influx_url, token: user.token, timeout: 20000}));
return await dbdsAPI.getDashboards();
};
const getDocTemplates = async(userName) => {
let user = getUser(userName);
let docsAPI = new DocumentsAPI(new InfluxDB({url: __config.influx_url, token: user.token, timeout: 20000, }));
return await docsAPI.getDocumentsTemplates({orgID: user.orgid});
};
const createTemplateFromFile = async(userName, filepath) => {
let user = getUser(userName);
let docsAPI = new DocumentsAPI(new InfluxDB({url: __config.influx_url, token: user.token, timeout: 20000}));
let content = await readFileToBuffer(process.cwd() + '/' + filepath);
let newTemplate = JSON.parse(content);
newTemplate.orgID = user.orgid;
docsAPI.postDocumentsTemplates({ body: newTemplate});
};
const getAuthorizations = async(userName) => {
let user = getUser(userName);
let authsAPI = new AuthorizationsAPI(new InfluxDB({url: __config.influx_url, token: user.token, timeout: 20000}));
return await authsAPI.getAuthorizations();
};
const createAlertCheckFromFile = async(userName, filepath) => {
let user = getUser(userName);
let content = await readFileToBuffer(process.cwd() + '/' + filepath);
let newCheck = JSON.parse(content);
newCheck.orgID = user.orgid;
let chkAPI = new ChecksAPI(new InfluxDB({url: __config.influx_url, token: user.token, timeout: 20000}));
chkAPI.createCheck({body: newCheck});
};
const setUserOrgId = async(user) => {
//now grab the first org
let orgsAPI = new OrgsAPI(new InfluxDB({url: __config.influx_url, token: user.token, timeout: 20000}));
let orgs = await orgsAPI.getOrgs();
user.orgid = orgs.orgs[0].id;
};