mirror of
https://github.com/pikami/cosmium.git
synced 2025-03-04 08:56:57 +00:00
Update azcosmos package
This commit is contained in:
parent
f062e03f0c
commit
bd4fe5abec
@ -11,10 +11,10 @@ type ApiServer struct {
|
|||||||
onServerShutdown chan interface{}
|
onServerShutdown chan interface{}
|
||||||
isActive bool
|
isActive bool
|
||||||
router *gin.Engine
|
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{})
|
stopChan := make(chan interface{})
|
||||||
onServerShutdownChan := make(chan interface{})
|
onServerShutdownChan := make(chan interface{})
|
||||||
|
|
||||||
|
@ -7,10 +7,10 @@ import (
|
|||||||
|
|
||||||
type Handlers struct {
|
type Handlers struct {
|
||||||
repository *repositories.DataRepository
|
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{
|
return &Handlers{
|
||||||
repository: dataRepository,
|
repository: dataRepository,
|
||||||
config: config,
|
config: config,
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/pikami/cosmium/internal/logger"
|
"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) {
|
return func(c *gin.Context) {
|
||||||
requestUrl := c.Request.URL.String()
|
requestUrl := c.Request.URL.String()
|
||||||
if config.DisableAuth ||
|
if config.DisableAuth ||
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/pikami/cosmium/api/config"
|
"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) {
|
return func(c *gin.Context) {
|
||||||
path := c.Request.URL.Path
|
path := c.Request.URL.Path
|
||||||
if len(path) > 1 && path[len(path)-1] == '/' && !strings.Contains(path, config.ExplorerBaseUrlLocation) {
|
if len(path) > 1 && path[len(path)-1] == '/' && !strings.Contains(path, config.ExplorerBaseUrlLocation) {
|
||||||
|
@ -27,7 +27,9 @@ func (h *Handlers) GetServerInfo(c *gin.Context) {
|
|||||||
"databaseAccountEndpoint": h.config.DatabaseEndpoint,
|
"databaseAccountEndpoint": h.config.DatabaseEndpoint,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"enableMultipleWriteLocations": false,
|
"enableMultipleWriteLocations": false,
|
||||||
|
"continuousBackupEnabled": false,
|
||||||
|
"enableNRegionSynchronousCommit": false,
|
||||||
"userReplicationPolicy": map[string]interface{}{
|
"userReplicationPolicy": map[string]interface{}{
|
||||||
"asyncReplication": false,
|
"asyncReplication": false,
|
||||||
"minReplicaSetSize": 1,
|
"minReplicaSetSize": 1,
|
||||||
|
@ -2,13 +2,11 @@ package tests_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
|
|
||||||
"github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos"
|
"github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos"
|
||||||
"github.com/pikami/cosmium/api/config"
|
"github.com/pikami/cosmium/api/config"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -47,12 +45,7 @@ func Test_Authentication(t *testing.T) {
|
|||||||
azcosmos.DatabaseProperties{ID: testDatabaseName},
|
azcosmos.DatabaseProperties{ID: testDatabaseName},
|
||||||
&azcosmos.CreateDatabaseOptions{})
|
&azcosmos.CreateDatabaseOptions{})
|
||||||
|
|
||||||
var respErr *azcore.ResponseError
|
assert.Contains(t, err.Error(), "401 Unauthorized")
|
||||||
if errors.As(err, &respErr) {
|
|
||||||
assert.Equal(t, respErr.StatusCode, http.StatusUnauthorized)
|
|
||||||
} else {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Should allow unauthorized requests to /_explorer", func(t *testing.T) {
|
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) {
|
func Test_Authentication_Disabled(t *testing.T) {
|
||||||
ts := runTestServerCustomConfig(config.ServerConfig{
|
ts := runTestServerCustomConfig(&config.ServerConfig{
|
||||||
AccountKey: config.DefaultAccountKey,
|
AccountKey: config.DefaultAccountKey,
|
||||||
ExplorerPath: "/tmp/nothing",
|
ExplorerPath: "/tmp/nothing",
|
||||||
ExplorerBaseUrlLocation: config.ExplorerBaseUrlLocation,
|
ExplorerBaseUrlLocation: config.ExplorerBaseUrlLocation,
|
||||||
|
@ -15,13 +15,15 @@ type TestServer struct {
|
|||||||
URL string
|
URL string
|
||||||
}
|
}
|
||||||
|
|
||||||
func runTestServerCustomConfig(config config.ServerConfig) *TestServer {
|
func runTestServerCustomConfig(config *config.ServerConfig) *TestServer {
|
||||||
repository := repositories.NewDataRepository(repositories.RepositoryOptions{})
|
repository := repositories.NewDataRepository(repositories.RepositoryOptions{})
|
||||||
|
|
||||||
api := api.NewApiServer(repository, config)
|
api := api.NewApiServer(repository, config)
|
||||||
|
|
||||||
server := httptest.NewServer(api.GetRouter())
|
server := httptest.NewServer(api.GetRouter())
|
||||||
|
|
||||||
|
config.DatabaseEndpoint = server.URL
|
||||||
|
|
||||||
return &TestServer{
|
return &TestServer{
|
||||||
Server: server,
|
Server: server,
|
||||||
Repository: repository,
|
Repository: repository,
|
||||||
@ -30,7 +32,7 @@ func runTestServerCustomConfig(config config.ServerConfig) *TestServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runTestServer() *TestServer {
|
func runTestServer() *TestServer {
|
||||||
config := config.ServerConfig{
|
config := &config.ServerConfig{
|
||||||
AccountKey: config.DefaultAccountKey,
|
AccountKey: config.DefaultAccountKey,
|
||||||
ExplorerPath: "/tmp/nothing",
|
ExplorerPath: "/tmp/nothing",
|
||||||
ExplorerBaseUrlLocation: config.ExplorerBaseUrlLocation,
|
ExplorerBaseUrlLocation: config.ExplorerBaseUrlLocation,
|
||||||
|
@ -18,7 +18,7 @@ func main() {
|
|||||||
PersistDataFilePath: configuration.PersistDataFilePath,
|
PersistDataFilePath: configuration.PersistDataFilePath,
|
||||||
})
|
})
|
||||||
|
|
||||||
server := api.NewApiServer(repository, configuration)
|
server := api.NewApiServer(repository, &configuration)
|
||||||
err := server.Start()
|
err := server.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
2
go.mod
2
go.mod
@ -4,7 +4,7 @@ go 1.24.0
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0
|
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/cosmiumdev/json-patch/v5 v5.9.3
|
||||||
github.com/gin-gonic/gin v1.10.0
|
github.com/gin-gonic/gin v1.10.0
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
|
13
go.sum
13
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 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 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/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.8.0 h1:B/dfvscEQtew9dVuoxqxrUKKv8Ih2f55PydknDamU+g=
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0/go.mod h1:9kIvujWAA58nmPmWB1m23fyWic1kYZMxD9CxaWn4Qpg=
|
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 v0.3.6 h1:oBqQLSI1pZwGOdXJAoJJSzmff9tlfD4KroVfjQQmd0g=
|
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 v0.3.6/go.mod h1:Beh5cHIXJ0oWEDWk9lNFtuklCojLLQ5hl+LqSNTTs0I=
|
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 h1:ywEEhmNahHBihViHepv3xPBn1663uRv2t2q/ESv9seY=
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0/go.mod h1:iZDifYGJTIgIIkYRNWPENUnqx6bJ2xnSDFI2tjwZNuY=
|
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.3.2 h1:kYRSnvJju5gYVyhkij+RTJ/VR6QIUaCfWeaFm2ycsjQ=
|
||||||
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/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
|
||||||
github.com/bytedance/sonic v1.12.9 h1:Od1BvK55NnewtGaJsTDeAOSnLVO2BTSLOe0+ooKokmQ=
|
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 v1.12.9/go.mod h1:uVvFidNmlt9+wa31S1urfwwthTWteBgG0hWuoKAXTx8=
|
||||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
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/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 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
|
||||||
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
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 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
|
@ -37,7 +37,7 @@ func CreateServerInstance(serverName *C.char, configurationJSON *C.char) int {
|
|||||||
PersistDataFilePath: configuration.PersistDataFilePath,
|
PersistDataFilePath: configuration.PersistDataFilePath,
|
||||||
})
|
})
|
||||||
|
|
||||||
server := api.NewApiServer(repository, configuration)
|
server := api.NewApiServer(repository, &configuration)
|
||||||
err = server.Start()
|
err = server.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ResponseFailedToStartServer
|
return ResponseFailedToStartServer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user