diff --git a/README.md b/README.md index 790ef0c..969a701 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This project consist in 4 folders: ## Requirements: -- Go >= 1.22(recommended) +- Go == 1.22 - Docker - Docker-compose - Node >= 20.10.0(recommended) @@ -17,13 +17,15 @@ This project consist in 4 folders: ## 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 ``` @@ -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 @@ -129,7 +137,7 @@ To start the web server run: ```bash cd ../web npm i - npm run lin + npm run lint npm run dev ``` diff --git a/data-embedding/main.go b/data-embedding/main.go index 7c8c964..1317652 100644 --- a/data-embedding/main.go +++ b/data-embedding/main.go @@ -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() @@ -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") @@ -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) diff --git a/data-embedding/profs/cpu.prof b/data-embedding/profs/cpu.prof index 55f011d..c1cfd1b 100644 Binary files a/data-embedding/profs/cpu.prof and b/data-embedding/profs/cpu.prof differ diff --git a/data-embedding/profs/mem.prof b/data-embedding/profs/mem.prof index bd224e9..704ee46 100644 Binary files a/data-embedding/profs/mem.prof and b/data-embedding/profs/mem.prof differ diff --git a/docker-compose.yml b/docker-compose.yml index f3d8b9f..5500ac5 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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' diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index a6b422d..a1503cf 100755 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -7,8 +7,8 @@ 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' @@ -16,6 +16,9 @@ services: build: ../server depends_on: - zincsearch + environment: + - ZINC_USER=$ZINC_USER + - ZINC_PASSWORD=$ZINC_PASSWORD ports: - '3001:3001' diff --git a/envs.sh b/envs.sh new file mode 100755 index 0000000..2f0c862 --- /dev/null +++ b/envs.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +export ZINC_USER="admin" +export ZINC_PASSWORD="password" diff --git a/server/config/credentials.go b/server/config/credentials.go index 06bca54..876357a 100644 --- a/server/config/credentials.go +++ b/server/config/credentials.go @@ -1,6 +1,9 @@ package config -import "log" +import ( + "log" + "os" +) type ZincsearchCredentials struct { User string @@ -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 diff --git a/server/config/credentials_test.go b/server/config/credentials_test.go index 4038a0e..fd5e6f7 100644 --- a/server/config/credentials_test.go +++ b/server/config/credentials_test.go @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -71,4 +74,5 @@ func TestLoadZincsearchCredentials(t *testing.T) { } }) } + fixtures.RemoveEnvs() } diff --git a/server/test/fixtures/config_fixtures.go b/server/test/fixtures/config_fixtures.go new file mode 100644 index 0000000..8ab3342 --- /dev/null +++ b/server/test/fixtures/config_fixtures.go @@ -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") +} diff --git a/web/src/services/emails.ts b/web/src/services/emails.ts index c09ff4b..82f4c26 100644 --- a/web/src/services/emails.ts +++ b/web/src/services/emails.ts @@ -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: {