Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
217 commits
Select commit Hold shift + click to select a range
d32b4b7
Updated for new deployment process
rodecapd Jun 7, 2024
49a0995
Updated for new deployment process
rodecapd Jun 7, 2024
58fc0fd
Merge branch '2486-create-new-pipeline-for-updated-build-deployment' …
rodecapd Jun 7, 2024
0944a06
Revert to original
rodecapd Jun 7, 2024
c5689c3
Merge branch 'develop' into 2486-create-new-pipeline-for-updated-buil…
rodecapd Jun 7, 2024
76dab2e
Updated workflow name
rodecapd Jun 7, 2024
73bfcb1
fix branch name
rodecapd Jun 7, 2024
890a5cd
move env: section
rodecapd Jun 7, 2024
6865a20
using secrets instead of env
rodecapd Jun 7, 2024
ad6883b
debugging auth
rodecapd Jun 10, 2024
18c3def
debugging auth - hardocde values
rodecapd Jun 10, 2024
ed9b591
debugging auth - add permissions
rodecapd Jun 10, 2024
8812612
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
bfdc50c
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
bfdc26e
debugging auth - revert WIP and SA
rodecapd Jun 10, 2024
31a9039
debugging auth - removed hardcoded values, updated Secrets names
rodecapd Jun 10, 2024
b37bff2
debugging run - change project id
rodecapd Jun 10, 2024
ea5c336
change service account variable name
rodecapd Jun 11, 2024
bf995b0
Updated for new deployment process
rodecapd Jun 7, 2024
c3230ea
Revert to original
rodecapd Jun 7, 2024
be027ad
Updated workflow name
rodecapd Jun 7, 2024
1a4f310
fix branch name
rodecapd Jun 7, 2024
b512c90
move env: section
rodecapd Jun 7, 2024
a0d79a9
using secrets instead of env
rodecapd Jun 7, 2024
f7942c7
debugging auth
rodecapd Jun 10, 2024
e19bf95
debugging auth - hardocde values
rodecapd Jun 10, 2024
902bda0
debugging auth - add permissions
rodecapd Jun 10, 2024
ee23b96
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
cfc4f74
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
480f6c4
debugging auth - revert WIP and SA
rodecapd Jun 10, 2024
1ea9e21
debugging auth - removed hardcoded values, updated Secrets names
rodecapd Jun 10, 2024
3c6df8e
debugging run - change project id
rodecapd Jun 10, 2024
1ef18d2
change service account variable name
rodecapd Jun 11, 2024
73b709a
Merge branch '2486-create-new-pipeline-for-updated-build-deployment' …
rodecapd Jun 13, 2024
fb05999
Updated for new deployment process
rodecapd Jun 7, 2024
6c9e9f0
Revert to original
rodecapd Jun 7, 2024
1b1e6d6
Updated workflow name
rodecapd Jun 7, 2024
7eb0331
fix branch name
rodecapd Jun 7, 2024
ab9f3ef
move env: section
rodecapd Jun 7, 2024
f4c7ac7
using secrets instead of env
rodecapd Jun 7, 2024
99f0fc4
debugging auth
rodecapd Jun 10, 2024
c7b51eb
debugging auth - hardocde values
rodecapd Jun 10, 2024
9849957
debugging auth - add permissions
rodecapd Jun 10, 2024
83c32e5
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
4bc4fd4
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
e2d8760
debugging auth - revert WIP and SA
rodecapd Jun 10, 2024
253d8bd
debugging auth - removed hardcoded values, updated Secrets names
rodecapd Jun 10, 2024
10aec2d
debugging run - change project id
rodecapd Jun 10, 2024
f623bae
change service account variable name
rodecapd Jun 11, 2024
9ab8d39
Updated for new deployment process
rodecapd Jun 7, 2024
faaa3f4
Revert to original
rodecapd Jun 7, 2024
c35b2d5
Updated workflow name
rodecapd Jun 7, 2024
ea82396
fix branch name
rodecapd Jun 7, 2024
42d7a8a
move env: section
rodecapd Jun 7, 2024
cda0353
using secrets instead of env
rodecapd Jun 7, 2024
60e8254
debugging auth
rodecapd Jun 10, 2024
a4b3a0d
debugging auth - hardocde values
rodecapd Jun 10, 2024
88c7250
debugging auth - add permissions
rodecapd Jun 10, 2024
188595c
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
dfc0c29
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
a0077ac
debugging auth - revert WIP and SA
rodecapd Jun 10, 2024
231c2a4
debugging auth - removed hardcoded values, updated Secrets names
rodecapd Jun 10, 2024
d09334a
debugging run - change project id
rodecapd Jun 10, 2024
80d6649
change service account variable name
rodecapd Jun 11, 2024
d784d33
Merge branch '2486-create-new-pipeline-for-updated-build-deployment' …
rodecapd Jun 18, 2024
598f4e6
Added VPC connector to deployment. Added permissions for Dave Rodeca…
rodecapd Jun 19, 2024
86c3f1b
Fix missing slash from gcloud run deploy command
rodecapd Jun 19, 2024
d81c8fe
Update gcloud run deploy to pull FROM_NAME from secrets manager
rodecapd Jun 19, 2024
cb44537
Updated for new deployment process
rodecapd Jun 7, 2024
75adcc7
Revert to original
rodecapd Jun 7, 2024
564fd98
Updated workflow name
rodecapd Jun 7, 2024
ce5fa6e
fix branch name
rodecapd Jun 7, 2024
4ed94ad
move env: section
rodecapd Jun 7, 2024
b63334d
using secrets instead of env
rodecapd Jun 7, 2024
e54c1b3
debugging auth
rodecapd Jun 10, 2024
32ab0ff
debugging auth - hardocde values
rodecapd Jun 10, 2024
2d44bd6
debugging auth - add permissions
rodecapd Jun 10, 2024
406108f
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
2bbc757
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
38dad05
debugging auth - revert WIP and SA
rodecapd Jun 10, 2024
c68ba92
debugging auth - removed hardcoded values, updated Secrets names
rodecapd Jun 10, 2024
fdae5c8
debugging run - change project id
rodecapd Jun 10, 2024
2b2b98a
change service account variable name
rodecapd Jun 11, 2024
2467889
Updated for new deployment process
rodecapd Jun 7, 2024
a4d6363
Revert to original
rodecapd Jun 7, 2024
aa819fb
Updated workflow name
rodecapd Jun 7, 2024
9661b41
fix branch name
rodecapd Jun 7, 2024
7eac5dd
move env: section
rodecapd Jun 7, 2024
4dd3db9
using secrets instead of env
rodecapd Jun 7, 2024
01440be
debugging auth
rodecapd Jun 10, 2024
ab7e33a
debugging auth - hardocde values
rodecapd Jun 10, 2024
c6cc422
debugging auth - add permissions
rodecapd Jun 10, 2024
55033c2
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
6bbfe39
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
469be89
debugging auth - revert WIP and SA
rodecapd Jun 10, 2024
cae8a2a
debugging auth - removed hardcoded values, updated Secrets names
rodecapd Jun 10, 2024
639257e
debugging run - change project id
rodecapd Jun 10, 2024
fa84b8d
change service account variable name
rodecapd Jun 11, 2024
26657cf
Updated for new deployment process
rodecapd Jun 7, 2024
32af3d3
Revert to original
rodecapd Jun 7, 2024
e45a7da
fix branch name
rodecapd Jun 7, 2024
c231462
move env: section
rodecapd Jun 7, 2024
896b8c4
using secrets instead of env
rodecapd Jun 7, 2024
9501b9e
debugging auth
rodecapd Jun 10, 2024
41f3a01
debugging auth - hardocde values
rodecapd Jun 10, 2024
2df11de
debugging auth - add permissions
rodecapd Jun 10, 2024
8c0feb3
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
db1e09c
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
40d2e64
debugging auth - revert WIP and SA
rodecapd Jun 10, 2024
130f32b
debugging auth - removed hardcoded values, updated Secrets names
rodecapd Jun 10, 2024
88d7f72
debugging run - change project id
rodecapd Jun 10, 2024
b638d97
change service account variable name
rodecapd Jun 11, 2024
e6cf59d
Updated for new deployment process
rodecapd Jun 7, 2024
a932a40
Revert to original
rodecapd Jun 7, 2024
e8ac02f
Updated workflow name
rodecapd Jun 7, 2024
2edf559
fix branch name
rodecapd Jun 7, 2024
061e11c
move env: section
rodecapd Jun 7, 2024
302963c
using secrets instead of env
rodecapd Jun 7, 2024
08e65e3
debugging auth
rodecapd Jun 10, 2024
6e6202a
debugging auth - hardocde values
rodecapd Jun 10, 2024
59081a1
debugging auth - add permissions
rodecapd Jun 10, 2024
376603a
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
ec65b49
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
6eb6041
debugging auth - revert WIP and SA
rodecapd Jun 10, 2024
7574256
debugging auth - removed hardcoded values, updated Secrets names
rodecapd Jun 10, 2024
2915f67
debugging run - change project id
rodecapd Jun 10, 2024
e77c6cc
change service account variable name
rodecapd Jun 11, 2024
a4e5b23
Added VPC connector to deployment. Added permissions for Dave Rodeca…
rodecapd Jun 19, 2024
b38cb02
Fix missing slash from gcloud run deploy command
rodecapd Jun 19, 2024
dc3e96a
Update gcloud run deploy to pull FROM_NAME from secrets manager
rodecapd Jun 19, 2024
90c39d3
Updates to support using the settings table
rodecapd Jul 2, 2024
24aab33
Updated for new deployment process
rodecapd Jun 7, 2024
689db51
Revert to original
rodecapd Jun 7, 2024
61543f1
fix branch name
rodecapd Jun 7, 2024
49361d3
move env: section
rodecapd Jun 7, 2024
33a8b70
using secrets instead of env
rodecapd Jun 7, 2024
4d84996
debugging auth
rodecapd Jun 10, 2024
7942cfe
debugging auth - hardocde values
rodecapd Jun 10, 2024
384acd2
debugging auth - add permissions
rodecapd Jun 10, 2024
599e3fe
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
7e89de5
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
138ebef
debugging auth - revert WIP and SA
rodecapd Jun 10, 2024
2bec28d
debugging auth - removed hardcoded values, updated Secrets names
rodecapd Jun 10, 2024
8665403
debugging run - change project id
rodecapd Jun 10, 2024
ab650ef
change service account variable name
rodecapd Jun 11, 2024
656b3f9
Updated for new deployment process
rodecapd Jun 7, 2024
13afb63
Revert to original
rodecapd Jun 7, 2024
e34e137
Updated workflow name
rodecapd Jun 7, 2024
5ac1aae
fix branch name
rodecapd Jun 7, 2024
1c721f6
move env: section
rodecapd Jun 7, 2024
1783dd1
using secrets instead of env
rodecapd Jun 7, 2024
bd90d4b
debugging auth
rodecapd Jun 10, 2024
d609149
debugging auth - hardocde values
rodecapd Jun 10, 2024
af32ff6
debugging auth - add permissions
rodecapd Jun 10, 2024
5156737
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
d87e1c1
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
87aaecc
debugging auth - revert WIP and SA
rodecapd Jun 10, 2024
059989a
debugging auth - removed hardcoded values, updated Secrets names
rodecapd Jun 10, 2024
4e0641d
debugging run - change project id
rodecapd Jun 10, 2024
17c63a3
change service account variable name
rodecapd Jun 11, 2024
c17a0e9
Updated for new deployment process
rodecapd Jun 7, 2024
5f9cb45
Revert to original
rodecapd Jun 7, 2024
ebb02ed
Updated workflow name
rodecapd Jun 7, 2024
fb32778
fix branch name
rodecapd Jun 7, 2024
9cba0e6
move env: section
rodecapd Jun 7, 2024
a8e67ed
using secrets instead of env
rodecapd Jun 7, 2024
eda0246
debugging auth
rodecapd Jun 10, 2024
d983db6
debugging auth - hardocde values
rodecapd Jun 10, 2024
dc5dd3b
debugging auth - add permissions
rodecapd Jun 10, 2024
5819ce1
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
ed33b64
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
9192926
debugging auth - revert WIP and SA
rodecapd Jun 10, 2024
781869e
debugging auth - removed hardcoded values, updated Secrets names
rodecapd Jun 10, 2024
ae1a26d
debugging run - change project id
rodecapd Jun 10, 2024
cd1a7f4
change service account variable name
rodecapd Jun 11, 2024
0580cb1
Updated for new deployment process
rodecapd Jun 7, 2024
511a1b5
Revert to original
rodecapd Jun 7, 2024
0194394
Updated workflow name
rodecapd Jun 7, 2024
1c8df8e
fix branch name
rodecapd Jun 7, 2024
5ff54c0
move env: section
rodecapd Jun 7, 2024
aa26bf9
using secrets instead of env
rodecapd Jun 7, 2024
27937e9
debugging auth
rodecapd Jun 10, 2024
98d02fb
debugging auth - hardocde values
rodecapd Jun 10, 2024
09667fe
debugging auth - add permissions
rodecapd Jun 10, 2024
d567afa
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
e3ddfa1
debugging auth - use project number instead of id
rodecapd Jun 10, 2024
5eedb3e
debugging auth - revert WIP and SA
rodecapd Jun 10, 2024
7981a0d
debugging auth - removed hardcoded values, updated Secrets names
rodecapd Jun 10, 2024
23f3144
debugging run - change project id
rodecapd Jun 10, 2024
6bed230
change service account variable name
rodecapd Jun 11, 2024
8d9ed41
Added VPC connector to deployment. Added permissions for Dave Rodeca…
rodecapd Jun 19, 2024
5e61171
Fix missing slash from gcloud run deploy command
rodecapd Jun 19, 2024
f0e8968
Update gcloud run deploy to pull FROM_NAME from secrets manager
rodecapd Jun 19, 2024
527931b
Merge branch '2486-create-new-pipeline-for-updated-build-deployment' …
rodecapd Jul 2, 2024
1ac36dc
Fix GoogleServiceConfiguration field names
timyates Jun 27, 2024
9f72ee7
Use GCP_CREDENTIALS_ENCODED_KEY for service-acct
timyates Jul 2, 2024
181f1bc
Fix tests
timyates Jul 2, 2024
7f924d9
whitespace
timyates Jul 3, 2024
9edd111
Rename env var to SERVICE_ACCOUNT_CREDENTIALS
timyates Jul 3, 2024
c7450c7
Update gradle-build-development.yml
timyates Jul 3, 2024
3054e70
Updated for new deployment process
rodecapd Jun 7, 2024
fefdc14
Updates to support using the settings table
rodecapd Jul 2, 2024
91f2abb
Removed unneeded settings, added mechanism to load and reload setting…
rodecapd Jul 9, 2024
212f8b6
Changes to fix tests, removed unneeded code.
rodecapd Jul 11, 2024
2740ad0
Changes to fix tests, removed unneeded code.
rodecapd Jul 11, 2024
f64d1b1
Removed OAUTH_CALLBACK_URI from run deployment command
rodecapd Jul 11, 2024
185deb0
Updated Settings for Directory and MJ_APIKEY_PUBLIC AND PRIVATE, and …
rodecapd Jul 19, 2024
3e7ebd9
Fix tests
rodecapd Jul 19, 2024
d1b2794
Add SERVICE_ACCOUNT_CREDENTIALS to Cloud Run deployment
rodecapd Jul 22, 2024
ee93212
Troubleshooting in GCP.
rodecapd Jul 22, 2024
8e24667
Explicitly setting the path instead of assuming a default
rodecapd Jul 22, 2024
35763a4
Add logging for debugging
rodecapd Jul 23, 2024
755cd72
Add logging for debugging
rodecapd Jul 23, 2024
f1430f1
Update settings URL
rodecapd Jul 23, 2024
c19822b
Merge branch 'develop' into 2486-create-new-pipeline-for-updated-buil…
mkimberlin Mar 17, 2025
eb66c16
Fixed a few mis-merged tests
mkimberlin Mar 17, 2025
e90d32c
Fixed a few more tests
mkimberlin Mar 17, 2025
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
Empty file.
125 changes: 125 additions & 0 deletions .github/workflows/gradle-build-poc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: Gradle Build & Deploy - POC
on:
push:
branches:
# - 'develop'
- '2486-create-new-pipeline-for-updated-build-deployment'

