Skip to content

Commit 21c3453

Browse files
committed
feat(mail): refactor email service loading and docs
1 parent 95f2dda commit 21c3453

11 files changed

+170
-24
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contributing to DWBH
1+
# Contributing to Patio
22

33
We love your input! We want to make contributing to this project as easy and transparent as possible,
44
whether it's:

README.md

+26-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
[![Travis](https://travis-ci.org/dont-worry-be-happy/dwbh-api.svg?branch=master)](https://travis-ci.org/dont-worry-be-happy/dwbh-api) [![License](https://img.shields.io/github/license/dont-worry-be-happy/dwbh-api.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html)
1+
![API Continuos Integration](https://github.com/patio-team/patio-api/workflows/API%20Continuos%20Integration/badge.svg) ![Continuous deployment in dev](https://github.com/patio-team/patio-api/workflows/Continuous%20deployment%20in%20dev/badge.svg) [![License](https://img.shields.io/github/license/dont-worry-be-happy/dwbh-api.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html)
22

3-
# Don't Worry Be Happy
3+
![dwbh](etc/site/imgs/patio.png)
44

5-
![dwbh](etc/site/imgs/dwbh.png)
6-
7-
**Don't Worry Be Happy** is a web application that tries to measure the happiness of a given team periodically by
5+
**Patio** is a web application that tries to measure the happiness of a given team periodically by
86
asking for a level of happiness between 1 and 5 (being 1 the saddest scenario and 5 the happiest). This repository
97
hosts the backend of the DWBH project. Cool!
108

@@ -164,19 +162,36 @@ And environment variables
164162
| DWBH_JDBC_PASSWORD | JDBC password | dwbh |
165163
| DWBH_JDBC_DRIVER | JDBC driver | org.postgresql.Driver |
166164
165+
##### EMAIL
166+
167+
By default, if no other email service has been configured a default dummy service will be used to debug email mailing. You
168+
can, for example, configure AWS credentials to enable AWS mailing service.
169+
170+
```yaml
171+
email:
172+
source: ${DWBH_EMAIL_SOURCE}
173+
enabled: ${DWBH_EMAIL_ENABLED}
174+
```
175+
176+
And environment variables:
177+
178+
| Name | Description | Default value |
179+
|:---------------------------|:----------------------------|:--------------------------------------------------------------|
180+
| DWBH_EMAIL_SOURCE | Source email | |
181+
| DWBH_EMAIL_ENABLED | Enable mailing | |
182+
167183
##### AWS integration
168184
185+
AWS credentials to use AWS services, such as AWS simple mail service.
186+
169187
Configuration file section:
170188
171189
```yaml
172190
aws:
173191
credentials:
174192
accessKey: ${DWBH_AWS_ACCESS_KEY}
175193
secretKey: ${DWBH_AWS_SECRET_KEY}
176-
mail:
177-
sourceemail: ${DWBH_AWS_EMAIL_SOURCE}
178-
region: ${DWBH_AWS_EMAIL_REGION}
179-
enabled: ${DWBH_AWS_EMAIL_ENABLED}
194+
region: ${DWBH_AWS_REGION}
180195
```
181196
182197
And environment variables:
@@ -185,9 +200,7 @@ And environment variables:
185200
|:---------------------------|:----------------------------|:--------------------------------------------------------------|
186201
| DWBH_ACCESS_KEY | AWS access key | |
187202
| DWBH_SECRET_KEY | AWS secret key | |
188-
| DWBH_AWS_EMAIL_SOURCE | AWS source email | |
189-
| DWBH_AWS_EMAIL_REGION | AWS region | |
190-
| DWBH_AWS_EMAIL_ENABLED | Enable AWS mailing | |
203+
| DWBH_AWS_REGION | AWS region | |
191204
192205
##### JWT
193206
@@ -315,7 +328,7 @@ on this project are:
315328
### Runtime
316329

317330
* [Micronaut](https://micronaut.io/) - A JVM-based micro-framework
318-
* [Jooq](https://www.jooq.org/) - Persistence framework
331+
* [Micronaut Data](https://micronaut-projects.github.io/micronaut-data/latest/guide/) - Persistence framework
319332
* [AWS API](https://aws.amazon.com/sdk-for-java/) - For AWS services (e.g. mailing)
320333

321334
### Testing

etc/site/imgs/dwbh.png

-4.72 KB
Binary file not shown.

etc/site/imgs/patio.png

3.27 KB
Loading

src/main/java/patio/infrastructure/email/services/internal/AwsSesMailService.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
*/
4242
@Singleton
4343
@Primary
44+
@RequiresAwsConfiguration
45+
@RequiresEmailConfiguration
4446
@SuppressWarnings("all")
4547
public class AwsSesMailService implements EmailService {
4648
private static final Logger LOG = LoggerFactory.getLogger(AwsSesMailService.class);
@@ -64,9 +66,9 @@ public class AwsSesMailService implements EmailService {
6466
*/
6567
public AwsSesMailService(
6668
AWSCredentialsProvider credentialsProvider,
67-
@Value("${aws.mail.enabled}") boolean emailEnabled,
68-
@Value("${aws.mail.region:none}") String awsRegion,
69-
@Value("${aws.mail.sourceemail:none}") String sourceEmail) {
69+
@Value("${email.enabled}") boolean emailEnabled,
70+
@Value("${aws.credentials.region:none}") String awsRegion,
71+
@Value("${email.source:none}") String sourceEmail) {
7072
this.credentialsProvider = credentialsProvider;
7173
this.emailEnabled = emailEnabled;
7274
this.awsRegion = awsRegion;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (C) 2019 Kaleidos Open Source SL
3+
*
4+
* This file is part of Don't Worry Be Happy (DWBH).
5+
* DWBH is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* DWBH is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with DWBH. If not, see <https://www.gnu.org/licenses/>
17+
*/
18+
package patio.infrastructure.email.services.internal;
19+
20+
import io.micronaut.context.annotation.Value;
21+
import javax.inject.Singleton;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
import patio.infrastructure.email.domain.Email;
25+
import patio.infrastructure.email.services.EmailService;
26+
27+
/**
28+
* Default email implementation. It just works as a placeholder when no other email service has been
29+
* configured
30+
*/
31+
@Singleton
32+
public class DummyEmailService implements EmailService {
33+
34+
private static final Logger LOG = LoggerFactory.getLogger(DummyEmailService.class);
35+
36+
private final boolean emailEnabled;
37+
38+
/**
39+
* Inits the service checking whether the emails should be sent or not
40+
*
41+
* @param emailEnabled whether emails should be sent or not
42+
*/
43+
public DummyEmailService(@Value("mail.enabled") boolean emailEnabled) {
44+
this.emailEnabled = emailEnabled;
45+
}
46+
47+
@Override
48+
public void send(Email email) {
49+
if (this.emailEnabled) {
50+
LOG.debug("emulate sending an email");
51+
} else {
52+
LOG.debug("email service disabled");
53+
}
54+
}
55+
56+
/**
57+
* Whether emails should be sent or not
58+
*
59+
* @return whether emails should be sent or not
60+
*/
61+
public boolean isEmailEnabled() {
62+
return emailEnabled;
63+
}
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2019 Kaleidos Open Source SL
3+
*
4+
* This file is part of Don't Worry Be Happy (DWBH).
5+
* DWBH is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* DWBH is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with DWBH. If not, see <https://www.gnu.org/licenses/>
17+
*/
18+
package patio.infrastructure.email.services.internal;
19+
20+
import io.micronaut.context.annotation.Requires;
21+
import java.lang.annotation.Documented;
22+
import java.lang.annotation.ElementType;
23+
import java.lang.annotation.Retention;
24+
import java.lang.annotation.RetentionPolicy;
25+
import java.lang.annotation.Target;
26+
27+
@Documented
28+
@Retention(RetentionPolicy.RUNTIME)
29+
@Target({ElementType.PACKAGE, ElementType.TYPE})
30+
@Requires(property = "aws.credentials.accesskey")
31+
@Requires(property = "aws.credentials.secretkey")
32+
@Requires(property = "aws.credentials.region")
33+
public @interface RequiresAwsConfiguration {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2019 Kaleidos Open Source SL
3+
*
4+
* This file is part of Don't Worry Be Happy (DWBH).
5+
* DWBH is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* DWBH is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with DWBH. If not, see <https://www.gnu.org/licenses/>
17+
*/
18+
package patio.infrastructure.email.services.internal;
19+
20+
import io.micronaut.context.annotation.Requires;
21+
import java.lang.annotation.Documented;
22+
import java.lang.annotation.ElementType;
23+
import java.lang.annotation.Retention;
24+
import java.lang.annotation.RetentionPolicy;
25+
import java.lang.annotation.Target;
26+
27+
@Documented
28+
@Retention(RetentionPolicy.RUNTIME)
29+
@Target({ElementType.PACKAGE, ElementType.TYPE})
30+
@Requires(property = "email.enabled")
31+
@Requires(property = "email.source")
32+
public @interface RequiresEmailConfiguration {}

src/main/resources/application-prod.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ aws:
5656
credentials:
5757
accesskey: ${DWBH_AWS_ACCESS_KEY}
5858
secretkey: ${DWBH_AWS_SECRET_KEY}
59-
mail:
60-
sourceemail: ${DWBH_AWS_EMAIL_SOURCE}
6159
region: ${DWBH_AWS_EMAIL_REGION}
62-
enabled: ${DWBH_AWS_EMAIL_ENABLED}
60+
61+
email:
62+
enabled: ${DWBH_EMAIL_ENABLED}
63+
source: ${DWBH_EMAIL_SOURCE}
6364

6465
crypto:
6566
password: SHA-256

src/main/resources/application.yml.template

+4-3
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ aws:
5656
credentials:
5757
accesskey: XXX
5858
secretkey: YYY
59-
mail:
60-
enabled: false
61-
sourceemail: [email protected]
6259
region: eu-west-1
6360

61+
email:
62+
enabled: false
63+
64+
6465
crypto:
6566
jwt:
6667
secret: secret

src/main/resources/logback.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<logger name="org.hibernate.SQL" level="ALL" />
3737
<logger name="org.hibernate.type.descriptor.sql" level="TRACE" />
3838
-->
39-
<logger name="dwbh.api" level="INFO" />
39+
<logger name="patio" level="DEBUG" />
4040

4141
<root level="info">
4242
<appender-ref ref="STDOUT"/>

0 commit comments

Comments
 (0)