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

feat(mail): refactor email service loading and docs #96

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to DWBH
# Contributing to Patio

We love your input! We want to make contributing to this project as easy and transparent as possible,
whether it's:
Expand Down
39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
[![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)
![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)

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

![dwbh](etc/site/imgs/dwbh.png)

**Don't Worry Be Happy** is a web application that tries to measure the happiness of a given team periodically by
**Patio** is a web application that tries to measure the happiness of a given team periodically by
asking for a level of happiness between 1 and 5 (being 1 the saddest scenario and 5 the happiest). This repository
hosts the backend of the DWBH project. Cool!

Expand Down Expand Up @@ -164,19 +162,36 @@ And environment variables
| DWBH_JDBC_PASSWORD | JDBC password | dwbh |
| DWBH_JDBC_DRIVER | JDBC driver | org.postgresql.Driver |

##### EMAIL

By default, if no other email service has been configured a default dummy service will be used to debug email mailing. You
can, for example, configure AWS credentials to enable AWS mailing service.

```yaml
email:
source: ${DWBH_EMAIL_SOURCE}
enabled: ${DWBH_EMAIL_ENABLED}
```

And environment variables:

| Name | Description | Default value |
|:---------------------------|:----------------------------|:--------------------------------------------------------------|
| DWBH_EMAIL_SOURCE | Source email | |
| DWBH_EMAIL_ENABLED | Enable mailing | |

##### AWS integration

AWS credentials to use AWS services, such as AWS simple mail service.

Configuration file section:

```yaml
aws:
credentials:
accessKey: ${DWBH_AWS_ACCESS_KEY}
secretKey: ${DWBH_AWS_SECRET_KEY}
mail:
sourceemail: ${DWBH_AWS_EMAIL_SOURCE}
region: ${DWBH_AWS_EMAIL_REGION}
enabled: ${DWBH_AWS_EMAIL_ENABLED}
region: ${DWBH_AWS_REGION}
```

And environment variables:
Expand All @@ -185,9 +200,7 @@ And environment variables:
|:---------------------------|:----------------------------|:--------------------------------------------------------------|
| DWBH_ACCESS_KEY | AWS access key | |
| DWBH_SECRET_KEY | AWS secret key | |
| DWBH_AWS_EMAIL_SOURCE | AWS source email | |
| DWBH_AWS_EMAIL_REGION | AWS region | |
| DWBH_AWS_EMAIL_ENABLED | Enable AWS mailing | |
| DWBH_AWS_REGION | AWS region | |

##### JWT

Expand Down Expand Up @@ -315,7 +328,7 @@ on this project are:
### Runtime

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

### Testing
Expand Down
Binary file removed etc/site/imgs/dwbh.png
Binary file not shown.
Binary file added etc/site/imgs/patio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
*/
@Singleton
@Primary
@RequiresAwsConfiguration
@RequiresEmailConfiguration
@SuppressWarnings("all")
public class AwsSesMailService implements EmailService {
private static final Logger LOG = LoggerFactory.getLogger(AwsSesMailService.class);
Expand All @@ -64,9 +66,9 @@ public class AwsSesMailService implements EmailService {
*/
public AwsSesMailService(
AWSCredentialsProvider credentialsProvider,
@Value("${aws.mail.enabled}") boolean emailEnabled,
@Value("${aws.mail.region:none}") String awsRegion,
@Value("${aws.mail.sourceemail:none}") String sourceEmail) {
@Value("${email.enabled}") boolean emailEnabled,
@Value("${aws.credentials.region:none}") String awsRegion,
@Value("${email.source:none}") String sourceEmail) {
this.credentialsProvider = credentialsProvider;
this.emailEnabled = emailEnabled;
this.awsRegion = awsRegion;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2019 Kaleidos Open Source SL
*
* This file is part of Don't Worry Be Happy (DWBH).
* DWBH is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DWBH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DWBH. If not, see <https://www.gnu.org/licenses/>
*/
package patio.infrastructure.email.services.internal;

import io.micronaut.context.annotation.Value;
import javax.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import patio.infrastructure.email.domain.Email;
import patio.infrastructure.email.services.EmailService;

/**
* Default email implementation. It just works as a placeholder when no other email service has been
* configured
*/
@Singleton
public class DummyEmailService implements EmailService {

private static final Logger LOG = LoggerFactory.getLogger(DummyEmailService.class);

private final boolean emailEnabled;

/**
* Inits the service checking whether the emails should be sent or not
*
* @param emailEnabled whether emails should be sent or not
*/
public DummyEmailService(@Value("mail.enabled") boolean emailEnabled) {
this.emailEnabled = emailEnabled;
}

@Override
public void send(Email email) {
if (this.emailEnabled) {
LOG.debug("emulate sending an email");
} else {
LOG.debug("email service disabled");
}
}

/**
* Whether emails should be sent or not
*
* @return whether emails should be sent or not
*/
public boolean isEmailEnabled() {
return emailEnabled;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2019 Kaleidos Open Source SL
*
* This file is part of Don't Worry Be Happy (DWBH).
* DWBH is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DWBH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DWBH. If not, see <https://www.gnu.org/licenses/>
*/
package patio.infrastructure.email.services.internal;

import io.micronaut.context.annotation.Requires;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PACKAGE, ElementType.TYPE})
@Requires(property = "aws.credentials.accesskey")
@Requires(property = "aws.credentials.secretkey")
@Requires(property = "aws.credentials.region")
public @interface RequiresAwsConfiguration {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2019 Kaleidos Open Source SL
*
* This file is part of Don't Worry Be Happy (DWBH).
* DWBH is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DWBH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DWBH. If not, see <https://www.gnu.org/licenses/>
*/
package patio.infrastructure.email.services.internal;

import io.micronaut.context.annotation.Requires;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PACKAGE, ElementType.TYPE})
@Requires(property = "email.enabled")
@Requires(property = "email.source")
public @interface RequiresEmailConfiguration {}
7 changes: 4 additions & 3 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ aws:
credentials:
accesskey: ${DWBH_AWS_ACCESS_KEY}
secretkey: ${DWBH_AWS_SECRET_KEY}
mail:
sourceemail: ${DWBH_AWS_EMAIL_SOURCE}
region: ${DWBH_AWS_EMAIL_REGION}
enabled: ${DWBH_AWS_EMAIL_ENABLED}

email:
enabled: ${DWBH_EMAIL_ENABLED}
source: ${DWBH_EMAIL_SOURCE}

crypto:
password: SHA-256
Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/application.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ aws:
credentials:
accesskey: XXX
secretkey: YYY
mail:
enabled: false
sourceemail: [email protected]
region: eu-west-1

email:
enabled: false
source: [email protected]

crypto:
jwt:
secret: secret
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<logger name="org.hibernate.SQL" level="ALL" />
<logger name="org.hibernate.type.descriptor.sql" level="TRACE" />
-->
<logger name="dwbh.api" level="INFO" />
<logger name="patio" level="DEBUG" />

<root level="info">
<appender-ref ref="STDOUT"/>
Expand Down