jobs:
build:
permissions:
id-token: 'write'
runs-on: ubuntu-latest
environment:
name: DEV-POC
# url: ${{ env.CLOUD_RUN_ADDRESS }}/
env:
PROJECT_NUMBER : ${{ secrets.PROJECT_NUM }}
PROJECT_ID: ${{ secrets.PROJECT_ID }}
PROJECT_NAME: ${{ secrets.PROJECT_NAME }}
RUN_REGION: us-central1
SERVICE_NAME: checkins-develop
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- id: 'auth_with_gcp'
uses: 'google-github-actions/auth@v2'
with:
project_id: '${{secrets.PROJECT_NUM}}'
workload_identity_provider: '${{secrets.WORKLOAD_IDENTITY_PROVIDER}}'
service_account: '${{secrets.AUTOMATION_SERVICE_ACCOUNT}}'
- id: 'secrets'
uses: 'google-github-actions/get-secretmanager-secrets@v2'
with:
secrets: |-
cloud_run_address:${{secrets.PROJECT_NUM}}/CLOUD_RUN_ADDRESS
cloud_db_connection_name:${{secrets.PROJECT_NUM}}/CLOUD_DB_CONNECTION_NAME
connector_id:${{secrets.PROJECT_NUM}}/CONNECTOR_ID
- name: Set up Node LTS
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: 21
- name: Cache SonarQube packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
- name: Build with Gradle
uses: gradle/gradle-build-action@4137be6a8bf7d7133955359dbd952c0ca73b1021
with:
arguments: assemble
env:
VITE_APP_API_URL: ${{steps.secrets.outputs.cloud_run_address}}
- name: Gradle runs tests
uses: gradle/gradle-build-action@4137be6a8bf7d7133955359dbd952c0ca73b1021
with:
arguments: check
# - name: Do SonarQube checks
# uses: gradle/gradle-build-action@4137be6a8bf7d7133955359dbd952c0ca73b1021
# with:
# arguments: sonarqube --info
# env:
# GITHUB_TOKEN: ${{ secrets.GIT_HUB_TOKEN }}
# SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Setup python
run: |
sudo apt-get install python2.7
- name: Export gcloud related env variable
run: export CLOUDSDK_PYTHON="/usr/bin/python2"
# Setup gcloud CLI
- uses: google-github-actions/setup-gcloud@v2
with:
version: "477.0.0"
# service_account_key: ${{ secrets.RUN_SA_KEY }}
# project_id: ${{ secrets.RUN_PROJECT }}
- name: Auth Configure Docker
run: |-
gcloud --quiet auth configure-docker
- name: Build the Docker image
run: |-
cd server
docker build --tag "gcr.io/$PROJECT_ID/$SERVICE_NAME:$GITHUB_SHA" .
- name: Push the Docker image to Google Container Registry
run: |-
cd server
docker push "gcr.io/$PROJECT_ID/$SERVICE_NAME:$GITHUB_SHA"
- name: Deploy image to Cloud Run
run: |-
gcloud run deploy "$SERVICE_NAME" \
--project "$PROJECT_ID" \
--region "$RUN_REGION" \
--image "gcr.io/$PROJECT_ID/$SERVICE_NAME:$GITHUB_SHA" \
--memory 1Gi \
--add-cloudsql-instances ${{steps.secrets.outputs.cloud_db_connection_name }} \
--vpc-connector ${{steps.secrets.outputs.connector_id}} \
--set-secrets "CLOUD_DB_CONNECTION_NAME=CLOUD_DB_CONNECTION_NAME:latest" \
--set-secrets "DB_NAME=DB_NAME:latest" \
--set-secrets "DATASOURCES_DEFAULT_PASSWORD=DATASOURCES_DEFAULT_PASSWORD:latest" \
--set-secrets "DATASOURCES_DEFAULT_USERNAME=DATASOURCES_DEFAULT_USERNAME:latest" \
--set-secrets "AES_KEY=AES_KEY:latest" \
--set-secrets "OAUTH_CLIENT_ID=OAUTH_CLIENT_ID:latest" \
--set-secrets "OAUTH_CLIENT_SECRET=OAUTH_CLIENT_SECRET:latest" \
--set-secrets "GSUITE_SUPER_ADMIN=GSUITE_SUPER_ADMIN:latest" \
--set-secrets "SERVICE_ACCOUNT_CREDENTIALS=SERVICE_ACCOUNT_CREDENTIALS:latest" \
--set-secrets "WEB_ADDRESS=CLOUD_RUN_ADDRESS:latest" \
--set-secrets "MICRONAUT_ENVIRONMENTS=MICRONAUT_ENVIRONMENTS:latest" \
--platform "managed" \
--max-instances 2 \
--allow-unauthenticated

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
import com.mailjet.client.MailjetClient;

