Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dazn/chaos-squirrel-runner

Package Overview
Dependencies
Maintainers
5
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dazn/chaos-squirrel-runner - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [0.7.0](https://github.com/getndazn/chaos-squirrel/compare/v0.6.0...v0.7.0) (2020-08-24)
### Features
* **runner:** allow defining a logger ([3188119](https://github.com/getndazn/chaos-squirrel/commit/3188119dad41fb0804b1bf6e5d201a40c044f51b))
# [0.6.0](https://github.com/getndazn/chaos-squirrel/compare/v0.5.0...v0.6.0) (2020-08-14)

@@ -8,0 +19,0 @@

6

dist/index.d.ts

@@ -10,5 +10,7 @@ declare type VoidOrPromise = void | Promise<void>;

}
declare type LogFn = (level: 'debug' | 'info', message: string, details: Record<string, unknown>) => void;
interface RunnerConfig {
probability?: number;
possibleAttacks: PossibleAttack[];
logger?: LogFn;
}

@@ -20,3 +22,5 @@ declare class Runner {

attack?: Attack;
constructor({ probability, possibleAttacks }: RunnerConfig);
logger: LogFn;
private attackStarted?;
constructor({ probability, possibleAttacks, logger, }: RunnerConfig);
start(): VoidOrPromise;

@@ -23,0 +27,0 @@ stop(): VoidOrPromise;

19

dist/index.js
"use strict";
class Runner {
constructor({ probability = 1, possibleAttacks }) {
constructor({ probability = 1, possibleAttacks, logger = (level, ...args) => console[level](...args), }) {
this.probability = probability;
this.possibleAttacks = possibleAttacks;
this.logger = logger;
}

@@ -13,4 +14,3 @@ static configure(opts) {

if (globalRandom > this.probability) {
// TODO: logging https://github.com/getndazn/chaos-squirrel/issues/8
// `Not running any attacks, ${globalRandom} is not less than ${probability}`,
this.logger('debug', `Not running any attacks, ${globalRandom} is greater than ${this.probability}`, { globalRandom, probability: this.probability });
return;

@@ -20,3 +20,7 @@ }

if (!this.attack)
return;
return; // logging handled in findAttack fn
this.logger('info', `Starting attack: ${this.attack.constructor.name}`, {
attackName: this.attack.constructor.name,
});
this.attackStarted = Date.now();
return this.attack.start();

@@ -27,2 +31,8 @@ }

return;
this.logger('info', `Stopping attack: ${this.attack.constructor.name}`, {
attackName: this.attack.constructor.name,
// attackStarted will be set immediately after this.attack is set, so this is safe
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
runTime: Date.now() - this.attackStarted,
});
return this.attack.stop();

@@ -46,4 +56,5 @@ }

}
this.logger('debug', 'Not running any attacks, no attack matched in findAttack', { weightedRandom, sumWeights });
}
}
module.exports = Runner;
{
"name": "@dazn/chaos-squirrel-runner",
"version": "0.6.0",
"version": "0.7.0",
"description": "Chaos Squirrel - Runner",

@@ -30,5 +30,5 @@ "main": "dist/index.js",

"devDependencies": {
"@dazn/chaos-squirrel-attack-cpu": "^0.6.0"
"@dazn/chaos-squirrel-attack-cpu": "^0.7.0"
},
"gitHead": "2b2336e4b5433a9bb6cc443553fc20cfb4da7e1e"
"gitHead": "2a914f49fc2c1fd455223f21432ec5ee6190ba47"
}

@@ -20,12 +20,19 @@ # @dazn/chaos-squirrel-runner

// weight: 1, // default value
createAttack: () => ({
start: () => {
/* do a custom attack!*/
},
stop: () => {
/* stop the attack */
},
}),
createAttack: () => {
// Use a class for Attacks, as the Runner will take the class name as the attack name
class CustomAttack {
start() {
// do a custom attack!
}
stop() {
// stop the attack
}
}
return new CustomAttack();
},
},
],
// OPTIONAL: define a custom logger, defaults to console methods
logger: (level, message, details) => console[level](message, details),
});

@@ -46,6 +53,7 @@

| Parameter | Type | Default | Description |
| ----------------- | -------- | ------- | ------------------------------------------------------------------------------------ |
| `probability` | `Number` | `1` | A "global" probability range between 0-1. Defaults to `1` which is 100% probability. |
| `possibleAttacks` | `Array` | - | An array of objects of [possible attacks](#possible-attack) that could be initiated |
| Parameter | Type | Default | Description |
| ----------------- | ---------- | --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| `probability` | `Number` | `1` | A "global" probability range between 0-1. Defaults to `1` which is 100% probability. |
| `possibleAttacks` | `Array` | - | An array of objects of [possible attacks](#possible-attack) that could be initiated |
| `logger` | `Function` | `(level, ...args) => console[level](...args)` | A logger function which is called for significant actions/decisions, such as starting an attack. Set to a no-op (`() => {}`) to disable logging |

@@ -57,3 +65,3 @@ ## Possible Attack

| `weight` | `Number` | `1` | Sets the weighting of an attack vs the other attacks. Default = 1, set to 0 to disable this attack. |
| `createAttack` | `Function` | - | Function which returns an attack object exposing a start and stop method. |
| `createAttack` | `Function` | - | Function which returns an attack class exposing a start and stop method. |

@@ -60,0 +68,0 @@ ## Probabilities

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc