diff --git a/.github/workflows/docker-deploy.yml b/.github/workflows/docker-deploy.yml new file mode 100644 index 0000000..884fa4c --- /dev/null +++ b/.github/workflows/docker-deploy.yml @@ -0,0 +1,26 @@ +on: + push: + branches: + - main + - dev + pull_request: + branches: + - main + - dev +jobs: + deploy: + runs-on: ubuntu-latest + steps: + + # indhu yen nu therla + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Login to Docker Hub + run: echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin + + - name: Build Docker Image for Auth service + run: docker build -t muruga21/auth-service -f Dockerfile.auth . + + - name: Push Docker Image of Auth Service + run: docker push muruga21/auth-service \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d70f193 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +/.env \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..c2098a2 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "linux-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "/usr/bin/gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "linux-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..15a34e0 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": false, + "cwd": "/home/muruga/muruga/letstry/neighborly/neighbourly", + "program": "/home/muruga/muruga/letstry/neighborly/neighbourly/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..bb879da --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/Dockerfile.auth b/Dockerfile.auth new file mode 100644 index 0000000..17907d8 --- /dev/null +++ b/Dockerfile.auth @@ -0,0 +1,18 @@ +FROM golang:1.24.1 AS builder + +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod tidy + +COPY . . + +RUN CGO_ENABLED=0 GOOS=linux go build -o auth-service ./cmd/auth + +#production +FROM alpine:latest +WORKDIR /root + +COPY --from=builder /app/auth-service . +EXPOSE 5000 +CMD [ "./auth-service" ] \ No newline at end of file diff --git a/README.md b/README.md index ddb271b..295308f 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# neighbourly \ No newline at end of file +# neighbourly + + diff --git a/backend/config/DatabaseSetup.go b/backend/config/DatabaseSetup.go index 22aadff..64783db 100644 --- a/backend/config/DatabaseSetup.go +++ b/backend/config/DatabaseSetup.go @@ -26,7 +26,6 @@ func ConnectDB() error { log.Fatal(err) return err } - ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second) defer cancel() err = Client.Ping(ctx, readpref.Primary()) diff --git a/backend/controllers/serviceProvider.go b/backend/controllers/serviceProvider.go index eebb9fc..0944df0 100644 --- a/backend/controllers/serviceProvider.go +++ b/backend/controllers/serviceProvider.go @@ -19,6 +19,8 @@ type Service struct { Time string `json:"time"` Description string `json:"description"` Status string `json:"status"` + Seekername string `json:"seekername"` + Seekerphone string `json:"Seekerphone"` } func ViewServices (c * gin.Context){ diff --git a/backend/go.mod b/backend/go.mod index ac65a0e..e258fa4 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -35,6 +35,7 @@ require ( github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/scram v1.1.2 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect + github.com/yelinaung/eng-name v0.0.0-20141214053408-d6af0256d2c0 // indirect github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect golang.org/x/arch v0.8.0 // indirect golang.org/x/crypto v0.23.0 // indirect diff --git a/backend/go.sum b/backend/go.sum index 3cb660b..b138975 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -79,6 +79,8 @@ github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= +github.com/yelinaung/eng-name v0.0.0-20141214053408-d6af0256d2c0 h1:ZUHUPeDkXqtVFMhwNVIrIHwJHAaXGXnvV9AYYW6xmxE= +github.com/yelinaung/eng-name v0.0.0-20141214053408-d6af0256d2c0/go.mod h1:QH/uGb7Ua5lon/ULhm9V2sYK3fwocdHPlDva927j3tU= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= diff --git a/backend/main.go b/backend/main.go index 248aafd..b3b1054 100644 --- a/backend/main.go +++ b/backend/main.go @@ -8,14 +8,14 @@ import ( ) func init() { - err := godotenv.Load(); + err := godotenv.Load() if err != nil { - panic("Error loading .env file"); + panic("Error loading .env file") } - fmt.Println("Environment variables loaded successfully"); + fmt.Println("Environment variables loaded successfully") } func main() { - r := routes.SetupRouter(); - r.Run(); -} \ No newline at end of file + r := routes.SetupRouter() + r.Run() +} diff --git a/backend/middlewares/auth.go b/backend/middlewares/auth.go index 2ec5619..889981e 100644 --- a/backend/middlewares/auth.go +++ b/backend/middlewares/auth.go @@ -23,6 +23,7 @@ func AuthMiddleware() gin.HandlerFunc{ "error": true, "message": "Authorization header is missing", }) + c.Abort(); return } @@ -42,6 +43,7 @@ func AuthMiddleware() gin.HandlerFunc{ "error": true, "message": "Error decoding token: " + err.Error(), }) + c.Abort(); return } @@ -55,6 +57,7 @@ func AuthMiddleware() gin.HandlerFunc{ "error": true, "message": "Invalid token", }) + c.Abort(); return } diff --git a/cmd/auth/main.go b/cmd/auth/main.go new file mode 100644 index 0000000..76a1a24 --- /dev/null +++ b/cmd/auth/main.go @@ -0,0 +1,12 @@ +package main + +import ( + "net/http" + + "github.com/muruga21/neighbourly/internal/service" +) + +func main() { + http.HandleFunc("/signup", service.HandleSignup) + http.ListenAndServe(":5000", nil) +} diff --git a/cmd/service_provider/main.go b/cmd/service_provider/main.go new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..764b98c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +version: '3.3' + +services: + auth-services: + image: muruga21/auth-service + container_name: auth-service + ports: + - "5000:5000" + depends_on: + - redis + environment: + - REDIS_HOST=redis + - REDIS_PORT=6379 + + redis: + image: redis:latest + container_name: redis + restart: always + ports: + - "6379:6379" + command: ["redis-server", "--appendonly", "yes"] diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..7f1973d --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module github.com/muruga21/neighbourly + +go 1.24.1 + +require ( + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/redis/go-redis/v9 v9.7.3 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..b050707 --- /dev/null +++ b/go.sum @@ -0,0 +1,6 @@ +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/redis/go-redis/v9 v9.7.3 h1:YpPyAayJV+XErNsatSElgRZZVCwXX9QzkKYNvO7x0wM= +github.com/redis/go-redis/v9 v9.7.3/go.mod h1:bGUrSggJ9X9GUmZpZNEOQKaANxSGgOEBRltRTZHSvrA= diff --git a/internal/service/auth.service.go b/internal/service/auth.service.go new file mode 100644 index 0000000..66ebeaa --- /dev/null +++ b/internal/service/auth.service.go @@ -0,0 +1,30 @@ +package service + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/redis/go-redis/v9" +) + +func HandleSignup(w http.ResponseWriter, r *http.Request) { + client := redis.NewClient(&redis.Options{ + Addr: "localhost:6379", + Password: "", // No password set + DB: 0, // Use default DB + Protocol: 2, // Connection protocol + }) + ctx := context.Background() + + err := client.Set(ctx, "foo", "bar", 0).Err() + if err != nil { + panic(err) + } + + val, err := client.Get(ctx, "foo").Result() + + fmt.Println(client) + json.NewEncoder(w).Encode(map[string]string{"error": "false", "message": val}) +} diff --git a/services/krakend.json b/services/krakend.json index 48c281b..7bde464 100644 --- a/services/krakend.json +++ b/services/krakend.json @@ -12,7 +12,7 @@ "backend": [ { "url_pattern": "/", - "host": ["https://neighbourly-user-service.onrender.com"], + "host": ["65.2.168.125"], "extra_config": { "backend/http": { "return_error_details": "backend_alias", @@ -29,7 +29,7 @@ "backend": [ { "url_pattern": "/signup", - "host": ["https://neighbourly-user-service.onrender.com"], + "host": ["65.2.168.125"], "extra_config": { "backend/http": { "return_error_details": "backend_alias", @@ -46,7 +46,7 @@ "backend": [ { "url_pattern": "/login", - "host": ["https://neighbourly-user-service.onrender.com"], + "host": ["65.2.168.125"], "extra_config": { "backend/http": { "return_error_details": "backend_alias", @@ -60,10 +60,13 @@ "endpoint": "/setProvider", "method": "POST", "output_encoding": "json", + "input_headers": [ + "Authorization" + ], "backend": [ { "url_pattern": "/setProvider", - "host": ["https://neighbourly-service-service.onrender.com"], + "host": ["13.126.20.82"], "extra_config": { "backend/http": { "return_error_details": "backend_alias", @@ -77,10 +80,13 @@ "endpoint": "/topRatedProviders", "method": "GET", "output_encoding": "json", + "input_headers": [ + "Authorization" + ], "backend": [ { "url_pattern": "/topRatedProviders", - "host": ["https://neighbourly-service-service.onrender.com"], + "host": ["13.126.20.82"], "extra_config": { "backend/http": { "return_error_details": "backend_alias", @@ -94,10 +100,13 @@ "endpoint": "/searchService", "method": "POST", "output_encoding": "json", + "input_headers": [ + "Authorization" + ], "backend": [ { "url_pattern": "/searchService", - "host": ["https://neighbourly-service-service.onrender.com"], + "host": ["13.126.20.82"], "extra_config": { "backend/http": { "return_error_details": "backend_alias", @@ -111,10 +120,13 @@ "endpoint": "/buyService", "method": "POST", "output_encoding": "json", + "input_headers": [ + "Authorization" + ], "backend": [ { "url_pattern": "/buyService", - "host": ["https://neighbourly-service-seeker-service.onrender.com"], + "host": ["3.111.171.134"], "extra_config": { "backend/http": { "return_error_details": "backend_alias", @@ -128,10 +140,13 @@ "endpoint": "/viewServices/{status}", "method": "GET", "output_encoding": "json", + "input_headers": [ + "Authorization" + ], "backend": [ { "url_pattern": "/viewServices/{status}", - "host": ["https://neighbourly-service-provider-service.onrender.com"], + "host": ["13.234.239.196"], "extra_config": { "backend/http": { "return_error_details": "backend_alias", @@ -145,10 +160,13 @@ "endpoint": "/updateService/{id}/{status}", "method": "POST", "output_encoding": "json", + "input_headers": [ + "Authorization" + ], "backend": [ { "url_pattern": "/updateService/{id}/{status}", - "host": ["https://neighbourly-service-provider-service.onrender.com"], + "host": ["13.234.239.196"], "extra_config": { "backend/http": { "return_error_details": "backend_alias", diff --git a/services/nginx.conf b/services/nginx.conf index 515a772..070d67f 100644 --- a/services/nginx.conf +++ b/services/nginx.conf @@ -1,61 +1,67 @@ - -upstream neighbourly_user_service { - server neighbourly-user-service.onrender.com; -} - -upstream neighbourly_service_service { - server neighbourly-service-service.onrender.com; -} - -upstream neighbourly_service_seeker_service { - server neighbourly-service-seeker-service.onrender.com; -} - -upstream neighbourly_service_provider_service { - server neighbourly-service-provider-service.onrender.com; -} - server { - listen 80; - server_name example.com; + listen 8081; + server_name localhost; + # Root endpoint location / { - proxy_pass https://neighbourly_user_service; + proxy_pass https://neighbourly-user-service.onrender.com; + proxy_set_header Authorization $http_authorization; + proxy_set_header Content-Type $http_content_type; } + # Signup endpoint location /signup { - proxy_pass https://neighbourly_user_service; + proxy_pass https://neighbourly-user-service.onrender.com/signup; + proxy_set_header Authorization $http_authorization; + proxy_set_header Content-Type $http_content_type; } + # Login endpoint location /login { - proxy_pass https://neighbourly_user_service; + proxy_pass https://neighbourly-user-service.onrender.com/login; + proxy_set_header Authorization $http_authorization; + proxy_set_header Content-Type $http_content_type; } + # Set Provider endpoint location /setProvider { - proxy_pass https://neighbourly_service_service; + proxy_pass https://neighbourly-service-service.onrender.com/setProvider; + proxy_set_header Authorization $http_authorization; + proxy_set_header Content-Type $http_content_type; } + # Top Rated Providers endpoint location /topRatedProviders { - proxy_pass https://neighbourly_service_service; + proxy_pass https://neighbourly-service-service.onrender.com/topRatedProviders; + proxy_set_header Authorization $http_authorization; + proxy_set_header Content-Type $http_content_type; } + # Search Service endpoint location /searchService { - proxy_pass https://neighbourly_service_service; + proxy_pass https://neighbourly-service-service.onrender.com/searchService; + proxy_set_header Authorization $http_authorization; + proxy_set_header Content-Type $http_content_type; } + # Buy Service endpoint location /buyService { - proxy_pass https://neighbourly_service_seeker_service; + proxy_pass https://neighbourly-service-seeker-service.onrender.com/buyService; + proxy_set_header Authorization $http_authorization; + proxy_set_header Content-Type $http_content_type; } - location /viewServices { - # Extract status parameter from the URI - rewrite ^/viewServices/([^/]+)$ /viewServices/$1 break; - proxy_pass https://neighbourly_service_provider_service; + # View Services endpoint with status parameter + location ~ ^/viewServices/(.*) { + proxy_pass https://neighbourly-service-provider-service.onrender.com/viewServices/$1; + proxy_set_header Authorization $http_authorization; + proxy_set_header Content-Type $http_content_type; } - location /updateService { - # Extract id and status parameters from the URI - rewrite ^/updateService/([^/]+)/([^/]+)$ /updateService/$1/$2 break; - proxy_pass https://neighbourly_service_provider_service; + # Update Service endpoint with id and status parameters + location ~ ^/updateService/(.*)/(.*) { + proxy_pass http://localhost:3000/updateService/$1/$2; + proxy_set_header Authorization $http_authorization; + proxy_set_header Content-Type $http_content_type; } } diff --git a/services/service_provider_service/controllers/serviceProvider.go b/services/service_provider_service/controllers/serviceProvider.go index a49663d..3a78356 100644 --- a/services/service_provider_service/controllers/serviceProvider.go +++ b/services/service_provider_service/controllers/serviceProvider.go @@ -19,6 +19,8 @@ type Service struct { Time string `json:"time"` Description string `json:"description"` Status string `json:"status"` + Seekername string `json:"seekername"` + Seekerphone string `json:"Seekerphone"` } func ViewServices (c * gin.Context){ diff --git a/services/service_provider_service/middlewares/auth.go b/services/service_provider_service/middlewares/auth.go index 2ec5619..5b730f2 100644 --- a/services/service_provider_service/middlewares/auth.go +++ b/services/service_provider_service/middlewares/auth.go @@ -23,9 +23,12 @@ func AuthMiddleware() gin.HandlerFunc{ "error": true, "message": "Authorization header is missing", }) + c.Abort(); return } + fmt.Println("checking authHeader", authHeader); + tokenString := strings.TrimPrefix(authHeader, "Bearer ") secretKey := []byte(os.Getenv("SECRET")) @@ -42,6 +45,7 @@ func AuthMiddleware() gin.HandlerFunc{ "error": true, "message": "Error decoding token: " + err.Error(), }) + c.Abort(); return } @@ -55,6 +59,7 @@ func AuthMiddleware() gin.HandlerFunc{ "error": true, "message": "Invalid token", }) + c.Abort(); return } diff --git a/services/service_seeker_service/middlewares/auth.go b/services/service_seeker_service/middlewares/auth.go index 2ec5619..889981e 100644 --- a/services/service_seeker_service/middlewares/auth.go +++ b/services/service_seeker_service/middlewares/auth.go @@ -23,6 +23,7 @@ func AuthMiddleware() gin.HandlerFunc{ "error": true, "message": "Authorization header is missing", }) + c.Abort(); return } @@ -42,6 +43,7 @@ func AuthMiddleware() gin.HandlerFunc{ "error": true, "message": "Error decoding token: " + err.Error(), }) + c.Abort(); return } @@ -55,6 +57,7 @@ func AuthMiddleware() gin.HandlerFunc{ "error": true, "message": "Invalid token", }) + c.Abort(); return } diff --git a/services/service_service/middlewares/auth.go b/services/service_service/middlewares/auth.go index 2ec5619..889981e 100644 --- a/services/service_service/middlewares/auth.go +++ b/services/service_service/middlewares/auth.go @@ -23,6 +23,7 @@ func AuthMiddleware() gin.HandlerFunc{ "error": true, "message": "Authorization header is missing", }) + c.Abort(); return } @@ -42,6 +43,7 @@ func AuthMiddleware() gin.HandlerFunc{ "error": true, "message": "Error decoding token: " + err.Error(), }) + c.Abort(); return } @@ -55,6 +57,7 @@ func AuthMiddleware() gin.HandlerFunc{ "error": true, "message": "Invalid token", }) + c.Abort(); return }