import com.mailjet.client.resource.Emailv31;
import com.objectcomputing.checkins.exceptions.NotFoundException;
import com.objectcomputing.checkins.services.settings.SettingOption;
import com.objectcomputing.checkins.services.settings.SettingsServices;
import io.micronaut.context.annotation.Bean;
import io.micronaut.context.annotation.Factory;

import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.inject.Singleton;

Expand All @@ -17,13 +21,33 @@ public class MailJetFactory {
public static final String MJML_FORMAT = "mjml";
public static final String TEXT_FORMAT = "text";

@Inject
SettingsServices settingsServices;

@Bean
MailjetClient getClient() {

String mj_apikey_public;
String mj_apikey_private;

try {
mj_apikey_public = settingsServices.findByName(SettingOption.MJ_APIKEY_PUBLIC.name()).getValue();
} catch (NotFoundException e) {
mj_apikey_public = "";
}
try {
mj_apikey_private = settingsServices.findByName(SettingOption.MJ_APIKEY_PRIVATE.name()).getValue();
} catch (NotFoundException e) {
mj_apikey_private = "";
}



return new MailjetClient(
ClientOptions
.builder()
.apiKey(System.getenv("MJ_APIKEY_PUBLIC"))
.apiSecretKey(System.getenv("MJ_APIKEY_PRIVATE"))
.apiKey(mj_apikey_public)
.apiSecretKey(mj_apikey_private)
.build()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import com.mailjet.client.resource.Emailv31;
import ch.digitalfondue.mjml4j.Mjml4j;
import com.objectcomputing.checkins.exceptions.BadArgException;
import com.objectcomputing.checkins.exceptions.NotFoundException;
import com.objectcomputing.checkins.services.settings.SettingOption;
import com.objectcomputing.checkins.services.settings.SettingsServices;
import io.micronaut.context.annotation.Prototype;
import io.micronaut.context.annotation.Requires;
import org.json.JSONArray;
Expand All @@ -19,27 +22,40 @@
import java.util.List;

@Prototype
@Requires(bean = MailJetConfiguration.class)
public class MailJetSender implements EmailSender {
public static final String MJMLPART = "MJMLPART";

private static final Logger LOG = LoggerFactory.getLogger(MailJetSender.class);
private final MailjetClient client;
private final SettingsServices settingsServices;

public static final int MAILJET_RECIPIENT_LIMIT = 49;

private final String fromAddress;
private final String fromName;
private String emailFormat;

private String getFromAddress() {
try {
return settingsServices.findByName(SettingOption.FROM_ADDRESS.name()).getValue();
} catch (NotFoundException e) {
return "";
}
}

private String getFromName() {
try {
return settingsServices.findByName(SettingOption.FROM_NAME.name()).getValue();
} catch (NotFoundException e) {
return "";
}
}

public MailJetSender(
MailjetClient client,
MailJetConfiguration configuration
SettingsServices settingsServices
) {
this.client = client;
this.fromAddress = configuration.getFromAddress();
this.fromName = configuration.getFromName();
this.emailFormat = Emailv31.Message.HTMLPART;
this.settingsServices = settingsServices;
}

/**
Expand Down Expand Up @@ -82,10 +98,23 @@ public static List<JSONArray> getEmailBatches(String... recipients) {
*/
@Override
public void sendEmail(String fromName, String fromAddress, String subject, String content, String... recipients) {
if(fromName == null) fromName = this.fromName;
if(fromAddress == null) fromAddress = this.fromAddress;
if(fromName == null) fromName = getFromName();
if(fromAddress == null) fromAddress = getFromAddress();

String mj_apikey_public;
String mj_apikey_private;
try {
mj_apikey_public = settingsServices.findByName(SettingOption.MJ_APIKEY_PUBLIC.name()).getValue();
} catch (NotFoundException e) {
mj_apikey_public = "";
}
try {
mj_apikey_private = settingsServices.findByName(SettingOption.MJ_APIKEY_PRIVATE.name()).getValue();
} catch (NotFoundException e) {
mj_apikey_private = "";
}

if(System.getenv("MJ_APIKEY_PUBLIC") == null || System.getenv("MJ_APIKEY_PRIVATE") == null) {
if(mj_apikey_public == "" || mj_apikey_private == "") {
LOG.error("API key(s) are missing for MailJetSender");
return;
}
Expand Down Expand Up @@ -117,7 +146,7 @@ public void sendEmail(String fromName, String fromAddress, String subject, Strin
List<JSONArray> failedBatches = new ArrayList<>();
final JSONArray to =
new JSONArray()
.put(new JSONObject().put("Email", this.fromAddress));
.put(new JSONObject().put("Email", fromAddress));
emailBatches.forEach((recipientList) -> {
try {
send(sender, to, recipientList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.micronaut.validation.validator.constraints.ConstraintValidator;
import jakarta.inject.Singleton;
import jakarta.validation.Constraint;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.slf4j.Logger;
Expand All @@ -29,9 +28,6 @@ public class GoogleServiceConfiguration {

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

@NotNull
private String directoryId;

@ValidEncodedGoogleServiceConfiguration
private String encodedValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.File;
import com.google.api.services.drive.model.FileList;
import com.objectcomputing.checkins.exceptions.NotFoundException;
import com.objectcomputing.checkins.security.GoogleServiceConfiguration;
import com.objectcomputing.checkins.services.checkindocument.CheckinDocument;
import com.objectcomputing.checkins.services.checkindocument.CheckinDocumentServices;
Expand All @@ -14,10 +15,11 @@
import com.objectcomputing.checkins.services.memberprofile.MemberProfileServices;
import com.objectcomputing.checkins.services.memberprofile.MemberProfileUtils;
import com.objectcomputing.checkins.services.memberprofile.currentuser.CurrentUserServices;
import com.objectcomputing.checkins.services.settings.SettingOption;
import com.objectcomputing.checkins.services.settings.SettingsServices;
import com.objectcomputing.checkins.util.googleapiaccess.GoogleApiAccess;
import io.micronaut.http.MediaType;
import io.micronaut.http.multipart.CompletedFileUpload;

import jakarta.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -38,17 +40,20 @@ public class FileServicesImpl extends FileServicesBaseImpl {

private final GoogleApiAccess googleApiAccess;
private final GoogleServiceConfiguration googleServiceConfiguration;
private SettingsServices settingsServices;

public FileServicesImpl(GoogleApiAccess googleApiAccess,
CheckInServices checkInServices,
CheckinDocumentServices checkinDocumentServices,
MemberProfileServices memberProfileServices,
CurrentUserServices currentUserServices,
GoogleServiceConfiguration googleServiceConfiguration) {
GoogleServiceConfiguration googleServiceConfiguration,
SettingsServices settingsServices) {
super(checkInServices, checkinDocumentServices, memberProfileServices,
currentUserServices);
this.googleApiAccess = googleApiAccess;
this.googleServiceConfiguration = googleServiceConfiguration;
this.settingsServices = settingsServices;
}

@Override
Expand All @@ -58,8 +63,8 @@ protected void getCheckinDocuments(
Drive drive = googleApiAccess.getDrive();
validate(drive == null, "Unable to access Google Drive");

String rootDirId = googleServiceConfiguration.getDirectoryId();
validate(rootDirId == null, "No destination folder has been configured. Contact your administrator for assistance.");
String rootDirId = getRootDirId();
validate(rootDirId == null || rootDirId == "", "No destination folder has been configured. Contact your administrator for assistance.");

if (checkinDocuments.isEmpty()) {
FileList driveIndex = getFoldersInRoot(drive, rootDirId);
Expand Down Expand Up @@ -87,6 +92,17 @@ protected void getCheckinDocuments(
}
}

private String getRootDirId() {
String rootDirId;
try {
rootDirId = settingsServices.findByName(SettingOption.DIRECTORY_ID.name()).getValue();
}
catch (NotFoundException e ) {
rootDirId = "";
}
return rootDirId;
}

@Override
protected void downloadSingleFile(String docId, FileOutputStream myWriter) throws IOException {
Drive drive = googleApiAccess.getDrive();
Expand All @@ -103,7 +119,7 @@ protected FileInfoDTO uploadSingleFile(CompletedFileUpload file, String director
Drive drive = googleApiAccess.getDrive();
validate(drive == null, "Unable to access Google Drive");

String rootDirId = googleServiceConfiguration.getDirectoryId();
String rootDirId = getRootDirId();
validate(rootDirId == null, "No destination folder has been configured. Contact your administrator for assistance.");

// Check if folder already exists on google drive. If exists, return folderId and name
Expand Down Expand Up @@ -153,7 +169,7 @@ public FileInfoDTO uploadDocument(String directoryName, String name, String text
Drive drive = googleApiAccess.getDrive();
validate(drive == null, "Unable to access Google Drive");

String rootDirId = googleServiceConfiguration.getDirectoryId();
String rootDirId = getRootDirId();
validate(rootDirId == null, "No destination folder has been configured. Contact your administrator for assistance.");

// Check if folder already exists on google drive. If exists, return folderId and name
Expand Down
Loading
Loading