Skip to content

Commit 2ef3189

Browse files
author
Arul Nedumaran
committed
Merge pull request #6 in KSD/cli-appsec from feature/KSD-14282 to develop
* commit 'ce0ff372104899b7003c4df889a7e9a6e6366a6b': correction remove old rules method
2 parents fc9fadb + ce0ff37 commit 2ef3189

File tree

2 files changed

+62
-6
lines changed

2 files changed

+62
-6
lines changed

bin/akamai-appsec

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ require("sywac")
5050
console.log(contents);
5151
}
5252
})
53+
.command("custom-rules", {
54+
desc: "List all custom rules",
55+
setup: sywac => {
56+
sywac.number("--config <id>", {
57+
desc: "Configuration id. Mandatory if you have more than one configuration.",
58+
group: "Options:",
59+
required: false
60+
});
61+
},
62+
run: options => {
63+
//new AppSecConfig().versions(options.config).then(data => {
64+
new AppSecConfig().versions(options.config).then(data => {
65+
console.log(data);
66+
}).catch(err=>{
67+
console.error(err);
68+
process.exit(1);
69+
});
70+
}
71+
})
5372
.command("config-versions", {
5473
desc: "List all versions",
5574
setup: sywac => {
@@ -67,6 +86,8 @@ require("sywac")
6786
process.exit(1);
6887
});
6988
}
89+
})
90+
.command("version", {
7091
}).command("config-version", {
7192
desc: "Read a config version",
7293
setup: sywac => {

src/crb.js

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,55 @@
1+
"use strict";
2+
3+
let Edge = process.env.MOCK_AKA_SEC_API == 'true' ? require("../mock/edgeClient") : require("./edgeClient");
4+
5+
let util = require('util');
6+
let URIs = require("./constants").URIS;
7+
let ConfigProvider = require('./configProvider').configProvider;
8+
let logger = require("./constants").logger("AppSecConfig");
9+
110
require("string-format");
2-
// var URIs = require("../constants").URIS;
311
var fs = require("fs");
4-
// var logger = require('pino')({
5-
// level: process.env.LOG_LEVEL ? process.env.LOG_LEVEL : "error",
6-
// prettyPrint: true,
7-
// name: "AppSecConfig"
8-
// });
912
const CRB_TEMPLATE_PATH=__dirname + '/../templates/crbTemplate.json';
1013
const ENCODING='utf8';
1114

1215
class CRBHandler {
16+
17+
constructor(auth) {
18+
this._edge = new Edge(auth);
19+
this._configProvider = new ConfigProvider(this._edge);
20+
}
21+
_getConfigId(configId) {
22+
if (!configId) {
23+
if (this.configs().length == 1) {
24+
configId = this.configs()[0].id;
25+
} else {
26+
throw "You have more than one configuration. Please provide a configuration id to work with.";
27+
}
28+
}
29+
}
30+
1331
template() {
1432
return new Promise((resolve) => {
1533
resolve(fs.readFileSync(CRB_TEMPLATE_PATH, ENCODING));
1634
});
1735
}
36+
rules(providedConfigId) {
37+
let configId = this._configProvider.getConfigId(providedConfigId);
38+
return new Promise((resolve, reject) => {
39+
let customRulesUrl = util.format(URIs.GET_CRB, configId);
40+
logger.debug("Attempting to get all custom rules at: " + customRulesUrl);
41+
let request = {
42+
method: "GET",
43+
path: customRulesUrl,
44+
followRedirect: false
45+
};
46+
this._edge.get(request).then(response => {
47+
resolve(response);
48+
}).catch(err => {
49+
reject(err);
50+
});
51+
});
52+
}
1853
}
1954
module.exports = {
2055
CRBHandler: CRBHandler

0 commit comments

Comments
 (0)