Skip to content

Commit

Permalink
feat: Set termii api key as a variable to the SmsOtpService.kt Singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
cybersokari committed May 3, 2024
1 parent c2e2037 commit be2acae
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 345 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,3 @@ firebase.json
storage.rules
ui-debug.log

## Firebase service account key
src/main/resources/service-account.json
94 changes: 0 additions & 94 deletions GCP_VM_SETUP.md

This file was deleted.

57 changes: 57 additions & 0 deletions HANDY_COMMANDS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Some handy commands to help you during development

Access the VM via SSH with Google Cloud CLI
```shell
$ gcloud compute ssh [vm-name]
```

Pull docker image from Artifact Registry
```shell
$ docker pull gcr.io/[project-id]/[image-name]
```
Run a container on your machine
```shell
$ docker run -ti --rm -p 8080:80 gcr.io/[project-id]/[image-name]
```

### Add tag to Compute Engine VM
```shell
$ gcloud compute instances add-tags [vm-name] --tags=[tag-name]
```
### Create Firewall rule for access to the VM
```shell
gcloud compute firewall-rules create [rule-name] \
--project=[project-id] \
--network=[network-name] \
--source-ranges=0.0.0.0/0 \
--target-tags=[vm-tag-name] \
--allow=tcp:[port-number]
```

## Update Ops Agent config on the VM
### Grant permission
```shell
$ sudo chmod u+o /etc/google-cloud-ops-agent/
```
### Deploy custom Ops Agent Config
```shell
gcloud compute scp config.yaml [vm-name]:/etc/google-cloud-ops-agent/config.yaml
```
Replace `[vm-name]` with the name of the new VM

## Find processes using a port
```shell
$ sudo lsof -i:[port-number]
```

## Create a new tmux session
```shell
$ tmux new -s [session-name]
```
Detach from a tmux session`Ctrl + B`, then release both keys and press `D`.
To reattach to the session run ``$ tmux attach-session``. If the is more than one session running `` $ tmux attach-session -t my_session``

## Run a java application
```shell
$ java -jar [file-path].jar
```
46 changes: 11 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
![coverage][coverage_badge]
## Before diving in 🙌

- Have a look into our [Contributing Guide](./.github/CONTRIBUTING.md)
- Our recommend IDE for this project is IntelliJ, but you can use any IDE that supports Springboot
- Request access to the `Firebase Developer Console` and `MongoDB Atlas console`
- Request access to the `Google Cloud Developer Console` and `MongoDB Atlas console`
- Install the latest stable version of [Maven](https://maven.apache.org/docs/history.html). This will be your main version across your machine.

## Getting Started 🚀
Expand All @@ -20,31 +19,13 @@ To run the desired profile use `mvn spring-boot:run -P dev|prod`
## Setup MongoDB



### Springboot application.properties for production environment

Create a `application-prod.properties` file in `src/main/resources` directory and add the following variables with the appropriate values

```properties
spring.application.name=gated_access_service
spring.data.mongodb.auto-index-creation=true
spring.data.mongodb.uri=string
springdoc.api-docs.enabled=false
```

### Packaging for deployment
Run
```sh
$ mvn clean package
```
The following file are required in the `src/main/resources` directory, but are not available in Git for security purposes
1. `application-prod.properties` file for data url and production configs
2. `service-account.json` file for Firebase Admin SDK

## Creating Routes

Routes can be found in `src/main/***/http/controller`
There is a `BaseController.kt` abstract class that every `@RestController` can must inherit.
## Creating Mongo Documents and Repositories
Documents can be found in `src/main/***/model`
Repositories can be found in `src/main/***/repository`


### Logging
This app uses [Logback](https://logback.qos.ch/manual) for logging. You can find the config in `/src/main/resources` folder
Expand All @@ -65,33 +46,28 @@ The app runs on a Google Compute Engine VM with full GCP API permissions and req

### Publishing a new version to Google Artifact Registry
You will need to have write access to our Google Artifact Registry.
Run the ``mvn clean package`` command to publish the new version to Google Artifact Registry

1. Run the ``mvn clean package`` command to publish the new version to Google Artifact Registry
2. Run the gcloud
### Updating the container image with the new image version
It takes the Compute Engine VM 20 to 30 seconds to update the container image. So we try not to run the following command
at peak hours of the day if possible.
```shell
$ gcloud compute instances update-container [instance-name] --zone=[zone-name] --container-image=[container-image-name]
```
Replace the `instance-name`, `zone-name` and `container-image-name` with the appropriate values.

### Inspecting the app on the VM
While will not need to log into the VM to get telementry information, you can SSH into the VM and run the following command to inspect the app
While will not need to log into the VM to get Telementry information, you can SSH into the VM and run the following command to inspect the app
1. Run ``docker ps`` to view the docker instances running
2. Run ``docker attach [container-id]`` to attach to the container and start seeing logs. Note that you will only see logs from when you attach, not the past logs.

Use Cloud logging to inspect the logs and health of the machine.





## Running Tests 🧪
## Tests 🧪
### Unit test
### Integration test


---

## Folder Architecture 🚀


Here are tips on [how to optimize java application](https://cloud.google.com/run/docs/tips/java).
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
<groupId>com.google.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-secretmanager</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.google.cloud</groupId>-->
<!-- <artifactId>spring-cloud-gcp-secretmanager</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand All @@ -53,22 +49,29 @@
<artifactId>firebase-admin</artifactId>
<version>9.2.0</version>
<exclusions>
<!-- https://devhub.checkmarx.com/cve-details/CVE-2023-2976/-->
<!-- Excluding old version due to exploit-->
<!-- https://devhub.checkmarx.com/cve-details/CVE-2023-2976/-->
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
<!-- Excluding old version due to exploit-->
<!-- https://devhub.checkmarx.com/cve-details/CVE-2023-2976/-->
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Using a later version due to exploit-->
<!-- https://devhub.checkmarx.com/cve-details/CVE-2023-2976/-->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.0-jre</version>
</dependency>
<!-- Using a later version due to exploit-->
<!-- https://devhub.checkmarx.com/cve-details/CVE-2023-2976/-->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
Expand Down Expand Up @@ -140,9 +143,6 @@
<filter>
<glob>**/service-account.json</glob>
</filter>
<filter>
<glob>**/vm-service-key.json</glob>
</filter>
</filters>
</configuration>
</pluginExtension>
Expand Down
Loading

0 comments on commit be2acae

Please sign in to comment.