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

Release v0.1.1 #20

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ This project consist in 4 folders:

## Requirements:

- Go >= 1.22(recommended)
- Go == 1.22
- Docker
- Docker-compose
- Node >= 20.10.0(recommended)
- Graphviz(if you want to generate the profiling graphs)

## I just want to see the project running!

- Give write permission:
- Give permissions:
```bash
| chmod a+rwx ./data-embedding
chmod +x envs.sh
chmod a+rwx ./data-embedding
```
- Only follow the instructions of [data-embedding](#data-embedding)
- Then run the following commands:
```bash
. envs.sh
cd docker
docker-compose up
```
Expand All @@ -34,6 +36,12 @@ This project consist in 4 folders:

To setup the project first run the following commands:

- Set up env variables(you can modify the file to set the values you want)
```bash
chmod +x envs.sh
. envs.sh
```

- Give write permission
```bash
chmod a+rwx ./data-embedding
Expand Down Expand Up @@ -129,7 +137,7 @@ To start the web server run:
```bash
cd ../web
npm i
npm run lin
npm run lint
npm run dev
```

Expand Down
12 changes: 8 additions & 4 deletions data-embedding/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const (
dateFormatLayout = "Mon, 2 Jan 2006 15:04:05 -0700 (MST)"
)

var (
zincUser = os.Getenv("ZINC_USER")
zincPassword = os.Getenv("ZINC_PASSWORD")
)

func main() {
log.Println("Starting indexer!")
utils.CpuProfiling()
Expand Down Expand Up @@ -140,8 +145,8 @@ func sendBulkToZincSearch(records []utils.EmailData) {
log.Println(err)
return
}
//TODO: change to .evn latter
req.SetBasicAuth("admin", "password")

req.SetBasicAuth(zincUser, zincPassword)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36")

Expand Down Expand Up @@ -211,8 +216,7 @@ func deleteIndexOnZincSearch(indexName string) error {
return err
}

//TODO: Change to .env file latter
req.SetBasicAuth("admin", "password")
req.SetBasicAuth(zincUser, zincPassword)

client := &http.Client{}
resp, err := client.Do(req)
Expand Down
Binary file modified data-embedding/profs/cpu.prof
Binary file not shown.
Binary file modified data-embedding/profs/mem.prof
Binary file not shown.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
- ./data-embedding:/data:Z
environment:
- ZINC_DATA_PATH=/data
- ZINC_FIRST_ADMIN_USER=admin
- ZINC_FIRST_ADMIN_PASSWORD=password
- ZINC_FIRST_ADMIN_USER=$ZINC_USER
- ZINC_FIRST_ADMIN_PASSWORD=$ZINC_PASSWORD
ports:
- '4080:4080'
7 changes: 5 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ services:
- ../data-embedding:/data:Z
environment:
- ZINC_DATA_PATH=/data
- ZINC_FIRST_ADMIN_USER=admin
- ZINC_FIRST_ADMIN_PASSWORD=password
- ZINC_FIRST_ADMIN_USER=$ZINC_USER
- ZINC_FIRST_ADMIN_PASSWORD=$ZINC_PASSWORD
ports:
- '4080:4080'

server:
build: ../server
depends_on:
- zincsearch
environment:
- ZINC_USER=$ZINC_USER
- ZINC_PASSWORD=$ZINC_PASSWORD
ports:
- '3001:3001'

Expand Down
4 changes: 4 additions & 0 deletions envs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

export ZINC_USER="admin"
export ZINC_PASSWORD="password"
12 changes: 8 additions & 4 deletions server/config/credentials.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package config

import "log"
import (
"log"
"os"
)

type ZincsearchCredentials struct {
User string
Expand All @@ -17,10 +20,11 @@ func LoadZincsearchCredentials() ZincsearchCredentials {

log.Println("Loading zincsearch credentials...")
credentials := &ZincsearchCredentials{}
// Emulation of config loading since the doc requested to no use any other external library

// Configure the env vars in the shell, since the doc requested to not use any other external library
// so I can't use something like `godotenv` to get the user credentials for a .env file
credentials.User = "admin"
credentials.Password = "password"
credentials.User = os.Getenv("ZINC_USER")
credentials.Password = os.Getenv("ZINC_PASSWORD")

zincsearchCredentials = credentials

Expand Down
8 changes: 6 additions & 2 deletions server/config/credentials_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package config_test

import (
"fmt"
"reflect"
"strings"
"testing"

"github.com/Odraxs/go-z-v-mail/server/config"
"github.com/Odraxs/go-z-v-mail/server/test/fixtures"
)

func TestGetZincsearchCredentials(t *testing.T) {
Expand All @@ -27,6 +27,7 @@ func TestGetZincsearchCredentials(t *testing.T) {
},
}

fixtures.CreateEnvs()
for _, test := range test {
tt := test
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -35,12 +36,13 @@ func TestGetZincsearchCredentials(t *testing.T) {
}

credentials := config.GetZincsearchCredentials()
fmt.Printf("-------- %+v", credentials)

if !reflect.DeepEqual(credentials, tt.expected) {
t.Fatalf("Expected %v but got %v", tt.expected, credentials)
}
})
}
fixtures.RemoveEnvs()
}

func TestLoadZincsearchCredentials(t *testing.T) {
Expand All @@ -62,6 +64,7 @@ func TestLoadZincsearchCredentials(t *testing.T) {
},
}}

fixtures.CreateEnvs()
for _, test := range test {
tt := test
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -71,4 +74,5 @@ func TestLoadZincsearchCredentials(t *testing.T) {
}
})
}
fixtures.RemoveEnvs()
}
13 changes: 13 additions & 0 deletions server/test/fixtures/config_fixtures.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package fixtures

import "os"

func CreateEnvs() {
os.Setenv("ZINC_USER", "admin")
os.Setenv("ZINC_PASSWORD", "password")
}

func RemoveEnvs() {
os.Unsetenv("ZINC_USER")
os.Unsetenv("ZINC_PASSWORD")
}
2 changes: 0 additions & 2 deletions web/src/services/emails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ async function searchEmails({ term, field, sort, order, maxResults }: FormData)
sort_fields: processSortField({ sort, order })
}

console.log(requestBody)

return fetch(searchEmailsEndpoint, {
method: 'POST',
headers: {
Expand Down
Loading