diff --git a/ttps/examples/ignore-errors/README.md b/ttps/examples/ignore-errors/README.md deleted file mode 100644 index 6a46e17..0000000 --- a/ttps/examples/ignore-errors/README.md +++ /dev/null @@ -1,127 +0,0 @@ -# Ignore Errors in a TTP step - -Understand the process of ignoring errors in a specific TTP step. - ---- - -## Running `ignore-errors.yaml` Demonstration - -To see the `ignore_errors` functionality in action, execute: - -```bash -ttpforge run forgearmory//examples/ignore-errors/ignore-errors.yaml -``` - -This will illustrate how to create a step that allows the TTP to continue, -even if an error occurs within a previous step. - -By setting the `ignore_errors: true` on a step, subsequent steps in the -TTP can continue executing even if there's an error in the current step. - ---- - -## Expected Output - -```text -INFO [*] Validating Steps -INFO executor set via extension {"exec": "sh"} -INFO [*] Validating Sub TTP: subttp-step-with-error -INFO [*] Finished validating Sub TTP -INFO [*] Validating Sub TTP: second_sub_ttp -INFO [*] Finished validating Sub TTP -INFO [+] Finished validating steps -INFO [+] Running current TTP: ignore-errors -INFO [+] Running current step: basic-step-expected-to-fail -INFO ========= Executing ========== -this will fail -ERROR {error 26 0 exit status 1} -WARN Error ignored due to 'ignore_errors' parameter -INFO [+] Finished running step: basic-step-expected-to-fail -INFO [+] Running current step: basic-step-post-error -INFO ========= Executing ========== -We still reach this step despite there being an error -in the previous inline step. -INFO ========= Result ========== -INFO [+] Finished running step: basic-step-post-error -INFO [+] Running current step: file-step-expected-to-fail -INFO ========= Executing ========== -ERROR bad exit of process {"stdout": "", "stderr": "", "exit code": 1} -ERROR {error 26 0 exit status 1} -WARN Error ignored due to 'ignore_errors' parameter -INFO [+] Finished running step: file-step-expected-to-fail -INFO [+] Running current step: file-step-post-error -INFO ========= Executing ========== -We still reach this step despite there being an error -in the previous file step. -INFO ========= Result ========== -INFO [+] Finished running step: file-step-post-error -INFO [+] Running current step: edit-step-expected-to-fail -INFO ========= Executing ========== -WARN Error ignored due to 'ignore_errors' parameter{error 26 0 -pattern 'I_DONT_EXIST_IN_THE_FILE' from edit #1 was not found in file ignore-errors-edit-example.txt} -WARN Error ignored due to 'ignore_errors' parameter{error 26 0 pattern -'(?ms:^result = await myclass\.multi_line_function_call\(.*?\)$)' from edit #2 was not found in file ignore-errors-edit-example.txt} -WARN Error ignored due to 'ignore_errors' parameter{error 26 0 pattern -'(?P(?ms:^another_multline_function_call\(.*?\)$))' from edit #3 was not found in file ignore-errors-edit-example.txt} -INFO ========= Result ========== -INFO [+] Finished running step: edit-step-expected-to-fail -INFO [+] Running current step: edit-step-post-error -INFO ========= Executing ========== -We still reach this step despite there being an error -in the previous edit step. -INFO ========= Result ========== -INFO [+] Finished running step: edit-step-post-error -INFO [+] Running current step: subttp-step-with-error -INFO [*] Executing Sub TTP: subttp-step-with-error -INFO [+] Running current step: step_one -INFO ========= Executing ========== -we are about to fail -ERROR {error 26 0 exit status 1} -WARN Error ignored due to 'ignore_errors' parametererrorexit status 1 -INFO [+] Finished running step: step_one -INFO ========= Result ========== -INFO [+] Finished running step: subttp-step-with-error -INFO [+] Running current step: second_sub_ttp -INFO [*] Executing Sub TTP: second_sub_ttp -INFO [+] Running current step: step_one -INFO ========= Executing ========== -you said testing -INFO ========= Result ========== -INFO [+] Finished running step: step_one -INFO ========= Result ========== -INFO [+] Finished running step: second_sub_ttp -INFO [+] Running current step: subttp-step-post-error -INFO ========= Executing ========== -We still reach this step despite there being an error -in one of the subttp steps. -INFO ========= Result ========== -INFO [+] Finished running step: subttp-step-post-error -INFO [+] Running current step: fetchURI-step-no-error -INFO ========= Executing ========== -INFO ========= Result ========== -INFO [+] Finished running step: fetchURI-step-no-error -INFO [+] Running current step: fetchURI-step-with-error -INFO ========= Executing ========== -ERROR {error 26 0 Get "http://not-a-real-siteabc123456.com": dial tcp: lookup not-a-real-siteabc123456.com: no such host} -WARN Error ignored due to 'ignore_errors' parameter -INFO [+] Finished running step: fetchURI-step-with-error -INFO [+] Running current step: fetchuri-step-post-error -INFO ========= Executing ========== -We still reach this step despite there being an error -in the fetchuri step. -INFO ========= Result ========== -INFO [+] Finished running step: fetchuri-step-post-error -INFO [*] Completed TTP -INFO [*] Beginning Cleanup -INFO ========= Executing ========== -INFO ========= Result ========== -INFO ========= Executing ========== -cleanup my_sub_ttp_2 -INFO ========= Result ========== -INFO ========= Executing ========== -cleanup my_sub_ttp_1 -INFO ========= Result ========== -INFO ========= Executing ========== -INFO ========= Result ========== -INFO [*] Finished Cleanup -``` diff --git a/ttps/examples/ignore-errors/ignore-errors-edit-example.txt b/ttps/examples/ignore-errors/ignore-errors-edit-example.txt deleted file mode 100644 index 9aa13af..0000000 --- a/ttps/examples/ignore-errors/ignore-errors-edit-example.txt +++ /dev/null @@ -1,18 +0,0 @@ -This is an example file. - -The TTP will replace the string below: - -REPLACE_ME - -It will also delete the multi-line string below and replace -it with a comment: - - -# replaced with comment - -Finally, it will comment out the line below using a C-Style /* ... */ comment. - -/*another_multline_function_call( - param1, - param2, -)*/ diff --git a/ttps/examples/ignore-errors/ignore-errors-file-example.sh b/ttps/examples/ignore-errors/ignore-errors-file-example.sh deleted file mode 100755 index b4b5f9d..0000000 --- a/ttps/examples/ignore-errors/ignore-errors-file-example.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -e - -exit 1 diff --git a/ttps/examples/ignore-errors/ignore-errors.yaml b/ttps/examples/ignore-errors/ignore-errors.yaml deleted file mode 100644 index bd7b6a5..0000000 --- a/ttps/examples/ignore-errors/ignore-errors.yaml +++ /dev/null @@ -1,78 +0,0 @@ ---- -name: ignore-errors -description: | - Illustrates how to create a step that will allow the TTP to continue, - even if an error occurs. -steps: - - name: basic-step-expected-to-fail - ignore_errors: true - inline: | - echo "this will fail" - exit 1 - - - name: basic-step-post-error - inline: | - echo -e "We still reach this step despite there being an error" - echo -e "in the previous inline step." - - - name: file-step-expected-to-fail - ignore_errors: true - file: ignore-errors-file-example.sh - - - name: file-step-post-error - inline: | - echo -e "We still reach this step despite there being an error" - echo -e "in the previous file step." - - - name: edit-step-expected-to-fail - ignore_errors: true - edit_file: ignore-errors-edit-example.txt - backup_file: "my-backup.txt" - edits: - - old: I_DONT_EXIST_IN_THE_FILE - new: REPLACED_BY_EDIT - ignore_errors: true - - old: (?ms:^result = await myclass\.multi_line_function_call\(.*?\)$) - new: "# replaced with comment" - regexp: true - - old: (?P(?ms:^another_multline_function_call\(.*?\)$)) - new: "/*${fn_call}*/" - regexp: true - - - name: edit-step-post-error - inline: | - echo -e "We still reach this step despite there being an error" - echo -e "in the previous edit step." - cleanup: - inline: rm my-backup.txt - - - name: subttp-step-with-error - ttp: examples/ignore-errors/my-sub-ttps/ttp1.yaml - ignore_errors: true - - name: second_sub_ttp - ttp: examples/ignore-errors/my-sub-ttps/ttp2.yaml - args: - arg1: testing - - - name: subttp-step-post-error - inline: | - echo -e "We still reach this step despite there being an error" - echo -e "in one of the subttp steps." - - - name: fetchURI-step-no-error - fetch_uri: https://google.com - location: ./google.txt - overwrite: true - cleanup: - inline: rm google.txt - - - name: fetchURI-step-with-error - fetch_uri: http://not-a-real-siteabc123456.com - location: ./bla.txt - overwrite: true - ignore_errors: true - - - name: fetchuri-step-post-error - inline: | - echo -e "We still reach this step despite there being an error" - echo -e "in the fetchuri step." diff --git a/ttps/examples/ignore-errors/my-sub-ttps/ttp1.yaml b/ttps/examples/ignore-errors/my-sub-ttps/ttp1.yaml deleted file mode 100644 index b5f434a..0000000 --- a/ttps/examples/ignore-errors/my-sub-ttps/ttp1.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -name: my_sub_ttp_1 -description: called from subttp example -steps: - - name: step_one - inline: | - echo "we are about to fail" - exit 1 - cleanup: - inline: echo cleanup my_sub_ttp_1 diff --git a/ttps/examples/ignore-errors/my-sub-ttps/ttp2.yaml b/ttps/examples/ignore-errors/my-sub-ttps/ttp2.yaml deleted file mode 100644 index f2495ca..0000000 --- a/ttps/examples/ignore-errors/my-sub-ttps/ttp2.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -name: my_sub_ttp_2 -description: called from subttp example -args: - - name: arg1 -steps: - - name: step_one - inline: echo "you said {{ .Args.arg1 }}" - cleanup: - inline: echo cleanup my_sub_ttp_2 diff --git a/ttps/examples/targets/README.md b/ttps/examples/targets/README.md deleted file mode 100644 index 3f0acda..0000000 --- a/ttps/examples/targets/README.md +++ /dev/null @@ -1,79 +0,0 @@ -# Specifying Targets for TTPs - -Gain insights on how to define specific targets for a TTP, be it a cloud service, -an operating system, or a certain architecture. - ---- - -## Running `cloud-target.yaml` Demonstration - -To demonstrate the specification of a cloud target, execute: - -```bash -ttpforge run forgearmory//examples/targets/cloud-target.yaml -``` - ---- - -## Expected Output (With Cloud Credentials) - -```text -INFO [*] Validating Steps -INFO [+] Finished validating steps -INFO [+] Running current TTP: cloud -INFO [+] Running current step: ensure-aws-creds-present -INFO ========= Executing ========== -You have AWS credentials set, well done! -INFO ========= Done ========== -INFO [+] Finished running step: ensure-aws-creds-present -INFO [*] Completed TTP -INFO [*] No Cleanup Steps Found -``` - -## Expected Output (Without Cloud Credentials) - -```text -INFO [*] Validating Steps -INFO [+] Finished validating steps -INFO [+] Running current TTP: cloud -INFO [+] Running current step: ensure-aws-creds-present -INFO ========= Executing ========== -error: AWS_DEFAULT_REGION must be set. -ERROR [*] Error executing TTP: exit status 1 -INFO [*] Completed TTP -INFO [*] No Cleanup Steps Found -ERROR failed to run command: - failed to run TTP at /Users/$USER/.ttpforge/repos/forgearmory/ttps/ - examples/targets/cloud-target.yaml: - exit status 1 -``` - ---- - -## Running `os-and-arch-target.yaml` Demonstration - -To visualize the mapping of operating systems and architectures to a TTP, execute: - -```bash -ttpforge run forgearmory//examples/targets/os-and-arch-target.yaml -``` - ---- - -## Expected Output - -```text -INFO [*] Validating Steps -INFO [+] Finished validating steps -INFO [+] Running current TTP: os-and-arch-target -INFO [+] Running current step: friendly-message -INFO ========= Executing ========== -You are running a TTP that works for the following operating systems: [linux macos] -and architectures: [x86_64 arm64]. -It can be used for the following cloud providers -at the specified regions as well: [aws:us-west-1 gcp:us-west1-a azure:eastus]. -INFO ========= Done ========== -INFO [+] Finished running step: friendly-message -INFO [*] Completed TTP -INFO [*] No Cleanup Steps Found -``` diff --git a/ttps/examples/targets/cloud-target.yaml b/ttps/examples/targets/cloud-target.yaml deleted file mode 100644 index 353e1fd..0000000 --- a/ttps/examples/targets/cloud-target.yaml +++ /dev/null @@ -1,33 +0,0 @@ ---- -name: cloud -description: | - Example to specify a cloud target for a TTP (specifically AWS in this case) -targets: - cloud: - - provider: "aws" - region: "us-west-1" - - provider: "gcp" - region: "us-west1-a" - - provider: "azure" - region: "eastus" - -steps: - - name: ensure-aws-creds-present - inline: | - set -e - - if [[ -z "${AWS_DEFAULT_REGION}" ]]; then - echo "error: AWS_DEFAULT_REGION must be set." - exit 1 - fi - - if [[ -n "${AWS_ACCESS_KEY_ID}" && -n "${AWS_SECRET_ACCESS_KEY}" ]]; then - if [[ -z "${AWS_SESSION_TOKEN}" ]]; then - echo "warning: AWS_SESSION_TOKEN is not set with AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY." - fi - elif [[ -z "${AWS_PROFILE}" ]]; then - echo "error: AWS credentials are not set, exiting." - exit 1 - fi - - echo "You have AWS credentials set, well done!" diff --git a/ttps/examples/targets/os-and-arch-target.yaml b/ttps/examples/targets/os-and-arch-target.yaml deleted file mode 100644 index c77e30e..0000000 --- a/ttps/examples/targets/os-and-arch-target.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -name: os-and-arch-target -description: | - Example demonstrating how to create a TTP that works for specific - operating systems and architectures. - - This TTP also demonstrates how to create a TTP that can - be used for specific cloud providers and regions. -targets: - os: - - linux - - macos - arch: - - x86_64 - - arm64 - cloud: - - provider: "aws" - region: "us-west-1" - - provider: "gcp" - region: "us-west1-a" - - provider: "azure" - region: "eastus" - -steps: - - name: friendly-message - inline: | - set -e - - echo -e "You are running a TTP that works for the following operating systems: {{ .Targets.os }}" - echo -e "and architectures: {{ .Targets.arch }}." - echo -e "It can be used for the following cloud providers" - echo -e "at the specified regions as well: {{ .Targets.cloud }}."