This is a Spring Boot-based utility application that interacts with a MongoDB database and provides an interface for saving, retrieving, and deleting documents in MongoDB. The documents that are saved represent runtime variables that can be consumed by other applications as and when needed. A new MongoDb collection is created for each application, and the application name should be sent with each request.
- Create: Persist data into a MongoDB collection. A new collection is created for each new application
- Read: Fetch stored documents from the corresponding MongoDB collection
- Update: Update functionality is not provided. If a document needs to be updated, it has to be recreated after deleting first.
- Delete: Delete document from a MongoDB collection
- Java
- Spring Boot
- Gradle
- MongoDB
- JUnit
- OpenApi
- git clone https://github.com/bibekaryal86/env-service.git
- Navigate to the project directory
cd env-service
- Build the project
./gradlew clean build
- Run the application
- The application requires the following environment variables to be provided at runtime:
- AUTH_USR: Username of Basic Authentication implemented in the application
- AUTH_PWD: Password of Basic Authentication implemented in the application
- MONGO_APP: MongoDB Application name, required/found in MongoDB connection string
- MONGO_DB: MongoDB Database name, required/found in MongoDB connection string
- MONGO_USR: MongoDB Database user name, required/found in MongoDB connection string
- MONGO_PWD: MongoDB Database user password, required/found in MongoDB connection string
- SPRING_PROFILES_ACTIVE: development or production or any, this is optional but best to set
- Profile
springboottest
is used when running JUnit tests - There are matching
springProfile
configuration inlogback.xml
- Profile
- Run command:
- java -jar -DAUTH_USR=some_username -DAUTH_PWD=some_password -DMONGO_APP=some_app -DMONGO_DB=some_database -DMONGO_USR=another_user -DMONGO_PWD=another_password SPRING_PROFILES_ACTIVE=production app/build/libs/env-service.jar
- The application requires the following environment variables to be provided at runtime:
- GET /tests/ping
- Returns
{"ping": "successful"}
, no other functionalities
- Returns
- POST /api/v1/{appName}
- Create a document in collection for
appName
- If a collection doesn't exist for the
appName
, collection is created and then the document in the collection - Constraints:
- There can not be two documents with same
name
attribute in a collection - A document must have
name
and one of eitherstringValue
,listValue
ormapValue
field populated
- There can not be two documents with same
- Create a document in collection for
- GET /api/v1/{appName}
- Retrieve all documents in collection for
appName
- Retrieve all documents in collection for
- PUT /api/v1/{appName}/{id}
- Update is not allowed, this returns
Method Not Allowed
response
- Update is not allowed, this returns
- DELETE /api/v1/{appName}/{envDetailsName}
- Delete a document in collection for
appName
whereenvDetailsName
matchesname
attribute in the document
- Delete a document in collection for
This is currently deployed to Google Cloud Platform App Engine's Free Tier:
- https://envsvc.appspot.com/envsvc/tests/ping
- Deployment instructions:
- Build the project:
./gradlew clean build
- Copy the generated jar file to the
gcp
library:cp app/build/libs/env-service.jar gcp
- Configure
app-credentials.yaml
- copy
app-credentials_DUMMY.yaml
and update with actual values
- copy
- Deploy to app engine:
gcloud app deploy app.yaml
- Best to start the process from
gcloud init
to select correct gcp project to deploy to
- Best to start the process from
- Build the project: