diff --git a/CHANGELOG.md b/CHANGELOG.md index 00d981c..0b9ecae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,15 @@ -## 2.9.0 (February 2024 release) +## 3.0.0 (August 2024 Release) + +- New Commands: + - `custom-bot-category-item-sequence` Display contents of custom bot category item sequence. + - `modify-custom-bot-category-item-sequence` Update existing custom bot category item sequence. + - `content-protection-javascript-injection-rule-list` Display contents of content protection javascript injection rules. + - `content-protection-javascript-injection-rule` Display contents of content protection javascript injection rule. + - `create-content-protection-javascript-injection-rule` Create a content protection javascript injection rule. + - `modify-content-protection-javascript-injection-rule` Update a content protection JavaScript injection rule. + - `delete-content-protection-javascript-injection-rule` Delete a content protection JavaScript injection rule. + +## 2.9.0 (February 2024 Release) - CLI Enhancements - "--debug" flag support to log output in the debug mode @@ -8,7 +19,7 @@ - `content-protection-rule` command displays contents of content protection rule. - `content-protection-detections` command displays content protection detections. - `content-protection-rule-detection-settings` command displays overridden detection settings of content protection rule. - - `content-protection-rule-list` command lists all content protection rules. + - `content-protection-rule-list` command lists all content protection rules. - `content-protection-rule-sequence` command displays contents of content bot category sequence. - `create-content-protection-rule` command creates a content protection rule. - `delete-content-protection-rule` command deletes a content protection rule. @@ -26,7 +37,7 @@ - Templates: - Adding `clientListMatch` sample object in crbTemplate.json -## 2.8.0 (June release) +## 2.8.0 (June 2023 release) - New Commands: - `api-pii-learning` command displays API PII settings. @@ -45,7 +56,7 @@ - `challenge-interception-rules` command displays contents of challenge interception rules. - `modify-challenge-interception-rules` command updates existing challenge interception rules. -## 2.7.0 (September Release) +## 2.7.0 (September 2022 Release) - New Commands: @@ -61,7 +72,6 @@ - `disable-malware-policy` command removes actions to an existing malware policy in a firewall policy. - `enable-malware-policy` command assigns actions to an existing malware policy in a firewall policy. - `malware-content-types` command lists all malware content types. - - Moving BOTMAN CLI commands - - `akamai-bot-category` command displays contents of akamai bot category. - `akamai-bot-category-action` command displays contents of akamai bot category action. @@ -154,19 +164,19 @@ - Supporting "--accountkey" flag to switch the account when performing the operation - Fixing security vulnerabilities -## 2.6.0 (February Release) +## 2.6.0 (February 2022 Release) - New Command: - `activation-history` command lists activation history for the configuration -## 2.5.0 (January Release) +## 2.5.0 (January 2022 Release) - New Command: - `evasive-path-match` command displays the evasive path match settings - `enable-evasive-path-match` command enables evasive path match settings - `disable-evasive-path-match` command disable evasive path match settings -## 2.4.0 (August Release) +## 2.4.0 (August 2021 Release) - New Command: - `recommendations` command displays recommendations in a policy @@ -175,14 +185,14 @@ - `reset-recommendation` command resets a recommendation - Renaming `start-eval` command parameter - `mode` to `eval-mode` -## 2.3.0 (July Release) +## 2.3.0 (July 2021 Release) - WAP Plus support for selected-hostnames, modify-hostnames, and network-lists - Added "mode" parameter to support ASE (Auto and Manual) for the "start-eval" command - Added "threat-intel", "enable-threat-intel", and "disable-threat-intel" commands - Support for including hostnames ("--include-hostnames") and contract-group ("--include-contract-group") in the "configs" command -## 2.2.0 (May Release) +## 2.2.0 (May 2021 Release) - CLI Enhancements - adding "--query", "--fields", "--raw", and "--sort" flags. - --query: @@ -199,15 +209,13 @@ - Usage: `akamai appsec configs --fields id,name,targetProduct --sort id,desc` - Adding option to specify "rule-update" flag while cloning a config version - New Command: - - `modify-hostnames`: Modify hostnames for the configuration version - - Bugfixes: - When all hostnames are selected for the website match-target, command will return "ALL_HOSTNAMES" (instead of "undefined") - `modify-bypass-network-lists` command will return all the network lists instead of JSON (when --json option is not provided) - `create-security-policy` command will return policyId instead of JSON (when --json option is not provided) -## 2.1.0 +## 2.1.0 (April 2021 Release) - Commands: - Pragma header (list and modify) diff --git a/README.md b/README.md index eac5252..e74f399 100755 --- a/README.md +++ b/README.md @@ -69,6 +69,8 @@ Commands: conditional-action-list List all conditional action. configs List all available configurations. content-protection-detections Display content protection detections. + content-protection-javascript-injection-rule-list Display contents of content protection javascript injection rules. + content-protection-javascript-injection-rule Display contents of content protection javascript injection rule. content-protection-rule Display contents of content protection rule. content-protection-rule-detection-settings Display overridden detection settings of content protection rule. content-protection-rule-list List all content protection rules. @@ -79,6 +81,7 @@ Commands: create-conditional-action Create a conditional action. create-config Create a new security config. create-content-protection-rule Create a content protection rule. + create-content-protection-javascript-injection-rule Create a content protection javascript injection rule. create-custom-bot-category Create a custom bot category. create-custom-client Create a custom client. create-custom-defined-bot Create a custom defined bot. @@ -100,6 +103,7 @@ Commands: custom-bot-category-action-list List all custom bot category action. custom-bot-category-list List all custom bot category. custom-bot-category-sequence Display contents of custom bot category sequence. + custom-bot-category-item-sequence Display contents of custom bot category item sequence. custom-client Display contents of custom client. custom-client-list List all custom client. custom-client-sequence Display contents of custom client sequence. @@ -116,6 +120,7 @@ Commands: delete-conditional-action Delete a conditional action. delete-config Delete a security config. delete-content-protection-rule Delete a content protection rule. + delete-content-protection-javascript-injection-rule Delete a content protection JavaScript injection rule. delete-custom-bot-category Delete a custom bot category. delete-custom-client Delete a custom client. delete-custom-defined-bot Delete a custom defined bot. @@ -196,11 +201,13 @@ Commands: modify-client-side-security Update existing client side security. modify-conditional-action Update existing conditional action. modify-content-protection-rule Update content protection rule. + modify-content-protection-javascript-injection-rule Update a content protection JavaScript injection rule. modify-content-protection-rule-detection-settings Update detection settings of content protection rule. modify-content-protection-rule-sequence Update existing content protection rule sequence. modify-custom-bot-category Update existing custom bot category. modify-custom-bot-category-action Update existing custom bot category action. modify-custom-bot-category-sequence Update existing custom bot category sequence. + modify-custom-bot-category-item-sequence Update existing custom bot category item sequence. modify-custom-client Update existing custom client. modify-custom-client-sequence Update existing custom client sequence. modify-custom-defined-bot Update existing custom defined bot. diff --git a/bin/commands/contentprotectionjavascriptinjectionrule.create.js b/bin/commands/contentprotectionjavascriptinjectionrule.create.js new file mode 100644 index 0000000..d82d8d0 --- /dev/null +++ b/bin/commands/contentprotectionjavascriptinjectionrule.create.js @@ -0,0 +1,57 @@ +let ContentProtectionJavaScriptInjectionRule = require('../../src/contentprotectionjavascriptinjectionrule') + .contentProtectionJavaScriptInjectionRule; +let out = require('./lib/out'); + +class CreateContentProtectionJavaScriptInjectionRuleCommand { + constructor() { + this.flags = 'create-content-protection-javascript-injection-rule'; + this.desc = 'Create a content protection javascript injection rule.'; + this.setup = this.setup.bind(this); + this.run = this.run.bind(this); + } + + setup(sywac) { + sywac + .positional('<@path>', { + paramsDesc: 'The input file path.' + }) + .number('--config ', { + desc: 'Configuration ID. Mandatory if you have more than one configuration.', + group: 'Optional:', + required: false + }) + .string('--version ', { + desc: + "Version Number. It can also take the values 'PROD' or 'PRODUCTION' or 'STAGING'. If not provided, latest version is assumed.", + group: 'Optional:', + required: false + }) + .string('--policy ', { + desc: + 'Policy ID. If not provided, we try to use the policy available on file. If you have more than one policy, this option must be provided.', + group: 'Optional:', + required: false + }) + .check((argv, context) => { + if (!argv['@path'].startsWith('@')) { + return context.cliMessage("ERROR: Invalid file name, should start with '@'"); + } + }); + } + + run(options) { + options.file = options['@path'].replace('@', ''); + + out.print({ + promise: new ContentProtectionJavaScriptInjectionRule( + options + ).addContentProtectionJavaScriptInjectionRule(), + args: options, + success: (args, data) => { + return JSON.stringify(data); + } + }); + } +} + +module.exports = new CreateContentProtectionJavaScriptInjectionRuleCommand(); diff --git a/bin/commands/contentprotectionjavascriptinjectionrule.delete.js b/bin/commands/contentprotectionjavascriptinjectionrule.delete.js new file mode 100644 index 0000000..7092a59 --- /dev/null +++ b/bin/commands/contentprotectionjavascriptinjectionrule.delete.js @@ -0,0 +1,52 @@ +let ContentProtectionJavaScriptInjectionRule = require('../../src/contentprotectionjavascriptinjectionrule') + .contentProtectionJavaScriptInjectionRule; +let out = require('./lib/out'); + +class DeleteContentProtectionJavaScriptInjectionRuleCommand { + constructor() { + this.flags = 'delete-content-protection-javascript-injection-rule'; + this.desc = 'Delete a content protection JavaScript injection rule.'; + this.setup = this.setup.bind(this); + this.run = this.run.bind(this); + } + + setup(sywac) { + sywac + .positional('', { + paramsDesc: 'Content protection JavaScript injection rule ID' + }) + .number('--config ', { + desc: 'Configuration ID. Mandatory if you have more than one configuration.', + group: 'Optional:', + required: false + }) + .string('--version ', { + desc: + "Version Number. It can also take the values 'PROD' or 'PRODUCTION' or 'STAGING'. If not provided, latest version is assumed.", + group: 'Optional:', + required: false + }) + .string('--policy ', { + desc: + 'Policy ID. If not provided, we try to use the policy available on file. If you have more than one policy, this option must be provided.', + group: 'Optional:', + required: false + }); + } + + run(options) { + options.rule_id = options['content-protection-javascript-injection-rule-id']; + + out.print({ + promise: new ContentProtectionJavaScriptInjectionRule( + options + ).deleteContentProtectionJavaScriptInjectionRule(), + args: options, + success: (args, data) => { + return data; + } + }); + } +} + +module.exports = new DeleteContentProtectionJavaScriptInjectionRuleCommand(); diff --git a/bin/commands/contentprotectionjavascriptinjectionrule.js b/bin/commands/contentprotectionjavascriptinjectionrule.js new file mode 100644 index 0000000..0275daa --- /dev/null +++ b/bin/commands/contentprotectionjavascriptinjectionrule.js @@ -0,0 +1,52 @@ +let ContentProtectionJavaScriptInjectionRule = require('../../src/contentprotectionjavascriptinjectionrule') + .contentProtectionJavaScriptInjectionRule; +let out = require('./lib/out'); + +class ContentProtectionJavaScriptInjectionRuleCommand { + constructor() { + this.flags = 'content-protection-javascript-injection-rule'; + this.desc = 'Display contents of content protection javascript injection rule.'; + this.setup = this.setup.bind(this); + this.run = this.run.bind(this); + } + + setup(sywac) { + sywac + .positional('', { + paramsDesc: 'Content protection JavaScript injection rule ID' + }) + .number('--config ', { + desc: 'Configuration ID. Mandatory if you have more than one configuration.', + group: 'Optional:', + required: false + }) + .string('--version ', { + desc: + "Version Number. It can also take the values 'PROD' or 'PRODUCTION' or 'STAGING'. If not provided, latest version is assumed.", + group: 'Optional:', + required: false + }) + .string('--policy ', { + desc: + 'Policy ID. If not provided, we try to use the policy available on file. If you have more than one policy, this option must be provided.', + group: 'Optional:', + required: false + }); + } + + run(options) { + options.rule_id = options['content-protection-javascript-injection-rule-id']; + + out.print({ + promise: new ContentProtectionJavaScriptInjectionRule( + options + ).getContentProtectionJavaScriptInjectionRule(), + args: options, + success: (args, data) => { + return JSON.stringify(data); + } + }); + } +} + +module.exports = new ContentProtectionJavaScriptInjectionRuleCommand(); diff --git a/bin/commands/contentprotectionjavascriptinjectionrule.modify.js b/bin/commands/contentprotectionjavascriptinjectionrule.modify.js new file mode 100644 index 0000000..ee64d9d --- /dev/null +++ b/bin/commands/contentprotectionjavascriptinjectionrule.modify.js @@ -0,0 +1,61 @@ +let ContentProtectionJavaScriptInjectionRule = require('../../src/contentprotectionjavascriptinjectionrule') + .contentProtectionJavaScriptInjectionRule; +let out = require('./lib/out'); + +class ModifyContentProtectionJavaScriptInjectionRulesCommand { + constructor() { + this.flags = 'modify-content-protection-javascript-injection-rule'; + this.desc = 'Update content protection JavaScript injection rule.'; + this.setup = this.setup.bind(this); + this.run = this.run.bind(this); + } + + setup(sywac) { + sywac + .positional('', { + paramsDesc: 'Content protection JavaScript injection rule ID' + }) + .positional('<@path>', { + paramsDesc: 'The input file path.' + }) + .number('--config ', { + desc: 'Configuration ID. Mandatory if you have more than one configuration.', + group: 'Optional:', + required: false + }) + .string('--version ', { + desc: + "Version Number. It can also take the values 'PROD' or 'PRODUCTION' or 'STAGING'. If not provided, latest version is assumed.", + group: 'Optional:', + required: false + }) + .string('--policy ', { + desc: + 'Policy ID. If not provided, we try to use the policy available on file. If you have more than one policy, this option must be provided.', + group: 'Optional:', + required: false + }) + .check((argv, context) => { + if (!argv['@path'].startsWith('@')) { + return context.cliMessage("ERROR: Invalid file name, should start with '@'"); + } + }); + } + + run(options) { + options.rule_id = options['content-protection-javascript-injection-rule-id']; + options.file = options['@path'].replace('@', ''); + + out.print({ + promise: new ContentProtectionJavaScriptInjectionRule( + options + ).updateContentProtectionJavaScriptInjectionRule(), + args: options, + success: (args, data) => { + return JSON.stringify(data); + } + }); + } +} + +module.exports = new ModifyContentProtectionJavaScriptInjectionRulesCommand(); diff --git a/bin/commands/contentprotectionjavascriptinjectionrulelist.js b/bin/commands/contentprotectionjavascriptinjectionrulelist.js new file mode 100644 index 0000000..3138c45 --- /dev/null +++ b/bin/commands/contentprotectionjavascriptinjectionrulelist.js @@ -0,0 +1,47 @@ +let ContentProtectionJavaScriptInjectionRule = require('../../src/contentprotectionjavascriptinjectionrule') + .contentProtectionJavaScriptInjectionRule; +let out = require('./lib/out'); + +class ContentProtectionJavaScriptInjectionRuleListCommand { + constructor() { + this.flags = 'content-protection-javascript-injection-rule-list'; + this.desc = 'Display contents of content protection javascript injection rules.'; + this.setup = this.setup.bind(this); + this.run = this.run.bind(this); + } + + setup(sywac) { + sywac + .number('--config ', { + desc: 'Configuration ID. Mandatory if you have more than one configuration.', + group: 'Optional:', + required: false + }) + .string('--version ', { + desc: + "Version Number. It can also take the values 'PROD' or 'PRODUCTION' or 'STAGING'. If not provided, latest version is assumed.", + group: 'Optional:', + required: false + }) + .string('--policy ', { + desc: + 'Policy ID. If not provided, we try to use the policy available on file. If you have more than one policy, this option must be provided.', + group: 'Optional:', + required: false + }); + } + + run(options) { + out.print({ + promise: new ContentProtectionJavaScriptInjectionRule( + options + ).getContentProtectionJavaScriptInjectionRules(), + args: options, + success: (args, data) => { + return JSON.stringify(data); + } + }); + } +} + +module.exports = new ContentProtectionJavaScriptInjectionRuleListCommand(); diff --git a/bin/commands/contentprotectionrulesequence.js b/bin/commands/contentprotectionrulesequence.js index 1e6d277..3ccbc2f 100644 --- a/bin/commands/contentprotectionrulesequence.js +++ b/bin/commands/contentprotectionrulesequence.js @@ -5,7 +5,7 @@ let out = require('./lib/out'); class ContentProtectionRuleSequenceCommand { constructor() { this.flags = 'content-protection-rule-sequence'; - this.desc = 'Display contents of content bot category sequence.'; + this.desc = 'Display contents of content protection rule sequence.'; this.setup = this.setup.bind(this); this.run = this.run.bind(this); } diff --git a/bin/commands/custombotcategoryitemsequence.js b/bin/commands/custombotcategoryitemsequence.js new file mode 100644 index 0000000..8704200 --- /dev/null +++ b/bin/commands/custombotcategoryitemsequence.js @@ -0,0 +1,42 @@ +let CustomBotCategoryItemSequence = require('../../src/custombotcategoryitemsequence') + .custombotcategoryitemsequence; +let out = require('./lib/out'); +class CustomBotCategoryItemSequenceCommand { + constructor() { + this.flags = 'custom-bot-category-item-sequence'; + this.desc = 'Display contents of custom bot category item sequence.'; + this.setup = this.setup.bind(this); + this.run = this.run.bind(this); + } + + setup(sywac) { + sywac + .positional('', { + paramsDesc: 'Custom Bot Category ID' + }) + .number('--config ', { + desc: 'Configuration ID. Mandatory if you have more than one configuration.', + group: 'Optional:', + required: false + }) + .string('--version ', { + desc: + "Version Number. It can also take the values 'PROD' or 'PRODUCTION' or 'STAGING'. If not provided, latest version is assumed.", + group: 'Optional:', + required: false + }); + } + + run(options) { + out.print({ + promise: new CustomBotCategoryItemSequence(options).getCustomBotCategoryItemSequence(), + args: options, + success: (args, data) => { + delete data.validation; + return JSON.stringify(data); + } + }); + } +} + +module.exports = new CustomBotCategoryItemSequenceCommand(); diff --git a/bin/commands/custombotcategoryitemsequence.modify.js b/bin/commands/custombotcategoryitemsequence.modify.js new file mode 100644 index 0000000..5707573 --- /dev/null +++ b/bin/commands/custombotcategoryitemsequence.modify.js @@ -0,0 +1,52 @@ +let CustomBotCategoryItemSequence = require('../../src/custombotcategoryitemsequence') + .custombotcategoryitemsequence; +let out = require('./lib/out'); + +class ModifyCustomBotCategoryItemSequenceCommand { + constructor() { + this.flags = 'modify-custom-bot-category-item-sequence'; + this.desc = 'Update existing custom bot category item sequence.'; + this.setup = this.setup.bind(this); + this.run = this.run.bind(this); + } + + setup(sywac) { + sywac + .positional('', { + paramsDesc: 'Custom Bot Category ID' + }) + .positional('<@path>', { + paramsDesc: 'The input file path.' + }) + .number('--config ', { + desc: 'Configuration ID. Mandatory if you have more than one configuration.', + group: 'Optional:', + required: false + }) + .string('--version ', { + desc: + "Version Number. It can also take the values 'PROD' or 'PRODUCTION' or 'STAGING'. If not provided, latest version is assumed.", + group: 'Optional:', + required: false + }) + .check((argv, context) => { + if (!argv['@path'].startsWith('@')) { + return context.cliMessage("ERROR: Invalid file name, should start with '@'"); + } + }); + } + + run(options) { + options.file = options['@path'].replace('@', ''); + + out.print({ + promise: new CustomBotCategoryItemSequence(options).updateCustomBotCategoryItemSequence(), + args: options, + success: (args, data) => { + return JSON.stringify(data); + } + }); + } +} + +module.exports = new ModifyCustomBotCategoryItemSequenceCommand(); diff --git a/cli.json b/cli.json index 9bf17d6..5ecc3ba 100644 --- a/cli.json +++ b/cli.json @@ -5,7 +5,7 @@ "commands": [ { "name": "appsec", - "version": "2.9.0", + "version": "3.0.0", "description": "Akamai Security tools for protecting websites." } ] diff --git a/package-lock.json b/package-lock.json index 41ebadd..dc1bc1e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "akamaicliappsec", - "version": "2.9.0", + "version": "3.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "akamaicliappsec", - "version": "2.9.0", + "version": "3.0.0", "license": "Apache-2.0", "dependencies": { "akamai-edgegrid": "^3.2.0", diff --git a/package.json b/package.json index adb2b86..2efa332 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "akamaicliappsec", - "version": "2.9.0", + "version": "3.0.0", "description": "A wrapping development kit to interface common tasks with akamai's Security {OPEN} API.", "repository": "https://github.com/akamai/cli-appsec", "license": "Apache-2.0", diff --git a/src/constants.js b/src/constants.js index 6685ac6..85fe5f4 100644 --- a/src/constants.js +++ b/src/constants.js @@ -136,6 +136,8 @@ const resources = { CUSTOM_BOT_CATEGORYS: '/appsec/v1/configs/%s/versions/%s/custom-bot-categories', CUSTOM_BOT_CATEGORY: '/appsec/v1/configs/%s/versions/%s/custom-bot-categories/%s', CUSTOM_BOT_CATEGORY_SEQUENCE: '/appsec/v1/configs/%s/versions/%s/custom-bot-category-sequence', + CUSTOM_BOT_CATEGORY_ITEM_SEQUENCE: + '/appsec/v1/configs/%s/versions/%s/custom-bot-categories/%s/custom-bot-category-item-sequence', CUSTOM_DEFINED_BOTS: '/appsec/v1/configs/%s/versions/%s/custom-defined-bots', CUSTOM_DEFINED_BOT: '/appsec/v1/configs/%s/versions/%s/custom-defined-bots/%s', RECATEGORIZED_AKAMAI_DEFINED_BOTS: @@ -203,6 +205,10 @@ const resources = { '/appsec/v1/configs/%s/versions/%s/security-policies/%s/content-protection-rules/%s/detection-settings', CONTENT_PROTECTION_RULE_SEQUENCE: '/appsec/v1/configs/%s/versions/%s/security-policies/%s/content-protection-rule-sequence', + CONTENT_PROTECTION_JS_INJECTION_RULES: + '/appsec/v1/configs/%s/versions/%s/security-policies/%s/content-protection-javascript-injection-rules', + CONTENT_PROTECTION_JS_INJECTION_RULE: + '/appsec/v1/configs/%s/versions/%s/security-policies/%s/content-protection-javascript-injection-rules/%s', PENALTY_BOX_CONDITIONS: '/appsec/v1/configs/%s/versions/%s/security-policies/%s/penalty-box/conditions', PENALTY_BOX_CONDITIONS_ALL: diff --git a/src/contentprotectionjavascriptinjectionrule.js b/src/contentprotectionjavascriptinjectionrule.js new file mode 100644 index 0000000..3babbcf --- /dev/null +++ b/src/contentprotectionjavascriptinjectionrule.js @@ -0,0 +1,67 @@ +'use strict'; + +const untildify = require('untildify'); +let fs = require('fs'); +let URIs = require('./constants').URIS; +let Policy = require('./policy').policy; + +class ContentProtectionJavaScriptInjectionRule { + constructor(options) { + this._options = options; + this._policy = new Policy(options); + } + + getContentProtectionJavaScriptInjectionRules() { + return this._policy.readResource(URIs.CONTENT_PROTECTION_JS_INJECTION_RULES, []); + } + + addContentProtectionJavaScriptInjectionRule() { + if (fs.existsSync(untildify(this._options['file']))) { + let payload = fs.readFileSync(untildify(this._options['file']), 'utf8'); + let data; + try { + data = JSON.parse(payload); + } catch (err) { + throw 'The input JSON is not valid'; + } + return this._policy.createResource(URIs.CONTENT_PROTECTION_JS_INJECTION_RULES, [], data); + } else { + throw `The file does not exists: ${this._options['file']}`; + } + } + + getContentProtectionJavaScriptInjectionRule() { + return this._policy.readResource(URIs.CONTENT_PROTECTION_JS_INJECTION_RULE, [ + this._options['rule_id'] + ]); + } + + updateContentProtectionJavaScriptInjectionRule() { + if (fs.existsSync(untildify(this._options['file']))) { + let payload = fs.readFileSync(untildify(this._options['file']), 'utf8'); + let data; + try { + data = JSON.parse(payload); + } catch (err) { + throw 'The input JSON is not valid'; + } + return this._policy.updateResource( + URIs.CONTENT_PROTECTION_JS_INJECTION_RULE, + [this._options['rule_id']], + data + ); + } else { + throw `The file does not exists: ${this._options['file']}`; + } + } + + deleteContentProtectionJavaScriptInjectionRule() { + return this._policy.deleteResource(URIs.CONTENT_PROTECTION_JS_INJECTION_RULE, [ + this._options['rule_id'] + ]); + } +} + +module.exports = { + contentProtectionJavaScriptInjectionRule: ContentProtectionJavaScriptInjectionRule +}; diff --git a/src/custombotcategoryitemsequence.js b/src/custombotcategoryitemsequence.js new file mode 100644 index 0000000..4899f43 --- /dev/null +++ b/src/custombotcategoryitemsequence.js @@ -0,0 +1,42 @@ +'use strict'; + +const untildify = require('untildify'); +let fs = require('fs'); +let URIs = require('./constants').URIS; +let Version = require('./versionsprovider').versionProvider; + +class CustomBotCategoryItemSequence { + constructor(options) { + this._options = options; + this._version = new Version(options); + } + + getCustomBotCategoryItemSequence() { + return this._version.readResource(URIs.CUSTOM_BOT_CATEGORY_ITEM_SEQUENCE, [ + this._options['category-id'] + ]); + } + + updateCustomBotCategoryItemSequence() { + if (fs.existsSync(untildify(this._options['file']))) { + let payload = fs.readFileSync(untildify(this._options['file']), 'utf8'); + let data; + try { + data = JSON.parse(payload); + } catch (err) { + throw 'The input JSON is not valid'; + } + return this._version.updateResource( + URIs.CUSTOM_BOT_CATEGORY_ITEM_SEQUENCE, + [this._options['category-id']], + data + ); + } else { + throw `The file does not exists: ${this._options['file']}`; + } + } +} + +module.exports = { + custombotcategoryitemsequence: CustomBotCategoryItemSequence +};