From 1e3a704e9fc46bf9e105da73d451a38e21d08707 Mon Sep 17 00:00:00 2001 From: Benjamin Gandon Date: Sun, 4 Feb 2024 17:37:43 +0100 Subject: [PATCH 1/6] Feat: interpolate text from file the same way as direct param-provided text --- out | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/out b/out index 205699a..9481138 100755 --- a/out +++ b/out @@ -72,7 +72,7 @@ fi export TEXT_FILE_CONTENT="" [[ -n "${text_file}" && ! -f "${text_file}" ]] && text_file="" -[[ -n "${text_file}" && -f "${text_file}" ]] && TEXT_FILE_CONTENT="$(cat "${text_file}")" +[[ -n "${text_file}" && -f "${text_file}" ]] && TEXT_FILE_CONTENT="$(envsubst < "${text_file}")" ATTACHMENTS_FILE_CONTENT="" [[ -n "${attachments_file}" && -f "${attachments_file}" ]] && ATTACHMENTS_FILE_CONTENT="$(cat "${attachments_file}")" From 849e6f7e53233f506e8c278e71dc298845d53910 Mon Sep 17 00:00:00 2001 From: Benjamin Gandon Date: Mon, 5 Feb 2024 13:56:16 +0100 Subject: [PATCH 2/6] Add test for interpolated vars in text file --- test/all.sh | 7 ++++++- test/sample-with-vars.txt | 9 +++++++++ test/text_file_with_env_vars.out | 11 +++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/sample-with-vars.txt create mode 100644 test/text_file_with_env_vars.out diff --git a/test/all.sh b/test/all.sh index d1414d2..1a1e5af 100755 --- a/test/all.sh +++ b/test/all.sh @@ -44,6 +44,7 @@ export BUILD_TEAM_NAME='main' webhook_url='https://some.url' base_text=":some_emoji:" sample_text="This text came from sample.txt. It could have been generated by a previous Concourse task.\n\nMultiple lines are allowed.\n" +env_vars_tail="BUILD_NAME=my-build\nVERSION=1.0.1\nQUALITY_GATE=B (ERROR)\nWITH_PIPE=\nwith_GLOB=./path/to/*.jar\n" missing_text="_(no notification provided)_" username="concourse" @@ -203,4 +204,8 @@ test env_file | jq -e " .body.attachments[1].text == \" - ./path/to/*.jar\" and ( .body.attachments | length == 2 )" -echo -e '\e[32;1m'"All tests passed!"'\e[0m' +test text_file_with_env_vars | jq -e " + .body.text == \"${sample_text}\n${env_vars_tail}\" + " + +echo -e '\e[32;1m'"All tests passed!"'\e[0m' diff --git a/test/sample-with-vars.txt b/test/sample-with-vars.txt new file mode 100644 index 0000000..29b73e1 --- /dev/null +++ b/test/sample-with-vars.txt @@ -0,0 +1,9 @@ +This text came from sample.txt. It could have been generated by a previous Concourse task. + +Multiple lines are allowed. + +BUILD_NAME=${BUILD_NAME} +VERSION=${VERSION} +QUALITY_GATE=$QUALITY_GATE +WITH_PIPE=${WITH_PIPE} +with_GLOB=$with_GLOB diff --git a/test/text_file_with_env_vars.out b/test/text_file_with_env_vars.out new file mode 100644 index 0000000..6a36f61 --- /dev/null +++ b/test/text_file_with_env_vars.out @@ -0,0 +1,11 @@ +{ + "params": { + "text_file": "sample-with-vars.txt", + "env_file": ".env", + "username": "concourse", + "debug": "true" + }, + "source": { + "url": "https://some.url" + } +} From c6fb21b02b56095715ee58e6b0cb2f2a79a22f1b Mon Sep 17 00:00:00 2001 From: Benjamin Gandon Date: Mon, 5 Feb 2024 14:54:08 +0100 Subject: [PATCH 3/6] Add second test with combined text and file, both requiring interpolation --- test/all.sh | 11 +++++++---- test/combined_text_template_and_file_with_vars.out | 12 ++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 test/combined_text_template_and_file_with_vars.out diff --git a/test/all.sh b/test/all.sh index 1a1e5af..42c108c 100755 --- a/test/all.sh +++ b/test/all.sh @@ -61,6 +61,9 @@ test combined_text_template_and_file | jq -e " ( .body | keys | contains([\"channel\",\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\",\"attachments\"]) ) and ( .body | keys | length == 7 )" +test combined_text_template_and_file_with_vars | jq -e " + .body.text == \"${base_text}\n${sample_text}\n${env_vars_tail}\" + " test combined_text_template_and_file_empty | jq -e " .webhook_url == $(echo $webhook_url | jq -R .) and @@ -111,6 +114,10 @@ test text_file | jq -e " ( .body | keys | contains([\"channel\",\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\",\"attachments\"]) ) and ( .body | keys | length == 7 )" +test text_file_with_env_vars | jq -e " + .body.text == \"${sample_text}\n${env_vars_tail}\" + " + test text_file_empty | jq -e " .webhook_url == $(echo $webhook_url | jq -R .) and .body.channel == null and @@ -204,8 +211,4 @@ test env_file | jq -e " .body.attachments[1].text == \" - ./path/to/*.jar\" and ( .body.attachments | length == 2 )" -test text_file_with_env_vars | jq -e " - .body.text == \"${sample_text}\n${env_vars_tail}\" - " - echo -e '\e[32;1m'"All tests passed!"'\e[0m' diff --git a/test/combined_text_template_and_file_with_vars.out b/test/combined_text_template_and_file_with_vars.out new file mode 100644 index 0000000..1cd2234 --- /dev/null +++ b/test/combined_text_template_and_file_with_vars.out @@ -0,0 +1,12 @@ +{ + "params": { + "text_file": "sample-with-vars.txt", + "text": ":some_emoji:\n$TEXT_FILE_CONTENT\n", + "env_file": ".env", + "username": "concourse", + "debug": "true" + }, + "source": { + "url": "https://some.url" + } +} From 2f7e74694e8e581fc6615c27cc9959bc0077f21a Mon Sep 17 00:00:00 2001 From: Benjamin Gandon Date: Tue, 6 Feb 2024 02:49:50 +0100 Subject: [PATCH 4/6] Mention new maintainers --- Dockerfile | 2 +- LICENSE | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0406cba..921665c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM alpine:3 ARG VERSION ARG BUILD_DATE ARG VCS_REF -LABEL maintainer="Stark & Wayne " \ +LABEL maintainer="Gstack " \ summary="Concourse Slack Notifications Resource" \ version=$VERSION \ org.label-schema.build-date=$BUILD_DATE \ diff --git a/LICENSE b/LICENSE index 12b05d7..21c50a5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ The MIT License (MIT) -Copyright (c) 2017-2020 James Hunt +Copyright (c) 2017-2020 James Hunt +Copyright (c) 2021-present Benjamin Gandon, Gstack Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to From f5885d57a6a44cf0904c738505d07f60d8bf2640 Mon Sep 17 00:00:00 2001 From: Benjamin Gandon Date: Tue, 6 Feb 2024 02:51:42 +0100 Subject: [PATCH 5/6] Document dummy implementations for 'check' and 'get' steps --- README.md | 58 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index ef435f7..d1da390 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,16 @@ Resource Type Configuration ```yaml resource_types: -- name: slack-notification - type: docker-image - source: - repository: cfcommunity/slack-notification-resource - tag: latest + - name: slack-notification + type: docker-image + source: + repository: cfcommunity/slack-notification-resource + tag: latest ``` +The `tag: latest` source property is optional, as the value `latest` in the +default. + Source Configuration -------------------- @@ -25,7 +28,7 @@ To setup an Incoming Webhook, go to in the form: `https://hooks.slack.com/services/XXXX`. - `insecure`: *Optional.* Connect to Slack insecurely - i.e. skip - SSL validation. Defaults to false if not provided. + SSL validation. Defaults to `false` if not provided. - `proxy`: *Optional.* Connect to Slack using an HTTP(S) proxy. In the form: `http://my.proxy:3128`. @@ -42,33 +45,46 @@ To setup an Incoming Webhook, go to ```yaml ca_certs: - - domain: example.com - cert: | - -----BEGIN CERTIFICATE----- - ... - -----END CERTIFICATE----- - - domain: 10.244.6.2 - cert: | - -----BEGIN CERTIFICATE----- - ... - -----END CERTIFICATE----- + - domain: example.com + cert: | + -----BEGIN CERTIFICATE----- + ... + -----END CERTIFICATE----- + - domain: 10.244.6.2 + cert: | + -----BEGIN CERTIFICATE----- + ... + -----END CERTIFICATE----- ``` Each entry specifies the x509 CA certificate for the trusted domain. +Example: + ```yaml resources: -- name: slack-alert - type: slack-notification - source: - url: https://hooks.slack.com/services/XXXX + - name: slack-alert + type: slack-notification + source: + url: https://hooks.slack.com/services/XXXX ``` Behavior -------- -### `out`: Sends a message to Slack. +### `check` Step (`check` script): No operation + +Checking for new version always returns the last timestamp-based dummy +version, created when the last `put` step was executed on this resource. + +### `get` Step (`in` script): No operation + +Getting a new version of this resource does nothing else that always returning +the last timestamp-based dummy version, created when the last `put` step was +executed on this resource. + +### `put` Step (`out` script): Sends a message to Slack. Send a message to Slack, with the configured parameters. From 964816c9fd5b067d72137204b8fef62244829a21 Mon Sep 17 00:00:00 2001 From: Benjamin Gandon Date: Tue, 6 Feb 2024 02:49:13 +0100 Subject: [PATCH 6/6] Update release notes --- ci/release_notes.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ci/release_notes.md b/ci/release_notes.md index e6a7573..b05784d 100644 --- a/ci/release_notes.md +++ b/ci/release_notes.md @@ -1,4 +1,9 @@ +### New feature + +- Now the content of `text_file` is interpolated the same way `text` is. This change in behavior may produce unexpected results when the content of the file designated by `text_file` includes some environment variables like `$BUILD_PIPELINE_NAME` that are to be printed verbatim and not expanded. This applies to any other environment variables of the `put` step execution. We expect the impact to be very limited though. + ### Improvements - Generated new CI pipeline from [template](https://github.com/cloudfoundry-community/pipeline-templates), hosted by Gstack, that has taken over maintenance of the project. -- Rebuilt with latest Alpine image v3.19.1 and Bash v5.2.21 +- Updated docs +- Rebuilt resource image with latest Alpine image v3.19.1 and Bash v5.2.21