Skip to content

Commit

Permalink
Improve auth config (GSI-953) (#18)
Browse files Browse the repository at this point in the history
* Improve auth config and remove validation function

* Bump version to 2.0.0 and update usual files

* Update config for change from template update

Update dockerfile for testcontainers on linux
  • Loading branch information
TheByronHimes authored Aug 28, 2024
1 parent 559ecec commit 91d7efc
Show file tree
Hide file tree
Showing 15 changed files with 641 additions and 608 deletions.
5 changes: 3 additions & 2 deletions .devcontainer/.dev_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ plaintext_email_template: "Dear $recipient_name,\n\n$plaintext_body\n\nWarm rega
html_email_template: '<!DOCTYPE html><html><head></head><body style="color: #00393f;padding: 12px;"><h2>Dear $recipient_name,</h2><p>$plaintext_body</p><p>Warm regards,</p><h3>The GHGA Team</h3></body></html>'
smtp_host: 127.0.0.1
smtp_port: 587
login_user: "[email protected]"
login_password: test
smtp_auth:
username: "[email protected]"
password: test
from_address: "[email protected]"
use_starttls: false
db_connection_str: "mongodb://mongodb:27017"
Expand Down
5 changes: 4 additions & 1 deletion .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ services:
USER_GID: 1000

init: true
privileged: true

# Enables the use of testcontainers on linux-based hosts
extra_hosts:
- host.docker.internal:host-gateway

volumes:
- ..:/workspace:cached
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ repos:
- id: no-commit-to-branch
args: [--branch, dev, --branch, int, --branch, main]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.5
rev: v0.6.2
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.0
rev: v1.11.2
hooks:
- id: mypy
args: [--no-warn-unused-ignores]
2 changes: 1 addition & 1 deletion .pyproject_generation/pyproject_custom.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "ns"
version = "1.2.0"
version = "2.0.0"
description = "The Notification Service (NS) handles notification kafka events."
dependencies = [
"typer>=0.12",
Expand Down
64 changes: 40 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ We recommend using the provided Docker container.

A pre-build version is available at [docker hub](https://hub.docker.com/repository/docker/ghga/notification-service):
```bash
docker pull ghga/notification-service:1.2.0
docker pull ghga/notification-service:2.0.0
```

Or you can build the container yourself from the [`./Dockerfile`](./Dockerfile):
```bash
# Execute in the repo's root dir:
docker build -t ghga/notification-service:1.2.0 .
docker build -t ghga/notification-service:2.0.0 .
```

For production-ready deployment, we recommend using Kubernetes, however,
for simple use cases, you could execute the service using docker
on a single server:
```bash
# The entrypoint is preconfigured:
docker run -p 8080:8080 ghga/notification-service:1.2.0 --help
docker run -p 8080:8080 ghga/notification-service:2.0.0 --help
```

If you prefer not to use containers, you may install the service from source:
Expand All @@ -64,7 +64,7 @@ ns --help
### Parameters

The service requires the following configuration parameters:
- **`db_connection_str`** *(string, format: password)*: MongoDB connection string. Might include credentials. For more information see: https://naiveskill.com/mongodb-connection-string/.
- **`db_connection_str`** *(string, format: password, required)*: MongoDB connection string. Might include credentials. For more information see: https://naiveskill.com/mongodb-connection-string/.


Examples:
Expand All @@ -74,7 +74,7 @@ The service requires the following configuration parameters:
```


- **`db_name`** *(string)*: Name of the database located on the MongoDB server.
- **`db_name`** *(string, required)*: Name of the database located on the MongoDB server.


Examples:
Expand All @@ -88,7 +88,7 @@ The service requires the following configuration parameters:

- **`service_name`** *(string)*: Default: `"ns"`.

- **`service_instance_id`** *(string)*: A string that uniquely identifies this instance across all instances of this service. A globally unique Kafka client ID will be created by concatenating the service_name and the service_instance_id.
- **`service_instance_id`** *(string, required)*: A string that uniquely identifies this instance across all instances of this service. A globally unique Kafka client ID will be created by concatenating the service_name and the service_instance_id.


Examples:
Expand Down Expand Up @@ -121,35 +121,27 @@ The service requires the following configuration parameters:

- **`log_traceback`** *(boolean)*: Whether to include exception tracebacks in log messages. Default: `true`.

- **`plaintext_email_template`** *(string)*: The plaintext template to use for email notifications.
- **`plaintext_email_template`** *(string, required)*: The plaintext template to use for email notifications.

- **`html_email_template`** *(string)*: The HTML template to use for email notifications.
- **`html_email_template`** *(string, required)*: The HTML template to use for email notifications.

- **`from_address`** *(string, format: email)*: The sender's address.
- **`from_address`** *(string, format: email, required)*: The sender's address.

- **`smtp_host`** *(string)*: The mail server host to connect to.
- **`smtp_host`** *(string, required)*: The mail server host to connect to.

- **`smtp_port`** *(integer)*: The port for the mail server connection.
- **`smtp_port`** *(integer, required)*: The port for the mail server connection.

- **`login_user`**: The login username or email. Default: `null`.
- **`smtp_auth`**: . Default: `null`.

- **Any of**

- *string*

- *null*

- **`login_password`**: The login password. Default: `null`.

- **Any of**

- *string, format: password*
- : Refer to *[#/$defs/SmtpAuthConfig](#%24defs/SmtpAuthConfig)*.

- *null*

- **`use_starttls`** *(boolean)*: Boolean flag indicating the use of STARTTLS. Default: `true`.

- **`notification_event_topic`** *(string)*: Name of the event topic used to track notification events.
- **`notification_event_topic`** *(string, required)*: Name of the event topic used to track notification events.


Examples:
Expand All @@ -159,7 +151,7 @@ The service requires the following configuration parameters:
```


- **`notification_event_type`** *(string)*: The type to use for events containing content to be sent.
- **`notification_event_type`** *(string, required)*: The type to use for events containing content to be sent.


Examples:
Expand All @@ -169,7 +161,7 @@ The service requires the following configuration parameters:
```


- **`kafka_servers`** *(array)*: A list of connection strings to connect to Kafka bootstrap servers.
- **`kafka_servers`** *(array, required)*: A list of connection strings to connect to Kafka bootstrap servers.

- **Items** *(string)*

Expand Down Expand Up @@ -208,6 +200,30 @@ The service requires the following configuration parameters:
```


- **`kafka_max_message_size`** *(integer)*: The largest message size that can be transmitted, in bytes. Only services that have a need to send/receive larger messages should set this. Exclusive minimum: `0`. Default: `1048576`.


Examples:

```json
1048576
```


```json
16777216
```


## Definitions


- <a id="%24defs/SmtpAuthConfig"></a>**`SmtpAuthConfig`** *(object)*: Model to encapsulate SMTP authentication details.

- **`username`** *(string, required)*: The login username or email.

- **`password`** *(string, format: password, required)*: The login password.


### Usage:

Expand Down
60 changes: 40 additions & 20 deletions config_schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
{
"$defs": {
"SmtpAuthConfig": {
"description": "Model to encapsulate SMTP authentication details.",
"properties": {
"username": {
"description": "The login username or email",
"title": "Username",
"type": "string"
},
"password": {
"description": "The login password",
"format": "password",
"title": "Password",
"type": "string",
"writeOnly": true
}
},
"required": [
"username",
"password"
],
"title": "SmtpAuthConfig",
"type": "object"
}
},
"additionalProperties": false,
"description": "Modifies the orginal Settings class provided by the user",
"description": "Modifies the original Settings class provided by the user",
"properties": {
"db_connection_str": {
"description": "MongoDB connection string. Might include credentials. For more information see: https://naiveskill.com/mongodb-connection-string/",
Expand Down Expand Up @@ -96,33 +121,17 @@
"title": "Smtp Port",
"type": "integer"
},
"login_user": {
"smtp_auth": {
"anyOf": [
{
"type": "string"
"$ref": "#/$defs/SmtpAuthConfig"
},
{
"type": "null"
}
],
"default": null,
"description": "The login username or email",
"title": "Login User"
},
"login_password": {
"anyOf": [
{
"format": "password",
"type": "string",
"writeOnly": true
},
{
"type": "null"
}
],
"default": null,
"description": "The login password",
"title": "Login Password"
"description": ""
},
"use_starttls": {
"default": true,
Expand Down Expand Up @@ -204,6 +213,17 @@
],
"title": "Generate Correlation Id",
"type": "boolean"
},
"kafka_max_message_size": {
"default": 1048576,
"description": "The largest message size that can be transmitted, in bytes. Only services that have a need to send/receive larger messages should set this.",
"examples": [
1048576,
16777216
],
"exclusiveMinimum": 0,
"title": "Kafka Max Message Size",
"type": "integer"
}
},
"required": [
Expand Down
6 changes: 4 additions & 2 deletions example_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ generate_correlation_id: true
html_email_template: '<!DOCTYPE html><html><head></head><body style="color: #00393f;padding:
12px;"><h2>Dear $recipient_name,</h2><p>$plaintext_body</p><p>Warm regards,</p><h3>The
GHGA Team</h3></body></html>'
kafka_max_message_size: 1048576
kafka_security_protocol: PLAINTEXT
kafka_servers:
- kafka:9092
Expand All @@ -15,8 +16,6 @@ kafka_ssl_password: ''
log_format: null
log_level: INFO
log_traceback: true
login_password: '**********'
login_user: [email protected]
notification_event_topic: notifications
notification_event_type: notification
plaintext_email_template: 'Dear $recipient_name,
Expand All @@ -31,6 +30,9 @@ plaintext_email_template: 'Dear $recipient_name,
The GHGA Team'
service_instance_id: '001'
service_name: ns
smtp_auth:
password: '**********'
username: [email protected]
smtp_host: 127.0.0.1
smtp_port: 587
use_starttls: false
Loading

0 comments on commit 91d7efc

Please sign in to comment.