Browse Source

watcher

master
zeus 4 years ago
parent
commit
4f9ed8b3f1
  1. 49
      swarmlab-app/src/run/app.js

49
swarmlab-app/src/run/app.js

@ -1,4 +1,4 @@
var path = require('path'); var pathmodule = require('path');
var app = require('express')(); var app = require('express')();
var http = require('http').Server(app); var http = require('http').Server(app);
var https = require('https'); var https = require('https');
@ -117,7 +117,7 @@ return new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), da
// get pipelines // get pipelines
// *************************************************** // ***************************************************
async function getpipelines(token) { async function getpipelines(token,pipelinename) {
const agent = new https.Agent({ const agent = new https.Agent({
rejectUnauthorized: false, rejectUnauthorized: false,
}); });
@ -133,21 +133,41 @@ async function getpipelines(token) {
'Authorization': 'Bearer '+token 'Authorization': 'Bearer '+token
} }
}) })
/*
var params = {
playbook: value
}
var options = {
params: params,
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` },
};
const playbook = await api.GET('playbookCode',options);
return playbook
*/
try { try {
var pipelines = { var pipelines = {
"source":'ssologin' "querytokenFilter":'uWr4FKRqrmpCRkJ9WLuI0DNuDWOGTkfcSzyZkJirZvJwwFDffLWrraqzzSPLeuQqL3TF9',
"filter":pipelinename
} }
//var params = {
// pipeline: pipelines
// }
var params = { var params = {
pipeline: pipelines querytokenFilter:'uWr4FKRqrmpCRkJ9WLuI0DNuDWOGTkfcSzyZkJirZvJwwFDffLWrraqzzSPLeuQqL3TF9',
filter:pipelinename
} }
var options = { var options = {
params: params,
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` }, headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` },
}; };
//https://api.swarmlab.io/gettutorlabrooms?sort=pipelinename%7Casc&page=1&per_page=5&filter=&type=scripts&tutor=yes //https://api.swarmlab.io/gettutorlabrooms?sort=pipelinename%7Casc&page=1&per_page=5&filter=&type=scripts&tutor=yes
instance.defaults.timeout = 30000; instance.defaults.timeout = 30000;
const res = await instance.get('/gettutorlabrooms',params,options); //const res = await instance.get('/getplaygrounds',params,options);
const res = await instance.get('/getplaygrounds',options);
if(res.status == 200){ if(res.status == 200){
return res.data return res.data
}else{ }else{
@ -175,6 +195,25 @@ global.online='ob';
watcher watcher
.on('add', function(path) { .on('add', function(path) {
console.log('File', path, 'has been added'); console.log('File', path, 'has been added');
var pathfile = pathmodule.basename(path);
console.log('Filepath ', pathfile, ' check');
// /var/lab/playground-serverlogs/ondemand_playgroundnodejs_masterJPMqt1Jr-RgpMZFwJ-log
var token = "d2539e5a7ae1f9f1b0eb2b8f22ca467a86d28407" // desto
(async() => {
var resdata = await getpipelines(token,path)
console.log('info', JSON.stringify(resdata));
/*
if(isvalid.action == 'ok'){
console.log("Authserver ok ", s.id + ' - ' + token);
global.SOCKET.user = isvalid.user
global.SOCKET.scope = isvalid.scope // space delimeter
global.SOCKET.token = isvalid.token
s.auth = true;
}else{
console.log("Authserver no ", s.id + ' - ' + token);
}
*/
})()
}) })
.on('addDir', function(path) { .on('addDir', function(path) {
console.log('Directory', path, 'has been added'); console.log('Directory', path, 'has been added');

Loading…
Cancel
Save