Skip to content

Instantly share code, notes, and snippets.

@tkh44
Last active February 11, 2021 21:20
Show Gist options
  • Select an option

  • Save tkh44/199295c10327aa46c2412b5130caebe8 to your computer and use it in GitHub Desktop.

Select an option

Save tkh44/199295c10327aa46c2412b5130caebe8 to your computer and use it in GitHub Desktop.

Revisions

  1. tkh44 revised this gist Feb 11, 2021. 1 changed file with 4 additions and 12 deletions.
    16 changes: 4 additions & 12 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -38,19 +38,11 @@ const createAttackMachine = Machine({
    },
    attackTypeSelection: {
    on: {
    SELECTION: {
    target: "targetTypeSelected",
    actions: assign({
    targetType: (_, event) => event.value
    })
    }
    SELECT_HOST: 'hostTarget',
    SELECT_CONTAINER: 'containerTarget',
    SELECT_KUBERNETES: "kubernetesTarget"
    }
    },
    targetTypeSelected: {
    always: [{ target: "host", cond: "isHostTarget" },
    { target: "container", cond: "isContainerTarget" },
    { target: "kubernetes", cond: "isKubernetesTarget" }]
    },
    hostTarget: {
    on: {
    SUBMIT: {
    @@ -106,7 +98,7 @@ const createAttackMachine = Machine({
    review: {
    on: {
    SUBMIT: "saving",
    OPEN_TARGET: "targetTypeSelected",
    OPEN_TARGET: "attackTypeSelection",
    OPEN_IMPACT: "impact",
    OPEN_SCHEDULE: "schedule"
    }
  2. tkh44 revised this gist Feb 11, 2021. 1 changed file with 36 additions and 10 deletions.
    46 changes: 36 additions & 10 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -39,14 +39,30 @@ const createAttackMachine = Machine({
    attackTypeSelection: {
    on: {
    SELECTION: {
    target: "target",
    target: "targetTypeSelected",
    actions: assign({
    targetType: (_, event) => event.value
    })
    }
    }
    },
    target: {
    targetTypeSelected: {
    always: [{ target: "host", cond: "isHostTarget" },
    { target: "container", cond: "isContainerTarget" },
    { target: "kubernetes", cond: "isKubernetesTarget" }]
    },
    hostTarget: {
    on: {
    SUBMIT: {
    target: "impact",
    actions: assign({
    target: (_, event) => event.value
    })
    }
    }

    },
    containerTarget: {
    on: {
    SUBMIT: {
    target: "impact",
    @@ -57,10 +73,20 @@ const createAttackMachine = Machine({
    }

    },
    kubernetesTarget: {
    on: {
    SUBMIT: {
    target: "impact",
    actions: assign({
    target: (_, event) => event.value
    })
    }
    }
    },
    impact: {
    on: {
    SUBMIT: {
    target: 'review',
    target: "review",
    actions: assign({
    impact: (_, event) => event.value
    })
    @@ -70,7 +96,7 @@ const createAttackMachine = Machine({
    schedule: {
    on: {
    SUBMIT: {
    target: 'review',
    target: "review",
    actions: assign({
    schedule: (_, event) => event.value
    })
    @@ -79,19 +105,19 @@ const createAttackMachine = Machine({
    },
    review: {
    on: {
    SUBMIT: 'saving',
    OPEN_TARGET: 'target',
    OPEN_IMPACT: 'impact',
    OPEN_SCHEDULE: 'schedule'
    SUBMIT: "saving",
    OPEN_TARGET: "targetTypeSelected",
    OPEN_IMPACT: "impact",
    OPEN_SCHEDULE: "schedule"
    }
    },
    saving: {
    on: {
    SUCCESS: {
    target: 'attackTypeSelection'
    target: "attackTypeSelection"
    },
    ERROR: {
    target: 'review'
    target: "review"
    }
    }
    }
  3. tkh44 revised this gist Feb 11, 2021. 1 changed file with 17 additions and 16 deletions.
    33 changes: 17 additions & 16 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -39,23 +39,23 @@ const createAttackMachine = Machine({
    attackTypeSelection: {
    on: {
    SELECTION: {
    target: "targeting",
    target: "target",
    actions: assign({
    targetType: (_, event) => event.value
    })
    }
    }
    },
    targeting: {
    on: {
    SUBMIT: {
    target: "impact",
    actions: assign({
    target: (_, event) => event.value
    })
    }
    target: {
    on: {
    SUBMIT: {
    target: "impact",
    actions: assign({
    target: (_, event) => event.value
    })
    }

    }

    },
    impact: {
    on: {
    @@ -79,9 +79,10 @@ const createAttackMachine = Machine({
    },
    review: {
    on: {
    SUBMIT: {
    target: 'saving'
    }
    SUBMIT: 'saving',
    OPEN_TARGET: 'target',
    OPEN_IMPACT: 'impact',
    OPEN_SCHEDULE: 'schedule'
    }
    },
    saving: {
    @@ -107,13 +108,13 @@ const createAttackMachine = Machine({
    isKubernetesTarget: (context) => {
    return context.targetType === "KUBERNETES";
    },
    verifyHostTargeting: (context) => {
    verifyHostTarget: (context) => {
    return context.targetType === "HOST";
    },
    verifyContainerTargeting: (context) => {
    verifyContainerTarget: (context) => {
    return context.targetType === "CONTAINER";
    },
    verifyKubernetesTargeting: (context) => {
    verifyKubernetesTarget: (context) => {
    return context.targetType === "KUBERNETES";
    }
    }
  4. tkh44 revised this gist Feb 11, 2021. 1 changed file with 2 additions and 28 deletions.
    30 changes: 2 additions & 28 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -47,41 +47,15 @@ const createAttackMachine = Machine({
    }
    },
    targeting: {
    always: [
    { target: "host", cond: "isHostTarget" },
    { target: "container", cond: "isContainerTarget" },
    { target: "kubernetes", cond: "isKubernetesTarget" }
    ],
    host: {
    on: {
    on: {
    SUBMIT: {
    target: "impact",
    actions: assign({
    target: (_, event) => event.value
    })
    }
    }
    },
    container: {
    on: {
    SUBMIT: {
    target: "impact",
    actions: assign({
    target: (_, event) => event.value
    })
    }
    }
    },
    kubernetes: {
    on: {
    SUBMIT: {
    target: "impact",
    actions: assign({
    target: (_, event) => event.value
    })
    }
    }
    }

    },
    impact: {
    on: {
  5. tkh44 revised this gist Feb 11, 2021. 1 changed file with 12 additions and 3 deletions.
    15 changes: 12 additions & 3 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -55,21 +55,30 @@ const createAttackMachine = Machine({
    host: {
    on: {
    SUBMIT: {
    target: "impact"
    target: "impact",
    actions: assign({
    target: (_, event) => event.value
    })
    }
    }
    },
    container: {
    on: {
    SUBMIT: {
    target: "impact"
    target: "impact",
    actions: assign({
    target: (_, event) => event.value
    })
    }
    }
    },
    kubernetes: {
    on: {
    SUBMIT: {
    target: "impact"
    target: "impact",
    actions: assign({
    target: (_, event) => event.value
    })
    }
    }
    }
  6. tkh44 revised this gist Feb 11, 2021. 1 changed file with 3 additions and 6 deletions.
    9 changes: 3 additions & 6 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -55,24 +55,21 @@ const createAttackMachine = Machine({
    host: {
    on: {
    SUBMIT: {
    target: "impact",
    cond: "verifyHostTargeting"
    target: "impact"
    }
    }
    },
    container: {
    on: {
    SUBMIT: {
    target: "impact",
    cond: "verifyContainerTargeting"
    target: "impact"
    }
    }
    },
    kubernetes: {
    on: {
    SUBMIT: {
    target: "impact",
    cond: "verifyKubernetesTargeting"
    target: "impact"
    }
    }
    }
  7. tkh44 revised this gist Feb 11, 2021. 1 changed file with 47 additions and 32 deletions.
    79 changes: 47 additions & 32 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -55,49 +55,64 @@ const createAttackMachine = Machine({
    host: {
    on: {
    SUBMIT: {
    target: 'impact',
    cond: 'verifyHostTargeting'
    target: "impact",
    cond: "verifyHostTargeting"
    }
    }
    },
    container: { on: {
    container: {
    on: {
    SUBMIT: {
    target: 'impact',
    cond: 'verifyContainerTargeting'
    target: "impact",
    cond: "verifyContainerTargeting"
    }
    } },
    kubernetes: { on: {
    }
    },
    kubernetes: {
    on: {
    SUBMIT: {
    target: 'impact',
    cond: 'verifyKubernetesTargeting'
    target: "impact",
    cond: "verifyKubernetesTargeting"
    }
    } }
    }
    }
    },
    impact: {
    on: {
    always: '.categorySelection'
    },
    state: {
    categorySelection: {
    on: {
    SELECT_CATEGORY: {
    target: '.attackSelection'
    }
    }
    SUBMIT: {
    target: 'review',
    actions: assign({
    impact: (_, event) => event.value
    })
    }
    }
    },
    schedule: {
    on: {
    SUBMIT: {
    target: 'review',
    actions: assign({
    schedule: (_, event) => event.value
    })
    }
    }
    },
    review: {
    on: {
    SUBMIT: {
    target: 'saving'
    }
    }
    },
    saving: {
    on: {
    SUCCESS: {
    target: 'attackTypeSelection'
    },
    categorySelection: {
    on: {
    SELECT_ATTACK: {
    target: '.attackSelection'
    }
    }
    ERROR: {
    target: 'review'
    }
    },
    host: {
    type: "final"
    },
    container: { type: "final" },
    kubernetes: { type: "final" }
    }
    }
    }
    },
    @@ -122,4 +137,4 @@ const createAttackMachine = Machine({
    return context.targetType === "KUBERNETES";
    }
    }
    });
    });
  8. tkh44 revised this gist Feb 11, 2021. No changes.
  9. tkh44 revised this gist Feb 11, 2021. 1 changed file with 102 additions and 21 deletions.
    123 changes: 102 additions & 21 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,19 @@
    // Available variables:
    // - Machine
    // - interpret
    // - assign
    // - send
    // - sendParent
    // - spawn
    // - raise
    // - actions
    // - XState (all XState exports)

    // Available variables:
    // - Machine
    // - interpret
    // - assign
    // - send
    // - sendParent
    // - spawn
    // - raise
    // - actions
    // - XState (all XState exports)

    const createAttackMachine = Machine({
    id: 'create-attack',
    initial: 'loading',
    const createAttackMachine = Machine({
    id: "create-attack",
    initial: "loading",
    context: {
    targetType: 'hosts',
    targetType: "HOST",
    target: {},
    impact: {},
    schedule: {},
    @@ -24,7 +23,7 @@
    error: {
    on: {
    RETRY: {
    target: 'loading',
    target: "loading",
    actions: assign({
    retries: (context, event) => context.retries + 1
    })
    @@ -33,12 +32,94 @@
    },
    loading: {
    on: {
    ERROR: 'error'
    SUCCESS: "attackTypeSelection",
    ERROR: "error"
    }
    },
    success: {
    type: 'final'
    attackTypeSelection: {
    on: {
    SELECTION: {
    target: "targeting",
    actions: assign({
    targetType: (_, event) => event.value
    })
    }
    }
    },
    targeting: {
    always: [
    { target: "host", cond: "isHostTarget" },
    { target: "container", cond: "isContainerTarget" },
    { target: "kubernetes", cond: "isKubernetesTarget" }
    ],
    host: {
    on: {
    SUBMIT: {
    target: 'impact',
    cond: 'verifyHostTargeting'
    }
    }
    },
    container: { on: {
    SUBMIT: {
    target: 'impact',
    cond: 'verifyContainerTargeting'
    }
    } },
    kubernetes: { on: {
    SUBMIT: {
    target: 'impact',
    cond: 'verifyKubernetesTargeting'
    }
    } }
    },
    impact: {
    on: {
    always: '.categorySelection'
    },
    state: {
    categorySelection: {
    on: {
    SELECT_CATEGORY: {
    target: '.attackSelection'
    }
    }
    },
    categorySelection: {
    on: {
    SELECT_ATTACK: {
    target: '.attackSelection'
    }
    }
    }
    },
    host: {
    type: "final"
    },
    container: { type: "final" },
    kubernetes: { type: "final" }
    }
    }
    },
    {
    guards: {
    isHostTarget: (context) => {
    return context.targetType === "HOST";
    },
    isContainerTarget: (context) => {
    return context.targetType === "CONTAINER";
    },
    isKubernetesTarget: (context) => {
    return context.targetType === "KUBERNETES";
    },
    verifyHostTargeting: (context) => {
    return context.targetType === "HOST";
    },
    verifyContainerTargeting: (context) => {
    return context.targetType === "CONTAINER";
    },
    verifyKubernetesTargeting: (context) => {
    return context.targetType === "KUBERNETES";
    }
    }
    });

    });
  10. tkh44 revised this gist Feb 11, 2021. 1 changed file with 14 additions and 16 deletions.
    30 changes: 14 additions & 16 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -12,34 +12,32 @@

    const createAttackMachine = Machine({
    id: 'create-attack',
    initial: 'idle',
    initial: 'loading',
    context: {
    targetType: 'hosts'
    targetType: 'hosts',
    target: {},
    impact: {},
    schedule: {},
    retries: 0
    },
    states: {
    idle: {
    error: {
    on: {
    FETCH: 'loading'
    RETRY: {
    target: 'loading',
    actions: assign({
    retries: (context, event) => context.retries + 1
    })
    }
    }
    },
    loading: {
    on: {
    RESOLVE: 'success',
    REJECT: 'failure'
    ERROR: 'error'
    }
    },
    success: {
    type: 'final'
    },
    failure: {
    on: {
    RETRY: {
    target: 'loading',
    actions: assign({
    retries: (context, event) => context.retries + 1
    })
    }
    }
    }
    }
    });
  11. tkh44 created this gist Feb 11, 2021.
    46 changes: 46 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@

    // Available variables:
    // - Machine
    // - interpret
    // - assign
    // - send
    // - sendParent
    // - spawn
    // - raise
    // - actions
    // - XState (all XState exports)

    const createAttackMachine = Machine({
    id: 'create-attack',
    initial: 'idle',
    context: {
    targetType: 'hosts'
    },
    states: {
    idle: {
    on: {
    FETCH: 'loading'
    }
    },
    loading: {
    on: {
    RESOLVE: 'success',
    REJECT: 'failure'
    }
    },
    success: {
    type: 'final'
    },
    failure: {
    on: {
    RETRY: {
    target: 'loading',
    actions: assign({
    retries: (context, event) => context.retries + 1
    })
    }
    }
    }
    }
    });