Skip to content

Commit

Permalink
Update to webda-shell 0.10.3 and move WUI to external source
Browse files Browse the repository at this point in the history
  • Loading branch information
loopingz committed Oct 6, 2018
1 parent 0a3f7d4 commit d0adc50
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 49 deletions.
6 changes: 2 additions & 4 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "ivoryshield",
"version": "0.10.0",
"version": "0.10.1",
"description": "Protect your cloud and automate it",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand All @@ -25,10 +25,8 @@
},
"files": [
"lib",
"wui",
"webda.module.json",
"webda.shell.json",
"wui",
"logo.json"
],
"homepage": "https://github.com/loopingz/ivoryshield#readme",
Expand All @@ -38,7 +36,7 @@
"jsonpath": "^1.0.0",
"open": "0.0.5",
"webda": "^0.10.0",
"webda-shell": "^0.10.1",
"webda-shell": "^0.10.3",
"webda-elasticsearch": "~1.0.0",
"yargs": "^11.0.0"
},
Expand Down
62 changes: 31 additions & 31 deletions src/console/shell.ts
Expand Up @@ -24,14 +24,13 @@ import {
import {
Configurer
} from '../configurers/configurer';

const path = require('path');
const fs = require('fs');
const glob = require('glob');
import * as path from 'path';
import * as fs from 'fs';
import * as glob from 'glob';

/*
const AWS = require('aws-sdk');
exports.handler = (event, context, callback) => {
exports.handler = async (event, context) => {
// TODO implement
var result = 'Run task at ' + new Date();
var ecs = new AWS.ECS();
Expand All @@ -55,13 +54,7 @@ exports.handler = (event, context, callback) => {
},
startedBy: 'nuxeo-cronchecker-scheduler'
};
ecs.runTask(params, function(err, data) {
if (err) {
callback(err, err.stack); // an error occurred
} else {
callback(null, result + ' ' + JSON.stringify(data));
}
});
await ecs.runTask(params).promise();
};
*/
export class ConfigurationService extends AWSServiceMixIn(Executor) {
Expand Down Expand Up @@ -163,6 +156,7 @@ export class ConfigurationService extends AWSServiceMixIn(Executor) {
}
// Set the CronChecker
unit.serviceName = this._config.deployment.croncheckServiceName || 'ivoryshield/cron';
unit.noService = true;
unit.workers = ['IvoryShield/CronCheckerService'];
webdaDeployment.units.push(unit);
// Duplicate the unit
Expand Down Expand Up @@ -345,27 +339,20 @@ export class ConfigurationService extends AWSServiceMixIn(Executor) {
});
}

save() {
return new Promise((resolve, reject) => {
this._config.lastUpdate = new Date();
if (this._config.accounts) {
this._config.accounts.map((acc) => {
delete acc.AssumeRoleSuccessful;
delete acc.AssumeRoleError;
});
}
fs.writeFile('./ivoryshield.config.json', JSON.stringify(this._config, null, ' '), (err, res) => {
if (err) {
reject(err);
}
resolve(res);
async save() {
this._config.lastUpdate = new Date();
if (this._config.accounts) {
this._config.accounts.map((acc) => {
delete acc.AssumeRoleSuccessful;
delete acc.AssumeRoleError;
});
});
}
fs.writeFileSync('./ivoryshield.config.json', JSON.stringify(this._config, null, ' '));
}

load() {
if (fs.existsSync(ConfigurationService.CONFIG_FILENAME)) {
this._config = JSON.parse(fs.readFileSync(ConfigurationService.CONFIG_FILENAME));
this._config = JSON.parse(fs.readFileSync(ConfigurationService.CONFIG_FILENAME).toString());
} else {
this._config = {
credentials: {
Expand Down Expand Up @@ -418,16 +405,16 @@ class IvoryShieldConfigurationServer extends WebdaServer {
_webdaModule: any = {};

serveStaticWebsite(express, app) {
app.use(express.static(__dirname + '/../../wui/'));
app.use(express.static(process.env.HOME + '/.webda-wui/ivoryshield/'));
}

serveIndex(express, app) {
app.use(express.static(__dirname + '/../../wui/index.html'));
app.use(express.static(process.env.HOME + '/.webda-wui/ivoryshield/index.html'));
app.get('*', this.handleStaticIndexRequest.bind(this));
}

async serve(port, openBrowser): Promise < Object > {
this._staticIndex = path.resolve(__dirname + '/../../wui/index.html');
this._staticIndex = process.env.HOME + '/.webda-wui/ivoryshield/index.html';
// This is the configuration server
super.serve(port);
if (openBrowser || openBrowser === undefined) {
Expand Down Expand Up @@ -483,11 +470,24 @@ export default class IvoryShieldConsole extends WebdaConsole {
console.log('');
}

static getWUIName() : string {
return 'ivoryshield';
}

static getLastWUIVersionURL() {
return 'https://ivoryshield.io/wuis/wuis.json';
}

static async config(argv): Promise < void > {
this.generateModule();
if (argv.deployment) {
return super.config(argv);
}
try {
await this.getLastWUIVersion();
} catch (err) {
this.log('ERROR', 'Cannot get latest version of Web UI', err);
}
let webda = new IvoryShieldConfigurationServer();
return new Promise < void > (() => {
webda.serve(18181, argv.open);
Expand Down
14 changes: 8 additions & 6 deletions src/services/cloudtrail.ts
Expand Up @@ -17,11 +17,11 @@ import {
import {
CloudTrailSetup
} from '../configurers/cloudtrail';
const fs = require('fs');
const moment = require('moment');
const zlib = require('zlib');
const elasticsearch = require('elasticsearch');
const PromiseUtil = require("bluebird");
import * as fs from 'fs';
import * as moment from 'moment';
import * as zlib from 'zlib';
import * as elasticsearch from 'elasticsearch';
import * as PromiseUtil from 'bluebird';


export default class CloudTrailService extends AWSServiceMixIn(SQSQueue) {
Expand Down Expand Up @@ -75,7 +75,7 @@ export default class CloudTrailService extends AWSServiceMixIn(SQSQueue) {

test(evtFile) {
this.log('INFO', 'Testing event from', evtFile);
return this.processTrailEvent(JSON.parse(fs.readFileSync(evtFile)));
return this.processTrailEvent(JSON.parse(fs.readFileSync(evtFile).toString()));
}

_getAWSForEvent(evt) {
Expand Down Expand Up @@ -107,11 +107,13 @@ export default class CloudTrailService extends AWSServiceMixIn(SQSQueue) {
}

async processTrailLog(bucket, key) {
this.log('DEBUG', 'Processing log', bucket, key);
let s3obj = await this._s3.getObject({
Bucket: bucket,
Key: key
}).promise();
let promises = [];
// @ts-ignore
let cloudEvents = JSON.parse(zlib.gunzipSync(s3obj.Body)).Records;
await PromiseUtil.map(cloudEvents, this.processTrailEvent.bind(this), {
concurrency: 10
Expand Down
11 changes: 4 additions & 7 deletions src/services/cronchecker.ts
@@ -1,8 +1,5 @@
import {
AWSServiceMixIn,
STS,
Webda,
AWS
} from '../services/aws-mixin';
import {
Service
Expand All @@ -16,9 +13,9 @@ import {
import {
Resource
} from '../resources/Resource';
const fs = require('fs');
const elasticsearch = require('elasticsearch');
const moment = require('moment');
import * as fs from 'fs';
import * as elasticsearch from 'elasticsearch';
import * as moment from 'moment';

export default class CronCheckerService extends AWSServiceMixIn(Service) {
_validatorService: ValidatorService;
Expand Down Expand Up @@ -353,7 +350,7 @@ export default class CronCheckerService extends AWSServiceMixIn(Service) {
let files = fs.readdirSync('./logs');
let promises = [];
files.forEach((file) => {
let obj = JSON.parse(fs.readFileSync('./logs/' + file));
let obj = JSON.parse(fs.readFileSync('./logs/' + file).toString());
promises.push(this.saveMetrics(obj));
});
return Promise.all(promises);
Expand Down
4 changes: 3 additions & 1 deletion src/services/validator.ts
Expand Up @@ -4,7 +4,9 @@ import {
import {
Validator
} from '../validators/validator';
const Resource = require('../resources/Resource');
import {
Resource
} from '../resources/Resource';

export default class ValidatorService extends IvoryShieldService {

Expand Down

0 comments on commit d0adc50

Please sign in to comment.