-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/uuid-query-endpoint
- Loading branch information
Showing
70 changed files
with
2,335 additions
and
1,320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
name: Build and push lambda image to production | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: [master] | ||
|
||
env: | ||
REGISTRY: ${{ secrets.PRODUCTION_API_LAMBDA_ECR_ACCOUNT }}.dkr.ecr.ca-central-1.amazonaws.com/notify | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
image: ["api-lambda"] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Build container | ||
run: | | ||
docker build \ | ||
--build-arg GIT_SHA=${GITHUB_SHA::7} \ | ||
-t $REGISTRY/${{ matrix.image }}:${GITHUB_SHA::7} \ | ||
. \ | ||
-f ci/Dockerfile.lambda | ||
- name: Configure AWS credentials | ||
id: aws-creds | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.PRODUCTION_ECR_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.PRODUCTION_ECR_SECRET_ACCESS_KEY }} | ||
aws-region: ca-central-1 | ||
|
||
- name: Login to ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: Push containers to ECR | ||
run: | | ||
docker push $REGISTRY/${{ matrix.image }}:${GITHUB_SHA::7} | ||
- name: Logout of Amazon ECR | ||
run: docker logout ${{ steps.login-ecr.outputs.registry }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
name: Build, push, and deploy lambda image to staging | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: [master] | ||
|
||
env: | ||
REGISTRY: ${{ secrets.STAGING_API_LAMBDA_ECR_ACCOUNT }}.dkr.ecr.ca-central-1.amazonaws.com/notify | ||
|
||
jobs: | ||
build-push-and-deploy: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
image: ["api-lambda"] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Build container | ||
run: | | ||
docker build \ | ||
--build-arg GIT_SHA=${GITHUB_SHA::7} \ | ||
-t $REGISTRY/${{ matrix.image }}:${GITHUB_SHA::7} \ | ||
. \ | ||
-f ci/Dockerfile.lambda | ||
- name: Configure AWS credentials | ||
id: aws-creds | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.STAGING_ECR_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.STAGING_ECR_SECRET_ACCESS_KEY }} | ||
aws-region: ca-central-1 | ||
|
||
- name: Login to ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: Push containers to ECR | ||
run: | | ||
docker push $REGISTRY/${{ matrix.image }}:${GITHUB_SHA::7} | ||
- name: Logout of Amazon ECR | ||
run: docker logout ${{ steps.login-ecr.outputs.registry }} | ||
|
||
- name: Deploy lambda | ||
run: | | ||
aws lambda update-function-code \ | ||
--function-name ${{ matrix.image }} \ | ||
--image-uri $REGISTRY/${{ matrix.image }}:${GITHUB_SHA::7} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Notify Performance / Load Tests | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install libcurl | ||
run: sudo apt-get update && sudo apt-get install libssl-dev libcurl4-openssl-dev | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
- name: Upgrade pip | ||
run: python -m pip install --upgrade pip | ||
- uses: actions/cache@v2 | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
- name: Run performance tests | ||
run: /bin/bash -c "pip install -r requirements_for_test.txt && locust --headless --config tests-perf/locust/locust.conf -f tests-perf/locust/locust-notifications.py" | ||
- name: Notify Slack channel if this performance test job fails | ||
if: ${{ failure() && github.ref == 'refs/heads/master' }} | ||
run: | | ||
json="{'text':'Scheduled CI Performance testing failed: <https://github.com/cds-snc/notification-api/actions|GitHub actions>'}" | ||
curl -X POST -H 'Content-type: application/json' --data "$json" ${{ secrets.SLACK_WEBHOOK }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# Security | ||
|
||
**Do not post any security issues on the public repository!** Security vulnerabilities must be reported by email to [[email protected]](mailto:[email protected]) and [[email protected]](mailto:[email protected].ca). | ||
**Do not post any security issues on the public repository!** Security vulnerabilities must be reported by email to [[email protected] ](mailto:security@cds-snc.ca). | ||
|
||
______________________ | ||
|
||
## Sécurité | ||
|
||
**Ne publiez aucun problème de sécurité sur le dépôt publique!** Les vulnérabilités de sécurité doivent être signalées par courriel à [[email protected]](mailto:[email protected]) et [[email protected]](mailto:[email protected].ca). | ||
**Ne publiez aucun problème de sécurité sur le dépôt publique!** Les vulnérabilités de sécurité doivent être signalées par courriel à [[email protected] ](mailto:security@cds-snc.ca). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from typing import Dict, List, Union | ||
from urllib.parse import urljoin | ||
|
||
import requests | ||
from flask import current_app | ||
from requests.auth import HTTPBasicAuth | ||
|
||
from app.user.contact_request import ContactRequest | ||
|
||
__all__ = ["Zendesk"] | ||
|
||
|
||
class Zendesk(object): | ||
def __init__(self, contact: ContactRequest): | ||
self.api_url = current_app.config["ZENDESK_API_URL"] | ||
self.token = current_app.config["ZENDESK_API_KEY"] | ||
self.contact = contact | ||
|
||
def _generate_description(self): | ||
message = self.contact.message | ||
if self.contact.is_go_live_request(): | ||
message = "<br>".join( | ||
[ | ||
f"{self.contact.service_name} just requested to go live.", | ||
"", | ||
f"- Department/org: {self.contact.department_org_name}", | ||
f"- Intended recipients: {self.contact.intended_recipients}", | ||
f"- Purpose: {self.contact.main_use_case}", | ||
f"- Notification types: {self.contact.notification_types}", | ||
f"- Expected monthly volume: {self.contact.expected_volume}", | ||
"---", | ||
self.contact.service_url, | ||
] | ||
) | ||
elif self.contact.is_branding_request(): | ||
message = "<br>".join( | ||
[ | ||
f"A new logo has been uploaded by {self.contact.name} ({self.contact.email_address}) for the following service:", | ||
f"- Service id: {self.contact.service_id}", | ||
f"- Service name: {self.contact.service_name}", | ||
f"- Logo filename: {self.contact.branding_url}", | ||
"<hr>", | ||
f"Un nouveau logo a été téléchargé par {self.contact.name} ({self.contact.email_address}) pour le service suivant :", | ||
f"- Identifiant du service : {self.contact.service_id}", | ||
f"- Nom du service : {self.contact.service_name}", | ||
f"- Nom du fichier du logo : {self.contact.branding_url}", | ||
] | ||
) | ||
|
||
if len(self.contact.user_profile): | ||
message += f"<br><br>---<br><br> {self.contact.user_profile}" | ||
|
||
return message | ||
|
||
# Update for Zendesk API Ticket format | ||
# read docs: https://developer.zendesk.com/rest_api/docs/core/tickets#create-ticket | ||
def _generate_ticket(self) -> Dict[str, Dict[str, Union[str, int, List[str]]]]: | ||
return { | ||
"ticket": { | ||
"subject": self.contact.friendly_support_type, | ||
"description": self._generate_description(), | ||
"email": self.contact.email_address, | ||
"tags": self.contact.tags | ||
+ ["notification_api"], # Custom tag used to auto-assign ticket to the notification support group | ||
} | ||
} | ||
|
||
def send_ticket(self): | ||
if not self.api_url or not self.token: | ||
raise NotImplementedError | ||
|
||
# The API and field definitions are defined here: | ||
# https://developer.zendesk.com/rest_api/docs/support/tickets | ||
response = requests.post( | ||
urljoin(self.api_url, "/api/v2/tickets"), | ||
json=self._generate_ticket(), | ||
auth=HTTPBasicAuth(f"{self.contact.email_address}/token", self.token), | ||
timeout=5, | ||
) | ||
|
||
if response.status_code != 201: | ||
raise requests.HTTPError(response.status_code, "Failed to create zendesk ticket") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.