Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
bgandon committed Feb 6, 2024
2 parents fea74a9 + 964816c commit 400906a
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM alpine:3
ARG VERSION
ARG BUILD_DATE
ARG VCS_REF
LABEL maintainer="Stark & Wayne <beahero@starkandwayne.com>" \
LABEL maintainer="Gstack <https://github.com/gstackio>" \
summary="Concourse Slack Notifications Resource" \
version=$VERSION \
org.label-schema.build-date=$BUILD_DATE \
Expand Down
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
58 changes: 37 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------

Expand All @@ -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`.
Expand All @@ -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.

Expand Down
7 changes: 6 additions & 1 deletion ci/release_notes.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion out
Original file line number Diff line number Diff line change
Expand Up @@ -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}")"
Expand Down
10 changes: 9 additions & 1 deletion test/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export BUILD_TEAM_NAME='main'
webhook_url='https://some.url'
base_text=":some_emoji:<https://my-ci.my-org.com/teams/main/pipelines/my-pipeline/jobs/my-job/builds/my-build|Alert!>"
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=<something>\nwith_GLOB=./path/to/*.jar\n"
missing_text="_(no notification provided)_"

username="concourse"
Expand All @@ -60,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
Expand Down Expand Up @@ -110,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
Expand Down Expand Up @@ -203,4 +211,4 @@ test env_file | jq -e "
.body.attachments[1].text == \"<something> - ./path/to/*.jar\" and
( .body.attachments | length == 2 )"

echo -e '\e[32;1m'"All tests passed!"'\e[0m'
echo -e '\e[32;1m'"All tests passed!"'\e[0m'
12 changes: 12 additions & 0 deletions test/combined_text_template_and_file_with_vars.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"params": {
"text_file": "sample-with-vars.txt",
"text": ":some_emoji:<https://my-ci.my-org.com/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME|Alert!>\n$TEXT_FILE_CONTENT\n",
"env_file": ".env",
"username": "concourse",
"debug": "true"
},
"source": {
"url": "https://some.url"
}
}
9 changes: 9 additions & 0 deletions test/sample-with-vars.txt
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions test/text_file_with_env_vars.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"params": {
"text_file": "sample-with-vars.txt",
"env_file": ".env",
"username": "concourse",
"debug": "true"
},
"source": {
"url": "https://some.url"
}
}

0 comments on commit 400906a

Please sign in to comment.