diff --git a/api/api_server.go b/api/api_server.go index 7c6a046..f1d24d3 100644 --- a/api/api_server.go +++ b/api/api_server.go @@ -11,10 +11,10 @@ type ApiServer struct { onServerShutdown chan interface{} isActive bool router *gin.Engine - config config.ServerConfig + config *config.ServerConfig } -func NewApiServer(dataRepository *repositories.DataRepository, config config.ServerConfig) *ApiServer { +func NewApiServer(dataRepository *repositories.DataRepository, config *config.ServerConfig) *ApiServer { stopChan := make(chan interface{}) onServerShutdownChan := make(chan interface{}) diff --git a/api/handlers/handlers.go b/api/handlers/handlers.go index 5e97442..16a073a 100644 --- a/api/handlers/handlers.go +++ b/api/handlers/handlers.go @@ -7,10 +7,10 @@ import ( type Handlers struct { repository *repositories.DataRepository - config config.ServerConfig + config *config.ServerConfig } -func NewHandlers(dataRepository *repositories.DataRepository, config config.ServerConfig) *Handlers { +func NewHandlers(dataRepository *repositories.DataRepository, config *config.ServerConfig) *Handlers { return &Handlers{ repository: dataRepository, config: config, diff --git a/api/handlers/middleware/authentication.go b/api/handlers/middleware/authentication.go index 5f94ce5..acb25ee 100644 --- a/api/handlers/middleware/authentication.go +++ b/api/handlers/middleware/authentication.go @@ -10,7 +10,7 @@ import ( "github.com/pikami/cosmium/internal/logger" ) -func Authentication(config config.ServerConfig) gin.HandlerFunc { +func Authentication(config *config.ServerConfig) gin.HandlerFunc { return func(c *gin.Context) { requestUrl := c.Request.URL.String() if config.DisableAuth || diff --git a/api/handlers/middleware/strip_trailing_slashes.go b/api/handlers/middleware/strip_trailing_slashes.go index 8a6f82c..d77c4f9 100644 --- a/api/handlers/middleware/strip_trailing_slashes.go +++ b/api/handlers/middleware/strip_trailing_slashes.go @@ -7,7 +7,7 @@ import ( "github.com/pikami/cosmium/api/config" ) -func StripTrailingSlashes(r *gin.Engine, config config.ServerConfig) gin.HandlerFunc { +func StripTrailingSlashes(r *gin.Engine, config *config.ServerConfig) gin.HandlerFunc { return func(c *gin.Context) { path := c.Request.URL.Path if len(path) > 1 && path[len(path)-1] == '/' && !strings.Contains(path, config.ExplorerBaseUrlLocation) { diff --git a/api/handlers/server_info.go b/api/handlers/server_info.go index fd1c31d..3fb0487 100644 --- a/api/handlers/server_info.go +++ b/api/handlers/server_info.go @@ -27,7 +27,9 @@ func (h *Handlers) GetServerInfo(c *gin.Context) { "databaseAccountEndpoint": h.config.DatabaseEndpoint, }, }, - "enableMultipleWriteLocations": false, + "enableMultipleWriteLocations": false, + "continuousBackupEnabled": false, + "enableNRegionSynchronousCommit": false, "userReplicationPolicy": map[string]interface{}{ "asyncReplication": false, "minReplicaSetSize": 1, diff --git a/api/tests/authentication_test.go b/api/tests/authentication_test.go index e519d07..8d5edb7 100644 --- a/api/tests/authentication_test.go +++ b/api/tests/authentication_test.go @@ -2,13 +2,11 @@ package tests_test import ( "context" - "errors" "fmt" "io" "net/http" "testing" - "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos" "github.com/pikami/cosmium/api/config" "github.com/stretchr/testify/assert" @@ -47,12 +45,7 @@ func Test_Authentication(t *testing.T) { azcosmos.DatabaseProperties{ID: testDatabaseName}, &azcosmos.CreateDatabaseOptions{}) - var respErr *azcore.ResponseError - if errors.As(err, &respErr) { - assert.Equal(t, respErr.StatusCode, http.StatusUnauthorized) - } else { - panic(err) - } + assert.Contains(t, err.Error(), "401 Unauthorized") }) t.Run("Should allow unauthorized requests to /_explorer", func(t *testing.T) { @@ -68,7 +61,7 @@ func Test_Authentication(t *testing.T) { } func Test_Authentication_Disabled(t *testing.T) { - ts := runTestServerCustomConfig(config.ServerConfig{ + ts := runTestServerCustomConfig(&config.ServerConfig{ AccountKey: config.DefaultAccountKey, ExplorerPath: "/tmp/nothing", ExplorerBaseUrlLocation: config.ExplorerBaseUrlLocation, diff --git a/api/tests/config_test.go b/api/tests/config_test.go index c92cf84..82765e2 100644 --- a/api/tests/config_test.go +++ b/api/tests/config_test.go @@ -15,13 +15,15 @@ type TestServer struct { URL string } -func runTestServerCustomConfig(config config.ServerConfig) *TestServer { +func runTestServerCustomConfig(config *config.ServerConfig) *TestServer { repository := repositories.NewDataRepository(repositories.RepositoryOptions{}) api := api.NewApiServer(repository, config) server := httptest.NewServer(api.GetRouter()) + config.DatabaseEndpoint = server.URL + return &TestServer{ Server: server, Repository: repository, @@ -30,7 +32,7 @@ func runTestServerCustomConfig(config config.ServerConfig) *TestServer { } func runTestServer() *TestServer { - config := config.ServerConfig{ + config := &config.ServerConfig{ AccountKey: config.DefaultAccountKey, ExplorerPath: "/tmp/nothing", ExplorerBaseUrlLocation: config.ExplorerBaseUrlLocation, diff --git a/cmd/server/server.go b/cmd/server/server.go index 6de6040..23aa371 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -18,7 +18,7 @@ func main() { PersistDataFilePath: configuration.PersistDataFilePath, }) - server := api.NewApiServer(repository, configuration) + server := api.NewApiServer(repository, &configuration) err := server.Start() if err != nil { panic(err) diff --git a/go.mod b/go.mod index b9ebfcf..0042136 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.24.0 require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0 - github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v0.3.6 + github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v1.3.0 github.com/cosmiumdev/json-patch/v5 v5.9.3 github.com/gin-gonic/gin v1.10.0 github.com/google/uuid v1.6.0 diff --git a/go.sum b/go.sum index 4f808a9..e9d6394 100644 --- a/go.sum +++ b/go.sum @@ -2,14 +2,14 @@ github.com/Azure/azure-sdk-for-go v68.0.0+incompatible h1:fcYLmCpyNYRnvJbPerq7U0 github.com/Azure/azure-sdk-for-go v68.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0 h1:g0EZJwz7xkXQiZAI5xi9f3WWFYBlX1CPTrR+NDToRkQ= github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0/go.mod h1:XCW7KnZet0Opnr7HccfUw1PLc4CjHqpcaxW8DHklNkQ= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0 h1:tfLQ34V6F7tVSwoTf/4lH5sE0o6eCJuNDTmH09nDpbc= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0/go.mod h1:9kIvujWAA58nmPmWB1m23fyWic1kYZMxD9CxaWn4Qpg= -github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v0.3.6 h1:oBqQLSI1pZwGOdXJAoJJSzmff9tlfD4KroVfjQQmd0g= -github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v0.3.6/go.mod h1:Beh5cHIXJ0oWEDWk9lNFtuklCojLLQ5hl+LqSNTTs0I= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0 h1:B/dfvscEQtew9dVuoxqxrUKKv8Ih2f55PydknDamU+g= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0/go.mod h1:fiPSssYvltE08HJchL04dOy+RD4hgrjph0cwGGMntdI= +github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v1.3.0 h1:RGcdpSElvcXCwxydI0xzOBu1Gvp88OoiTGfbtO/z1m0= +github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v1.3.0/go.mod h1:YwUyrNUtcZcibA99JcfCP6UUp95VVQKO2MJfBzgJDwA= github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 h1:ywEEhmNahHBihViHepv3xPBn1663uRv2t2q/ESv9seY= github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0/go.mod h1:iZDifYGJTIgIIkYRNWPENUnqx6bJ2xnSDFI2tjwZNuY= -github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 h1:XHOnouVk1mxXfQidrMEnLlPk9UMeRtyBTnEFtxkV0kU= -github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= +github.com/AzureAD/microsoft-authentication-library-for-go v1.3.2 h1:kYRSnvJju5gYVyhkij+RTJ/VR6QIUaCfWeaFm2ycsjQ= +github.com/AzureAD/microsoft-authentication-library-for-go v1.3.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/bytedance/sonic v1.12.9 h1:Od1BvK55NnewtGaJsTDeAOSnLVO2BTSLOe0+ooKokmQ= github.com/bytedance/sonic v1.12.9/go.mod h1:uVvFidNmlt9+wa31S1urfwwthTWteBgG0hWuoKAXTx8= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= @@ -39,7 +39,6 @@ github.com/go-playground/validator/v10 v10.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0 github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus= github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= -github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c= github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= diff --git a/sharedlibrary/sharedlibrary.go b/sharedlibrary/sharedlibrary.go index 2334a02..a13aebe 100644 --- a/sharedlibrary/sharedlibrary.go +++ b/sharedlibrary/sharedlibrary.go @@ -37,7 +37,7 @@ func CreateServerInstance(serverName *C.char, configurationJSON *C.char) int { PersistDataFilePath: configuration.PersistDataFilePath, }) - server := api.NewApiServer(repository, configuration) + server := api.NewApiServer(repository, &configuration) err = server.Start() if err != nil { return ResponseFailedToStartServer