From c5f675165f7eaf46a2f25d18e2b1c6e69338dc8b Mon Sep 17 00:00:00 2001 From: anhcx Date: Mon, 31 Jul 2023 16:34:45 +0700 Subject: [PATCH] Initial api --- .gitignore | 47 ++ README.md | 356 +++++++++++++++- api/handler/gns_handler.go | 54 +++ api/handler/hep_handler.go | 54 +++ api/handler/login_handler.go | 57 +++ api/handler/option_handler.go | 42 ++ api/handler/policy_handler.go | 54 +++ api/handler/profile_handler.go | 75 ++++ api/handler/refresh_token_handler.go | 56 +++ api/handler/signup_handler.go | 81 ++++ api/handler/statistic_handler.go | 34 ++ api/handler/user_handler.go | 142 +++++++ api/middleware/casbin_middleware.go | 39 ++ api/middleware/cors_middleware.go | 23 + api/middleware/jwt_auth_middleware.go | 37 ++ api/route/gns_route.go | 22 + api/route/hep_route.go | 22 + api/route/login_route.go | 22 + api/route/option_route.go | 25 ++ api/route/ping_route.go | 16 + api/route/policy_route.go | 22 + api/route/profile_route.go | 24 ++ api/route/refresh_token_route.go | 23 + api/route/route.go | 68 +++ api/route/signup_route.go | 24 ++ api/route/statistic_route.go | 26 ++ api/route/user_route.go | 26 ++ bootstrap/app.go | 19 + bootstrap/database.go | 44 ++ bootstrap/env.go | 45 ++ cmd/create_admin/create_admin.go | 76 ++++ cmd/main.go | 26 ++ config.json | 13 + config/rbac_model.conf | 14 + deployment/.env | 13 + deployment/Dockerfile | 21 + deployment/docker-compose.yaml | 31 ++ domain/calico_object_response.go | 8 + domain/error_response.go | 5 + domain/gns.go | 25 ++ domain/hep.go | 26 ++ domain/jwt_custom.go | 16 + domain/login.go | 22 + domain/metadata.go | 10 + domain/option.go | 10 + domain/option_request.go | 7 + domain/policy.go | 25 ++ domain/profile.go | 19 + domain/refresh_token.go | 21 + domain/search_request.go | 5 + domain/signup.go | 24 ++ domain/statistic.go | 28 ++ domain/success_response.go | 6 + domain/user.go | 56 +++ go.mod | 63 +++ go.sum | 591 ++++++++++++++++++++++++++ internal/optionutil/optionutil.go | 19 + internal/tokenutil/tokenutil.go | 75 ++++ mongo/mongo.go | 207 +++++++++ repository/gns_repository.go | 122 ++++++ repository/hep_repository.go | 157 +++++++ repository/policy_repository.go | 122 ++++++ repository/user_repository.go | 94 ++++ usecase/gns_usecase.go | 48 +++ usecase/hep_usecase.go | 52 +++ usecase/login_usecase.go | 35 ++ usecase/policy_usecase.go | 47 ++ usecase/profile_usecase.go | 32 ++ usecase/refresh_token_usecase.go | 39 ++ usecase/signup_usecase.go | 41 ++ usecase/statistic_usecase.go | 71 ++++ usecase/user_usecase.go | 58 +++ 72 files changed, 3958 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 api/handler/gns_handler.go create mode 100644 api/handler/hep_handler.go create mode 100644 api/handler/login_handler.go create mode 100644 api/handler/option_handler.go create mode 100644 api/handler/policy_handler.go create mode 100644 api/handler/profile_handler.go create mode 100644 api/handler/refresh_token_handler.go create mode 100644 api/handler/signup_handler.go create mode 100644 api/handler/statistic_handler.go create mode 100644 api/handler/user_handler.go create mode 100644 api/middleware/casbin_middleware.go create mode 100644 api/middleware/cors_middleware.go create mode 100644 api/middleware/jwt_auth_middleware.go create mode 100644 api/route/gns_route.go create mode 100644 api/route/hep_route.go create mode 100644 api/route/login_route.go create mode 100644 api/route/option_route.go create mode 100644 api/route/ping_route.go create mode 100644 api/route/policy_route.go create mode 100644 api/route/profile_route.go create mode 100644 api/route/refresh_token_route.go create mode 100644 api/route/route.go create mode 100644 api/route/signup_route.go create mode 100644 api/route/statistic_route.go create mode 100644 api/route/user_route.go create mode 100644 bootstrap/app.go create mode 100644 bootstrap/database.go create mode 100644 bootstrap/env.go create mode 100644 cmd/create_admin/create_admin.go create mode 100644 cmd/main.go create mode 100644 config.json create mode 100644 config/rbac_model.conf create mode 100644 deployment/.env create mode 100644 deployment/Dockerfile create mode 100644 deployment/docker-compose.yaml create mode 100644 domain/calico_object_response.go create mode 100644 domain/error_response.go create mode 100644 domain/gns.go create mode 100644 domain/hep.go create mode 100644 domain/jwt_custom.go create mode 100644 domain/login.go create mode 100644 domain/metadata.go create mode 100644 domain/option.go create mode 100644 domain/option_request.go create mode 100644 domain/policy.go create mode 100644 domain/profile.go create mode 100644 domain/refresh_token.go create mode 100644 domain/search_request.go create mode 100644 domain/signup.go create mode 100644 domain/statistic.go create mode 100644 domain/success_response.go create mode 100644 domain/user.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/optionutil/optionutil.go create mode 100644 internal/tokenutil/tokenutil.go create mode 100644 mongo/mongo.go create mode 100644 repository/gns_repository.go create mode 100644 repository/hep_repository.go create mode 100644 repository/policy_repository.go create mode 100644 repository/user_repository.go create mode 100644 usecase/gns_usecase.go create mode 100644 usecase/hep_usecase.go create mode 100644 usecase/login_usecase.go create mode 100644 usecase/policy_usecase.go create mode 100644 usecase/profile_usecase.go create mode 100644 usecase/refresh_token_usecase.go create mode 100644 usecase/signup_usecase.go create mode 100644 usecase/statistic_usecase.go create mode 100644 usecase/user_usecase.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cfd6bf3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,47 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib +create_admin + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (created by `go get`) +/bin/ +/pkg/ + +# Generated files +*.pb.go +*.pb.gw.go +*.swagger.json + +# IDE-specific files (e.g., Visual Studio Code, IntelliJ IDEA) +.vscode/ +.idea/ + +# Logs and error files +*.log +*.log.* + +# Operating System-generated files +.DS_Store +Thumbs.db + +# Output directories for coverage and profiling tools +/cover +/profile + +# Binary release files +/dist/ + +# Go module cache directory +/go.sum + +# Ignore vendor folder if using dep or Go modules +/vendor/ diff --git a/README.md b/README.md index b2187e6..ced1b66 100644 --- a/README.md +++ b/README.md @@ -1 +1,355 @@ -# be \ No newline at end of file +# Bamboo Firewall API Server + +API for gathering bamboo firewall information: + +* Host End Point +* Global Network Set +* Global Network Policy (Policy) + +## How to run? + +Using https://github.com/spf13/viper to read configs. Priority: + +- env +- json config +- key/value store +- default + +Container way: modified file `deployment/.env` + +"Go run" way: modified file `./config.json` + +## Requirement + +* mongodb + +## Public API + +1. Ping + +```bash +curl --location 'localhost:8080/api/ping' +``` + +2. Register + +```bash +curl -L 'localhost:8080/api/signup' \ +-H 'Content-Type: application/json' \ +--data-raw '{ + "name": "buycoffee+3c1c0z2b", + "email": "buycoffee+3c1c0z2b@example.com", + "password": "immorally8578" +}' +``` + +3. Login + +```bash +curl -L 'localhost:8080/api/login' \ +-H 'Content-Type: application/json' \ +--data-raw '{ + "email": "buycoffee+3c1c0z2b@example.com", + "password": "immorally8578" +}' +``` + +## Protected API + +1. Fetch HEP + +```bash +curl -L -X POST 'localhost:8080/api/v1/hep/fetch' \ +-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiQ2FvIFh1YW4gQW5oIiwiaWQiOiI2NDk5NGUzMDc0YWRhZWFiZDY0MWNmMDIiLCJleHAiOjE2ODc4NTc4NzF9.dOzvXgUM12epaJDXZ4jbF0KjZddh2B1UHr_MrbXIubk' +``` + +2. Fetch GNS - Global Network Set + +```bash +curl -L -X POST 'localhost:8080/api/v1/gns/fetch' \ +-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiQ2FvIFh1YW4gQW5oIiwiaWQiOiI2NDk5NGUzMDc0YWRhZWFiZDY0MWNmMDIiLCJleHAiOjE2ODc4NTc4NzF9.dOzvXgUM12epaJDXZ4jbF0KjZddh2B1UHr_MrbXIubk' +``` + +3. Fetch Policy + +```bash +curl -L -X POST 'localhost:8080/api/v1/policy/fetch' \ +-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiQ2FvIFh1YW4gQW5oIiwiaWQiOiI2NDk5NGUzMDc0YWRhZWFiZDY0MWNmMDIiLCJleHAiOjE2ODc4NTc4NzF9.dOzvXgUM12epaJDXZ4jbF0KjZddh2B1UHr_MrbXIubk' +``` + +4. Fetch options + +Option - object using to searching +Option.key - field name +Option.value - value of field + +Filter: value to filters + +```bash +curl -L 'localhost:9091/api/v1/options/fetch' \ +-H 'Content-Type: application/json' \ +-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiQWRtaW4iLCJpZCI6IjY0YjYwMmQ0ODk2YTJhODc3ZTI3NGE0YSIsImV4cCI6MTY4OTkzMTU5OH0.iAyD2nsRCmfkaGgyQBA1LnsG7ly1wM59HC2e4Lm5F-U' \ +-d '{ + "type": "hostendpoints", + "label": "zone", + "filter": [ + { + "key": "namespace", + "value": "non-production" + }, + { + "key": "role", + "value": "lb" + } + ] +}' +``` + +Valid input: + +| Type | Label | +| --------------------- | ---------------------------------- | +| hostendpoints | ip, namespace, project, role, zone | +| globalnetworksets | name, zone | +| globalnetworkpolicies | name | + +5. Search HEP - Host End Point + +```bash +curl -L 'localhost:9091/api/v1/hep/search' \ +-H 'Content-Type: application/json' \ +-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiQWRtaW4iLCJpZCI6IjY0YWZkYWNiNDhiNTBiNDhiMTk2MTFiOCIsImV4cCI6MTY4OTU4OTMwNH0.BqPgjbe644GST2uNWDCTgOC4LsuFB6B-f8SOoguZVEc' \ +-d '{ + "options": [ + { + "key": "namespace", + "value": "non-production" + }, + { + "key": "role", + "value": "lb" + } + ] +}' +``` + +6. Search Policy + +```bash +curl -L 'localhost:9091/api/v1/policy/search' \ +-H 'Content-Type: application/json' \ +-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiQWRtaW4iLCJpZCI6IjY0YWZkYWNiNDhiNTBiNDhiMTk2MTFiOCIsImV4cCI6MTY4OTU5NjY2OX0.LcfpvySJHtRCuG4VvY4clMjmOAOYV7XanHVKVrdWR1E' \ +-d '{ + "options": [ + { + "key": "name", + "value": "gchat-gdrives-app" + } + ] +}' +``` + +7. Search GNS - Global Network Set + +```bash +curl -L 'localhost:9091/api/v1/gns/search' \ +-H 'Content-Type: application/json' \ +-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiQWRtaW4iLCJpZCI6IjY0YWZkYWNiNDhiNTBiNDhiMTk2MTFiOCIsImV4cCI6MTY4OTU5NjY2OX0.LcfpvySJHtRCuG4VvY4clMjmOAOYV7XanHVKVrdWR1E' \ +-d '{ + "options": [ + { + "key": "zone", + "value": "gray" + }, + { + "key": "name", + "value": "vpn-devops" + } + ] +}' +``` + +8. Statistic API - Summary + +```bash +curl -L -X POST 'localhost:9091/api/v1/statistic/summary' \ +-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiQWRtaW4iLCJpZCI6IjY0YWZkYWNiNDhiNTBiNDhiMTk2MTFiOCIsImV4cCI6MTY4OTYwOTU3OX0.tObMwnGLrzeVehA5EvpXEloyRO63NManFQ6fUkGDleY' +``` + +Sample response + +```json +{ + "summary": { + "total_global_network_set": 122, + "total_policy": 431, + "total_host_endpoint": 1397, + "total_user": 2 + } +} +``` + +9. Statistic API - Project Summary + +```bash +curl -L -X POST 'localhost:9091/api/v1/statistic/project-summary' \ +-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiQWRtaW4iLCJpZCI6IjY0YWZkYWNiNDhiNTBiNDhiMTk2MTFiOCIsImV4cCI6MTY4OTYwOTU3OX0.tObMwnGLrzeVehA5EvpXEloyRO63NManFQ6fUkGDleY' +``` + +Sample response + +``` +{ + "project_summary": [ + { + "project_name": "deceiver5553", + "total": 5 + }, + { + "project_name": "disgrace3860", + "total": 2 + }, + { + "project_name": "taunt7475", + "total": 201 + } + ] +} +``` + +10. Get Profile + +```bash +curl -L -X POST 'localhost:9091/api/v1/profile' \ +-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiTmd1eWVuIFF1YW5nIFRoaW5oIiwiaWQiOiI2NGI3NjM4M2Q4Nzg3NDhjZmE1ZTVhZTciLCJleHAiOjE2ODk3NDczNjN9.3rMgxjQH0yoZfoZJvZi5yqJv4neoNS-0evmR6bZyInk' +``` + +Sample response + +```json +{ + "user_id:": "64b60588eed1f4a039c0fc9f", + "name": "buycoffee+763eub9b", + "email": "buycoffee+763eub9b@example.com", + "role": "devops" +} +``` + +11. Update profile + +```bash +curl -L 'localhost:9091/api/v1/profile/update' \ +-H 'Content-Type: application/json' \ +-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiQWRtaW4iLCJpZCI6IjY0YjYwMmQ0ODk2YTJhODc3ZTI3NGE0YSIsImV4cCI6MTY4OTkzMTU5OH0.iAyD2nsRCmfkaGgyQBA1LnsG7ly1wM59HC2e4Lm5F-U' \ +-d '{ + "name": "buycoffee+763eub9b" +}' +``` + +**// TODO: revoke token when password is updated** + +for now, frontend will erase token in local storage and make "fake" revoke token :( + +Sample response + +```json +{ + "message": "Update profile successfully", + "data": { + "name": "fragrant1852", + "email": "admin@example.com", + "role": "admin" + } +} +``` + + + +## Admin API - User management + +Required: Role = admin + +1. Fetch User + +```bash +curl -L -X POST 'localhost:9091/api/v1/admin/user/fetch' \ +-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiQWRtaW4iLCJpZCI6IjY0YjYwMmQ0ODk2YTJhODc3ZTI3NGE0YSIsImV4cCI6MTY4OTY1NzY2NX0.dGji61f160f_eJUSRd7tLJU_wEJ4KDppNx5NZgz0nfE' +``` + +Sample response: + +```json +[ + { + "ID": "64b602d4896a2a877e274a4a", + "name": "Admin", + "email": "admin@example.com", + "role": "admin" + }, + { + "ID": "64b604733b869b6e81dbee8d", + "name": "buycoffee+3c1c0z2b", + "email": "buycoffee+3c1c0z2b@example.com", + "role": "devops" + } +] +``` + + + +2. Create User + +```bash +curl -L 'localhost:9091/api/v1/admin/user/create' \ +-H 'Content-Type: application/json' \ +-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiQWRtaW4iLCJpZCI6IjY0YjYwMmQ0ODk2YTJhODc3ZTI3NGE0YSIsImV4cCI6MTY4OTY1NzY2NX0.dGji61f160f_eJUSRd7tLJU_wEJ4KDppNx5NZgz0nfE' \ +--data-raw '{ + "name": "buycoffee+0hb01cy5", + "email": "buycoffee+0hb01cy5@example.com", + "password": "6Ga9yGqMmgLdSRrs", + "role": "admin" +}' +``` + + + +3. Delete User + +```bash +curl -L 'localhost:9091/api/v1/admin/user/delete' \ +-H 'Content-Type: application/json' \ +-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiVHJpbmggRGluaCBCaWVuIiwiaWQiOiI2NGI2MDU4OGVlZDFmNGEwMzljMGZjOWYiLCJleHAiOjE2OTAwMzc1OTh9.rrgdQNJ8CCJey5xEHhmi5Zv9s3WRpIkr2wuV9qhkEwc' \ +-d '{ + "id": "64bbd1ed0b175d0395806bd9" +}' +``` + +**// TODO: revoke token when password is updated** + +Response: + +```json +{ + "message": "User deleted successfully!" +} +``` + +4. Update User + +```bash +curl -L 'localhost:9091/api/v1/admin/user/update' \ +-H 'Content-Type: application/json' \ +-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiQWRtaW4iLCJpZCI6IjY0YjYwMmQ0ODk2YTJhODc3ZTI3NGE0YSIsImV4cCI6MTY4OTkzMTU5OH0.iAyD2nsRCmfkaGgyQBA1LnsG7ly1wM59HC2e4Lm5F-U' \ +-d '{ + "id": "64b60588eed1f4a039c0fc9f", + "name": "buycoffee+9wvp2i6v", + "password": "dedicate4673", + "role": "admin" +}' +``` + +Required: ID + +Can't not update email + +**// TODO: revoke token when password is updated** diff --git a/api/handler/gns_handler.go b/api/handler/gns_handler.go new file mode 100644 index 0000000..49471cd --- /dev/null +++ b/api/handler/gns_handler.go @@ -0,0 +1,54 @@ +package handler + +import ( + "net/http" + + "github.com/bamboo-firewall/be/domain" + models "github.com/bamboo-firewall/watcher/model" + "github.com/gin-gonic/gin" +) + +type GNSHandler struct { + GNSUsecase domain.GNSUsecase +} + +func (hh *GNSHandler) convertToCalicoObjectResponse(gns []models.GlobalNetworkSet) []domain.CalicoObjectResponse { + response := make([]domain.CalicoObjectResponse, len(gns)) + for i, item := range gns { + response[i] = domain.CalicoObjectResponse{ + Kind: item.Kind, + ApiVersion: item.ApiVersion, + Metadata: item.Metadata, + Spec: item.Spec, + } + + } + return response +} + +func (hh *GNSHandler) Fetch(c *gin.Context) { + gns, err := hh.GNSUsecase.Fetch(c) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + c.JSON(http.StatusOK, hh.convertToCalicoObjectResponse(gns)) +} + +func (hh *GNSHandler) Search(c *gin.Context) { + var request domain.SearchRequest + + err := c.ShouldBind(&request) + if err != nil { + c.JSON(http.StatusBadRequest, domain.ErrorResponse{Message: err.Error()}) + return + } + + gns, err := hh.GNSUsecase.Search(c, request.Options) + + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + c.JSON(http.StatusOK, hh.convertToCalicoObjectResponse(gns)) +} diff --git a/api/handler/hep_handler.go b/api/handler/hep_handler.go new file mode 100644 index 0000000..6d1a1fd --- /dev/null +++ b/api/handler/hep_handler.go @@ -0,0 +1,54 @@ +package handler + +import ( + "net/http" + + "github.com/bamboo-firewall/be/domain" + models "github.com/bamboo-firewall/watcher/model" + "github.com/gin-gonic/gin" +) + +type HEPHandler struct { + HEPUsecase domain.HEPUsecase +} + +func (hh *HEPHandler) convertToCalicoObjectResponse(heps []models.HostEndPoint) []domain.CalicoObjectResponse { + response := make([]domain.CalicoObjectResponse, len(heps)) + for i, hep := range heps { + response[i] = domain.CalicoObjectResponse{ + Kind: hep.Kind, + ApiVersion: hep.ApiVersion, + Metadata: hep.Metadata, + Spec: hep.Spec, + } + + } + return response +} + +func (hh *HEPHandler) Fetch(c *gin.Context) { + heps, err := hh.HEPUsecase.Fetch(c) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + c.JSON(http.StatusOK, hh.convertToCalicoObjectResponse(heps)) +} + +func (hh *HEPHandler) Search(c *gin.Context) { + var request domain.SearchRequest + + err := c.ShouldBind(&request) + if err != nil { + c.JSON(http.StatusBadRequest, domain.ErrorResponse{Message: err.Error()}) + return + } + + heps, err := hh.HEPUsecase.Search(c, request.Options) + + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + c.JSON(http.StatusOK, hh.convertToCalicoObjectResponse(heps)) +} diff --git a/api/handler/login_handler.go b/api/handler/login_handler.go new file mode 100644 index 0000000..5c03cce --- /dev/null +++ b/api/handler/login_handler.go @@ -0,0 +1,57 @@ +package handler + +import ( + "net/http" + + "github.com/bamboo-firewall/be/bootstrap" + "github.com/bamboo-firewall/be/domain" + "golang.org/x/crypto/bcrypt" + + "github.com/gin-gonic/gin" +) + +type LoginHandler struct { + LoginUsecase domain.LoginUsecase + Env *bootstrap.Env +} + +func (lc *LoginHandler) Login(c *gin.Context) { + var request domain.LoginRequest + + err := c.ShouldBind(&request) + if err != nil { + c.JSON(http.StatusBadRequest, domain.ErrorResponse{Message: err.Error()}) + return + } + + user, err := lc.LoginUsecase.GetUserByEmail(c, request.Email) + if err != nil { + c.JSON(http.StatusNotFound, domain.ErrorResponse{Message: "User not found with the given email"}) + return + } + + if bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(request.Password)) != nil { + c.JSON(http.StatusUnauthorized, domain.ErrorResponse{Message: "Invalid credentials"}) + return + } + + accessToken, err := lc.LoginUsecase.CreateAccessToken(&user, lc.Env.AccessTokenSecret, lc.Env.AccessTokenExpiryHour) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + refreshToken, err := lc.LoginUsecase.CreateRefreshToken(&user, lc.Env.RefreshTokenSecret, lc.Env.RefreshTokenExpiryHour) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + loginResponse := domain.LoginResponse{ + AccessToken: accessToken, + RefreshToken: refreshToken, + User: user, + } + + c.JSON(http.StatusOK, loginResponse) +} diff --git a/api/handler/option_handler.go b/api/handler/option_handler.go new file mode 100644 index 0000000..6874ef4 --- /dev/null +++ b/api/handler/option_handler.go @@ -0,0 +1,42 @@ +package handler + +import ( + "net/http" + + "github.com/bamboo-firewall/be/domain" + "github.com/gin-gonic/gin" +) + +type OptionHandler struct { + HEPUsecase domain.HEPUsecase + GNSUsecase domain.GNSUsecase + PolicyUsecase domain.PolicyUsecase +} + +func (hh *OptionHandler) FetchByType(c *gin.Context) { + var request domain.FetchOptionRequest + err := c.ShouldBind(&request) + if err != nil { + c.JSON(http.StatusBadRequest, domain.ErrorResponse{Message: err.Error()}) + return + } + if !(request.Type == domain.CollectionHEP || request.Type == domain.CollectionPolicy || request.Type == domain.CollectionGNS) { + c.JSON(http.StatusNotFound, domain.ErrorResponse{Message: "Type is not in valid!"}) + } + var options []domain.Option + + switch request.Type { + case domain.CollectionHEP: + options, err = hh.HEPUsecase.GetOptions(c, request.Filter, request.Label) + case domain.CollectionGNS: + options, err = hh.GNSUsecase.GetOptions(c, request.Filter, request.Label) + case domain.CollectionPolicy: + options, err = hh.PolicyUsecase.GetOptions(c, request.Filter, request.Label) + } + + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + c.JSON(http.StatusOK, options) +} diff --git a/api/handler/policy_handler.go b/api/handler/policy_handler.go new file mode 100644 index 0000000..aede602 --- /dev/null +++ b/api/handler/policy_handler.go @@ -0,0 +1,54 @@ +package handler + +import ( + "net/http" + + "github.com/bamboo-firewall/be/domain" + models "github.com/bamboo-firewall/watcher/model" + "github.com/gin-gonic/gin" +) + +type PolicyHandler struct { + PolicyUsecase domain.PolicyUsecase +} + +func (h *PolicyHandler) convertToCalicoObjectResponse(policies []models.GlobalNetworkPolicies) []domain.CalicoObjectResponse { + response := make([]domain.CalicoObjectResponse, len(policies)) + for i, item := range policies { + response[i] = domain.CalicoObjectResponse{ + Kind: item.Kind, + ApiVersion: item.ApiVersion, + Metadata: item.Metadata, + Spec: item.Spec, + } + + } + return response +} + +func (h *PolicyHandler) Fetch(c *gin.Context) { + items, err := h.PolicyUsecase.Fetch(c) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + c.JSON(http.StatusOK, h.convertToCalicoObjectResponse(items)) +} + +func (hh *PolicyHandler) Search(c *gin.Context) { + var request domain.SearchRequest + + err := c.ShouldBind(&request) + if err != nil { + c.JSON(http.StatusBadRequest, domain.ErrorResponse{Message: err.Error()}) + return + } + + policies, err := hh.PolicyUsecase.Search(c, request.Options) + + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + c.JSON(http.StatusOK, hh.convertToCalicoObjectResponse(policies)) +} diff --git a/api/handler/profile_handler.go b/api/handler/profile_handler.go new file mode 100644 index 0000000..36aff39 --- /dev/null +++ b/api/handler/profile_handler.go @@ -0,0 +1,75 @@ +package handler + +import ( + "net/http" + + "github.com/bamboo-firewall/be/domain" + "github.com/gin-gonic/gin" + "golang.org/x/crypto/bcrypt" +) + +type ProfileHandler struct { + ProfileUsecase domain.ProfileUsecase + UserUsecase domain.UserUsecase +} + +func (pc *ProfileHandler) Fetch(c *gin.Context) { + userID := c.GetString("x-user-id") + + profile, err := pc.ProfileUsecase.GetProfileByID(c, userID) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + c.JSON(http.StatusOK, profile) +} + +func (pc *ProfileHandler) Update(c *gin.Context) { + var request domain.RequestUpdateProfile + if err := c.ShouldBindJSON(&request); err != nil { + c.JSON(http.StatusBadRequest, domain.ErrorResponse{Message: err.Error()}) + return + } + + userID := c.GetString("x-user-id") + + user, err := pc.UserUsecase.GetUserByID(c, userID) + + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + if request.Name != "" { + user.Name = request.Name + } + + if request.Password != "" { + encryptedPassword, err := bcrypt.GenerateFromPassword( + []byte(request.Password), + bcrypt.DefaultCost, + ) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + request.Password = string(encryptedPassword) + user.Password = request.Password + } + + err = pc.UserUsecase.Update(c, &user) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + profile, err := pc.ProfileUsecase.GetProfileByID(c, userID) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + c.JSON(http.StatusOK, domain.SuccessResponse{Message: "Update profile successfully", Data: profile}) +} diff --git a/api/handler/refresh_token_handler.go b/api/handler/refresh_token_handler.go new file mode 100644 index 0000000..97361a2 --- /dev/null +++ b/api/handler/refresh_token_handler.go @@ -0,0 +1,56 @@ +package handler + +import ( + "net/http" + + "github.com/bamboo-firewall/be/bootstrap" + "github.com/bamboo-firewall/be/domain" + + "github.com/gin-gonic/gin" +) + +type RefreshTokenHandler struct { + RefreshTokenUsecase domain.RefreshTokenUsecase + Env *bootstrap.Env +} + +func (rtc *RefreshTokenHandler) RefreshToken(c *gin.Context) { + var request domain.RefreshTokenRequest + + err := c.ShouldBind(&request) + if err != nil { + c.JSON(http.StatusBadRequest, domain.ErrorResponse{Message: err.Error()}) + return + } + + id, err := rtc.RefreshTokenUsecase.ExtractIDFromToken(request.RefreshToken, rtc.Env.RefreshTokenSecret) + if err != nil { + c.JSON(http.StatusUnauthorized, domain.ErrorResponse{Message: "User not found"}) + return + } + + user, err := rtc.RefreshTokenUsecase.GetUserByID(c, id) + if err != nil { + c.JSON(http.StatusUnauthorized, domain.ErrorResponse{Message: "User not found"}) + return + } + + accessToken, err := rtc.RefreshTokenUsecase.CreateAccessToken(&user, rtc.Env.AccessTokenSecret, rtc.Env.AccessTokenExpiryHour) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + refreshToken, err := rtc.RefreshTokenUsecase.CreateRefreshToken(&user, rtc.Env.RefreshTokenSecret, rtc.Env.RefreshTokenExpiryHour) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + refreshTokenResponse := domain.RefreshTokenResponse{ + AccessToken: accessToken, + RefreshToken: refreshToken, + } + + c.JSON(http.StatusOK, refreshTokenResponse) +} diff --git a/api/handler/signup_handler.go b/api/handler/signup_handler.go new file mode 100644 index 0000000..5e8b305 --- /dev/null +++ b/api/handler/signup_handler.go @@ -0,0 +1,81 @@ +package handler + +import ( + "net/http" + + "github.com/bamboo-firewall/be/bootstrap" + "github.com/bamboo-firewall/be/domain" + "github.com/casbin/casbin/v2" + "github.com/gin-gonic/gin" + "go.mongodb.org/mongo-driver/bson/primitive" + "golang.org/x/crypto/bcrypt" +) + +type SignupHandler struct { + SignupUsecase domain.SignupUsecase + Enforcer *casbin.Enforcer + Env *bootstrap.Env +} + +func (sc *SignupHandler) Signup(c *gin.Context) { + var request domain.SignupRequest + + err := c.ShouldBind(&request) + if err != nil { + c.JSON(http.StatusBadRequest, domain.ErrorResponse{Message: err.Error()}) + return + } + + _, err = sc.SignupUsecase.GetUserByEmail(c, request.Email) + if err == nil { + c.JSON(http.StatusConflict, domain.ErrorResponse{Message: "User already exists with the given email"}) + return + } + + encryptedPassword, err := bcrypt.GenerateFromPassword( + []byte(request.Password), + bcrypt.DefaultCost, + ) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + request.Password = string(encryptedPassword) + + user := domain.User{ + ID: primitive.NewObjectID(), + Name: request.Name, + Email: request.Email, + Password: request.Password, + Role: "devops", // signup-function only for devops + } + + err = sc.SignupUsecase.Create(c, &user) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + accessToken, err := sc.SignupUsecase.CreateAccessToken(&user, sc.Env.AccessTokenSecret, sc.Env.AccessTokenExpiryHour) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + refreshToken, err := sc.SignupUsecase.CreateRefreshToken(&user, sc.Env.RefreshTokenSecret, sc.Env.RefreshTokenExpiryHour) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + sc.Enforcer.AddGroupingPolicy(user.ID.Hex(), user.Role) + + signupResponse := domain.SignupResponse{ + AccessToken: accessToken, + RefreshToken: refreshToken, + User: user, + } + + c.JSON(http.StatusOK, signupResponse) +} diff --git a/api/handler/statistic_handler.go b/api/handler/statistic_handler.go new file mode 100644 index 0000000..ed12445 --- /dev/null +++ b/api/handler/statistic_handler.go @@ -0,0 +1,34 @@ +package handler + +import ( + "net/http" + + "github.com/bamboo-firewall/be/domain" + "github.com/gin-gonic/gin" +) + +type StatisticHandler struct { + StatisticUsecase domain.StatisticUsecase +} + +func (hh *StatisticHandler) GetSummary(c *gin.Context) { + summary, err := hh.StatisticUsecase.GetSummary(c) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + c.JSON(http.StatusOK, domain.SummaryResponse{ + Summary: summary, + }) +} + +func (hh *StatisticHandler) GetProjectSummary(c *gin.Context) { + projectSummary, err := hh.StatisticUsecase.GetProjectSummary(c) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + c.JSON(http.StatusOK, domain.ProjectSummaryResponse{ + ProjectSummary: projectSummary, + }) +} diff --git a/api/handler/user_handler.go b/api/handler/user_handler.go new file mode 100644 index 0000000..28409f6 --- /dev/null +++ b/api/handler/user_handler.go @@ -0,0 +1,142 @@ +package handler + +import ( + "net/http" + + "github.com/bamboo-firewall/be/domain" + "github.com/casbin/casbin/v2" + "github.com/gin-gonic/gin" + "go.mongodb.org/mongo-driver/bson/primitive" + "golang.org/x/crypto/bcrypt" +) + +type UserHandler struct { + UserUsecase domain.UserUsecase + Enforcer *casbin.Enforcer +} + +func (h *UserHandler) Fetch(c *gin.Context) { + items, err := h.UserUsecase.Fetch(c) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + c.JSON(http.StatusOK, items) +} + +func (h *UserHandler) Create(c *gin.Context) { + var request domain.CreateUserRequest + + err := c.ShouldBind(&request) + if err != nil { + c.JSON(http.StatusBadRequest, domain.ErrorResponse{Message: err.Error()}) + return + } + + _, err = h.UserUsecase.GetUserByEmail(c, request.Email) + if err == nil { + c.JSON(http.StatusConflict, domain.ErrorResponse{Message: "User already exists with the given email"}) + return + } + + encryptedPassword, err := bcrypt.GenerateFromPassword( + []byte(request.Password), + bcrypt.DefaultCost, + ) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + request.Password = string(encryptedPassword) + + user := domain.User{ + ID: primitive.NewObjectID(), + Name: request.Name, + Email: request.Email, + Password: request.Password, + Role: request.Role, + } + + err = h.UserUsecase.Create(c, &user) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + h.Enforcer.AddGroupingPolicy(user.ID.Hex(), user.Role) + + c.JSON(http.StatusOK, user) +} + +func (h *UserHandler) Update(c *gin.Context) { + var request domain.UpdateUserRequest + + err := c.ShouldBind(&request) + if err != nil { + c.JSON(http.StatusBadRequest, domain.ErrorResponse{Message: err.Error()}) + return + } + + user, err := h.UserUsecase.GetUserByID(c, request.ID) + if err != nil { + c.JSON(http.StatusNotFound, domain.ErrorResponse{Message: "User not found"}) + return + } + + encryptedPassword, err := bcrypt.GenerateFromPassword( + []byte(request.Password), + bcrypt.DefaultCost, + ) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + request.Password = string(encryptedPassword) + + if request.Password != "" { + user.Password = request.Password + } + if request.Name != "" { + user.Name = request.Name + } + if request.Role != "" { + user.Role = request.Role + } + + err = h.UserUsecase.Update(c, &user) + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + h.Enforcer.AddGroupingPolicy(user.ID.Hex(), user.Role) + + c.JSON(http.StatusOK, user) +} + +func (h *UserHandler) DeleteById(c *gin.Context) { + var request domain.DeleteUserRequest + + err := c.ShouldBind(&request) + if err != nil { + c.JSON(http.StatusBadRequest, domain.ErrorResponse{Message: err.Error()}) + return + } + + err = h.UserUsecase.DeleteById(c, request.ID) + + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + return + } + + h.Enforcer.RemoveGroupingPolicy(request.ID) + + if err != nil { + c.JSON(http.StatusInternalServerError, domain.ErrorResponse{Message: err.Error()}) + } + + c.JSON(http.StatusOK, domain.SuccessResponse{Message: "User deleted successfully!", Data: nil}) +} diff --git a/api/middleware/casbin_middleware.go b/api/middleware/casbin_middleware.go new file mode 100644 index 0000000..42cf8f4 --- /dev/null +++ b/api/middleware/casbin_middleware.go @@ -0,0 +1,39 @@ +package middleware + +import ( + "github.com/bamboo-firewall/be/domain" + "github.com/casbin/casbin/v2" + "github.com/gin-gonic/gin" +) + +func Authorize(obj string, act string, enforcer *casbin.Enforcer) gin.HandlerFunc { + return func(c *gin.Context) { + // Get current user/subject + sub, existed := c.Get("x-user-id") + if !existed { + c.AbortWithStatusJSON(401, domain.ErrorResponse{Message: "User hasn't logged in yet"}) + return + } + + // Load policy from Database + err := enforcer.LoadPolicy() + if err != nil { + c.AbortWithStatusJSON(500, domain.ErrorResponse{Message: "Failed to load policy from DB"}) + return + } + + // Casbin enforces policy + ok, err := enforcer.Enforce(sub, obj, act) + + if err != nil { + c.AbortWithStatusJSON(500, domain.ErrorResponse{Message: "Error occurred when authorizing user"}) + return + } + + if !ok { + c.AbortWithStatusJSON(403, domain.ErrorResponse{Message: "You are not authorized"}) + return + } + c.Next() + } +} diff --git a/api/middleware/cors_middleware.go b/api/middleware/cors_middleware.go new file mode 100644 index 0000000..98acd5b --- /dev/null +++ b/api/middleware/cors_middleware.go @@ -0,0 +1,23 @@ +package middleware + +import ( + "github.com/gin-gonic/gin" +) + +func CORSMiddleware() gin.HandlerFunc { + return func(c *gin.Context) { + // Set CORS headers + c.Writer.Header().Set("Access-Control-Allow-Origin", "*") + c.Writer.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS") + c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization") + + // Handle preflight requests + if c.Request.Method == "OPTIONS" { + c.AbortWithStatus(204) + return + } + + // Continue to the next middleware + c.Next() + } +} diff --git a/api/middleware/jwt_auth_middleware.go b/api/middleware/jwt_auth_middleware.go new file mode 100644 index 0000000..787fb55 --- /dev/null +++ b/api/middleware/jwt_auth_middleware.go @@ -0,0 +1,37 @@ +package middleware + +import ( + "net/http" + "strings" + + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/internal/tokenutil" + "github.com/gin-gonic/gin" +) + +func JwtAuthMiddleware(secret string) gin.HandlerFunc { + return func(c *gin.Context) { + authHeader := c.Request.Header.Get("Authorization") + t := strings.Split(authHeader, " ") + if len(t) == 2 { + authToken := t[1] + authorized, err := tokenutil.IsAuthorized(authToken, secret) + if authorized { + userID, err := tokenutil.ExtractIDFromToken(authToken, secret) + if err != nil { + c.JSON(http.StatusUnauthorized, domain.ErrorResponse{Message: err.Error()}) + c.Abort() + return + } + c.Set("x-user-id", userID) + c.Next() + return + } + c.JSON(http.StatusUnauthorized, domain.ErrorResponse{Message: err.Error()}) + c.Abort() + return + } + c.JSON(http.StatusUnauthorized, domain.ErrorResponse{Message: "Not authorized"}) + c.Abort() + } +} diff --git a/api/route/gns_route.go b/api/route/gns_route.go new file mode 100644 index 0000000..bb1e07b --- /dev/null +++ b/api/route/gns_route.go @@ -0,0 +1,22 @@ +package route + +import ( + "time" + + "github.com/bamboo-firewall/be/api/handler" + "github.com/bamboo-firewall/be/bootstrap" + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/mongo" + "github.com/bamboo-firewall/be/repository" + "github.com/bamboo-firewall/be/usecase" + "github.com/gin-gonic/gin" +) + +func NewGNSRouter(env *bootstrap.Env, timeout time.Duration, db mongo.Database, group *gin.RouterGroup) { + gr := repository.NewGNSRepository(db, domain.CollectionGNS) + gc := &handler.GNSHandler{ + GNSUsecase: usecase.NewGNSUsecase(gr, timeout), + } + group.POST("/gns/fetch", gc.Fetch) + group.POST("/gns/search", gc.Search) +} diff --git a/api/route/hep_route.go b/api/route/hep_route.go new file mode 100644 index 0000000..e9ed41f --- /dev/null +++ b/api/route/hep_route.go @@ -0,0 +1,22 @@ +package route + +import ( + "time" + + "github.com/bamboo-firewall/be/api/handler" + "github.com/bamboo-firewall/be/bootstrap" + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/mongo" + "github.com/bamboo-firewall/be/repository" + "github.com/bamboo-firewall/be/usecase" + "github.com/gin-gonic/gin" +) + +func NewHEPRouter(env *bootstrap.Env, timeout time.Duration, db mongo.Database, group *gin.RouterGroup) { + hr := repository.NewHEPRepository(db, domain.CollectionHEP) + hc := &handler.HEPHandler{ + HEPUsecase: usecase.NewHEPUsecase(hr, timeout), + } + group.POST("/hep/fetch", hc.Fetch) + group.POST("/hep/search", hc.Search) +} diff --git a/api/route/login_route.go b/api/route/login_route.go new file mode 100644 index 0000000..23978c1 --- /dev/null +++ b/api/route/login_route.go @@ -0,0 +1,22 @@ +package route + +import ( + "time" + + "github.com/bamboo-firewall/be/api/handler" + "github.com/bamboo-firewall/be/bootstrap" + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/mongo" + "github.com/bamboo-firewall/be/repository" + "github.com/bamboo-firewall/be/usecase" + "github.com/gin-gonic/gin" +) + +func NewLoginRouter(env *bootstrap.Env, timeout time.Duration, db mongo.Database, group *gin.RouterGroup) { + ur := repository.NewUserRepository(db, domain.CollectionUser) + lc := &handler.LoginHandler{ + LoginUsecase: usecase.NewLoginUsecase(ur, timeout), + Env: env, + } + group.POST("/login", lc.Login) +} diff --git a/api/route/option_route.go b/api/route/option_route.go new file mode 100644 index 0000000..9740ec3 --- /dev/null +++ b/api/route/option_route.go @@ -0,0 +1,25 @@ +package route + +import ( + "time" + + "github.com/bamboo-firewall/be/api/handler" + "github.com/bamboo-firewall/be/bootstrap" + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/mongo" + "github.com/bamboo-firewall/be/repository" + "github.com/bamboo-firewall/be/usecase" + "github.com/gin-gonic/gin" +) + +func NewOptionRoute(env *bootstrap.Env, timeout time.Duration, db mongo.Database, group *gin.RouterGroup) { + hepRepo := repository.NewHEPRepository(db, domain.CollectionHEP) + gnsRepo := repository.NewGNSRepository(db, domain.CollectionGNS) + policyRepo := repository.NewPolicyRepository(db, domain.CollectionPolicy) + hl := &handler.OptionHandler{ + HEPUsecase: usecase.NewHEPUsecase(hepRepo, timeout), + GNSUsecase: usecase.NewGNSUsecase(gnsRepo, timeout), + PolicyUsecase: usecase.NewPolicyUsecase(policyRepo, timeout), + } + group.POST("/options/fetch", hl.FetchByType) +} diff --git a/api/route/ping_route.go b/api/route/ping_route.go new file mode 100644 index 0000000..8cd31ff --- /dev/null +++ b/api/route/ping_route.go @@ -0,0 +1,16 @@ +package route + +import ( + "net/http" + "time" + + "github.com/bamboo-firewall/be/bootstrap" + "github.com/bamboo-firewall/be/mongo" + "github.com/gin-gonic/gin" +) + +func NewPingRouter(env *bootstrap.Env, timeout time.Duration, db mongo.Database, group *gin.RouterGroup) { + group.GET("/ping", func(ctx *gin.Context) { + ctx.String(http.StatusOK, "pong") + }) +} diff --git a/api/route/policy_route.go b/api/route/policy_route.go new file mode 100644 index 0000000..096c571 --- /dev/null +++ b/api/route/policy_route.go @@ -0,0 +1,22 @@ +package route + +import ( + "time" + + "github.com/bamboo-firewall/be/api/handler" + "github.com/bamboo-firewall/be/bootstrap" + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/mongo" + "github.com/bamboo-firewall/be/repository" + "github.com/bamboo-firewall/be/usecase" + "github.com/gin-gonic/gin" +) + +func NewPolicyRouter(env *bootstrap.Env, timeout time.Duration, db mongo.Database, group *gin.RouterGroup) { + r := repository.NewPolicyRepository(db, domain.CollectionPolicy) + h := &handler.PolicyHandler{ + PolicyUsecase: usecase.NewPolicyUsecase(r, timeout), + } + group.POST("/policy/fetch", h.Fetch) + group.POST("/policy/search", h.Search) +} diff --git a/api/route/profile_route.go b/api/route/profile_route.go new file mode 100644 index 0000000..8d5f500 --- /dev/null +++ b/api/route/profile_route.go @@ -0,0 +1,24 @@ +package route + +import ( + "time" + + "github.com/bamboo-firewall/be/api/handler" + "github.com/bamboo-firewall/be/bootstrap" + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/mongo" + "github.com/bamboo-firewall/be/repository" + "github.com/bamboo-firewall/be/usecase" + "github.com/casbin/casbin/v2" + "github.com/gin-gonic/gin" +) + +func NewProfileRouter(env *bootstrap.Env, timeout time.Duration, db mongo.Database, group *gin.RouterGroup, enforcer *casbin.Enforcer) { + ur := repository.NewUserRepository(db, domain.CollectionUser) + pc := &handler.ProfileHandler{ + ProfileUsecase: usecase.NewProfileUsecase(ur, timeout), + UserUsecase: usecase.NewUserUsecase(ur, enforcer, timeout), + } + group.POST("/profile", pc.Fetch) + group.POST("/profile/update", pc.Update) +} diff --git a/api/route/refresh_token_route.go b/api/route/refresh_token_route.go new file mode 100644 index 0000000..7763a85 --- /dev/null +++ b/api/route/refresh_token_route.go @@ -0,0 +1,23 @@ +package route + +import ( + "time" + + "github.com/bamboo-firewall/be/api/handler" + "github.com/bamboo-firewall/be/bootstrap" + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/mongo" + "github.com/bamboo-firewall/be/repository" + "github.com/bamboo-firewall/be/usecase" + + "github.com/gin-gonic/gin" +) + +func NewRefreshTokenRouter(env *bootstrap.Env, timeout time.Duration, db mongo.Database, group *gin.RouterGroup) { + ur := repository.NewUserRepository(db, domain.CollectionUser) + rtc := &handler.RefreshTokenHandler{ + RefreshTokenUsecase: usecase.NewRefreshTokenUsecase(ur, timeout), + Env: env, + } + group.POST("/refresh", rtc.RefreshToken) +} diff --git a/api/route/route.go b/api/route/route.go new file mode 100644 index 0000000..580a5ad --- /dev/null +++ b/api/route/route.go @@ -0,0 +1,68 @@ +package route + +import ( + "fmt" + "time" + + "github.com/bamboo-firewall/be/api/middleware" + "github.com/bamboo-firewall/be/bootstrap" + "github.com/bamboo-firewall/be/mongo" + "github.com/casbin/casbin/v2" + + mongodbadapter "github.com/casbin/mongodb-adapter/v3" + + "github.com/gin-gonic/gin" +) + +func Setup(env *bootstrap.Env, timeout time.Duration, db mongo.Database, gin *gin.Engine) { + gin.Use(middleware.CORSMiddleware()) + + adapterConfig := mongodbadapter.AdapterConfig{ + DatabaseName: env.DBName, + } + + adapter, err := mongodbadapter.NewAdapterByDB(db.Client().MongoClient(), &adapterConfig) + + if err != nil { + panic(err) + } + + enforcer, err := casbin.NewEnforcer("config/rbac_model.conf", adapter) + if err != nil { + panic(fmt.Sprintf("failed to create casbin enforcer: %v", err)) + } + + //add policy + if hasPolicy := enforcer.HasPolicy("admin", "user", "write"); !hasPolicy { + enforcer.AddPolicy("admin", "user", "write") + } + if hasPolicy := enforcer.HasPolicy("admin", "user", "read"); !hasPolicy { + enforcer.AddPolicy("admin", "user", "read") + } + if hasPolicy := enforcer.HasPolicy("devops", "user", "read"); !hasPolicy { + enforcer.AddPolicy("devops", "user", "read") + } + + publicRouter := gin.Group("api/") + // All Public APIs + NewPingRouter(env, timeout, db, publicRouter) + NewSignupRouter(env, timeout, db, publicRouter, enforcer) + NewLoginRouter(env, timeout, db, publicRouter) + NewRefreshTokenRouter(env, timeout, db, publicRouter) + + // Privated APIs + protectedRouter := gin.Group("api/v1/") + protectedRouter.Use(middleware.JwtAuthMiddleware(env.AccessTokenSecret)) + NewProfileRouter(env, timeout, db, protectedRouter, enforcer) + NewOptionRoute(env, timeout, db, protectedRouter) + NewHEPRouter(env, timeout, db, protectedRouter) + NewGNSRouter(env, timeout, db, protectedRouter) + NewPolicyRouter(env, timeout, db, protectedRouter) + NewStatisticRouter(env, timeout, db, protectedRouter) + + // Admin APIs + adminRouter := gin.Group("api/v1/admin/") + adminRouter.Use(middleware.JwtAuthMiddleware(env.AccessTokenSecret)) + adminRouter.Use(middleware.Authorize("user", "write", enforcer)) + NewUserRouter(env, timeout, db, adminRouter, enforcer) +} diff --git a/api/route/signup_route.go b/api/route/signup_route.go new file mode 100644 index 0000000..6eb79f5 --- /dev/null +++ b/api/route/signup_route.go @@ -0,0 +1,24 @@ +package route + +import ( + "time" + + "github.com/bamboo-firewall/be/api/handler" + "github.com/bamboo-firewall/be/bootstrap" + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/mongo" + "github.com/bamboo-firewall/be/repository" + "github.com/bamboo-firewall/be/usecase" + "github.com/casbin/casbin/v2" + "github.com/gin-gonic/gin" +) + +func NewSignupRouter(env *bootstrap.Env, timeout time.Duration, db mongo.Database, group *gin.RouterGroup, enforcer *casbin.Enforcer) { + ur := repository.NewUserRepository(db, domain.CollectionUser) + sc := handler.SignupHandler{ + SignupUsecase: usecase.NewSignupUsecase(ur, timeout), + Enforcer: enforcer, + Env: env, + } + group.POST("/signup", sc.Signup) +} diff --git a/api/route/statistic_route.go b/api/route/statistic_route.go new file mode 100644 index 0000000..df13e48 --- /dev/null +++ b/api/route/statistic_route.go @@ -0,0 +1,26 @@ +package route + +import ( + "time" + + "github.com/bamboo-firewall/be/api/handler" + "github.com/bamboo-firewall/be/bootstrap" + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/mongo" + "github.com/bamboo-firewall/be/repository" + "github.com/bamboo-firewall/be/usecase" + "github.com/gin-gonic/gin" +) + +func NewStatisticRouter(env *bootstrap.Env, timeout time.Duration, db mongo.Database, group *gin.RouterGroup) { + hr := repository.NewHEPRepository(db, domain.CollectionHEP) + gr := repository.NewGNSRepository(db, domain.CollectionGNS) + pr := repository.NewPolicyRepository(db, domain.CollectionPolicy) + ur := repository.NewUserRepository(db, domain.CollectionUser) + + h := &handler.StatisticHandler{ + StatisticUsecase: usecase.NewStatisticUsecase(pr, gr, hr, ur, timeout), + } + group.POST("/statistic/summary", h.GetSummary) + group.POST("/statistic/project-summary", h.GetProjectSummary) +} diff --git a/api/route/user_route.go b/api/route/user_route.go new file mode 100644 index 0000000..ac9bcb6 --- /dev/null +++ b/api/route/user_route.go @@ -0,0 +1,26 @@ +package route + +import ( + "time" + + "github.com/bamboo-firewall/be/api/handler" + "github.com/bamboo-firewall/be/bootstrap" + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/mongo" + "github.com/bamboo-firewall/be/repository" + "github.com/bamboo-firewall/be/usecase" + "github.com/casbin/casbin/v2" + "github.com/gin-gonic/gin" +) + +func NewUserRouter(env *bootstrap.Env, timeout time.Duration, db mongo.Database, group *gin.RouterGroup, enforcer *casbin.Enforcer) { + repo := repository.NewUserRepository(db, domain.CollectionUser) + hl := &handler.UserHandler{ + UserUsecase: usecase.NewUserUsecase(repo, enforcer, timeout), + Enforcer: enforcer, + } + group.POST("/user/fetch", hl.Fetch) + group.POST("/user/create", hl.Create) + group.POST("/user/update", hl.Update) + group.POST("/user/delete", hl.DeleteById) +} diff --git a/bootstrap/app.go b/bootstrap/app.go new file mode 100644 index 0000000..d533664 --- /dev/null +++ b/bootstrap/app.go @@ -0,0 +1,19 @@ +package bootstrap + +import "github.com/bamboo-firewall/be/mongo" + +type Application struct { + Env *Env + Mongo mongo.Client +} + +func App() Application { + app := &Application{} + app.Env = NewEnv(".") + app.Mongo = NewMongoDatabase(app.Env) + return *app +} + +func (app *Application) CloseDBConnection() { + CloseMongoDBConnection(app.Mongo) +} diff --git a/bootstrap/database.go b/bootstrap/database.go new file mode 100644 index 0000000..fd3d1c6 --- /dev/null +++ b/bootstrap/database.go @@ -0,0 +1,44 @@ +package bootstrap + +import ( + "context" + "log" + "time" + + "github.com/bamboo-firewall/be/mongo" +) + +func NewMongoDatabase(env *Env) mongo.Client { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + client, err := mongo.NewClient(env.MongoDbURI) + if err != nil { + log.Fatal(err) + } + + err = client.Connect(ctx) + if err != nil { + log.Fatal(err) + } + + err = client.Ping(ctx) + if err != nil { + log.Fatal(err) + } + + return client +} + +func CloseMongoDBConnection(client mongo.Client) { + if client == nil { + return + } + + err := client.Disconnect(context.TODO()) + if err != nil { + log.Fatal(err) + } + + log.Println("Connection to MongoDB closed.") +} diff --git a/bootstrap/env.go b/bootstrap/env.go new file mode 100644 index 0000000..be00d66 --- /dev/null +++ b/bootstrap/env.go @@ -0,0 +1,45 @@ +package bootstrap + +import ( + "log" + + "github.com/spf13/viper" +) + +type Env struct { + AppEnv string `mapstructure:"APP_ENV" json:"APP_ENV"` + ServerAddress string `mapstructure:"SERVER_ADDRESS" json:"SERVER_ADDRESS"` + ContextTimeout int `mapstructure:"CONTEXT_TIMEOUT" json:"CONTEXT_TIMEOUT"` + DBName string `mapstructure:"DB_NAME" json:"DB_NAME"` + AccessTokenExpiryHour int `mapstructure:"ACCESS_TOKEN_EXPIRY_HOUR" json:"ACCESS_TOKEN_EXPIRY_HOUR"` + RefreshTokenExpiryHour int `mapstructure:"REFRESH_TOKEN_EXPIRY_HOUR" json:"REFRESH_TOKEN_EXPIRY_HOUR"` + AccessTokenSecret string `mapstructure:"ACCESS_TOKEN_SECRET" json:"ACCESS_TOKEN_SECRET"` + RefreshTokenSecret string `mapstructure:"REFRESH_TOKEN_SECRET" json:"REFRESH_TOKEN_SECRET"` + MongoDbURI string `mapstructure:"MONGO_URI" json:"MONGO_URI"` + AdminPassword string `mapstructure:"ADMIN_PASSWORD" json:"ADMIN_PASSWORD"` +} + +func NewEnv(path string) *Env { + env := Env{} + viper.AddConfigPath(path) + viper.SetConfigType("json") + viper.SetConfigName("config") + + viper.AutomaticEnv() + + err := viper.ReadInConfig() + if err != nil { + log.Fatal("Can't find config file : ", err) + } + + err = viper.Unmarshal(&env) + if err != nil { + log.Fatal("Environment can't be loaded: ", err) + } + + if env.AppEnv == "development" { + log.Println("The App is running in development env") + } + + return &env +} diff --git a/cmd/create_admin/create_admin.go b/cmd/create_admin/create_admin.go new file mode 100644 index 0000000..1d2d201 --- /dev/null +++ b/cmd/create_admin/create_admin.go @@ -0,0 +1,76 @@ +package main + +import ( + "context" + "log" + + "github.com/bamboo-firewall/be/bootstrap" + "github.com/bamboo-firewall/be/domain" + "github.com/casbin/casbin/v2" + mongodbadapter "github.com/casbin/mongodb-adapter/v3" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + "golang.org/x/crypto/bcrypt" +) + +func main() { + app := bootstrap.App() + env := app.Env + + db := app.Mongo.Database(env.DBName) + defer app.CloseDBConnection() + + // Check if admin user already exists + var admin domain.User + res := db.Collection(domain.CollectionUser).FindOne(context.Background(), bson.M{"email": "admin@example.com"}).Decode(&admin) + if res == nil { + log.Println("Admin user already exists") + return + } + + // Create admin user + encryptedPassword, err := bcrypt.GenerateFromPassword( + []byte(env.AdminPassword), + bcrypt.DefaultCost, + ) + + if err != nil { + log.Println(err) + return + } + + user := domain.User{ + ID: primitive.NewObjectID(), + Name: "Admin", + Email: "admin@example.com", + Password: string(encryptedPassword), + Role: "admin", + } + + _, err = db.Collection(domain.CollectionUser).InsertOne(context.Background(), &user) + if err != nil { + log.Println(err) + return + } + + adapterConfig := mongodbadapter.AdapterConfig{ + DatabaseName: env.DBName, + } + + adapter, err := mongodbadapter.NewAdapterByDB(db.Client().MongoClient(), &adapterConfig) + + if err != nil { + log.Println(err) + return + } + + enforcer, err := casbin.NewEnforcer("config/rbac_model.conf", adapter) + if err != nil { + log.Println(err) + return + } + // Add policy for admin + enforcer.AddGroupingPolicy(user.ID.Hex(), user.Role) + + log.Println("Admin user created successfully") +} diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 0000000..3a279fe --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "time" + + route "github.com/bamboo-firewall/be/api/route" + "github.com/bamboo-firewall/be/bootstrap" + "github.com/gin-gonic/gin" +) + +func main() { + app := bootstrap.App() + + env := app.Env + + db := app.Mongo.Database(env.DBName) + defer app.CloseDBConnection() + + timeout := time.Duration(env.ContextTimeout) * time.Second + + gin := gin.Default() + + route.Setup(env, timeout, db, gin) + + gin.Run(env.ServerAddress) +} diff --git a/config.json b/config.json new file mode 100644 index 0000000..7dfcabd --- /dev/null +++ b/config.json @@ -0,0 +1,13 @@ +{ + "APP_ENV": "development", + "SERVER_ADDRESS": ":9091", + "PORT": "9091", + "DB_NAME": "bamboofw", + "CONTEXT_TIMEOUT": "2", + "ACCESS_TOKEN_EXPIRY_HOUR": "2", + "REFRESH_TOKEN_EXPIRY_HOUR": "168", + "ACCESS_TOKEN_SECRET": "jzZU3qXB6QEArUPLFi3g", + "REFRESH_TOKEN_SECRET": "kdrqZnivLJ5UoNq3ZkYT", + "MONGO_URI": "mongodb://mongou:mongopass@mongodb:27017/?authSource=admin", + "ADMIN_PASSWORD": "n9dR63zeCAxEPY92" +} \ No newline at end of file diff --git a/config/rbac_model.conf b/config/rbac_model.conf new file mode 100644 index 0000000..71159e3 --- /dev/null +++ b/config/rbac_model.conf @@ -0,0 +1,14 @@ +[request_definition] +r = sub, obj, act + +[policy_definition] +p = sub, obj, act + +[role_definition] +g = _, _ + +[policy_effect] +e = some(where (p.eft == allow)) + +[matchers] +m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act \ No newline at end of file diff --git a/deployment/.env b/deployment/.env new file mode 100644 index 0000000..bfc2fe0 --- /dev/null +++ b/deployment/.env @@ -0,0 +1,13 @@ +APP_ENV=development +SERVER_ADDRESS=:9091 +PORT=9091 +DB_NAME=bamboofw +DB_PORT=27017 +DB_ROOT_USER=mongou +DB_ROOT_PASS=mongopass +CONTEXT_TIMEOUT=2 +ACCESS_TOKEN_EXPIRY_HOUR=2 +REFRESH_TOKEN_EXPIRY_HOUR=168 +ACCESS_TOKEN_SECRET=jzZU3qXB6QEArUPLFi3g +REFRESH_TOKEN_SECRET=kdrqZnivLJ5UoNq3ZkYT +MONGO_URI=mongodb://bamboofw:nvaNhKvSJUu7sLR4NfGn@mongodb:27017/bamboofw?authSource=bamboofw \ No newline at end of file diff --git a/deployment/Dockerfile b/deployment/Dockerfile new file mode 100644 index 0000000..5a083ab --- /dev/null +++ b/deployment/Dockerfile @@ -0,0 +1,21 @@ +FROM golang:1.20 as builder + +WORKDIR /go/src/github.com/bamboo-firewall/be +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +RUN CGO_ENABLED=0 GOOS=linux go build -o /bin/service /go/src/github.com/bamboo-firewall/be/cmd/main.go + +FROM alpine:3.15 +WORKDIR /app +ENV TZ=Asia/Ho_Chi_Minh +RUN mkdir config +COPY --from=builder /bin/service /app/service +COPY --from=builder /go/src/github.com/bamboo-firewall/be/config.json /app/config.json +COPY --from=builder /go/src/github.com/bamboo-firewall/be/config/rbac_model.conf /app/config/rbac_model.conf +# add package for handle timezone in alpine +RUN apk add tzdata \ + && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \ + && chmod u+x /app/service + +CMD [ "/app/service" ] \ No newline at end of file diff --git a/deployment/docker-compose.yaml b/deployment/docker-compose.yaml new file mode 100644 index 0000000..af0104a --- /dev/null +++ b/deployment/docker-compose.yaml @@ -0,0 +1,31 @@ +version: "3.8" + +services: + api: + build: + context: ../ + dockerfile: deployment/Dockerfile + image: bamboo-api + container_name: bamboo-api + restart: unless-stopped + env_file: .env + ports: + - "$PORT:$PORT" + depends_on: + - mongodb + + mongodb: + image: mongo:6.0 + container_name: bamboo-mongodb + restart: unless-stopped + env_file: .env + environment: + - MONGO_INITDB_ROOT_USERNAME=$DB_ROOT_USER + - MONGO_INITDB_ROOT_PASSWORD=$DB_ROOT_PASS + ports: + - "$DB_PORT:$DB_PORT" + volumes: + - dbdata:/data/db + +volumes: + dbdata: diff --git a/domain/calico_object_response.go b/domain/calico_object_response.go new file mode 100644 index 0000000..b4a275c --- /dev/null +++ b/domain/calico_object_response.go @@ -0,0 +1,8 @@ +package domain + +type CalicoObjectResponse struct { + Kind string `json:"kind"` + ApiVersion string `json:"apiVersion"` + Metadata interface{} `json:"metadata,omitempty"` + Spec interface{} `json:"spec,omitempty"` +} diff --git a/domain/error_response.go b/domain/error_response.go new file mode 100644 index 0000000..ef263a0 --- /dev/null +++ b/domain/error_response.go @@ -0,0 +1,5 @@ +package domain + +type ErrorResponse struct { + Message string `json:"message"` +} diff --git a/domain/gns.go b/domain/gns.go new file mode 100644 index 0000000..f287551 --- /dev/null +++ b/domain/gns.go @@ -0,0 +1,25 @@ +package domain + +import ( + "context" + + models "github.com/bamboo-firewall/watcher/model" + "go.mongodb.org/mongo-driver/bson" +) + +const ( + CollectionGNS = "globalnetworksets" +) + +type GNSRepository interface { + Fetch(c context.Context) ([]models.GlobalNetworkSet, error) + Search(c context.Context, options bson.M) ([]models.GlobalNetworkSet, error) + GetTotal(c context.Context) (int64, error) + AggGroupBy(c context.Context, query bson.M, key string, jsonPath string) ([]Option, error) +} + +type GNSUsecase interface { + Fetch(c context.Context) ([]models.GlobalNetworkSet, error) + Search(c context.Context, options []Option) ([]models.GlobalNetworkSet, error) + GetOptions(c context.Context, filter []Option, key string) ([]Option, error) +} diff --git a/domain/hep.go b/domain/hep.go new file mode 100644 index 0000000..2f21145 --- /dev/null +++ b/domain/hep.go @@ -0,0 +1,26 @@ +package domain + +import ( + "context" + + models "github.com/bamboo-firewall/watcher/model" + "go.mongodb.org/mongo-driver/bson" +) + +const ( + CollectionHEP = "hostendpoints" +) + +type HEPRepository interface { + Fetch(c context.Context) ([]models.HostEndPoint, error) + Search(c context.Context, options bson.M) ([]models.HostEndPoint, error) + GetTotal(c context.Context) (int64, error) + GetProjectSummary(c context.Context) ([]ProjectSummary, error) + AggGroupBy(c context.Context, query bson.M, key string, jsonPath string) ([]Option, error) +} + +type HEPUsecase interface { + Fetch(c context.Context) ([]models.HostEndPoint, error) + Search(c context.Context, options []Option) ([]models.HostEndPoint, error) + GetOptions(c context.Context, filter []Option, key string) ([]Option, error) +} diff --git a/domain/jwt_custom.go b/domain/jwt_custom.go new file mode 100644 index 0000000..5107a72 --- /dev/null +++ b/domain/jwt_custom.go @@ -0,0 +1,16 @@ +package domain + +import ( + "github.com/golang-jwt/jwt/v4" +) + +type JwtCustomClaims struct { + Name string `json:"name"` + ID string `json:"id"` + jwt.StandardClaims +} + +type JwtCustomRefreshClaims struct { + ID string `json:"id"` + jwt.StandardClaims +} diff --git a/domain/login.go b/domain/login.go new file mode 100644 index 0000000..ead21e2 --- /dev/null +++ b/domain/login.go @@ -0,0 +1,22 @@ +package domain + +import ( + "context" +) + +type LoginRequest struct { + Email string `form:"email" binding:"required,email"` + Password string `form:"password" binding:"required"` +} + +type LoginResponse struct { + AccessToken string `json:"accessToken"` + RefreshToken string `json:"refreshToken"` + User User `json:"user"` +} + +type LoginUsecase interface { + GetUserByEmail(c context.Context, email string) (User, error) + CreateAccessToken(user *User, secret string, expiry int) (accessToken string, err error) + CreateRefreshToken(user *User, secret string, expiry int) (refreshToken string, err error) +} diff --git a/domain/metadata.go b/domain/metadata.go new file mode 100644 index 0000000..d9f1b54 --- /dev/null +++ b/domain/metadata.go @@ -0,0 +1,10 @@ +package domain + +import "time" + +type Metadata struct { + Name string `bson:"name"` + UID string `bson:"uid"` + CreationTimestamp time.Time `bson:"creationTimestamp"` + Labels map[string]string `bson:"labels"` +} diff --git a/domain/option.go b/domain/option.go new file mode 100644 index 0000000..3369557 --- /dev/null +++ b/domain/option.go @@ -0,0 +1,10 @@ +package domain + +const ( + CollectionOption = "options" +) + +type Option struct { + Key string `bson:"key" json:"key"` + Value string `bson:"value" json:"value"` +} diff --git a/domain/option_request.go b/domain/option_request.go new file mode 100644 index 0000000..bcb3e1d --- /dev/null +++ b/domain/option_request.go @@ -0,0 +1,7 @@ +package domain + +type FetchOptionRequest struct { + Type string `json:"type" binding:"required"` + Label string `json:"label" binding:"required"` + Filter []Option `json:"filter" binding:"required"` +} diff --git a/domain/policy.go b/domain/policy.go new file mode 100644 index 0000000..6ced08f --- /dev/null +++ b/domain/policy.go @@ -0,0 +1,25 @@ +package domain + +import ( + "context" + + models "github.com/bamboo-firewall/watcher/model" + "go.mongodb.org/mongo-driver/bson" +) + +const ( + CollectionPolicy = "globalnetworkpolicies" +) + +type PolicyRepository interface { + Fetch(c context.Context) ([]models.GlobalNetworkPolicies, error) + Search(c context.Context, options bson.M) ([]models.GlobalNetworkPolicies, error) + GetTotal(c context.Context) (int64, error) + AggGroupBy(c context.Context, query bson.M, key string, jsonPath string) ([]Option, error) +} + +type PolicyUsecase interface { + Fetch(c context.Context) ([]models.GlobalNetworkPolicies, error) + Search(c context.Context, options []Option) ([]models.GlobalNetworkPolicies, error) + GetOptions(c context.Context, filter []Option, key string) ([]Option, error) +} diff --git a/domain/profile.go b/domain/profile.go new file mode 100644 index 0000000..747bd8e --- /dev/null +++ b/domain/profile.go @@ -0,0 +1,19 @@ +package domain + +import "context" + +type Profile struct { + UserId string `json:"user_id"` + Name string `json:"name"` + Email string `json:"email"` + Role string `json:"role"` +} + +type RequestUpdateProfile struct { + Name string `json:"name"` + Password string `json:"password"` +} + +type ProfileUsecase interface { + GetProfileByID(c context.Context, userID string) (*Profile, error) +} diff --git a/domain/refresh_token.go b/domain/refresh_token.go new file mode 100644 index 0000000..6374abd --- /dev/null +++ b/domain/refresh_token.go @@ -0,0 +1,21 @@ +package domain + +import ( + "context" +) + +type RefreshTokenRequest struct { + RefreshToken string `form:"refreshToken" binding:"required"` +} + +type RefreshTokenResponse struct { + AccessToken string `json:"accessToken"` + RefreshToken string `json:"refreshToken"` +} + +type RefreshTokenUsecase interface { + GetUserByID(c context.Context, id string) (User, error) + CreateAccessToken(user *User, secret string, expiry int) (accessToken string, err error) + CreateRefreshToken(user *User, secret string, expiry int) (refreshToken string, err error) + ExtractIDFromToken(requestToken string, secret string) (string, error) +} diff --git a/domain/search_request.go b/domain/search_request.go new file mode 100644 index 0000000..cae4e7d --- /dev/null +++ b/domain/search_request.go @@ -0,0 +1,5 @@ +package domain + +type SearchRequest struct { + Options []Option `json:"options" binding:"required"` +} diff --git a/domain/signup.go b/domain/signup.go new file mode 100644 index 0000000..ddbef8d --- /dev/null +++ b/domain/signup.go @@ -0,0 +1,24 @@ +package domain + +import ( + "context" +) + +type SignupRequest struct { + Name string `form:"name" binding:"required"` + Email string `form:"email" binding:"required,email"` + Password string `form:"password" binding:"required"` +} + +type SignupResponse struct { + AccessToken string `json:"accessToken"` + RefreshToken string `json:"refreshToken"` + User User `json:"user"` +} + +type SignupUsecase interface { + Create(c context.Context, user *User) error + GetUserByEmail(c context.Context, email string) (User, error) + CreateAccessToken(user *User, secret string, expiry int) (accessToken string, err error) + CreateRefreshToken(user *User, secret string, expiry int) (refreshToken string, err error) +} diff --git a/domain/statistic.go b/domain/statistic.go new file mode 100644 index 0000000..2ad2ee2 --- /dev/null +++ b/domain/statistic.go @@ -0,0 +1,28 @@ +package domain + +import "context" + +type Summary struct { + TotalGlobalNetworkSet int64 `json:"total_global_network_set"` + TotalPolicy int64 `json:"total_policy"` + TotalHostEndpoint int64 `json:"total_host_endpoint"` + TotalUser int64 `json:"total_user"` +} + +type ProjectSummary struct { + ProjectName string `json:"project_name"` + Total int64 `json:"total"` +} + +type SummaryResponse struct { + Summary Summary `json:"summary"` +} + +type ProjectSummaryResponse struct { + ProjectSummary []ProjectSummary `json:"project_summary"` +} + +type StatisticUsecase interface { + GetSummary(c context.Context) (Summary, error) + GetProjectSummary(c context.Context) ([]ProjectSummary, error) +} diff --git a/domain/success_response.go b/domain/success_response.go new file mode 100644 index 0000000..44388f3 --- /dev/null +++ b/domain/success_response.go @@ -0,0 +1,6 @@ +package domain + +type SuccessResponse struct { + Message string `json:"message"` + Data interface{} `json:"data"` +} diff --git a/domain/user.go b/domain/user.go new file mode 100644 index 0000000..774a522 --- /dev/null +++ b/domain/user.go @@ -0,0 +1,56 @@ +package domain + +import ( + "context" + + "go.mongodb.org/mongo-driver/bson/primitive" +) + +const ( + CollectionUser = "users" +) + +type CreateUserRequest struct { + Name string `json:"name" binding:"required|email"` + Email string `json:"email" binding:"required"` + Role string `json:"role" binding:"required"` + Password string `json:"password" binding:"required"` +} + +type UpdateUserRequest struct { + ID string `json:"id" binding:"required"` + Name string `json:"name"` + Role string `json:"role"` + Password string `json:"password"` +} + +type DeleteUserRequest struct { + ID string `json:"id" binding:"required"` +} + +type User struct { + ID primitive.ObjectID `bson:"_id"` + Name string `bson:"name" json:"name"` + Email string `bson:"email" json:"email"` + Role string `bson:"role" json:"role"` + Password string `bson:"password" json:"-"` +} + +type UserRepository interface { + Create(c context.Context, user *User) error + Update(c context.Context, user *User) error + DeleteById(c context.Context, id string) error + Fetch(c context.Context) ([]User, error) + GetByEmail(c context.Context, email string) (User, error) + GetByID(c context.Context, id string) (User, error) + GetTotal(c context.Context) (int64, error) +} + +type UserUsecase interface { + Create(c context.Context, user *User) error + Update(c context.Context, user *User) error + Fetch(c context.Context) ([]User, error) + DeleteById(c context.Context, id string) error + GetUserByEmail(c context.Context, email string) (User, error) + GetUserByID(c context.Context, id string) (User, error) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e9cf1df --- /dev/null +++ b/go.mod @@ -0,0 +1,63 @@ +module github.com/bamboo-firewall/be + +go 1.20 + +require ( + github.com/casbin/casbin/v2 v2.71.1 + github.com/casbin/mongodb-adapter/v3 v3.5.0 + github.com/gin-gonic/gin v1.9.1 + github.com/golang-jwt/jwt/v4 v4.5.0 + github.com/spf13/viper v1.16.0 + go.mongodb.org/mongo-driver v1.12.0 + golang.org/x/crypto v0.11.0 +) + +require ( + github.com/bamboo-firewall/watcher v0.0.1 + github.com/projectcalico/api v0.0.0-20230602153125-fb7148692637 // indirect +) + +require ( + github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect + github.com/bytedance/sonic v1.9.1 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect + github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.2 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.14.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/golang/snappy v0.0.4 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/compress v1.16.7 // indirect + github.com/klauspost/cpuid/v2 v2.2.4 // indirect + github.com/leodido/go-urn v1.2.4 // indirect + github.com/magiconair/properties v1.8.7 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/montanaflynn/stats v0.7.1 // indirect + github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/spf13/afero v1.9.5 // indirect + github.com/spf13/cast v1.5.1 // indirect + github.com/spf13/jwalterweatherman v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/subosito/gotenv v1.4.2 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.11 // indirect + 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/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect + golang.org/x/arch v0.3.0 // indirect + golang.org/x/net v0.10.0 // indirect + golang.org/x/sync v0.3.0 // indirect + golang.org/x/sys v0.10.0 // indirect + golang.org/x/text v0.11.0 // indirect + google.golang.org/protobuf v1.30.0 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..0e0735f --- /dev/null +++ b/go.sum @@ -0,0 +1,591 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.44.3/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI= +cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk= +cloud.google.com/go v0.75.0/go.mod h1:VGuuCn7PG0dwsd5XPVm2Mm3wlh3EL55/79EKB6hlPTY= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1:1G1pk05UrOh0NlF1oeaaix1x8XzrfjIDK47TY0Zehcw= +github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= +github.com/bamboo-firewall/watcher v0.0.1 h1:R91bQUpIOzoH0Dnon05w5aarvaeYq9d3yhz9Hvxfw9c= +github.com/bamboo-firewall/watcher v0.0.1/go.mod h1:35Mob5LW4G4X6NEdNd1qISSjzwr12zYm/fVOtmTlIW0= +github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= +github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= +github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= +github.com/casbin/casbin/v2 v2.71.1 h1:LRHyqM0S1LzM/K59PmfUIN0ZJfLgcOjL4OhOQI/FNXU= +github.com/casbin/casbin/v2 v2.71.1/go.mod h1:vByNa/Fchek0KZUgG5wEsl7iFsiviAYKRtgrQfcJqHg= +github.com/casbin/mongodb-adapter/v3 v3.5.0 h1:WacrRWP0PfKgwo/+m5a81tsyDG7LODaLcecZr5zFHuc= +github.com/casbin/mongodb-adapter/v3 v3.5.0/go.mod h1:R5491PozS7Nx4dnHRSTu9CzRsJZ62IZrzAaC7PFych8= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= +github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= +github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= +github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= +github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= +github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= +github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= +github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= +github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= +github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= +github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= +github.com/onsi/gomega v1.23.0 h1:/oxKu9c2HVap+F3PfKort2Hw5DEU+HGlW8n+tguWsys= +github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= +github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/projectcalico/api v0.0.0-20230602153125-fb7148692637 h1:F48and+6vKJsRMl95Y/XKVik0Kwhos8YShTH9Fsdqlw= +github.com/projectcalico/api v0.0.0-20230602153125-fb7148692637/go.mod h1:d3yVTVhVHDawgeKrru/ZZD8QLEtiKQciUaAwnua47Qg= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= +github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= +github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= +github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= +github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= +github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc= +github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= +github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= +github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +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/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= +github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk= +github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.mongodb.org/mongo-driver v1.12.0 h1:aPx33jmn/rQuJXPQLZQ8NtfPQG8CaqgLThFtqRb0PiE= +go.mongodb.org/mongo-driver v1.12.0/go.mod h1:AZkxhPnFJUoH7kZlFkVKucV20K387miPfm7oimrSmK0= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= +golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= +golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= +golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= +golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= +google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg= +google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE= +google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= +google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= +google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/internal/optionutil/optionutil.go b/internal/optionutil/optionutil.go new file mode 100644 index 0000000..e82e740 --- /dev/null +++ b/internal/optionutil/optionutil.go @@ -0,0 +1,19 @@ +package optionutil + +import ( + "strings" + + "github.com/bamboo-firewall/be/domain" + "go.mongodb.org/mongo-driver/bson" +) + +func ConvertToBsonM(options []domain.Option, mapping map[string]string) bson.M { + query := bson.M{} + for _, item := range options { + key := strings.Split(mapping[item.Key], "$") + if len(key) > 1 { + query[key[1]] = item.Value + } + } + return query +} diff --git a/internal/tokenutil/tokenutil.go b/internal/tokenutil/tokenutil.go new file mode 100644 index 0000000..1f2189c --- /dev/null +++ b/internal/tokenutil/tokenutil.go @@ -0,0 +1,75 @@ +package tokenutil + +import ( + "fmt" + "time" + + "github.com/bamboo-firewall/be/domain" + jwt "github.com/golang-jwt/jwt/v4" +) + +func CreateAccessToken(user *domain.User, secret string, expiry int) (accessToken string, err error) { + exp := time.Now().Add(time.Hour * time.Duration(expiry)).Unix() + claims := &domain.JwtCustomClaims{ + Name: user.Name, + ID: user.ID.Hex(), + StandardClaims: jwt.StandardClaims{ + ExpiresAt: exp, + }, + } + token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) + t, err := token.SignedString([]byte(secret)) + if err != nil { + return "", err + } + return t, err +} + +func CreateRefreshToken(user *domain.User, secret string, expiry int) (refreshToken string, err error) { + claimsRefresh := &domain.JwtCustomRefreshClaims{ + ID: user.ID.Hex(), + StandardClaims: jwt.StandardClaims{ + ExpiresAt: time.Now().Add(time.Hour * time.Duration(expiry)).Unix(), + }, + } + token := jwt.NewWithClaims(jwt.SigningMethodHS256, claimsRefresh) + rt, err := token.SignedString([]byte(secret)) + if err != nil { + return "", err + } + return rt, err +} + +func IsAuthorized(requestToken string, secret string) (bool, error) { + _, err := jwt.Parse(requestToken, func(token *jwt.Token) (interface{}, error) { + if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { + return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"]) + } + return []byte(secret), nil + }) + if err != nil { + return false, err + } + return true, nil +} + +func ExtractIDFromToken(requestToken string, secret string) (string, error) { + token, err := jwt.Parse(requestToken, func(token *jwt.Token) (interface{}, error) { + if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { + return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"]) + } + return []byte(secret), nil + }) + + if err != nil { + return "", err + } + + claims, ok := token.Claims.(jwt.MapClaims) + + if !ok && !token.Valid { + return "", fmt.Errorf("Invalid Token") + } + + return claims["id"].(string), nil +} diff --git a/mongo/mongo.go b/mongo/mongo.go new file mode 100644 index 0000000..4e5d710 --- /dev/null +++ b/mongo/mongo.go @@ -0,0 +1,207 @@ +package mongo + +import ( + "context" + "errors" + "reflect" + "time" + + "go.mongodb.org/mongo-driver/bson/bsoncodec" + "go.mongodb.org/mongo-driver/bson/bsonrw" + "go.mongodb.org/mongo-driver/bson/bsontype" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/mongo/readpref" +) + +type Database interface { + Collection(string) Collection + Client() Client +} + +type Collection interface { + FindOne(context.Context, interface{}) SingleResult + InsertOne(context.Context, interface{}) (interface{}, error) + InsertMany(context.Context, []interface{}) ([]interface{}, error) + DeleteOne(context.Context, interface{}) (int64, error) + Find(context.Context, interface{}, ...*options.FindOptions) (Cursor, error) + CountDocuments(context.Context, interface{}, ...*options.CountOptions) (int64, error) + Aggregate(context.Context, interface{}) (Cursor, error) + UpdateOne(context.Context, interface{}, interface{}, ...*options.UpdateOptions) (*mongo.UpdateResult, error) + UpdateMany(context.Context, interface{}, interface{}, ...*options.UpdateOptions) (*mongo.UpdateResult, error) +} + +type SingleResult interface { + Decode(interface{}) error +} + +type Cursor interface { + Close(context.Context) error + Next(context.Context) bool + Decode(interface{}) error + All(context.Context, interface{}) error +} + +type Client interface { + Database(string) Database + Connect(context.Context) error + Disconnect(context.Context) error + StartSession() (mongo.Session, error) + MongoClient() *mongo.Client + UseSession(ctx context.Context, fn func(mongo.SessionContext) error) error + Ping(context.Context) error +} + +type mongoClient struct { + cl *mongo.Client +} +type mongoDatabase struct { + db *mongo.Database +} +type mongoCollection struct { + coll *mongo.Collection +} + +type mongoSingleResult struct { + sr *mongo.SingleResult +} + +type mongoCursor struct { + mc *mongo.Cursor +} + +type mongoSession struct { + mongo.Session +} + +type nullawareDecoder struct { + defDecoder bsoncodec.ValueDecoder + zeroValue reflect.Value +} + +func (d *nullawareDecoder) DecodeValue(dctx bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error { + if vr.Type() != bsontype.Null { + return d.defDecoder.DecodeValue(dctx, vr, val) + } + + if !val.CanSet() { + return errors.New("value not settable") + } + if err := vr.ReadNull(); err != nil { + return err + } + // Set the zero value of val's type: + val.Set(d.zeroValue) + return nil +} + +func NewClient(connection string) (Client, error) { + + time.Local = time.UTC + c, err := mongo.NewClient(options.Client().ApplyURI(connection)) + + return &mongoClient{cl: c}, err + +} + +func (mc *mongoClient) Ping(ctx context.Context) error { + return mc.cl.Ping(ctx, readpref.Primary()) +} + +func (mc *mongoClient) Database(dbName string) Database { + db := mc.cl.Database(dbName) + return &mongoDatabase{db: db} +} + +func (mc *mongoClient) UseSession(ctx context.Context, fn func(mongo.SessionContext) error) error { + return mc.cl.UseSession(ctx, fn) +} + +func (mc *mongoClient) StartSession() (mongo.Session, error) { + session, err := mc.cl.StartSession() + return &mongoSession{session}, err +} + +func (mc *mongoClient) MongoClient() *mongo.Client { + return mc.cl +} + +func (mc *mongoClient) Connect(ctx context.Context) error { + return mc.cl.Connect(ctx) +} + +func (mc *mongoClient) Disconnect(ctx context.Context) error { + return mc.cl.Disconnect(ctx) +} + +func (md *mongoDatabase) Collection(colName string) Collection { + collection := md.db.Collection(colName) + return &mongoCollection{coll: collection} +} + +func (md *mongoDatabase) Client() Client { + client := md.db.Client() + return &mongoClient{cl: client} +} + +func (mc *mongoCollection) FindOne(ctx context.Context, filter interface{}) SingleResult { + singleResult := mc.coll.FindOne(ctx, filter) + return &mongoSingleResult{sr: singleResult} +} + +func (mc *mongoCollection) UpdateOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error) { + return mc.coll.UpdateOne(ctx, filter, update, opts[:]...) +} + +func (mc *mongoCollection) InsertOne(ctx context.Context, document interface{}) (interface{}, error) { + id, err := mc.coll.InsertOne(ctx, document) + return id.InsertedID, err +} + +func (mc *mongoCollection) InsertMany(ctx context.Context, document []interface{}) ([]interface{}, error) { + res, err := mc.coll.InsertMany(ctx, document) + return res.InsertedIDs, err +} + +func (mc *mongoCollection) DeleteOne(ctx context.Context, filter interface{}) (int64, error) { + count, err := mc.coll.DeleteOne(ctx, filter) + return count.DeletedCount, err +} + +func (mc *mongoCollection) Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (Cursor, error) { + findResult, err := mc.coll.Find(ctx, filter, opts...) + return &mongoCursor{mc: findResult}, err +} + +func (mc *mongoCollection) Aggregate(ctx context.Context, pipeline interface{}) (Cursor, error) { + aggregateResult, err := mc.coll.Aggregate(ctx, pipeline) + return &mongoCursor{mc: aggregateResult}, err +} + +func (mc *mongoCollection) UpdateMany(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error) { + return mc.coll.UpdateMany(ctx, filter, update, opts[:]...) +} + +func (mc *mongoCollection) CountDocuments(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error) { + return mc.coll.CountDocuments(ctx, filter, opts...) +} + +func (sr *mongoSingleResult) Decode(v interface{}) error { + return sr.sr.Decode(v) +} + +func (mr *mongoCursor) Close(ctx context.Context) error { + return mr.mc.Close(ctx) +} + +func (mr *mongoCursor) Next(ctx context.Context) bool { + return mr.mc.Next(ctx) +} + +func (mr *mongoCursor) Decode(v interface{}) error { + return mr.mc.Decode(v) +} + +func (mr *mongoCursor) All(ctx context.Context, result interface{}) error { + return mr.mc.All(ctx, result) +} diff --git a/repository/gns_repository.go b/repository/gns_repository.go new file mode 100644 index 0000000..ae9c84f --- /dev/null +++ b/repository/gns_repository.go @@ -0,0 +1,122 @@ +package repository + +import ( + "context" + + models "github.com/bamboo-firewall/watcher/model" + + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/mongo" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo/options" +) + +type gnsRepository struct { + database mongo.Database + collection string +} + +func (r *gnsRepository) GetTotal(c context.Context) (int64, error) { + collection := r.database.Collection(r.collection) + total, err := collection.CountDocuments(c, bson.D{}) + return total, err +} + +func (gr *gnsRepository) Fetch(c context.Context) ([]models.GlobalNetworkSet, error) { + collection := gr.database.Collection(gr.collection) + + opts := options.Find().SetProjection(bson.D{{Key: "password", Value: 0}}) + cursor, err := collection.Find(c, bson.D{}, opts) + + if err != nil { + return nil, err + } + + var gns []models.GlobalNetworkSet + + err = cursor.All(c, &gns) + if gns == nil { + return []models.GlobalNetworkSet{}, err + } + + return gns, err +} + +func (gr *gnsRepository) Search(c context.Context, searchOptions bson.M) ([]models.GlobalNetworkSet, error) { + collection := gr.database.Collection(gr.collection) + + opts := options.Find() + cursor, err := collection.Find(c, searchOptions, opts) + + if err != nil { + return nil, err + } + + var networkset []models.GlobalNetworkSet + + err = cursor.All(c, &networkset) + if networkset == nil { + return []models.GlobalNetworkSet{}, err + } + + return networkset, err +} + +func (gr *gnsRepository) AggGroupBy(c context.Context, filter bson.M, key string, jsonPath string) ([]domain.Option, error) { + collection := gr.database.Collection(gr.collection) + + pipeline := []bson.M{ + { + "$match": filter, + }, + { + "$group": bson.M{ + "_id": bson.TypeNull, + key: bson.M{ + "$addToSet": jsonPath, + }, + }, + }, + { + "$project": bson.M{ + "_id": 0, + key: 1, + }, + }, + } + + cursor, err := collection.Aggregate(c, pipeline) + if err != nil { + return nil, err + } + + var results []bson.M + if err := cursor.All(c, &results); err != nil { + return nil, err + } + var options []domain.Option + if len(results) == 0 { + return []domain.Option{}, nil + } + for _, item := range results[0][key].(primitive.A) { + option := domain.Option{ + Key: key, + Value: item.(string), + } + options = append(options, option) + } + + if options == nil { + return []domain.Option{}, err + } + + return options, err +} + +func NewGNSRepository(db mongo.Database, collection string) domain.GNSRepository { + return &gnsRepository{ + database: db, + collection: collection, + } +} diff --git a/repository/hep_repository.go b/repository/hep_repository.go new file mode 100644 index 0000000..e966bea --- /dev/null +++ b/repository/hep_repository.go @@ -0,0 +1,157 @@ +package repository + +import ( + "context" + + models "github.com/bamboo-firewall/watcher/model" + + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/mongo" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo/options" +) + +type hepRepository struct { + database mongo.Database + collection string +} + +func (hr *hepRepository) GetProjectSummary(c context.Context) ([]domain.ProjectSummary, error) { + collection := hr.database.Collection(hr.collection) + pipeline := []bson.M{ + { + "$group": bson.M{ + "_id": bson.M{ + "project": "$metadata.labels.project", + }, + "count": bson.M{ + "$sum": 1, + }, + }, + }, + { + "$project": bson.M{ + "ProjectName": "$_id.project", + "Total": "$count", + }, + }, + } + + cursor, err := collection.Aggregate(c, pipeline) + if err != nil { + return nil, err + } + + var projectSummary []domain.ProjectSummary + err = cursor.All(c, &projectSummary) + + return projectSummary, err +} + +func (hr *hepRepository) GetTotal(c context.Context) (int64, error) { + collection := hr.database.Collection(hr.collection) + total, err := collection.CountDocuments(c, bson.D{}) + return total, err +} + +func (hr *hepRepository) Fetch(c context.Context) ([]models.HostEndPoint, error) { + collection := hr.database.Collection(hr.collection) + + opts := options.Find() + cursor, err := collection.Find(c, bson.D{}, opts) + + if err != nil { + return nil, err + } + + var heps []models.HostEndPoint + + err = cursor.All(c, &heps) + if heps == nil { + return []models.HostEndPoint{}, err + } + + return heps, err +} + +func (hr *hepRepository) Search(c context.Context, searchOptions bson.M) ([]models.HostEndPoint, error) { + collection := hr.database.Collection(hr.collection) + + opts := options.Find() + cursor, err := collection.Find(c, searchOptions, opts) + + if err != nil { + return nil, err + } + + var heps []models.HostEndPoint + + err = cursor.All(c, &heps) + if heps == nil { + return []models.HostEndPoint{}, err + } + + return heps, err +} + +func (hr *hepRepository) AggGroupBy(c context.Context, filter bson.M, key string, jsonPath string) ([]domain.Option, error) { + collection := hr.database.Collection(hr.collection) + + pipeline := []bson.M{ + { + "$match": filter, + }, + { + "$unwind": "$spec.expectedIPs", // unwind array + }, + { + "$group": bson.M{ + "_id": bson.TypeNull, + key: bson.M{ + "$addToSet": jsonPath, + }, + }, + }, + { + "$project": bson.M{ + "_id": 0, + key: 1, + }, + }, + } + + cursor, err := collection.Aggregate(c, pipeline) + if err != nil { + return nil, err + } + + var results []bson.M + if err := cursor.All(c, &results); err != nil { + return nil, err + } + var options []domain.Option + if len(results) == 0 { + return []domain.Option{}, nil + } + for _, item := range results[0][key].(primitive.A) { + option := domain.Option{ + Key: key, + Value: item.(string), + } + options = append(options, option) + } + + if options == nil { + return []domain.Option{}, err + } + + return options, err +} + +func NewHEPRepository(db mongo.Database, collection string) domain.HEPRepository { + return &hepRepository{ + database: db, + collection: collection, + } +} diff --git a/repository/policy_repository.go b/repository/policy_repository.go new file mode 100644 index 0000000..15a0ccf --- /dev/null +++ b/repository/policy_repository.go @@ -0,0 +1,122 @@ +package repository + +import ( + "context" + + models "github.com/bamboo-firewall/watcher/model" + + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/mongo" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo/options" +) + +type policyRepository struct { + database mongo.Database + collection string +} + +func (r *policyRepository) GetTotal(c context.Context) (int64, error) { + collection := r.database.Collection(r.collection) + total, err := collection.CountDocuments(c, bson.D{}) + return total, err +} + +func (r *policyRepository) Fetch(c context.Context) ([]models.GlobalNetworkPolicies, error) { + collection := r.database.Collection(r.collection) + + opts := options.Find().SetProjection(bson.D{{Key: "password", Value: 0}}) + cursor, err := collection.Find(c, bson.D{}, opts) + + if err != nil { + return nil, err + } + + var policies []models.GlobalNetworkPolicies + + err = cursor.All(c, &policies) + if policies == nil { + return []models.GlobalNetworkPolicies{}, err + } + + return policies, err +} + +func (r *policyRepository) Search(c context.Context, searchOptions bson.M) ([]models.GlobalNetworkPolicies, error) { + collection := r.database.Collection(r.collection) + + opts := options.Find() + cursor, err := collection.Find(c, searchOptions, opts) + + if err != nil { + return nil, err + } + + var policies []models.GlobalNetworkPolicies + + err = cursor.All(c, &policies) + if policies == nil { + return []models.GlobalNetworkPolicies{}, err + } + + return policies, err +} + +func (r *policyRepository) AggGroupBy(c context.Context, filter bson.M, key string, jsonPath string) ([]domain.Option, error) { + collection := r.database.Collection(r.collection) + + pipeline := []bson.M{ + { + "$match": filter, + }, + { + "$group": bson.M{ + "_id": bson.TypeNull, + key: bson.M{ + "$addToSet": jsonPath, + }, + }, + }, + { + "$project": bson.M{ + "_id": 0, + key: 1, + }, + }, + } + + cursor, err := collection.Aggregate(c, pipeline) + if err != nil { + return nil, err + } + + var results []bson.M + if err := cursor.All(c, &results); err != nil { + return nil, err + } + var options []domain.Option + if len(results) == 0 { + return []domain.Option{}, nil + } + for _, item := range results[0][key].(primitive.A) { + option := domain.Option{ + Key: key, + Value: item.(string), + } + options = append(options, option) + } + + if options == nil { + return []domain.Option{}, err + } + + return options, err +} + +func NewPolicyRepository(db mongo.Database, collection string) domain.PolicyRepository { + return &policyRepository{ + database: db, + collection: collection, + } +} diff --git a/repository/user_repository.go b/repository/user_repository.go new file mode 100644 index 0000000..ae1998d --- /dev/null +++ b/repository/user_repository.go @@ -0,0 +1,94 @@ +package repository + +import ( + "context" + + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/mongo" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo/options" +) + +type userRepository struct { + database mongo.Database + collection string +} + +func (ur *userRepository) Update(c context.Context, user *domain.User) error { + collection := ur.database.Collection(ur.collection) + _, err := collection.UpdateOne(c, bson.M{"_id": user.ID}, bson.M{"$set": user}) + return err +} + +func (ur *userRepository) DeleteById(c context.Context, id string) error { + collection := ur.database.Collection(ur.collection) + idHex, err := primitive.ObjectIDFromHex(id) + if err != nil { + return err + } + _, err = collection.DeleteOne(c, bson.M{"_id": idHex}) + return err +} + +func (ur *userRepository) GetTotal(c context.Context) (int64, error) { + collection := ur.database.Collection(ur.collection) + total, err := collection.CountDocuments(c, bson.D{}) + return total, err +} + +func (ur *userRepository) Create(c context.Context, user *domain.User) error { + collection := ur.database.Collection(ur.collection) + + _, err := collection.InsertOne(c, user) + + return err +} + +func (ur *userRepository) Fetch(c context.Context) ([]domain.User, error) { + collection := ur.database.Collection(ur.collection) + + opts := options.Find().SetProjection(bson.D{{Key: "password", Value: 0}}) + cursor, err := collection.Find(c, bson.D{}, opts) + + if err != nil { + return nil, err + } + + var users []domain.User + + err = cursor.All(c, &users) + if users == nil { + return []domain.User{}, err + } + + return users, err +} + +func (ur *userRepository) GetByEmail(c context.Context, email string) (domain.User, error) { + collection := ur.database.Collection(ur.collection) + var user domain.User + err := collection.FindOne(c, bson.M{"email": email}).Decode(&user) + return user, err +} + +func (ur *userRepository) GetByID(c context.Context, id string) (domain.User, error) { + collection := ur.database.Collection(ur.collection) + + var user domain.User + + idHex, err := primitive.ObjectIDFromHex(id) + if err != nil { + return user, err + } + + err = collection.FindOne(c, bson.M{"_id": idHex}).Decode(&user) + return user, err +} + +func NewUserRepository(db mongo.Database, collection string) domain.UserRepository { + return &userRepository{ + database: db, + collection: collection, + } +} diff --git a/usecase/gns_usecase.go b/usecase/gns_usecase.go new file mode 100644 index 0000000..8271c45 --- /dev/null +++ b/usecase/gns_usecase.go @@ -0,0 +1,48 @@ +package usecase + +import ( + "context" + "time" + + models "github.com/bamboo-firewall/watcher/model" + + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/internal/optionutil" +) + +type gnsUsecase struct { + gnsRepository domain.GNSRepository + contextTimeout time.Duration +} + +var GNSMapping = map[string]string{ + "name": "$metadata.name", + "zone": "$metadata.labels.zone", +} + +func (gu *gnsUsecase) Fetch(c context.Context) ([]models.GlobalNetworkSet, error) { + ctx, cancel := context.WithTimeout(c, gu.contextTimeout) + defer cancel() + return gu.gnsRepository.Fetch(ctx) +} + +func (u *gnsUsecase) Search(c context.Context, options []domain.Option) ([]models.GlobalNetworkSet, error) { + ctx, cancel := context.WithTimeout(c, u.contextTimeout) + defer cancel() + findOptions := optionutil.ConvertToBsonM(options, GNSMapping) + return u.gnsRepository.Search(ctx, findOptions) +} + +func (u *gnsUsecase) GetOptions(c context.Context, filter []domain.Option, key string) ([]domain.Option, error) { + ctx, cancel := context.WithTimeout(c, u.contextTimeout) + defer cancel() + query := optionutil.ConvertToBsonM(filter, GNSMapping) + return u.gnsRepository.AggGroupBy(ctx, query, key, GNSMapping[key]) +} + +func NewGNSUsecase(gnsRepository domain.GNSRepository, timeout time.Duration) domain.GNSUsecase { + return &gnsUsecase{ + gnsRepository: gnsRepository, + contextTimeout: timeout, + } +} diff --git a/usecase/hep_usecase.go b/usecase/hep_usecase.go new file mode 100644 index 0000000..70382a5 --- /dev/null +++ b/usecase/hep_usecase.go @@ -0,0 +1,52 @@ +package usecase + +import ( + "context" + "time" + + models "github.com/bamboo-firewall/watcher/model" + + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/internal/optionutil" +) + +type hepUsecase struct { + hepRepository domain.HEPRepository + contextTimeout time.Duration +} + +var HEPMapping = map[string]string{ + "name": "$spec.node", + "ip": "$spec.expectedIPs", + "namespace": "$metadata.labels.namespace", + "project": "$metadata.labels.project", + "role": "$metadata.labels.role", + "zone": "$metadata.labels.zone", +} + +func (hu *hepUsecase) Fetch(c context.Context) ([]models.HostEndPoint, error) { + ctx, cancel := context.WithTimeout(c, hu.contextTimeout) + defer cancel() + return hu.hepRepository.Fetch(ctx) +} + +func (hu *hepUsecase) Search(c context.Context, options []domain.Option) ([]models.HostEndPoint, error) { + ctx, cancel := context.WithTimeout(c, hu.contextTimeout) + defer cancel() + query := optionutil.ConvertToBsonM(options, HEPMapping) + return hu.hepRepository.Search(ctx, query) +} + +func (hu *hepUsecase) GetOptions(c context.Context, filter []domain.Option, key string) ([]domain.Option, error) { + ctx, cancel := context.WithTimeout(c, hu.contextTimeout) + defer cancel() + query := optionutil.ConvertToBsonM(filter, HEPMapping) + return hu.hepRepository.AggGroupBy(ctx, query, key, HEPMapping[key]) +} + +func NewHEPUsecase(hepRepository domain.HEPRepository, timeout time.Duration) domain.HEPUsecase { + return &hepUsecase{ + hepRepository: hepRepository, + contextTimeout: timeout, + } +} diff --git a/usecase/login_usecase.go b/usecase/login_usecase.go new file mode 100644 index 0000000..ebf2620 --- /dev/null +++ b/usecase/login_usecase.go @@ -0,0 +1,35 @@ +package usecase + +import ( + "context" + "time" + + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/internal/tokenutil" +) + +type loginUsecase struct { + userRepository domain.UserRepository + contextTimeout time.Duration +} + +func NewLoginUsecase(userRepository domain.UserRepository, timeout time.Duration) domain.LoginUsecase { + return &loginUsecase{ + userRepository: userRepository, + contextTimeout: timeout, + } +} + +func (lu *loginUsecase) GetUserByEmail(c context.Context, email string) (domain.User, error) { + ctx, cancel := context.WithTimeout(c, lu.contextTimeout) + defer cancel() + return lu.userRepository.GetByEmail(ctx, email) +} + +func (lu *loginUsecase) CreateAccessToken(user *domain.User, secret string, expiry int) (accessToken string, err error) { + return tokenutil.CreateAccessToken(user, secret, expiry) +} + +func (lu *loginUsecase) CreateRefreshToken(user *domain.User, secret string, expiry int) (refreshToken string, err error) { + return tokenutil.CreateRefreshToken(user, secret, expiry) +} diff --git a/usecase/policy_usecase.go b/usecase/policy_usecase.go new file mode 100644 index 0000000..e1e7a59 --- /dev/null +++ b/usecase/policy_usecase.go @@ -0,0 +1,47 @@ +package usecase + +import ( + "context" + "time" + + models "github.com/bamboo-firewall/watcher/model" + + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/internal/optionutil" +) + +type policyUsecase struct { + policyRepository domain.PolicyRepository + contextTimeout time.Duration +} + +var PolicyMapping = map[string]string{ + "name": "$metadata.name", +} + +func (u *policyUsecase) Search(c context.Context, options []domain.Option) ([]models.GlobalNetworkPolicies, error) { + ctx, cancel := context.WithTimeout(c, u.contextTimeout) + defer cancel() + findOptions := optionutil.ConvertToBsonM(options, PolicyMapping) + return u.policyRepository.Search(ctx, findOptions) +} + +func (u *policyUsecase) Fetch(c context.Context) ([]models.GlobalNetworkPolicies, error) { + ctx, cancel := context.WithTimeout(c, u.contextTimeout) + defer cancel() + return u.policyRepository.Fetch(ctx) +} + +func (u *policyUsecase) GetOptions(c context.Context, filter []domain.Option, key string) ([]domain.Option, error) { + ctx, cancel := context.WithTimeout(c, u.contextTimeout) + defer cancel() + query := optionutil.ConvertToBsonM(filter, PolicyMapping) + return u.policyRepository.AggGroupBy(ctx, query, key, PolicyMapping[key]) +} + +func NewPolicyUsecase(policyRepository domain.PolicyRepository, timeout time.Duration) domain.PolicyUsecase { + return &policyUsecase{ + policyRepository: policyRepository, + contextTimeout: timeout, + } +} diff --git a/usecase/profile_usecase.go b/usecase/profile_usecase.go new file mode 100644 index 0000000..310411c --- /dev/null +++ b/usecase/profile_usecase.go @@ -0,0 +1,32 @@ +package usecase + +import ( + "context" + "time" + + "github.com/bamboo-firewall/be/domain" +) + +type profileUsecase struct { + userRepository domain.UserRepository + contextTimeout time.Duration +} + +func NewProfileUsecase(userRepository domain.UserRepository, timeout time.Duration) domain.ProfileUsecase { + return &profileUsecase{ + userRepository: userRepository, + contextTimeout: timeout, + } +} + +func (pu *profileUsecase) GetProfileByID(c context.Context, userID string) (*domain.Profile, error) { + ctx, cancel := context.WithTimeout(c, pu.contextTimeout) + defer cancel() + + user, err := pu.userRepository.GetByID(ctx, userID) + if err != nil { + return nil, err + } + + return &domain.Profile{UserId: user.ID.Hex(), Name: user.Name, Email: user.Email, Role: user.Role}, nil +} diff --git a/usecase/refresh_token_usecase.go b/usecase/refresh_token_usecase.go new file mode 100644 index 0000000..72f27fc --- /dev/null +++ b/usecase/refresh_token_usecase.go @@ -0,0 +1,39 @@ +package usecase + +import ( + "context" + "time" + + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/internal/tokenutil" +) + +type refreshTokenUsecase struct { + userRepository domain.UserRepository + contextTimeout time.Duration +} + +func NewRefreshTokenUsecase(userRepository domain.UserRepository, timeout time.Duration) domain.RefreshTokenUsecase { + return &refreshTokenUsecase{ + userRepository: userRepository, + contextTimeout: timeout, + } +} + +func (rtu *refreshTokenUsecase) GetUserByID(c context.Context, email string) (domain.User, error) { + ctx, cancel := context.WithTimeout(c, rtu.contextTimeout) + defer cancel() + return rtu.userRepository.GetByID(ctx, email) +} + +func (rtu *refreshTokenUsecase) CreateAccessToken(user *domain.User, secret string, expiry int) (accessToken string, err error) { + return tokenutil.CreateAccessToken(user, secret, expiry) +} + +func (rtu *refreshTokenUsecase) CreateRefreshToken(user *domain.User, secret string, expiry int) (refreshToken string, err error) { + return tokenutil.CreateRefreshToken(user, secret, expiry) +} + +func (rtu *refreshTokenUsecase) ExtractIDFromToken(requestToken string, secret string) (string, error) { + return tokenutil.ExtractIDFromToken(requestToken, secret) +} diff --git a/usecase/signup_usecase.go b/usecase/signup_usecase.go new file mode 100644 index 0000000..74fd1f3 --- /dev/null +++ b/usecase/signup_usecase.go @@ -0,0 +1,41 @@ +package usecase + +import ( + "context" + "time" + + "github.com/bamboo-firewall/be/domain" + "github.com/bamboo-firewall/be/internal/tokenutil" +) + +type signupUsecase struct { + userRepository domain.UserRepository + contextTimeout time.Duration +} + +func NewSignupUsecase(userRepository domain.UserRepository, timeout time.Duration) domain.SignupUsecase { + return &signupUsecase{ + userRepository: userRepository, + contextTimeout: timeout, + } +} + +func (su *signupUsecase) Create(c context.Context, user *domain.User) error { + ctx, cancel := context.WithTimeout(c, su.contextTimeout) + defer cancel() + return su.userRepository.Create(ctx, user) +} + +func (su *signupUsecase) GetUserByEmail(c context.Context, email string) (domain.User, error) { + ctx, cancel := context.WithTimeout(c, su.contextTimeout) + defer cancel() + return su.userRepository.GetByEmail(ctx, email) +} + +func (su *signupUsecase) CreateAccessToken(user *domain.User, secret string, expiry int) (accessToken string, err error) { + return tokenutil.CreateAccessToken(user, secret, expiry) +} + +func (su *signupUsecase) CreateRefreshToken(user *domain.User, secret string, expiry int) (refreshToken string, err error) { + return tokenutil.CreateRefreshToken(user, secret, expiry) +} diff --git a/usecase/statistic_usecase.go b/usecase/statistic_usecase.go new file mode 100644 index 0000000..0d188e9 --- /dev/null +++ b/usecase/statistic_usecase.go @@ -0,0 +1,71 @@ +package usecase + +import ( + "context" + "time" + + "github.com/bamboo-firewall/be/domain" +) + +type statisticUsecase struct { + policyRepository domain.PolicyRepository + gnsRepository domain.GNSRepository + hepRepository domain.HEPRepository + userRepository domain.UserRepository + contextTimeout time.Duration +} + +// GetSummary implements domain.StatisticUsecase. +func (su *statisticUsecase) GetSummary(c context.Context) (domain.Summary, error) { + ctx, cancel := context.WithTimeout(c, su.contextTimeout) + defer cancel() + totalGns, err := su.gnsRepository.GetTotal(ctx) + if err != nil { + return domain.Summary{}, err + } + totalHep, err := su.hepRepository.GetTotal(ctx) + if err != nil { + return domain.Summary{}, err + } + totalPolicy, err := su.policyRepository.GetTotal(ctx) + if err != nil { + return domain.Summary{}, err + } + totalUser, err := su.userRepository.GetTotal(ctx) + if err != nil { + return domain.Summary{}, err + } + + return domain.Summary{ + TotalGlobalNetworkSet: totalGns, + TotalHostEndpoint: totalHep, + TotalPolicy: totalPolicy, + TotalUser: totalUser, + }, err +} + +func (su *statisticUsecase) GetProjectSummary(c context.Context) ([]domain.ProjectSummary, error) { + ctx, cancel := context.WithTimeout(c, su.contextTimeout) + defer cancel() + projects, err := su.hepRepository.GetProjectSummary(ctx) + if err != nil { + return nil, err + } + return projects, nil +} + +func NewStatisticUsecase( + policyRepository domain.PolicyRepository, + gnsRepository domain.GNSRepository, + hepRepository domain.HEPRepository, + userRepository domain.UserRepository, + timeout time.Duration, +) domain.StatisticUsecase { + return &statisticUsecase{ + policyRepository: policyRepository, + gnsRepository: gnsRepository, + hepRepository: hepRepository, + userRepository: userRepository, + contextTimeout: timeout, + } +} diff --git a/usecase/user_usecase.go b/usecase/user_usecase.go new file mode 100644 index 0000000..f74dacf --- /dev/null +++ b/usecase/user_usecase.go @@ -0,0 +1,58 @@ +package usecase + +import ( + "context" + "time" + + "github.com/bamboo-firewall/be/domain" + "github.com/casbin/casbin/v2" +) + +type userUsecase struct { + userRepository domain.UserRepository + contextTimeout time.Duration +} + +// Update implements domain.UserUsecase. +func (su *userUsecase) Update(c context.Context, user *domain.User) error { + ctx, cancel := context.WithTimeout(c, su.contextTimeout) + defer cancel() + return su.userRepository.Update(ctx, user) +} + +func (su *userUsecase) DeleteById(c context.Context, id string) error { + ctx, cancel := context.WithTimeout(c, su.contextTimeout) + defer cancel() + return su.userRepository.DeleteById(ctx, id) +} + +func (su *userUsecase) Create(c context.Context, user *domain.User) error { + ctx, cancel := context.WithTimeout(c, su.contextTimeout) + defer cancel() + return su.userRepository.Create(ctx, user) +} + +func (su *userUsecase) Fetch(c context.Context) ([]domain.User, error) { + ctx, cancel := context.WithTimeout(c, su.contextTimeout) + defer cancel() + return su.userRepository.Fetch(ctx) +} + +func (su *userUsecase) GetUserByEmail(c context.Context, email string) (domain.User, error) { + ctx, cancel := context.WithTimeout(c, su.contextTimeout) + defer cancel() + return su.userRepository.GetByEmail(ctx, email) +} + +func (su *userUsecase) GetUserByID(c context.Context, id string) (domain.User, error) { + ctx, cancel := context.WithTimeout(c, su.contextTimeout) + defer cancel() + return su.userRepository.GetByID(ctx, id) +} + +func NewUserUsecase(userRepository domain.UserRepository, enforcer *casbin.Enforcer, timeout time.Duration) domain.UserUsecase { + return &userUsecase{ + userRepository: userRepository, + contextTimeout: timeout, + } +}