Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[minor] Add support for SMTP disabledTemplates in gitops #1491

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion image/cli/mascli/functions/gitops_mas_config
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ SMTP Configuration (required if MAS_CONFIG_TYPE is "smtp"):
--smtp-username ${COLOR_YELLOW}SMTP_USERNAME${TEXT_RESET} Username for SMTP server authentication (Optional, if secret is already set in SM)
--smtp-password ${COLOR_YELLOW}SMTP_PASSWORD${TEXT_RESET} Password for SMTP server authentication (Optional, if secret is already set in SM)
--mas-smtpcfg-pod-template-yaml ${COLOR_YELLOW}MAS_SMTPCFG_POD_TEMPLATE_YAML${TEXT_RESET} The location of a file containing the POD template
--smtp-disabled-templates ${COLOR_YELLOW}SMTP_DISABLED_TEMPLATES${TEXT_RESET} JSON string specifying a list of MAS Suite email templates to disable
E.g. '["UserPasswordReset", "WelcomeUsername", "WelcomePassword"]'
See https://www.ibm.com/docs/en/masv-and-l/continuous-delivery?topic=notifications-disabling-email

Automatic GitHub Push:
-P, --github-push ${COLOR_YELLOW}GITHUB_PUSH${TEXT_RESET} Enable automatic push to GitHub
Expand Down Expand Up @@ -247,6 +250,9 @@ function gitops_mas_config_noninteractive() {
--smtp-password)
export SMTP_PASSWORD=$1 && shift
;;
--smtp-disabled-templates)
export SMTP_DISABLED_TEMPLATES=$1 && shift
;;
--mas-smtpcfg-pod-template-yaml)
export MAS_SMTPCFG_POD_TEMPLATE_YAML=$1 && shift
;;
Expand Down Expand Up @@ -392,6 +398,19 @@ function gitops_mas_config_noninteractive() {
[[ -z "$SMTP_DEFAULT_SENDER_EMAIL" ]] && gitops_mas_config_help "SMTP_DEFAULT_SENDER_EMAIL is not set"
[[ -z "$SMTP_DEFAULT_SENDER_NAME" ]] && gitops_mas_config_help "SMTP_DEFAULT_SENDER_NAME is not set"
[[ -z "$SMTP_DEFAULT_RECIPIENT_EMAIL" ]] && gitops_mas_config_help "SMTP_DEFAULT_RECIPIENT_EMAIL is not set"

if [[ -n "${SMTP_DISABLED_TEMPLATES}" ]]; then
export SMTP_DISABLED_TEMPLATES
echo "${SMTP_DISABLED_TEMPLATES}" | yq --input-format=json 1>/dev/null || gitops_mas_config_help "SMTP_DISABLED_TEMPLATES is not valid JSON"

# Check it's just a list of strings
echo "${SMTP_DISABLED_TEMPLATES}" | yq eval --input-format=json --exit-status=1 \
'type == "!!seq" and
(.[] | type == "!!str") as $item ireduce (true; . and $item)' \
1>/dev/null 2>&1 \
|| gitops_mas_config_help "SMTP_DISABLED_TEMPLATES must be a list of strings"

fi
fi
fi # [ "${CONFIG_ACTION}" == "upsert" ]

Expand Down Expand Up @@ -600,7 +619,8 @@ function gitops_mas_config() {
echo_reset_dim "Smtp Default Recipient Email ................... ${COLOR_MAGENTA}${SMTP_DEFAULT_RECIPIENT_EMAIL}"
echo_reset_dim "Smtp Should Email Passwords .................... ${COLOR_MAGENTA}${SMTP_DEFAULT_SHOULD_EMAIL_PASSWORDS}"
echo_reset_dim "Smtp Server Username ........................... ${COLOR_MAGENTA}${SMTP_USERNAME}"
echo_reset_dim "Smtp Server Password ........................... ${COLOR_MAGENTA}${SMTP_PASSWORD:0:4}<snip>"
echo_reset_dim "Smtp Server Password ........................... ${COLOR_MAGENTA}${SMTP_PASSWORD:0:4}<snip>"
echo_reset_dim "Smtp Disabled Templates ........................ ${COLOR_MAGENTA}${SMTP_DISABLED_TEMPLATES}"
echo_reset_dim "Pod Template YAML File ........................ ${COLOR_MAGENTA}${MAS_SMTPCFG_POD_TEMPLATE_YAML}"
reset_colors
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ suite_smtp_default_should_email_passwords: {{ SMTP_DEFAULT_SHOULD_EMAIL_PASSWORD
{% if MAS_SMTPCFG_POD_TEMPLATE is defined and MAS_SMTPCFG_POD_TEMPLATE !='' %}
mas_smtpcfg_pod_templates:
{{ MAS_SMTPCFG_POD_TEMPLATE | indent(2) }}
{% endif %}

{% if SMTP_DISABLED_TEMPLATES is defined and SMTP_DISABLED_TEMPLATES !='' %}
suite_smtp_disabled_templates: {{ SMTP_DISABLED_TEMPLATES }}
{% endif %}
6 changes: 6 additions & 0 deletions tekton/src/pipelines/gitops/gitops-mas-instance.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ spec:
type: string
- name: smtp_use_sendgrid
type: string
- name: smtp_disabled_templates
type: string

- name: ldap_url
type: string
Expand Down Expand Up @@ -541,6 +543,8 @@ spec:
value: $(params.smtp_default_recipient_email)
- name: smtp_default_should_email_passwords
value: $(params.smtp_default_should_email_passwords)
- name: smtp_disabled_templates
value: $(params.smtp_disabled_templates)
- name: cluster_url
value: $(params.cluster_url)
- name: mas_smtpcfg_pod_template_yaml
Expand Down Expand Up @@ -581,6 +585,8 @@ spec:
value: $(params.github_host)
- name: avp_aws_secret_region
value: $(params.avp_aws_secret_region)
- name: smtp_disabled_templates
value: $(params.smtp_disabled_templates)
- name: mas_smtpcfg_pod_template_yaml
value: $(params.mas_smtpcfg_pod_template_yaml)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ spec:
type: string
- name: avp_aws_secret_region
type: string
- name: smtp_disabled_templates
type: string
default: ""
- name: mas_smtpcfg_pod_template_yaml
type: string
default: ""
Expand Down Expand Up @@ -56,6 +59,8 @@ spec:
value: $(params.github_repo)
- name: SM_AWS_REGION
value: $(params.avp_aws_secret_region)
- name: SMTP_DISABLED_TEMPLATES
value: $(params.smtp_disabled_templates)
- name: MAS_SMTPCFG_POD_TEMPLATE_YAML
value: $(params.mas_smtpcfg_pod_template_yaml)

Expand Down Expand Up @@ -208,6 +213,7 @@ spec:
export SMTP_DEFAULT_SENDER_NAME="MASAdmin"
export SMTP_DEFAULT_RECIPIENT_EMAIL="[email protected]"
export SMTP_DEFAULT_SHOULD_EMAIL_PASSWORDS="true"
export SMTP_DISABLED_TEMPLATES # set in task env vars

# Ensure any SMTP_USERNAME/SMTP_PASSWORD values set in pipeline context properties
# are not used by the gitops-mas-config script to override the values in the AWS SM Secret
Expand Down Expand Up @@ -237,6 +243,7 @@ spec:
--smtp-default-sender-name "${SMTP_DEFAULT_SENDER_NAME}" \
--smtp-default-recipient-email "${SMTP_DEFAULT_RECIPIENT_EMAIL}" \
--smtp-default-should-email-passwords "${SMTP_DEFAULT_SHOULD_EMAIL_PASSWORDS}" \
--smtp-disabled-templates "${SMTP_DISABLED_TEMPLATES}" \
--mas-smtpcfg-pod-template-yaml "${MAS_SMTPCFG_POD_TEMPLATE_YAML}"

exit $?
Expand Down
5 changes: 5 additions & 0 deletions tekton/src/tasks/gitops/gitops-suite-smtp-config.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ spec:
- name: smtp_default_should_email_passwords
type: string
default: ""
- name: smtp_disabled_templates
type: string
default: ""
- name: cluster_url
type: string
default: ""
Expand Down Expand Up @@ -92,6 +95,8 @@ spec:
value: $(params.smtp_default_recipient_email)
- name: SMTP_DEFAULT_SHOULD_EMAIL_PASSWORDS
value: $(params.smtp_default_should_email_passwords)
- name: SMTP_DISABLED_TEMPLATES
value: $(params.smtp_disabled_templates)
- name: MAS_SMTPCFG_POD_TEMPLATE_YAML
value: $(params.mas_smtpcfg_pod_template_yaml)
envFrom:
Expand Down
Loading