Skip to content

Commit

Permalink
Add Virtual Objects (#479)
Browse files Browse the repository at this point in the history
* feat(api) replace - by _

To be uniform with collections and category fields

* feat(api) implement virtual objs

* fix(back) force remove network on delete tenant

* feat(cli) add virtual objs

* feat(app) add virtual objs

* feat(app) add translations

* fix(cli) replace - by _

* fix(cli) replace - by _

* fix(api) get phierarchy with vobj

* fix(api) vobj always with tags

* feat(cli) add layers to virtual

* feat(api) adjustments for virtual

* fix(cli) tests

* fix(api) tests

* refactor(api) simplify validateParent

* refactor(cli) simplify name change on virtual root

* refactor(cli) simplify layer FromObjects

* refactor(cli) simplify update vlinks

* feat(cli) add +vobj tests

* feat(cli) add vlink update test

* feat(cli) test ls vobj

* feat(api) update test and doc

* refactor(api) improve Cognitive Complexity

* fix(api) fix tests

* Feat476 virtual objects (#2)

* feat(api) replace - by _

To be uniform with collections and category fields

* feat(api) implement virtual objs

* fix(back) force remove network on delete tenant

* feat(cli) add virtual objs

* feat(app) add virtual objs

* feat(app) add translations

* fix(cli) replace - by _

* fix(cli) replace - by _

* fix(api) get phierarchy with vobj

* fix(api) vobj always with tags

* feat(cli) add layers to virtual

* feat(api) adjustments for virtual

* fix(cli) tests

* fix(api) tests

* refactor(api) simplify validateParent

* refactor(cli) simplify name change on virtual root

* refactor(cli) simplify layer FromObjects

* refactor(cli) simplify update vlinks

* feat(cli) add +vobj tests

* feat(cli) add vlink update test

* feat(cli) test ls vobj

* feat(api) update test and doc

* refactor(api) improve Cognitive Complexity

* fix(api) fix tests

* refactor(api) improve Cognitive Complexity

* fix(api) remove duplicate

* feat(cli,api) nodes on both namespaces

* feat(app) add graph view

* feat(app) add graph view

* feat(api) update readme

* feat(app) add complex filter
  • Loading branch information
helderbetiol authored Jun 20, 2024
1 parent ae3b92e commit 77ce4a9
Show file tree
Hide file tree
Showing 70 changed files with 1,743 additions and 835 deletions.
77 changes: 17 additions & 60 deletions API/ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# Notes for The API
Designed with JWT, MongoDB and CI tested using Jenkins and docker with a
script to start up MongoDB
# OGrEE-API


Introduction
------------
This is an API interfacing with a MongoDB cluster for data centre management.


Expand Down Expand Up @@ -49,15 +44,8 @@ For Linux, consult your respective Distribution docs

Running
-------------
You can modify the port of the API in the .env file. This is the port that the API will use to listen for requests.
- Navigate in your terminal to the ```init_db``` directory
- Execute the bash script ```ogreeBoot.sh```
- Enter your password when the prompt asks you
- Be sure to enter your user password and the desired the DB access password
- Update your .env file ```db_user=myCompanyName``` and ```db_pass=dbAccessPassword```
- Execute the binary ```main```

This .env file is not provided, so you must create it yourself. Here is an example of the ```.env``` file:
This .env file is not provided, so you must create it yourself. Here is an example of the ```.env``` file to be placed in this same directory (`API/`):
```
PORT = 3001
db_host = 0.0.0.0
Expand All @@ -72,59 +60,28 @@ email_password = ""
reset_url = "http://localhost:8082/#/reset?token="
```

Jenkins
--------------------------

### Jenkins Standalone

### External URL
```
ci.ogree.ditrit.io
```

This is easier but less portable
Execute the following:
```
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb https://pkg.jenkins.io/debian binary/ > \
/etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins
```
### With Docker Compose

I then got an error with Failed to start LSB: Start Jenkins at boot time.
This was fixed by installing default-jre default-jdk and ensuring that
Java is installed. Strangely, it requires Java 8 while insisting that support
for Java 11 is limited but works with Java 11
There is a development version of the docker deploy with the following features:

Now to select the HTTP Port edit the file: /etc/default/jenkins
* The MongoDB database is accessible on the `DB_PORT` (27017 by default) port. This will allow you to connect to the database using mongosh or mongodb-compass using the following url: `mongodb://ogreemytenantAdmin:pass123@localhost:27017/ogreemytenant?authSource=ogreemytenant&directConnection=true`.
* HotReload for the api: each time a change is made to the code, the api is recompiled and relaunched.

Jenkins username:
```
admin
```
Jenkins password:
```
9f4e634c5d174af9b2f35f30abe2a0d5
```
This version can be launched by running the following command in the `OGrEE-Core/deploy/` folder:

Encountered a permission denied error while trying to build a docker container in the pipeline which was solved by using these commands:
```
sudo usermod -aG docker jenkins
sudo systemctl restart jenkins
```bash
OGrEE-Core/deploy/> make dev_api
```
The problem with this is that the docker group has root permissions so this is risky, I will look into a better solution later

MongoDB
--------------------------
A document (JSON) Based Database. The current DB can be started using the **ogreemdb.sh** script found in the root dir. The most useful interface for the DB is to access the shell. If you have started the DB already using the script you can directly execute this command to access the DB Shell
```
mongo --shell
```
### With local Mongo

Running a MongoDB container
--------------------------
docker run --name mdb -v /home/ziad/mongoDir:/docker-entrypoint-initdb.d/ -p 27017:27017 -d mongo:latest
Considering you have a local Mongo installed, you can create a database locally to then connect your local API:
- Navigate in your terminal to the ```deploy/db``` directory
- Execute the bash script ```ogreeBoot.sh```
- Enter your password when the prompt asks you
- Be sure to enter your user password and the desired the DB access password
- Update your .env file ```db_user=myCompanyName``` and ```db_pass=dbAccessPassword```
- Execute the binary ```main```

Swagger Docs
--------------------------
Expand Down
4 changes: 0 additions & 4 deletions API/app/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ var JwtAuthentication = func(next http.Handler) http.Handler {
if tokenHeader == "" {
response = u.Message("Missing auth token")
w.WriteHeader(http.StatusForbidden)
w.Header().Add("Content-Type", "application/json")
u.Respond(w, response)
return
}
Expand All @@ -58,7 +57,6 @@ var JwtAuthentication = func(next http.Handler) http.Handler {
if len(splitted) != 2 {
response = u.Message("Invalid/Malformed auth token")
w.WriteHeader(http.StatusForbidden)
w.Header().Add("Content-Type", "application/json")
u.Respond(w, response)
return
}
Expand All @@ -75,7 +73,6 @@ var JwtAuthentication = func(next http.Handler) http.Handler {
if err != nil {
response = u.Message("Malformed authentication token")
w.WriteHeader(http.StatusForbidden)
w.Header().Add("Content-Type", "application/json")
u.Respond(w, response)
return
}
Expand All @@ -84,7 +81,6 @@ var JwtAuthentication = func(next http.Handler) http.Handler {
if !token.Valid || ((tk.Email == u.RESET_TAG) != (requestPath == "/api/users/password/reset")) {
response = u.Message("Token is not valid.")
w.WriteHeader(http.StatusForbidden)
w.Header().Add("Content-Type", "application/json")
u.Respond(w, response)
return
}
Expand Down
Loading

0 comments on commit 77ce4a9

Please sign in to comment.