diff --git a/api/billing/documents/go.mod b/api/billing/documents/go.mod index e7dd1ae6..44b00889 100644 --- a/api/billing/documents/go.mod +++ b/api/billing/documents/go.mod @@ -13,7 +13,7 @@ require ( github.com/prometheus/client_golang v1.23.2 github.com/shopspring/decimal v1.4.0 github.com/tech/sendico/pkg v0.1.0 - go.mongodb.org/mongo-driver v1.17.8 + go.mongodb.org/mongo-driver/v2 v2.5.0 go.uber.org/zap v1.27.1 google.golang.org/grpc v1.78.0 gopkg.in/yaml.v3 v3.0.1 @@ -39,16 +39,14 @@ require ( github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect github.com/casbin/casbin/v2 v2.135.0 // indirect github.com/casbin/govaluate v1.10.0 // indirect - github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect + github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/go-chi/chi/v5 v5.2.4 // indirect - github.com/golang/snappy v1.0.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/klauspost/compress v1.18.3 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/montanaflynn/stats v0.7.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nats-io/nats.go v1.48.0 // indirect github.com/nats-io/nkeys v0.4.15 // indirect diff --git a/api/billing/documents/go.sum b/api/billing/documents/go.sum index 643757f7..8e4995f3 100644 --- a/api/billing/documents/go.sum +++ b/api/billing/documents/go.sum @@ -53,8 +53,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0= github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= -github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E= -github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA= +github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ= +github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -93,8 +93,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs= -github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -132,8 +130,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= -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/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -199,8 +195,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM= -go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= diff --git a/api/billing/documents/storage/mongo/repository.go b/api/billing/documents/storage/mongo/repository.go index 3de37f50..31f5378a 100644 --- a/api/billing/documents/storage/mongo/repository.go +++ b/api/billing/documents/storage/mongo/repository.go @@ -9,7 +9,7 @@ import ( "github.com/tech/sendico/pkg/db" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/billing/documents/storage/mongo/store/documents.go b/api/billing/documents/storage/mongo/store/documents.go index 5717d701..6dc4674a 100644 --- a/api/billing/documents/storage/mongo/store/documents.go +++ b/api/billing/documents/storage/mongo/store/documents.go @@ -12,7 +12,7 @@ import ( ri "github.com/tech/sendico/pkg/db/repository/index" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/billing/fees/go.mod b/api/billing/fees/go.mod index 99dd2ca1..e708bbc0 100644 --- a/api/billing/fees/go.mod +++ b/api/billing/fees/go.mod @@ -9,27 +9,28 @@ replace github.com/tech/sendico/fx/oracle => ../../fx/oracle require ( github.com/tech/sendico/fx/oracle v0.0.0 github.com/tech/sendico/pkg v0.1.0 - go.mongodb.org/mongo-driver v1.17.8 go.uber.org/zap v1.27.1 google.golang.org/grpc v1.78.0 gopkg.in/yaml.v3 v3.0.1 ) +require ( + github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect + go.mongodb.org/mongo-driver/v2 v2.5.0 +) + require ( github.com/beorn7/perks v1.0.1 // indirect github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect github.com/casbin/casbin/v2 v2.135.0 // indirect github.com/casbin/govaluate v1.10.0 // indirect - github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/go-chi/chi/v5 v5.2.4 // indirect - github.com/golang/snappy v1.0.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/klauspost/compress v1.18.3 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/montanaflynn/stats v0.7.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nats-io/nats.go v1.48.0 // indirect github.com/nats-io/nkeys v0.4.15 // indirect diff --git a/api/billing/fees/go.sum b/api/billing/fees/go.sum index 83f878ad..7e99ce3a 100644 --- a/api/billing/fees/go.sum +++ b/api/billing/fees/go.sum @@ -14,8 +14,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0= github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= -github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E= -github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA= +github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ= +github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -53,8 +53,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs= -github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -89,8 +87,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= -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/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -150,8 +146,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM= -go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= diff --git a/api/billing/fees/internal/service/fees/internal/resolver/impl.go b/api/billing/fees/internal/service/fees/internal/resolver/impl.go index 5a500281..714e7a07 100644 --- a/api/billing/fees/internal/service/fees/internal/resolver/impl.go +++ b/api/billing/fees/internal/service/fees/internal/resolver/impl.go @@ -10,12 +10,12 @@ import ( "github.com/tech/sendico/billing/fees/storage/model" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) type planFinder interface { - FindActiveOrgPlan(ctx context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error) + FindActiveOrgPlan(ctx context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error) FindActiveGlobalPlan(ctx context.Context, at time.Time) (*model.FeePlan, error) } @@ -40,7 +40,7 @@ func New(plans storage.PlansStore, logger *zap.Logger) *feeResolver { } } -func (r *feeResolver) ResolveFeeRule(ctx context.Context, orgRef *primitive.ObjectID, trigger model.Trigger, at time.Time, attrs map[string]string) (*model.FeePlan, *model.FeeRule, error) { +func (r *feeResolver) ResolveFeeRule(ctx context.Context, orgRef *bson.ObjectID, trigger model.Trigger, at time.Time, attrs map[string]string) (*model.FeePlan, *model.FeeRule, error) { if r.plans == nil { return nil, nil, merrors.InvalidArgument("fees: plans store is required") } @@ -117,7 +117,7 @@ func (r *feeResolver) ResolveFeeRule(ctx context.Context, orgRef *primitive.Obje return plan, rule, nil } -func (r *feeResolver) getOrgPlan(ctx context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error) { +func (r *feeResolver) getOrgPlan(ctx context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error) { if r.finder != nil { return r.finder.FindActiveOrgPlan(ctx, orgRef, at) } @@ -129,7 +129,7 @@ func (r *feeResolver) getGlobalPlan(ctx context.Context, at time.Time) (*model.F return r.finder.FindActiveGlobalPlan(ctx, at) } // Treat zero ObjectID as global in legacy path. - return r.plans.GetActivePlan(ctx, primitive.NilObjectID, at) + return r.plans.GetActivePlan(ctx, bson.NilObjectID, at) } func selectRule(plan *model.FeePlan, trigger model.Trigger, at time.Time, attrs map[string]string) (*model.FeeRule, error) { diff --git a/api/billing/fees/internal/service/fees/internal/resolver/resolver_test.go b/api/billing/fees/internal/service/fees/internal/resolver/resolver_test.go index ff547fe4..9ec54846 100644 --- a/api/billing/fees/internal/service/fees/internal/resolver/resolver_test.go +++ b/api/billing/fees/internal/service/fees/internal/resolver/resolver_test.go @@ -8,7 +8,7 @@ import ( "github.com/tech/sendico/billing/fees/storage" "github.com/tech/sendico/billing/fees/storage/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -27,7 +27,7 @@ func TestResolver_GlobalFallbackWhenOrgMissing(t *testing.T) { store := &memoryPlansStore{plans: []*model.FeePlan{globalPlan}} resolver := New(store, zap.NewNop()) - orgA := primitive.NewObjectID() + orgA := bson.NewObjectID() plan, rule, err := resolver.ResolveFeeRule(context.Background(), &orgA, model.TriggerCapture, now, nil) if err != nil { t.Fatalf("expected fallback to global, got error: %v", err) @@ -44,7 +44,7 @@ func TestResolver_OrgOverridesGlobal(t *testing.T) { t.Helper() now := time.Now() - org := primitive.NewObjectID() + org := bson.NewObjectID() globalPlan := &model.FeePlan{ Active: true, EffectiveFrom: now.Add(-time.Hour), @@ -71,7 +71,7 @@ func TestResolver_OrgOverridesGlobal(t *testing.T) { t.Fatalf("expected org rule, got %s", rule.RuleID) } - otherOrg := primitive.NewObjectID() + otherOrg := bson.NewObjectID() _, rule, err = resolver.ResolveFeeRule(context.Background(), &otherOrg, model.TriggerCapture, now, nil) if err != nil { t.Fatalf("expected global fallback for other org, got error: %v", err) @@ -85,7 +85,7 @@ func TestResolver_SelectsHighestPriority(t *testing.T) { t.Helper() now := time.Now() - org := primitive.NewObjectID() + org := bson.NewObjectID() plan := &model.FeePlan{ Active: true, EffectiveFrom: now.Add(-time.Hour), @@ -124,7 +124,7 @@ func TestResolver_EffectiveDateFiltering(t *testing.T) { t.Helper() now := time.Now() - org := primitive.NewObjectID() + org := bson.NewObjectID() past := now.Add(-24 * time.Hour) future := now.Add(24 * time.Hour) @@ -253,7 +253,7 @@ func TestResolver_MultipleActivePlansConflict(t *testing.T) { t.Helper() now := time.Now() - org := primitive.NewObjectID() + org := bson.NewObjectID() p1 := &model.FeePlan{ Active: true, EffectiveFrom: now.Add(-time.Hour), @@ -285,11 +285,11 @@ type memoryPlansStore struct { func (m *memoryPlansStore) Create(context.Context, *model.FeePlan) error { return nil } func (m *memoryPlansStore) Update(context.Context, *model.FeePlan) error { return nil } -func (m *memoryPlansStore) Get(context.Context, primitive.ObjectID) (*model.FeePlan, error) { +func (m *memoryPlansStore) Get(context.Context, bson.ObjectID) (*model.FeePlan, error) { return nil, storage.ErrFeePlanNotFound } -func (m *memoryPlansStore) GetActivePlan(ctx context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error) { +func (m *memoryPlansStore) GetActivePlan(ctx context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error) { if !orgRef.IsZero() { if plan, err := m.FindActiveOrgPlan(ctx, orgRef, at); err == nil { return plan, nil @@ -300,7 +300,7 @@ func (m *memoryPlansStore) GetActivePlan(ctx context.Context, orgRef primitive.O return m.FindActiveGlobalPlan(ctx, at) } -func (m *memoryPlansStore) FindActiveOrgPlan(_ context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error) { +func (m *memoryPlansStore) FindActiveOrgPlan(_ context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error) { var matches []*model.FeePlan for _, plan := range m.plans { if plan == nil || plan.OrganizationRef == nil || plan.OrganizationRef.IsZero() || (*plan.OrganizationRef != orgRef) { diff --git a/api/billing/fees/internal/service/fees/resolver.go b/api/billing/fees/internal/service/fees/resolver.go index 92ba8195..dba1eab9 100644 --- a/api/billing/fees/internal/service/fees/resolver.go +++ b/api/billing/fees/internal/service/fees/resolver.go @@ -5,11 +5,11 @@ import ( "time" "github.com/tech/sendico/billing/fees/storage/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // FeeResolver centralises plan/rule resolution with org override and global fallback. // Implementations live under the internal/resolver package. type FeeResolver interface { - ResolveFeeRule(ctx context.Context, orgID *primitive.ObjectID, trigger model.Trigger, at time.Time, attrs map[string]string) (*model.FeePlan, *model.FeeRule, error) + ResolveFeeRule(ctx context.Context, orgID *bson.ObjectID, trigger model.Trigger, at time.Time, attrs map[string]string) (*model.FeePlan, *model.FeeRule, error) } diff --git a/api/billing/fees/internal/service/fees/service.go b/api/billing/fees/internal/service/fees/service.go index 33cb92ad..8b284253 100644 --- a/api/billing/fees/internal/service/fees/service.go +++ b/api/billing/fees/internal/service/fees/service.go @@ -24,7 +24,7 @@ import ( "github.com/tech/sendico/pkg/mservice" feesv1 "github.com/tech/sendico/pkg/proto/billing/fees/v1" tracev1 "github.com/tech/sendico/pkg/proto/common/trace/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -151,7 +151,7 @@ func (s *Service) QuoteFees(ctx context.Context, req *feesv1.QuoteFeesRequest) ( return nil, err } - orgRef, parseErr := primitive.ObjectIDFromHex(req.GetMeta().GetOrganizationRef()) + orgRef, parseErr := bson.ObjectIDFromHex(req.GetMeta().GetOrganizationRef()) if parseErr != nil { logger.Warn("QuoteFees invalid organization_ref", zap.Error(parseErr)) err = status.Error(codes.InvalidArgument, "invalid organization_ref") @@ -233,7 +233,7 @@ func (s *Service) PrecomputeFees(ctx context.Context, req *feesv1.PrecomputeFees now := s.clock.Now() - orgRef, parseErr := primitive.ObjectIDFromHex(req.GetMeta().GetOrganizationRef()) + orgRef, parseErr := bson.ObjectIDFromHex(req.GetMeta().GetOrganizationRef()) if parseErr != nil { logger.Warn("PrecomputeFees invalid organization_ref", zap.Error(parseErr)) err = status.Error(codes.InvalidArgument, "invalid organization_ref") @@ -351,7 +351,7 @@ func (s *Service) ValidateFeeToken(ctx context.Context, req *feesv1.ValidateFeeT return resp, nil } - orgRef, parseErr := primitive.ObjectIDFromHex(payload.OrganizationRef) + orgRef, parseErr := bson.ObjectIDFromHex(payload.OrganizationRef) if parseErr != nil { resultReason = "invalid_token" logger.Warn("token contained invalid organization reference", zap.Error(parseErr)) @@ -408,11 +408,11 @@ func (s *Service) validatePrecomputeRequest(req *feesv1.PrecomputeFeesRequest) e return s.validateQuoteRequest(&feesv1.QuoteFeesRequest{Meta: req.GetMeta(), Intent: req.GetIntent()}) } -func (s *Service) computeQuote(ctx context.Context, orgRef primitive.ObjectID, intent *feesv1.Intent, overrides *feesv1.PolicyOverrides, trace *tracev1.TraceContext) ([]*feesv1.DerivedPostingLine, []*feesv1.AppliedRule, *feesv1.FXUsed, error) { +func (s *Service) computeQuote(ctx context.Context, orgRef bson.ObjectID, intent *feesv1.Intent, overrides *feesv1.PolicyOverrides, trace *tracev1.TraceContext) ([]*feesv1.DerivedPostingLine, []*feesv1.AppliedRule, *feesv1.FXUsed, error) { return s.computeQuoteWithTime(ctx, orgRef, intent, overrides, trace, s.clock.Now()) } -func (s *Service) computeQuoteWithTime(ctx context.Context, orgRef primitive.ObjectID, intent *feesv1.Intent, _ *feesv1.PolicyOverrides, trace *tracev1.TraceContext, now time.Time) ([]*feesv1.DerivedPostingLine, []*feesv1.AppliedRule, *feesv1.FXUsed, error) { +func (s *Service) computeQuoteWithTime(ctx context.Context, orgRef bson.ObjectID, intent *feesv1.Intent, _ *feesv1.PolicyOverrides, trace *tracev1.TraceContext, now time.Time) ([]*feesv1.DerivedPostingLine, []*feesv1.AppliedRule, *feesv1.FXUsed, error) { bookedAt := now if intent.GetBookedAt() != nil && intent.GetBookedAt().IsValid() { bookedAt = intent.GetBookedAt().AsTime() @@ -428,7 +428,7 @@ func (s *Service) computeQuoteWithTime(ctx context.Context, orgRef primitive.Obj logFields = append(logFields, logFieldsFromTrace(trace)...) logger := s.logger.With(logFields...) - var orgPtr *primitive.ObjectID + var orgPtr *bson.ObjectID if !orgRef.IsZero() { orgPtr = &orgRef } diff --git a/api/billing/fees/internal/service/fees/service_test.go b/api/billing/fees/internal/service/fees/service_test.go index 3b58390e..78adb750 100644 --- a/api/billing/fees/internal/service/fees/service_test.go +++ b/api/billing/fees/internal/service/fees/service_test.go @@ -14,7 +14,7 @@ import ( feesv1 "github.com/tech/sendico/pkg/proto/billing/fees/v1" moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1" tracev1 "github.com/tech/sendico/pkg/proto/common/trace/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -23,7 +23,7 @@ func TestQuoteFees_ComputesDerivedLines(t *testing.T) { t.Helper() now := time.Date(2024, 1, 10, 16, 0, 0, 0, time.UTC) - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() plan := &model.FeePlan{ Active: true, @@ -48,7 +48,7 @@ func TestQuoteFees_ComputesDerivedLines(t *testing.T) { }, }, } - plan.SetID(primitive.NewObjectID()) + plan.SetID(bson.NewObjectID()) plan.OrganizationRef = &orgRef service := NewService( @@ -123,7 +123,7 @@ func TestQuoteFees_FiltersByAttributesAndDates(t *testing.T) { t.Helper() now := time.Date(2024, 5, 20, 9, 30, 0, 0, time.UTC) - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() plan := &model.FeePlan{ Active: true, @@ -162,7 +162,7 @@ func TestQuoteFees_FiltersByAttributesAndDates(t *testing.T) { }, }, } - plan.SetID(primitive.NewObjectID()) + plan.SetID(bson.NewObjectID()) plan.OrganizationRef = &orgRef service := NewService( @@ -205,7 +205,7 @@ func TestQuoteFees_RoundingDown(t *testing.T) { t.Helper() now := time.Date(2024, 3, 15, 12, 0, 0, 0, time.UTC) - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() plan := &model.FeePlan{ Active: true, @@ -223,7 +223,7 @@ func TestQuoteFees_RoundingDown(t *testing.T) { }, }, } - plan.SetID(primitive.NewObjectID()) + plan.SetID(bson.NewObjectID()) plan.OrganizationRef = &orgRef service := NewService( @@ -261,7 +261,7 @@ func TestQuoteFees_UsesInjectedCalculator(t *testing.T) { t.Helper() now := time.Date(2024, 6, 1, 8, 0, 0, 0, time.UTC) - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() plan := &model.FeePlan{ Active: true, EffectiveFrom: now.Add(-time.Hour), @@ -276,7 +276,7 @@ func TestQuoteFees_UsesInjectedCalculator(t *testing.T) { }, }, } - plan.SetID(primitive.NewObjectID()) + plan.SetID(bson.NewObjectID()) plan.OrganizationRef = &orgRef result := &types.CalculationResult{ @@ -334,7 +334,7 @@ func TestQuoteFees_PopulatesFxUsed(t *testing.T) { t.Helper() now := time.Date(2024, 7, 1, 9, 30, 0, 0, time.UTC) - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() plan := &model.FeePlan{ Active: true, @@ -352,7 +352,7 @@ func TestQuoteFees_PopulatesFxUsed(t *testing.T) { }, }, } - plan.SetID(primitive.NewObjectID()) + plan.SetID(bson.NewObjectID()) plan.OrganizationRef = &orgRef fakeOracle := &oracleclient.Fake{ @@ -433,11 +433,11 @@ func (s *stubPlansStore) Update(context.Context, *model.FeePlan) error { return nil } -func (s *stubPlansStore) Get(context.Context, primitive.ObjectID) (*model.FeePlan, error) { +func (s *stubPlansStore) Get(context.Context, bson.ObjectID) (*model.FeePlan, error) { return nil, storage.ErrFeePlanNotFound } -func (s *stubPlansStore) GetActivePlan(_ context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error) { +func (s *stubPlansStore) GetActivePlan(_ context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error) { if !orgRef.IsZero() { if plan, err := s.FindActiveOrgPlan(context.Background(), orgRef, at); err == nil { return plan, nil @@ -448,7 +448,7 @@ func (s *stubPlansStore) GetActivePlan(_ context.Context, orgRef primitive.Objec return s.FindActiveGlobalPlan(context.Background(), at) } -func (s *stubPlansStore) FindActiveOrgPlan(_ context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error) { +func (s *stubPlansStore) FindActiveOrgPlan(_ context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error) { if s.plan == nil { return nil, storage.ErrFeePlanNotFound } diff --git a/api/billing/fees/storage/model/plan.go b/api/billing/fees/storage/model/plan.go index 22a76e51..c63f0284 100644 --- a/api/billing/fees/storage/model/plan.go +++ b/api/billing/fees/storage/model/plan.go @@ -5,7 +5,7 @@ import ( "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) const ( @@ -28,12 +28,12 @@ const ( type FeePlan struct { storable.Base `bson:",inline" json:",inline"` model.Describable `bson:",inline" json:",inline"` - OrganizationRef *primitive.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"` - Active bool `bson:"active" json:"active"` - EffectiveFrom time.Time `bson:"effectiveFrom" json:"effectiveFrom"` - EffectiveTo *time.Time `bson:"effectiveTo,omitempty" json:"effectiveTo,omitempty"` - Rules []FeeRule `bson:"rules,omitempty" json:"rules,omitempty"` - Metadata map[string]string `bson:"metadata,omitempty" json:"metadata,omitempty"` + OrganizationRef *bson.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"` + Active bool `bson:"active" json:"active"` + EffectiveFrom time.Time `bson:"effectiveFrom" json:"effectiveFrom"` + EffectiveTo *time.Time `bson:"effectiveTo,omitempty" json:"effectiveTo,omitempty"` + Rules []FeeRule `bson:"rules,omitempty" json:"rules,omitempty"` + Metadata map[string]string `bson:"metadata,omitempty" json:"metadata,omitempty"` } // Collection implements storable.Storable. diff --git a/api/billing/fees/storage/mongo/repository.go b/api/billing/fees/storage/mongo/repository.go index 0b2c7a67..149e3774 100644 --- a/api/billing/fees/storage/mongo/repository.go +++ b/api/billing/fees/storage/mongo/repository.go @@ -9,7 +9,7 @@ import ( "github.com/tech/sendico/pkg/db" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/billing/fees/storage/mongo/store/plans.go b/api/billing/fees/storage/mongo/store/plans.go index a80cefe2..9151cb4b 100644 --- a/api/billing/fees/storage/mongo/store/plans.go +++ b/api/billing/fees/storage/mongo/store/plans.go @@ -18,8 +18,8 @@ import ( "github.com/tech/sendico/pkg/mlogger" m "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -112,7 +112,7 @@ func (p *plansStore) Update(ctx context.Context, plan *model.FeePlan) error { return nil } -func (p *plansStore) Get(ctx context.Context, planRef primitive.ObjectID) (*model.FeePlan, error) { +func (p *plansStore) Get(ctx context.Context, planRef bson.ObjectID) (*model.FeePlan, error) { if planRef.IsZero() { return nil, merrors.InvalidArgument("plansStore: zero plan reference") } @@ -126,7 +126,7 @@ func (p *plansStore) Get(ctx context.Context, planRef primitive.ObjectID) (*mode return result, nil } -func (p *plansStore) GetActivePlan(ctx context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error) { +func (p *plansStore) GetActivePlan(ctx context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error) { // Compatibility shim: prefer org plan, fall back to global; allow zero org to mean global. if orgRef.IsZero() { return p.FindActiveGlobalPlan(ctx, at) @@ -142,7 +142,7 @@ func (p *plansStore) GetActivePlan(ctx context.Context, orgRef primitive.ObjectI return nil, err } -func (p *plansStore) FindActiveOrgPlan(ctx context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error) { +func (p *plansStore) FindActiveOrgPlan(ctx context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error) { if orgRef.IsZero() { return nil, merrors.InvalidArgument("plansStore: zero organization reference") } diff --git a/api/billing/fees/storage/storage.go b/api/billing/fees/storage/storage.go index e0b128b8..9b4d04e5 100644 --- a/api/billing/fees/storage/storage.go +++ b/api/billing/fees/storage/storage.go @@ -5,7 +5,7 @@ import ( "time" "github.com/tech/sendico/billing/fees/storage/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type storageError string @@ -33,7 +33,7 @@ type Repository interface { type PlansStore interface { Create(ctx context.Context, plan *model.FeePlan) error Update(ctx context.Context, plan *model.FeePlan) error - Get(ctx context.Context, planRef primitive.ObjectID) (*model.FeePlan, error) + Get(ctx context.Context, planRef bson.ObjectID) (*model.FeePlan, error) // Legacy helper that now prefers an org plan and falls back to a global plan. - GetActivePlan(ctx context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error) + GetActivePlan(ctx context.Context, orgRef bson.ObjectID, at time.Time) (*model.FeePlan, error) } diff --git a/api/discovery/go.mod b/api/discovery/go.mod index 94f6fc07..9687a652 100644 --- a/api/discovery/go.mod +++ b/api/discovery/go.mod @@ -17,15 +17,13 @@ require ( github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect github.com/casbin/casbin/v2 v2.135.0 // indirect github.com/casbin/govaluate v1.10.0 // indirect - github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect + github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/golang/snappy v1.0.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/klauspost/compress v1.18.3 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/montanaflynn/stats v0.7.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nats-io/nats.go v1.48.0 // indirect github.com/nats-io/nkeys v0.4.15 // indirect @@ -37,7 +35,7 @@ require ( github.com/xdg-go/scram v1.2.0 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect - go.mongodb.org/mongo-driver v1.17.8 // indirect + go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.yaml.in/yaml/v2 v2.4.3 // indirect golang.org/x/crypto v0.47.0 // indirect diff --git a/api/discovery/go.sum b/api/discovery/go.sum index 83f878ad..7e99ce3a 100644 --- a/api/discovery/go.sum +++ b/api/discovery/go.sum @@ -14,8 +14,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0= github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= -github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E= -github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA= +github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ= +github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -53,8 +53,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs= -github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -89,8 +87,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= -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/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -150,8 +146,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM= -go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= diff --git a/api/fx/ingestor/go.mod b/api/fx/ingestor/go.mod index 0019dbe0..3a091a87 100644 --- a/api/fx/ingestor/go.mod +++ b/api/fx/ingestor/go.mod @@ -22,15 +22,13 @@ require ( github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect github.com/casbin/casbin/v2 v2.135.0 // indirect github.com/casbin/govaluate v1.10.0 // indirect - github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect + github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/golang/snappy v1.0.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/klauspost/compress v1.18.3 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/montanaflynn/stats v0.7.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nats-io/nats.go v1.48.0 // indirect github.com/nats-io/nkeys v0.4.15 // indirect @@ -42,7 +40,7 @@ require ( github.com/xdg-go/scram v1.2.0 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect - go.mongodb.org/mongo-driver v1.17.8 // indirect + go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.yaml.in/yaml/v2 v2.4.3 // indirect golang.org/x/crypto v0.47.0 // indirect diff --git a/api/fx/ingestor/go.sum b/api/fx/ingestor/go.sum index 83f878ad..7e99ce3a 100644 --- a/api/fx/ingestor/go.sum +++ b/api/fx/ingestor/go.sum @@ -14,8 +14,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0= github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= -github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E= -github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA= +github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ= +github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -53,8 +53,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs= -github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -89,8 +87,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= -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/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -150,8 +146,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM= -go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= diff --git a/api/fx/oracle/go.mod b/api/fx/oracle/go.mod index 600091ba..f08bbac6 100644 --- a/api/fx/oracle/go.mod +++ b/api/fx/oracle/go.mod @@ -11,7 +11,7 @@ require ( github.com/prometheus/client_golang v1.23.2 github.com/tech/sendico/fx/storage v0.0.0 github.com/tech/sendico/pkg v0.1.0 - go.mongodb.org/mongo-driver v1.17.8 + go.mongodb.org/mongo-driver/v2 v2.5.0 go.uber.org/zap v1.27.1 google.golang.org/grpc v1.78.0 google.golang.org/protobuf v1.36.11 @@ -23,15 +23,13 @@ require ( github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect github.com/casbin/casbin/v2 v2.135.0 // indirect github.com/casbin/govaluate v1.10.0 // indirect - github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect + github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/go-chi/chi/v5 v5.2.4 // indirect - github.com/golang/snappy v1.0.0 // indirect github.com/klauspost/compress v1.18.3 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/montanaflynn/stats v0.7.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nats-io/nats.go v1.48.0 // indirect github.com/nats-io/nkeys v0.4.15 // indirect diff --git a/api/fx/oracle/go.sum b/api/fx/oracle/go.sum index 83f878ad..7e99ce3a 100644 --- a/api/fx/oracle/go.sum +++ b/api/fx/oracle/go.sum @@ -14,8 +14,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0= github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= -github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E= -github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA= +github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ= +github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -53,8 +53,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs= -github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -89,8 +87,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= -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/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -150,8 +146,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM= -go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= diff --git a/api/fx/oracle/internal/service/oracle/calculator.go b/api/fx/oracle/internal/service/oracle/calculator.go index 61865ef5..251b99c9 100644 --- a/api/fx/oracle/internal/service/oracle/calculator.go +++ b/api/fx/oracle/internal/service/oracle/calculator.go @@ -12,7 +12,7 @@ import ( fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1" moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1" oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type quoteComputation struct { @@ -179,7 +179,7 @@ func buildQuoteMeta(meta *oraclev1.RequestMeta) *model.QuoteMeta { qm.IdempotencyKey = strings.TrimSpace(trace.GetIdempotencyKey()) } if org := strings.TrimSpace(meta.GetOrganizationRef()); org != "" { - if objID, err := primitive.ObjectIDFromHex(org); err == nil { + if objID, err := bson.ObjectIDFromHex(org); err == nil { qm.SetOrganizationRef(objID) } } diff --git a/api/fx/storage/go.mod b/api/fx/storage/go.mod index 24c0310a..4c364ef9 100644 --- a/api/fx/storage/go.mod +++ b/api/fx/storage/go.mod @@ -6,7 +6,7 @@ replace github.com/tech/sendico/pkg => ../../pkg require ( github.com/tech/sendico/pkg v0.1.0 - go.mongodb.org/mongo-driver v1.17.8 + go.mongodb.org/mongo-driver/v2 v2.5.0 go.uber.org/zap v1.27.1 ) @@ -14,12 +14,10 @@ require ( github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect github.com/casbin/casbin/v2 v2.135.0 // indirect github.com/casbin/govaluate v1.10.0 // indirect - github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect - github.com/golang/snappy v1.0.0 // indirect + github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/klauspost/compress v1.18.3 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/montanaflynn/stats v0.7.1 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/scram v1.2.0 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect diff --git a/api/fx/storage/go.sum b/api/fx/storage/go.sum index b0eddc05..ae57ca1a 100644 --- a/api/fx/storage/go.sum +++ b/api/fx/storage/go.sum @@ -12,8 +12,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0= github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= -github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E= -github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA= +github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ= +github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= @@ -45,8 +45,6 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69 github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= -github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs= -github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -75,8 +73,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= -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/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= @@ -118,8 +114,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM= -go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= diff --git a/api/fx/storage/mongo/repository.go b/api/fx/storage/mongo/repository.go index c54d7980..fd469fde 100644 --- a/api/fx/storage/mongo/repository.go +++ b/api/fx/storage/mongo/repository.go @@ -10,7 +10,7 @@ import ( "github.com/tech/sendico/pkg/db/transaction" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/fx/storage/mongo/store/currency.go b/api/fx/storage/mongo/store/currency.go index 6ebb34ef..40bf04c9 100644 --- a/api/fx/storage/mongo/store/currency.go +++ b/api/fx/storage/mongo/store/currency.go @@ -10,7 +10,7 @@ import ( ri "github.com/tech/sendico/pkg/db/repository/index" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/fx/storage/mongo/store/currency_test.go b/api/fx/storage/mongo/store/currency_test.go index 066460f4..53c8d719 100644 --- a/api/fx/storage/mongo/store/currency_test.go +++ b/api/fx/storage/mongo/store/currency_test.go @@ -10,7 +10,7 @@ import ( rd "github.com/tech/sendico/pkg/db/repository/decoder" "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/merrors" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -84,7 +84,7 @@ func TestCurrencyStoreUpsertUpdate(t *testing.T) { repo := &repoStub{ findOneFn: func(_ context.Context, _ builder.Query, result storable.Storable) error { currency := result.(*model.Currency) - currency.SetID(primitive.NewObjectID()) + currency.SetID(bson.NewObjectID()) currency.Code = "USD" return nil }, diff --git a/api/fx/storage/mongo/store/pair.go b/api/fx/storage/mongo/store/pair.go index 78ed7967..59cae2bc 100644 --- a/api/fx/storage/mongo/store/pair.go +++ b/api/fx/storage/mongo/store/pair.go @@ -10,7 +10,7 @@ import ( ri "github.com/tech/sendico/pkg/db/repository/index" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/fx/storage/mongo/store/pair_test.go b/api/fx/storage/mongo/store/pair_test.go index 6eda3335..211608a8 100644 --- a/api/fx/storage/mongo/store/pair_test.go +++ b/api/fx/storage/mongo/store/pair_test.go @@ -10,7 +10,7 @@ import ( rd "github.com/tech/sendico/pkg/db/repository/decoder" "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/merrors" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -82,7 +82,7 @@ func TestPairStoreUpsertUpdate(t *testing.T) { repo := &repoStub{ findOneFn: func(_ context.Context, _ builder.Query, result storable.Storable) error { pair := result.(*model.Pair) - pair.SetID(primitive.NewObjectID()) + pair.SetID(bson.NewObjectID()) return nil }, updateFn: func(_ context.Context, obj storable.Storable) error { diff --git a/api/fx/storage/mongo/store/quotes.go b/api/fx/storage/mongo/store/quotes.go index 20390d8a..22201768 100644 --- a/api/fx/storage/mongo/store/quotes.go +++ b/api/fx/storage/mongo/store/quotes.go @@ -13,7 +13,7 @@ import ( "github.com/tech/sendico/pkg/db/transaction" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/fx/storage/mongo/store/rates.go b/api/fx/storage/mongo/store/rates.go index e1b38117..2aa335b5 100644 --- a/api/fx/storage/mongo/store/rates.go +++ b/api/fx/storage/mongo/store/rates.go @@ -11,7 +11,7 @@ import ( ri "github.com/tech/sendico/pkg/db/repository/index" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/fx/storage/mongo/store/rates_test.go b/api/fx/storage/mongo/store/rates_test.go index 023ff04d..66f64dfd 100644 --- a/api/fx/storage/mongo/store/rates_test.go +++ b/api/fx/storage/mongo/store/rates_test.go @@ -10,7 +10,7 @@ import ( rd "github.com/tech/sendico/pkg/db/repository/decoder" "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/merrors" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -40,7 +40,7 @@ func TestRatesStoreUpsertInsert(t *testing.T) { func TestRatesStoreUpsertUpdate(t *testing.T) { ctx := context.Background() - existingID := primitive.NewObjectID() + existingID := bson.NewObjectID() var updated *model.RateSnapshot repo := &repoStub{ diff --git a/api/fx/storage/mongo/store/testing_helpers_test.go b/api/fx/storage/mongo/store/testing_helpers_test.go index 261e936a..27fdbda6 100644 --- a/api/fx/storage/mongo/store/testing_helpers_test.go +++ b/api/fx/storage/mongo/store/testing_helpers_test.go @@ -12,8 +12,8 @@ import ( "github.com/tech/sendico/pkg/db/transaction" "github.com/tech/sendico/pkg/merrors" pmodel "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" ) type repoStub struct { @@ -44,7 +44,7 @@ func (r *repoStub) InsertMany(ctx context.Context, objects []storable.Storable) return nil } -func (r *repoStub) Get(ctx context.Context, id primitive.ObjectID, result storable.Storable) error { +func (r *repoStub) Get(ctx context.Context, id bson.ObjectID, result storable.Storable) error { return merrors.NotImplemented("Get not used") } @@ -69,7 +69,7 @@ func (r *repoStub) Update(ctx context.Context, obj storable.Storable) error { return nil } -func (r *repoStub) Patch(ctx context.Context, id primitive.ObjectID, patch builder.Patch) error { +func (r *repoStub) Patch(ctx context.Context, id bson.ObjectID, patch builder.Patch) error { return merrors.NotImplemented("Patch not used") } @@ -80,7 +80,7 @@ func (r *repoStub) PatchMany(ctx context.Context, filter builder.Query, patch bu return 0, nil } -func (r *repoStub) Delete(ctx context.Context, id primitive.ObjectID) error { +func (r *repoStub) Delete(ctx context.Context, id bson.ObjectID) error { return merrors.NotImplemented("Delete not used") } @@ -95,7 +95,7 @@ func (r *repoStub) CreateIndex(def *ri.Definition) error { return nil } -func (r *repoStub) ListIDs(ctx context.Context, query builder.Query) ([]primitive.ObjectID, error) { +func (r *repoStub) ListIDs(ctx context.Context, query builder.Query) ([]bson.ObjectID, error) { return nil, merrors.NotImplemented("ListIDs not used") } diff --git a/api/fx/storage/mongo/transaction.go b/api/fx/storage/mongo/transaction.go index 64b7b652..52bad57e 100644 --- a/api/fx/storage/mongo/transaction.go +++ b/api/fx/storage/mongo/transaction.go @@ -4,7 +4,7 @@ import ( "context" "github.com/tech/sendico/pkg/db/transaction" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" ) type mongoTransactionFactory struct { @@ -26,7 +26,7 @@ func (t *mongoTransaction) Execute(ctx context.Context, cb transaction.Callback) } defer session.EndSession(ctx) - run := func(sessCtx mongo.SessionContext) (any, error) { + run := func(sessCtx context.Context) (any, error) { return cb(sessCtx) } diff --git a/api/gateway/chain/go.mod b/api/gateway/chain/go.mod index 24b798ed..f72010dd 100644 --- a/api/gateway/chain/go.mod +++ b/api/gateway/chain/go.mod @@ -13,7 +13,7 @@ require ( github.com/shopspring/decimal v1.4.0 github.com/stretchr/testify v1.11.1 github.com/tech/sendico/pkg v0.1.0 - go.mongodb.org/mongo-driver v1.17.8 + go.mongodb.org/mongo-driver/v2 v2.5.0 go.uber.org/zap v1.27.1 google.golang.org/grpc v1.78.0 google.golang.org/protobuf v1.36.11 @@ -28,7 +28,7 @@ require ( github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect github.com/casbin/casbin/v2 v2.135.0 // indirect github.com/casbin/govaluate v1.10.0 // indirect - github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect + github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/consensys/gnark-crypto v0.19.2 // indirect @@ -41,7 +41,6 @@ require ( github.com/go-chi/chi/v5 v5.2.4 // indirect github.com/go-jose/go-jose/v4 v4.1.3 // indirect github.com/go-ole/go-ole v1.3.0 // indirect - github.com/golang/snappy v1.0.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect @@ -58,7 +57,6 @@ require ( github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect - github.com/montanaflynn/stats v0.7.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nats-io/nats.go v1.48.0 // indirect github.com/nats-io/nkeys v0.4.15 // indirect diff --git a/api/gateway/chain/go.sum b/api/gateway/chain/go.sum index 1f4c2ee9..bf8b5ecd 100644 --- a/api/gateway/chain/go.sum +++ b/api/gateway/chain/go.sum @@ -22,8 +22,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0= github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= -github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E= -github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA= +github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ= +github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -201,8 +201,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= -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/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -294,8 +292,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM= -go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= diff --git a/api/gateway/chain/internal/service/gateway/service_test.go b/api/gateway/chain/internal/service/gateway/service_test.go index 89f3c7ce..54e2d569 100644 --- a/api/gateway/chain/internal/service/gateway/service_test.go +++ b/api/gateway/chain/internal/service/gateway/service_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1" ichainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -297,10 +297,10 @@ func (w *inMemoryWallets) Create(ctx context.Context, wallet *model.ManagedWalle } if wallet.WalletRef == "" { - wallet.WalletRef = primitive.NewObjectID().Hex() + wallet.WalletRef = bson.NewObjectID().Hex() } if wallet.GetID() == nil || wallet.GetID().IsZero() { - wallet.SetID(primitive.NewObjectID()) + wallet.SetID(bson.NewObjectID()) } else { wallet.Update() } @@ -350,7 +350,7 @@ func (w *inMemoryWallets) List(ctx context.Context, filter model.ManagedWalletFi startIndex := 0 if cursor := strings.TrimSpace(filter.Cursor); cursor != "" { - if oid, err := primitive.ObjectIDFromHex(cursor); err == nil { + if oid, err := bson.ObjectIDFromHex(cursor); err == nil { for idx, item := range items { if item.ID.Timestamp().After(oid.Timestamp()) { startIndex = idx @@ -394,7 +394,7 @@ func (w *inMemoryWallets) SaveBalance(ctx context.Context, balance *model.Wallet existing, ok := w.balances[balance.WalletRef] if !ok { if balance.GetID() == nil || balance.GetID().IsZero() { - balance.SetID(primitive.NewObjectID()) + balance.SetID(bson.NewObjectID()) } w.balances[balance.WalletRef] = balance return nil @@ -446,10 +446,10 @@ func (t *inMemoryTransfers) Create(ctx context.Context, transfer *model.Transfer return t.items[ref], merrors.ErrDataConflict } if transfer.TransferRef == "" { - transfer.TransferRef = primitive.NewObjectID().Hex() + transfer.TransferRef = bson.NewObjectID().Hex() } if transfer.GetID() == nil || transfer.GetID().IsZero() { - transfer.SetID(primitive.NewObjectID()) + transfer.SetID(bson.NewObjectID()) } else { transfer.Update() } @@ -491,7 +491,7 @@ func (t *inMemoryTransfers) List(ctx context.Context, filter model.TransferFilte start := 0 if cursor := strings.TrimSpace(filter.Cursor); cursor != "" { - if oid, err := primitive.ObjectIDFromHex(cursor); err == nil { + if oid, err := bson.ObjectIDFromHex(cursor); err == nil { for idx, item := range items { if item.ID.Timestamp().After(oid.Timestamp()) { start = idx @@ -573,7 +573,7 @@ func (d *inMemoryDeposits) Record(ctx context.Context, deposit *model.Deposit) e return nil } if deposit.GetID() == nil || deposit.GetID().IsZero() { - deposit.SetID(primitive.NewObjectID()) + deposit.SetID(bson.NewObjectID()) } if deposit.ObservedAt.IsZero() { deposit.ObservedAt = time.Now().UTC() diff --git a/api/gateway/chain/internal/service/gateway/shared/helpers.go b/api/gateway/chain/internal/service/gateway/shared/helpers.go index 608c572b..b13e9065 100644 --- a/api/gateway/chain/internal/service/gateway/shared/helpers.go +++ b/api/gateway/chain/internal/service/gateway/shared/helpers.go @@ -7,7 +7,7 @@ import ( chainasset "github.com/tech/sendico/pkg/chain" moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1" chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // CloneMoney defensively copies a Money proto. @@ -42,11 +42,11 @@ func ResolveContractAddress(tokens []TokenContract, symbol string) string { } func GenerateWalletRef() string { - return primitive.NewObjectID().Hex() + return bson.NewObjectID().Hex() } func GenerateTransferRef() string { - return primitive.NewObjectID().Hex() + return bson.NewObjectID().Hex() } func ChainKeyFromEnum(chain chainv1.ChainNetwork) (string, chainv1.ChainNetwork) { diff --git a/api/gateway/chain/storage/mongo/repository.go b/api/gateway/chain/storage/mongo/repository.go index 65927ef8..f89eae75 100644 --- a/api/gateway/chain/storage/mongo/repository.go +++ b/api/gateway/chain/storage/mongo/repository.go @@ -9,7 +9,7 @@ import ( "github.com/tech/sendico/pkg/db" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/gateway/chain/storage/mongo/store/deposits.go b/api/gateway/chain/storage/mongo/store/deposits.go index 60d8b4d2..e74ff49b 100644 --- a/api/gateway/chain/storage/mongo/store/deposits.go +++ b/api/gateway/chain/storage/mongo/store/deposits.go @@ -13,7 +13,7 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/gateway/chain/storage/mongo/store/transfers.go b/api/gateway/chain/storage/mongo/store/transfers.go index ead1eb51..cba38e07 100644 --- a/api/gateway/chain/storage/mongo/store/transfers.go +++ b/api/gateway/chain/storage/mongo/store/transfers.go @@ -14,8 +14,8 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -123,7 +123,7 @@ func (t *Transfers) List(ctx context.Context, filter model.TransferFilter) (*mod } if cursor := strings.TrimSpace(filter.Cursor); cursor != "" { - if oid, err := primitive.ObjectIDFromHex(cursor); err == nil { + if oid, err := bson.ObjectIDFromHex(cursor); err == nil { query = query.Comparison(repository.IDField(), builder.Gt, oid) } else { t.logger.Warn("Ignoring invalid transfer cursor", zap.String("cursor", cursor), zap.Error(err)) diff --git a/api/gateway/chain/storage/mongo/store/wallets.go b/api/gateway/chain/storage/mongo/store/wallets.go index bd902b9a..c932d24d 100644 --- a/api/gateway/chain/storage/mongo/store/wallets.go +++ b/api/gateway/chain/storage/mongo/store/wallets.go @@ -15,8 +15,8 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/mservice" mutil "github.com/tech/sendico/pkg/mutil/db" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -173,7 +173,7 @@ func (w *Wallets) List(ctx context.Context, filter model.ManagedWalletFilter) (* } if cursor := strings.TrimSpace(filter.Cursor); cursor != "" { - if oid, err := primitive.ObjectIDFromHex(cursor); err == nil { + if oid, err := bson.ObjectIDFromHex(cursor); err == nil { query = query.Comparison(repository.IDField(), builder.Gt, oid) fields = append(fields, zap.String("cursor", cursor)) } else { diff --git a/api/gateway/mntx/go.mod b/api/gateway/mntx/go.mod index 03ba37fe..a2bb3641 100644 --- a/api/gateway/mntx/go.mod +++ b/api/gateway/mntx/go.mod @@ -20,15 +20,13 @@ require ( github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect github.com/casbin/casbin/v2 v2.135.0 // indirect github.com/casbin/govaluate v1.10.0 // indirect - github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect + github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/golang/snappy v1.0.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/klauspost/compress v1.18.3 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/montanaflynn/stats v0.7.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nats-io/nats.go v1.48.0 // indirect github.com/nats-io/nkeys v0.4.15 // indirect @@ -42,7 +40,7 @@ require ( github.com/xdg-go/scram v1.2.0 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect - go.mongodb.org/mongo-driver v1.17.8 // indirect + go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.yaml.in/yaml/v2 v2.4.3 // indirect golang.org/x/crypto v0.47.0 // indirect diff --git a/api/gateway/mntx/go.sum b/api/gateway/mntx/go.sum index c0a1f4f8..9ec69a0f 100644 --- a/api/gateway/mntx/go.sum +++ b/api/gateway/mntx/go.sum @@ -14,8 +14,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0= github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= -github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E= -github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA= +github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ= +github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -53,8 +53,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs= -github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -89,8 +87,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= -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/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -152,8 +148,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM= -go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= diff --git a/api/gateway/tgsettle/go.mod b/api/gateway/tgsettle/go.mod index 889f94bd..361ef24c 100644 --- a/api/gateway/tgsettle/go.mod +++ b/api/gateway/tgsettle/go.mod @@ -6,7 +6,7 @@ replace github.com/tech/sendico/pkg => ../../pkg require ( github.com/tech/sendico/pkg v0.1.0 - go.mongodb.org/mongo-driver v1.17.8 + go.mongodb.org/mongo-driver/v2 v2.5.0 go.uber.org/zap v1.27.1 google.golang.org/grpc v1.78.0 google.golang.org/protobuf v1.36.11 @@ -18,16 +18,14 @@ require ( github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect github.com/casbin/casbin/v2 v2.135.0 // indirect github.com/casbin/govaluate v1.10.0 // indirect - github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect + github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/go-chi/chi/v5 v5.2.4 // indirect - github.com/golang/snappy v1.0.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/klauspost/compress v1.18.3 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/montanaflynn/stats v0.7.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nats-io/nats.go v1.48.0 // indirect github.com/nats-io/nkeys v0.4.15 // indirect diff --git a/api/gateway/tgsettle/go.sum b/api/gateway/tgsettle/go.sum index 83f878ad..7e99ce3a 100644 --- a/api/gateway/tgsettle/go.sum +++ b/api/gateway/tgsettle/go.sum @@ -14,8 +14,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0= github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= -github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E= -github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA= +github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ= +github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -53,8 +53,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs= -github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -89,8 +87,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= -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/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -150,8 +146,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM= -go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= diff --git a/api/gateway/tgsettle/storage/model/execution.go b/api/gateway/tgsettle/storage/model/execution.go index 600cc861..1c7ddb17 100644 --- a/api/gateway/tgsettle/storage/model/execution.go +++ b/api/gateway/tgsettle/storage/model/execution.go @@ -5,7 +5,7 @@ import ( "github.com/tech/sendico/pkg/model" paymenttypes "github.com/tech/sendico/pkg/payments/types" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type PaymentStatus string @@ -17,7 +17,7 @@ const ( ) type PaymentRecord struct { - ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` + ID bson.ObjectID `bson:"_id,omitempty" json:"id"` IdempotencyKey string `bson:"idempotencyKey,omitempty" json:"idempotency_key,omitempty"` PaymentIntentID string `bson:"paymentIntentId,omitempty" json:"payment_intent_id,omitempty"` QuoteRef string `bson:"quoteRef,omitempty" json:"quote_ref,omitempty"` @@ -34,7 +34,7 @@ type PaymentRecord struct { } type TelegramConfirmation struct { - ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` + ID bson.ObjectID `bson:"_id,omitempty" json:"id"` RequestID string `bson:"requestId,omitempty" json:"request_id,omitempty"` PaymentIntentID string `bson:"paymentIntentId,omitempty" json:"payment_intent_id,omitempty"` QuoteRef string `bson:"quoteRef,omitempty" json:"quote_ref,omitempty"` diff --git a/api/gateway/tgsettle/storage/mongo/repository.go b/api/gateway/tgsettle/storage/mongo/repository.go index 238a9bb7..0db396f6 100644 --- a/api/gateway/tgsettle/storage/mongo/repository.go +++ b/api/gateway/tgsettle/storage/mongo/repository.go @@ -9,7 +9,7 @@ import ( "github.com/tech/sendico/pkg/db" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/gateway/tgsettle/storage/mongo/store/payments.go b/api/gateway/tgsettle/storage/mongo/store/payments.go index 53cd50a5..6228f4b0 100644 --- a/api/gateway/tgsettle/storage/mongo/store/payments.go +++ b/api/gateway/tgsettle/storage/mongo/store/payments.go @@ -12,10 +12,9 @@ import ( ri "github.com/tech/sendico/pkg/db/repository/index" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" "go.uber.org/zap" ) @@ -91,11 +90,11 @@ func (p *Payments) Upsert(ctx context.Context, record *model.PaymentRecord) erro record.CreatedAt = now } record.UpdatedAt = now - record.ID = primitive.NilObjectID + record.ID = bson.NilObjectID update := bson.M{ "$set": record, } - _, err := p.coll.UpdateOne(ctx, bson.M{fieldIdempotencyKey: record.IdempotencyKey}, update, options.Update().SetUpsert(true)) + _, err := p.coll.UpdateOne(ctx, bson.M{fieldIdempotencyKey: record.IdempotencyKey}, update, options.UpdateOne().SetUpsert(true)) if err != nil { if !errors.Is(err, context.Canceled) && !errors.Is(err, context.DeadlineExceeded) { p.logger.Warn("Failed to upsert payment record", diff --git a/api/gateway/tgsettle/storage/mongo/store/telegram_confirmations.go b/api/gateway/tgsettle/storage/mongo/store/telegram_confirmations.go index 9a42239f..8ada11f7 100644 --- a/api/gateway/tgsettle/storage/mongo/store/telegram_confirmations.go +++ b/api/gateway/tgsettle/storage/mongo/store/telegram_confirmations.go @@ -12,9 +12,9 @@ import ( ri "github.com/tech/sendico/pkg/db/repository/index" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" "go.uber.org/zap" ) @@ -70,7 +70,7 @@ func (t *TelegramConfirmations) Upsert(ctx context.Context, record *model.Telegr update := bson.M{ "$set": record, } - _, err := t.coll.UpdateOne(ctx, bson.M{fieldRequestID: record.RequestID}, update, options.Update().SetUpsert(true)) + _, err := t.coll.UpdateOne(ctx, bson.M{fieldRequestID: record.RequestID}, update, options.UpdateOne().SetUpsert(true)) if err != nil && !errors.Is(err, context.Canceled) && !errors.Is(err, context.DeadlineExceeded) { fields := []zap.Field{zap.String("request_id", record.RequestID)} if record.PaymentIntentID != "" { diff --git a/api/gateway/tron/go.mod b/api/gateway/tron/go.mod index 71832fee..8016db2a 100644 --- a/api/gateway/tron/go.mod +++ b/api/gateway/tron/go.mod @@ -14,7 +14,7 @@ require ( github.com/shopspring/decimal v1.4.0 github.com/stretchr/testify v1.11.1 github.com/tech/sendico/pkg v0.1.0 - go.mongodb.org/mongo-driver v1.17.8 + go.mongodb.org/mongo-driver/v2 v2.5.0 go.uber.org/zap v1.27.1 google.golang.org/grpc v1.78.0 google.golang.org/protobuf v1.36.11 @@ -30,7 +30,7 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.3.6 // indirect github.com/casbin/casbin/v2 v2.135.0 // indirect github.com/casbin/govaluate v1.10.0 // indirect - github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect + github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/consensys/gnark-crypto v0.19.2 // indirect @@ -44,7 +44,6 @@ require ( github.com/go-chi/chi/v5 v5.2.4 // indirect github.com/go-jose/go-jose/v4 v4.1.3 // indirect github.com/go-ole/go-ole v1.3.0 // indirect - github.com/golang/snappy v1.0.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect @@ -61,7 +60,6 @@ require ( github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect - github.com/montanaflynn/stats v0.7.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nats-io/nats.go v1.48.0 // indirect github.com/nats-io/nkeys v0.4.15 // indirect diff --git a/api/gateway/tron/go.sum b/api/gateway/tron/go.sum index 40cb5a45..560ab3b8 100644 --- a/api/gateway/tron/go.sum +++ b/api/gateway/tron/go.sum @@ -24,8 +24,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0= github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= -github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E= -github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA= +github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ= +github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -208,8 +208,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= -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/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -309,8 +307,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM= -go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= diff --git a/api/gateway/tron/internal/service/gateway/service_test.go b/api/gateway/tron/internal/service/gateway/service_test.go index 451d6294..f679344d 100644 --- a/api/gateway/tron/internal/service/gateway/service_test.go +++ b/api/gateway/tron/internal/service/gateway/service_test.go @@ -14,7 +14,7 @@ import ( pmodel "github.com/tech/sendico/pkg/model" connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1" ichainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -299,10 +299,10 @@ func (w *inMemoryWallets) Create(ctx context.Context, wallet *model.ManagedWalle } if wallet.WalletRef == "" { - wallet.WalletRef = primitive.NewObjectID().Hex() + wallet.WalletRef = bson.NewObjectID().Hex() } if wallet.GetID() == nil || wallet.GetID().IsZero() { - wallet.SetID(primitive.NewObjectID()) + wallet.SetID(bson.NewObjectID()) } else { wallet.Update() } @@ -352,7 +352,7 @@ func (w *inMemoryWallets) List(ctx context.Context, filter model.ManagedWalletFi startIndex := 0 if cursor := strings.TrimSpace(filter.Cursor); cursor != "" { - if oid, err := primitive.ObjectIDFromHex(cursor); err == nil { + if oid, err := bson.ObjectIDFromHex(cursor); err == nil { for idx, item := range items { if item.ID.Timestamp().After(oid.Timestamp()) { startIndex = idx @@ -396,7 +396,7 @@ func (w *inMemoryWallets) SaveBalance(ctx context.Context, balance *model.Wallet existing, ok := w.balances[balance.WalletRef] if !ok { if balance.GetID() == nil || balance.GetID().IsZero() { - balance.SetID(primitive.NewObjectID()) + balance.SetID(bson.NewObjectID()) } w.balances[balance.WalletRef] = balance return nil @@ -448,10 +448,10 @@ func (t *inMemoryTransfers) Create(ctx context.Context, transfer *model.Transfer return t.items[ref], merrors.ErrDataConflict } if transfer.TransferRef == "" { - transfer.TransferRef = primitive.NewObjectID().Hex() + transfer.TransferRef = bson.NewObjectID().Hex() } if transfer.GetID() == nil || transfer.GetID().IsZero() { - transfer.SetID(primitive.NewObjectID()) + transfer.SetID(bson.NewObjectID()) } else { transfer.Update() } @@ -493,7 +493,7 @@ func (t *inMemoryTransfers) List(ctx context.Context, filter model.TransferFilte start := 0 if cursor := strings.TrimSpace(filter.Cursor); cursor != "" { - if oid, err := primitive.ObjectIDFromHex(cursor); err == nil { + if oid, err := bson.ObjectIDFromHex(cursor); err == nil { for idx, item := range items { if item.ID.Timestamp().After(oid.Timestamp()) { start = idx @@ -575,7 +575,7 @@ func (d *inMemoryDeposits) Record(ctx context.Context, deposit *model.Deposit) e return nil } if deposit.GetID() == nil || deposit.GetID().IsZero() { - deposit.SetID(primitive.NewObjectID()) + deposit.SetID(bson.NewObjectID()) } if deposit.ObservedAt.IsZero() { deposit.ObservedAt = time.Now().UTC() diff --git a/api/gateway/tron/internal/service/gateway/shared/helpers.go b/api/gateway/tron/internal/service/gateway/shared/helpers.go index 069c4359..961c47bc 100644 --- a/api/gateway/tron/internal/service/gateway/shared/helpers.go +++ b/api/gateway/tron/internal/service/gateway/shared/helpers.go @@ -8,7 +8,7 @@ import ( pmodel "github.com/tech/sendico/pkg/model" moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1" chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // CloneMoney defensively copies a Money proto. @@ -43,11 +43,11 @@ func ResolveContractAddress(tokens []TokenContract, symbol string) string { } func GenerateWalletRef() string { - return primitive.NewObjectID().Hex() + return bson.NewObjectID().Hex() } func GenerateTransferRef() string { - return primitive.NewObjectID().Hex() + return bson.NewObjectID().Hex() } func ChainKeyFromEnum(chain chainv1.ChainNetwork) (string, chainv1.ChainNetwork) { diff --git a/api/gateway/tron/storage/mongo/repository.go b/api/gateway/tron/storage/mongo/repository.go index 1c5e4e34..f607727c 100644 --- a/api/gateway/tron/storage/mongo/repository.go +++ b/api/gateway/tron/storage/mongo/repository.go @@ -9,7 +9,7 @@ import ( "github.com/tech/sendico/pkg/db" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/gateway/tron/storage/mongo/store/deposits.go b/api/gateway/tron/storage/mongo/store/deposits.go index 46bc5c9d..9d876671 100644 --- a/api/gateway/tron/storage/mongo/store/deposits.go +++ b/api/gateway/tron/storage/mongo/store/deposits.go @@ -13,7 +13,7 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/gateway/tron/storage/mongo/store/transfers.go b/api/gateway/tron/storage/mongo/store/transfers.go index 9f116720..205cfda5 100644 --- a/api/gateway/tron/storage/mongo/store/transfers.go +++ b/api/gateway/tron/storage/mongo/store/transfers.go @@ -14,8 +14,8 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -123,7 +123,7 @@ func (t *Transfers) List(ctx context.Context, filter model.TransferFilter) (*mod } if cursor := strings.TrimSpace(filter.Cursor); cursor != "" { - if oid, err := primitive.ObjectIDFromHex(cursor); err == nil { + if oid, err := bson.ObjectIDFromHex(cursor); err == nil { query = query.Comparison(repository.IDField(), builder.Gt, oid) } else { t.logger.Warn("Ignoring invalid transfer cursor", zap.String("cursor", cursor), zap.Error(err)) diff --git a/api/gateway/tron/storage/mongo/store/wallets.go b/api/gateway/tron/storage/mongo/store/wallets.go index 19c9865d..3ae97a59 100644 --- a/api/gateway/tron/storage/mongo/store/wallets.go +++ b/api/gateway/tron/storage/mongo/store/wallets.go @@ -15,8 +15,8 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/mservice" mutil "github.com/tech/sendico/pkg/mutil/db" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -173,7 +173,7 @@ func (w *Wallets) List(ctx context.Context, filter model.ManagedWalletFilter) (* } if cursor := strings.TrimSpace(filter.Cursor); cursor != "" { - if oid, err := primitive.ObjectIDFromHex(cursor); err == nil { + if oid, err := bson.ObjectIDFromHex(cursor); err == nil { query = query.Comparison(repository.IDField(), builder.Gt, oid) fields = append(fields, zap.String("cursor", cursor)) } else { diff --git a/api/gateway/tron/tmp/build-errors.log b/api/gateway/tron/tmp/build-errors.log index 6c6d0807..f50898d0 100644 --- a/api/gateway/tron/tmp/build-errors.log +++ b/api/gateway/tron/tmp/build-errors.log @@ -1 +1 @@ -exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1 \ No newline at end of file +exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1 \ No newline at end of file diff --git a/api/ledger/go.mod b/api/ledger/go.mod index 46329302..a7843d19 100644 --- a/api/ledger/go.mod +++ b/api/ledger/go.mod @@ -9,7 +9,7 @@ require ( github.com/shopspring/decimal v1.4.0 github.com/stretchr/testify v1.11.1 github.com/tech/sendico/pkg v0.1.0 - go.mongodb.org/mongo-driver v1.17.8 + go.mongodb.org/mongo-driver/v2 v2.5.0 go.uber.org/zap v1.27.1 google.golang.org/grpc v1.78.0 google.golang.org/protobuf v1.36.11 @@ -21,17 +21,15 @@ require ( github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect github.com/casbin/casbin/v2 v2.135.0 // indirect github.com/casbin/govaluate v1.10.0 // indirect - github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect + github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-chi/chi/v5 v5.2.4 // indirect - github.com/golang/snappy v1.0.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/klauspost/compress v1.18.3 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/montanaflynn/stats v0.7.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nats-io/nats.go v1.48.0 // indirect github.com/nats-io/nkeys v0.4.15 // indirect diff --git a/api/ledger/go.sum b/api/ledger/go.sum index a11be9e8..56858006 100644 --- a/api/ledger/go.sum +++ b/api/ledger/go.sum @@ -14,8 +14,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0= github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= -github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E= -github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA= +github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ= +github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -53,8 +53,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs= -github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -89,8 +87,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= -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/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -152,8 +148,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM= -go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= diff --git a/api/ledger/internal/model/account.go b/api/ledger/internal/model/account.go index ff8098e0..6f74218f 100644 --- a/api/ledger/internal/model/account.go +++ b/api/ledger/internal/model/account.go @@ -7,7 +7,7 @@ import ( "time" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // AccountType controls normal balance side. @@ -35,7 +35,7 @@ type Account struct { Currency string `bson:"currency,omitempty" json:"currency,omitempty"` // Managing entity in your platform (not legal owner). - OrganizationRef *primitive.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"` + OrganizationRef *bson.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"` // Posting policy & lifecycle AllowNegative bool `bson:"allowNegative" json:"allowNegative"` @@ -131,7 +131,7 @@ func (a *Account) BalanceSide() int { } // CloseOwnershipPeriod sets the To date for the first matching active ownership. -func (a *Account) CloseOwnershipPeriod(partyID primitive.ObjectID, role OwnershipRole, to time.Time) bool { +func (a *Account) CloseOwnershipPeriod(partyID bson.ObjectID, role OwnershipRole, to time.Time) bool { for i := range a.Ownerships { o := &a.Ownerships[i] if o.OwnerPartyRef == partyID && o.Role == role && o.ActiveAt(to) { diff --git a/api/ledger/internal/model/balance.go b/api/ledger/internal/model/balance.go index 12548da5..23ac7fd7 100644 --- a/api/ledger/internal/model/balance.go +++ b/api/ledger/internal/model/balance.go @@ -1,17 +1,17 @@ package ledger import ( + "github.com/shopspring/decimal" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "github.com/shopspring/decimal" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type AccountBalance struct { model.PermissionBound `bson:",inline" json:",inline"` - LedgerAccountRef primitive.ObjectID `bson:"ledgerAccountRef" json:"ledgerAccountRef"` // unique - Balance decimal.Decimal `bson:"balance" json:"balance"` - Version int64 `bson:"version" json:"version"` // for optimistic locking + LedgerAccountRef bson.ObjectID `bson:"ledgerAccountRef" json:"ledgerAccountRef"` // unique + Balance decimal.Decimal `bson:"balance" json:"balance"` + Version int64 `bson:"version" json:"version"` // for optimistic locking } func (a *AccountBalance) Collection() string { diff --git a/api/ledger/internal/model/jentry.go b/api/ledger/internal/model/jentry.go index 12c0bea3..3dc2a968 100644 --- a/api/ledger/internal/model/jentry.go +++ b/api/ledger/internal/model/jentry.go @@ -6,7 +6,7 @@ import ( "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // EntryType is a closed set of journal entry kinds. @@ -35,10 +35,10 @@ type JournalEntry struct { Version int64 `bson:"version" json:"version"` // Denormalized set of all affected ledger accounts (for entry-level access control & queries) - LedgerAccountRefs []primitive.ObjectID `bson:"ledgerAccountRefs,omitempty" json:"ledgerAccountRefs,omitempty"` + LedgerAccountRefs []bson.ObjectID `bson:"ledgerAccountRefs,omitempty" json:"ledgerAccountRefs,omitempty"` // Optional backlink for reversals - ReversalOf *primitive.ObjectID `bson:"reversalOf,omitempty" json:"reversalOf,omitempty"` + ReversalOf *bson.ObjectID `bson:"reversalOf,omitempty" json:"reversalOf,omitempty"` } func (j *JournalEntry) Collection() string { diff --git a/api/ledger/internal/model/ownership.go b/api/ledger/internal/model/ownership.go index d5b9b9ba..bff539e2 100644 --- a/api/ledger/internal/model/ownership.go +++ b/api/ledger/internal/model/ownership.go @@ -3,7 +3,7 @@ package ledger import ( "time" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // OwnershipRole captures legal roles (not permissions). @@ -17,11 +17,11 @@ const ( ) type Ownership struct { - OwnerPartyRef primitive.ObjectID `bson:"ownerPartyRef" json:"ownerPartyRef"` - Role OwnershipRole `bson:"role" json:"role"` - SharePct *float64 `bson:"sharePct,omitempty" json:"sharePct,omitempty"` // 0..100; nil = unspecified - From time.Time `bson:"effectiveFrom" json:"effectiveFrom"` - To *time.Time `bson:"effectiveTo,omitempty" json:"effectiveTo,omitempty"` // active if t < To; nil = open + OwnerPartyRef bson.ObjectID `bson:"ownerPartyRef" json:"ownerPartyRef"` + Role OwnershipRole `bson:"role" json:"role"` + SharePct *float64 `bson:"sharePct,omitempty" json:"sharePct,omitempty"` // 0..100; nil = unspecified + From time.Time `bson:"effectiveFrom" json:"effectiveFrom"` + To *time.Time `bson:"effectiveTo,omitempty" json:"effectiveTo,omitempty"` // active if t < To; nil = open } func (o *Ownership) Validate() error { diff --git a/api/ledger/internal/model/party.go b/api/ledger/internal/model/party.go index 10f54a7e..aa3e408a 100644 --- a/api/ledger/internal/model/party.go +++ b/api/ledger/internal/model/party.go @@ -6,7 +6,7 @@ import ( "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // PartyKind (string-backed enum) — readable in BSON/JSON, safe in Go. @@ -39,10 +39,10 @@ func (k *PartyKind) UnmarshalJSON(b []byte) error { type Party struct { model.PermissionBound `bson:",inline" json:",inline"` - Kind PartyKind `bson:"kind" json:"kind"` - Name string `bson:"name" json:"name"` - UserRef *primitive.ObjectID `bson:"userRef,omitempty" json:"userRef,omitempty"` // internal user, if applicable - OrganizationRef *primitive.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"` // internal org, if applicable + Kind PartyKind `bson:"kind" json:"kind"` + Name string `bson:"name" json:"name"` + UserRef *bson.ObjectID `bson:"userRef,omitempty" json:"userRef,omitempty"` // internal user, if applicable + OrganizationRef *bson.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"` // internal org, if applicable // add your own fields here if needed (KYC flags, etc.) } diff --git a/api/ledger/internal/model/pline.go b/api/ledger/internal/model/pline.go index 419c503c..e71ce2b2 100644 --- a/api/ledger/internal/model/pline.go +++ b/api/ledger/internal/model/pline.go @@ -2,11 +2,11 @@ package ledger import ( + "github.com/shopspring/decimal" "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "github.com/shopspring/decimal" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // LineType is a closed set of posting line roles within an entry. @@ -22,8 +22,8 @@ const ( type PostingLine struct { storable.Base `bson:",inline" json:",inline"` - JournalEntryRef primitive.ObjectID `bson:"journalEntryRef" json:"journalEntryRef"` - LedgerAccountRef primitive.ObjectID `bson:"ledgerAccountRef" json:"ledgerAccountRef"` + JournalEntryRef bson.ObjectID `bson:"journalEntryRef" json:"journalEntryRef"` + LedgerAccountRef bson.ObjectID `bson:"ledgerAccountRef" json:"ledgerAccountRef"` // Amount sign convention: positive = credit, negative = debit Amount decimal.Decimal `bson:"amount" json:"amount"` diff --git a/api/ledger/internal/service/ledger/accounts.go b/api/ledger/internal/service/ledger/accounts.go index d7251a80..0a492b16 100644 --- a/api/ledger/internal/service/ledger/accounts.go +++ b/api/ledger/internal/service/ledger/accounts.go @@ -14,14 +14,14 @@ import ( "github.com/tech/sendico/pkg/mutil/mzap" describablev1 "github.com/tech/sendico/pkg/proto/common/describable/v1" ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "google.golang.org/protobuf/types/known/timestamppb" ) // createAccountParams holds validated and normalized fields from a CreateAccountRequest. type createAccountParams struct { - orgRef primitive.ObjectID + orgRef bson.ObjectID currency string modelType pmodel.LedgerAccountType modelStatus pmodel.LedgerAccountStatus @@ -104,7 +104,7 @@ func (s *Service) createAccountResponder(_ context.Context, req *ledgerv1.Create } // resolveTopologyAccount ensures ledger topology is initialized and returns the system account for the given role. -func (s *Service) resolveTopologyAccount(ctx context.Context, orgRef primitive.ObjectID, currency string, role pmodel.AccountRole) (*ledgerv1.CreateAccountResponse, error) { +func (s *Service) resolveTopologyAccount(ctx context.Context, orgRef bson.ObjectID, currency string, role pmodel.AccountRole) (*ledgerv1.CreateAccountResponse, error) { if err := s.ensureLedgerTopology(ctx, orgRef, currency); err != nil { recordAccountOperation("create", "error") return nil, err @@ -142,7 +142,7 @@ func (s *Service) persistNewAccount(ctx context.Context, p createAccountParams, const maxCreateAttempts = 3 for attempt := 0; attempt < maxCreateAttempts; attempt++ { - accountID := primitive.NewObjectID() + accountID := bson.NewObjectID() account := buildNewAccount(p, metadata, describable, ownerRef, req.GetAllowNegative(), accountID) err := s.storage.Accounts().Create(ctx, account) @@ -180,7 +180,7 @@ func (s *Service) persistNewAccount(ctx context.Context, p createAccountParams, } // parseOwnerRef parses an optional owner reference string into an ObjectID pointer. -func parseOwnerRef(ownerRefStr string) (*primitive.ObjectID, error) { +func parseOwnerRef(ownerRefStr string) (*bson.ObjectID, error) { if ownerRefStr == "" { return nil, nil } @@ -192,7 +192,7 @@ func parseOwnerRef(ownerRefStr string) (*primitive.ObjectID, error) { } // buildNewAccount constructs a LedgerAccount model from validated parameters. -func buildNewAccount(p createAccountParams, metadata map[string]string, describable *pmodel.Describable, ownerRef *primitive.ObjectID, allowNegative bool, accountRef primitive.ObjectID) *pmodel.LedgerAccount { +func buildNewAccount(p createAccountParams, metadata map[string]string, describable *pmodel.Describable, ownerRef *bson.ObjectID, allowNegative bool, accountRef bson.ObjectID) *pmodel.LedgerAccount { account := &pmodel.LedgerAccount{ AccountCode: generateAccountCode(p.modelType, p.currency, accountRef), Currency: p.currency, @@ -353,14 +353,14 @@ func toProtoAccount(account *pmodel.LedgerAccount) *ledgerv1.LedgerAccount { } } -func objectIDHex(id primitive.ObjectID) string { +func objectIDHex(id bson.ObjectID) string { if id.IsZero() { return "" } return id.Hex() } -func objectIDPtrHex(id *primitive.ObjectID) string { +func objectIDPtrHex(id *bson.ObjectID) string { if id == nil || id.IsZero() { return "" } @@ -413,11 +413,11 @@ func describableToProto(desc pmodel.Describable) *describablev1.Describable { } } -func (s *Service) ensureSettlementAccount(ctx context.Context, orgRef primitive.ObjectID, currency string) (*pmodel.LedgerAccount, error) { +func (s *Service) ensureSettlementAccount(ctx context.Context, orgRef bson.ObjectID, currency string) (*pmodel.LedgerAccount, error) { return s.ensureRoleAccount(ctx, orgRef, currency, pmodel.AccountRoleSettlement) } -func generateAccountCode(accountType pmodel.LedgerAccountType, currency string, id primitive.ObjectID) string { +func generateAccountCode(accountType pmodel.LedgerAccountType, currency string, id bson.ObjectID) string { typePart := strings.ToLower(strings.TrimSpace(string(accountType))) if typePart == "" { typePart = "account" diff --git a/api/ledger/internal/service/ledger/accounts_test.go b/api/ledger/internal/service/ledger/accounts_test.go index 6d44942f..d7cf8658 100644 --- a/api/ledger/internal/service/ledger/accounts_test.go +++ b/api/ledger/internal/service/ledger/accounts_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/stretchr/testify/require" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "github.com/tech/sendico/ledger/storage" @@ -45,7 +45,7 @@ func (s *accountStoreStub) Create(_ context.Context, account *pmodel.LedgerAccou } if account.GetID() == nil || account.GetID().IsZero() { - account.SetID(primitive.NewObjectID()) + account.SetID(bson.NewObjectID()) } account.CreatedAt = account.CreatedAt.UTC() @@ -55,18 +55,18 @@ func (s *accountStoreStub) Create(_ context.Context, account *pmodel.LedgerAccou return nil } -func (s *accountStoreStub) GetByAccountCode(_ context.Context, _ primitive.ObjectID, _ string, _ string) (*pmodel.LedgerAccount, error) { +func (s *accountStoreStub) GetByAccountCode(_ context.Context, _ bson.ObjectID, _ string, _ string) (*pmodel.LedgerAccount, error) { if s.existingErr != nil { return nil, s.existingErr } return s.existing, nil } -func (s *accountStoreStub) Get(context.Context, primitive.ObjectID) (*pmodel.LedgerAccount, error) { +func (s *accountStoreStub) Get(context.Context, bson.ObjectID) (*pmodel.LedgerAccount, error) { return nil, storage.ErrAccountNotFound } -func (s *accountStoreStub) GetByRole(_ context.Context, orgRef primitive.ObjectID, currency string, role pmodel.AccountRole) (*pmodel.LedgerAccount, error) { +func (s *accountStoreStub) GetByRole(_ context.Context, orgRef bson.ObjectID, currency string, role pmodel.AccountRole) (*pmodel.LedgerAccount, error) { if s.existingByRole != nil { if acc, ok := s.existingByRole[role]; ok { return acc, nil @@ -84,7 +84,7 @@ func (s *accountStoreStub) GetSystemAccount(context.Context, pmodel.SystemAccoun return nil, storage.ErrAccountNotFound } -func (s *accountStoreStub) GetDefaultSettlement(context.Context, primitive.ObjectID, string) (*pmodel.LedgerAccount, error) { +func (s *accountStoreStub) GetDefaultSettlement(context.Context, bson.ObjectID, string) (*pmodel.LedgerAccount, error) { if s.defaultErr != nil { return nil, s.defaultErr } @@ -94,11 +94,11 @@ func (s *accountStoreStub) GetDefaultSettlement(context.Context, primitive.Objec return nil, storage.ErrAccountNotFound } -func (s *accountStoreStub) ListByOrganization(context.Context, primitive.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) { +func (s *accountStoreStub) ListByOrganization(context.Context, bson.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) { return nil, nil } -func (s *accountStoreStub) UpdateStatus(context.Context, primitive.ObjectID, pmodel.LedgerAccountStatus) error { +func (s *accountStoreStub) UpdateStatus(context.Context, bson.ObjectID, pmodel.LedgerAccountStatus) error { return nil } @@ -116,7 +116,7 @@ func (r *repositoryStub) Outbox() storage.OutboxStore { return n func TestCreateAccountResponder_Success(t *testing.T) { t.Parallel() - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() accountStore := &accountStoreStub{} svc := &Service{ @@ -161,7 +161,7 @@ func TestCreateAccountResponder_Success(t *testing.T) { func TestCreateAccountResponder_AutoCreatesSettlementAccount(t *testing.T) { t.Parallel() - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() accountStore := &accountStoreStub{} svc := &Service{ @@ -237,7 +237,7 @@ func TestCreateAccountResponder_AutoCreatesSettlementAccount(t *testing.T) { func TestCreateAccountResponder_RetriesOnConflict(t *testing.T) { t.Parallel() - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() accountStore := &accountStoreStub{ // first create attempt returns conflict, second succeeds createErrs: []error{merrors.DataConflict("duplicate")}, @@ -292,7 +292,7 @@ func TestCreateAccountResponder_InvalidAccountType(t *testing.T) { // AccountType missing => must fail req := &ledgerv1.CreateAccountRequest{ - OrganizationRef: primitive.NewObjectID().Hex(), + OrganizationRef: bson.NewObjectID().Hex(), Currency: "USD", } diff --git a/api/ledger/internal/service/ledger/external_operations_test.go b/api/ledger/internal/service/ledger/external_operations_test.go index 01ccb3e8..3a4dc814 100644 --- a/api/ledger/internal/service/ledger/external_operations_test.go +++ b/api/ledger/internal/service/ledger/external_operations_test.go @@ -18,7 +18,7 @@ import ( pmodel "github.com/tech/sendico/pkg/model" moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1" ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -50,16 +50,16 @@ func (r *memoryRepository) Outbox() storage.OutboxStore { return func (r *memoryRepository) TransactionFactory() transaction.Factory { return r.txFactory } type memoryAccountsStore struct { - records map[primitive.ObjectID]*pmodel.LedgerAccount + records map[bson.ObjectID]*pmodel.LedgerAccount systemByPurposeKey map[string]*pmodel.LedgerAccount } func (s *memoryAccountsStore) Create(_ context.Context, account *pmodel.LedgerAccount) error { if account.GetID() == nil || account.GetID().IsZero() { - account.SetID(primitive.NewObjectID()) + account.SetID(bson.NewObjectID()) } if s.records == nil { - s.records = make(map[primitive.ObjectID]*pmodel.LedgerAccount) + s.records = make(map[bson.ObjectID]*pmodel.LedgerAccount) } s.records[*account.GetID()] = account if account.SystemPurpose != nil { @@ -72,7 +72,7 @@ func (s *memoryAccountsStore) Create(_ context.Context, account *pmodel.LedgerAc return nil } -func (s *memoryAccountsStore) Get(_ context.Context, accountRef primitive.ObjectID) (*pmodel.LedgerAccount, error) { +func (s *memoryAccountsStore) Get(_ context.Context, accountRef bson.ObjectID) (*pmodel.LedgerAccount, error) { if s.records == nil { return nil, storage.ErrAccountNotFound } @@ -82,11 +82,11 @@ func (s *memoryAccountsStore) Get(_ context.Context, accountRef primitive.Object return nil, storage.ErrAccountNotFound } -func (s *memoryAccountsStore) GetByAccountCode(context.Context, primitive.ObjectID, string, string) (*pmodel.LedgerAccount, error) { +func (s *memoryAccountsStore) GetByAccountCode(context.Context, bson.ObjectID, string, string) (*pmodel.LedgerAccount, error) { return nil, merrors.NotImplemented("get by code") } -func (s *memoryAccountsStore) GetByRole(context.Context, primitive.ObjectID, string, pmodel.AccountRole) (*pmodel.LedgerAccount, error) { +func (s *memoryAccountsStore) GetByRole(context.Context, bson.ObjectID, string, pmodel.AccountRole) (*pmodel.LedgerAccount, error) { return nil, merrors.NotImplemented("get by role") } @@ -101,15 +101,15 @@ func (s *memoryAccountsStore) GetSystemAccount(_ context.Context, purpose pmodel return nil, storage.ErrAccountNotFound } -func (s *memoryAccountsStore) GetDefaultSettlement(context.Context, primitive.ObjectID, string) (*pmodel.LedgerAccount, error) { +func (s *memoryAccountsStore) GetDefaultSettlement(context.Context, bson.ObjectID, string) (*pmodel.LedgerAccount, error) { return nil, merrors.NotImplemented("get default settlement") } -func (s *memoryAccountsStore) ListByOrganization(context.Context, primitive.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) { +func (s *memoryAccountsStore) ListByOrganization(context.Context, bson.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) { return nil, merrors.NotImplemented("list by organization") } -func (s *memoryAccountsStore) UpdateStatus(context.Context, primitive.ObjectID, pmodel.LedgerAccountStatus) error { +func (s *memoryAccountsStore) UpdateStatus(context.Context, bson.ObjectID, pmodel.LedgerAccountStatus) error { return merrors.NotImplemented("update status") } @@ -136,7 +136,7 @@ type memoryJournalEntriesStore struct { func (s *memoryJournalEntriesStore) Create(_ context.Context, entry *model.JournalEntry) error { if entry.GetID() == nil || entry.GetID().IsZero() { - entry.SetID(primitive.NewObjectID()) + entry.SetID(bson.NewObjectID()) } if s.byKey == nil { s.byKey = make(map[string]*model.JournalEntry) @@ -146,11 +146,11 @@ func (s *memoryJournalEntriesStore) Create(_ context.Context, entry *model.Journ return nil } -func (s *memoryJournalEntriesStore) Get(context.Context, primitive.ObjectID) (*model.JournalEntry, error) { +func (s *memoryJournalEntriesStore) Get(context.Context, bson.ObjectID) (*model.JournalEntry, error) { return nil, merrors.NotImplemented("get entry") } -func (s *memoryJournalEntriesStore) GetByIdempotencyKey(_ context.Context, orgRef primitive.ObjectID, key string) (*model.JournalEntry, error) { +func (s *memoryJournalEntriesStore) GetByIdempotencyKey(_ context.Context, orgRef bson.ObjectID, key string) (*model.JournalEntry, error) { if s.byKey == nil { return nil, storage.ErrJournalEntryNotFound } @@ -161,7 +161,7 @@ func (s *memoryJournalEntriesStore) GetByIdempotencyKey(_ context.Context, orgRe return entry, nil } -func (s *memoryJournalEntriesStore) ListByOrganization(context.Context, primitive.ObjectID, int, int) ([]*model.JournalEntry, error) { +func (s *memoryJournalEntriesStore) ListByOrganization(context.Context, bson.ObjectID, int, int) ([]*model.JournalEntry, error) { return nil, merrors.NotImplemented("list entries") } @@ -174,19 +174,19 @@ func (s *memoryPostingLinesStore) CreateMany(_ context.Context, lines []*model.P return nil } -func (s *memoryPostingLinesStore) ListByJournalEntry(context.Context, primitive.ObjectID) ([]*model.PostingLine, error) { +func (s *memoryPostingLinesStore) ListByJournalEntry(context.Context, bson.ObjectID) ([]*model.PostingLine, error) { return nil, merrors.NotImplemented("list lines by entry") } -func (s *memoryPostingLinesStore) ListByAccount(context.Context, primitive.ObjectID, int, int) ([]*model.PostingLine, error) { +func (s *memoryPostingLinesStore) ListByAccount(context.Context, bson.ObjectID, int, int) ([]*model.PostingLine, error) { return nil, merrors.NotImplemented("list lines by account") } type memoryBalancesStore struct { - records map[primitive.ObjectID]*model.AccountBalance + records map[bson.ObjectID]*model.AccountBalance } -func (s *memoryBalancesStore) Get(_ context.Context, accountRef primitive.ObjectID) (*model.AccountBalance, error) { +func (s *memoryBalancesStore) Get(_ context.Context, accountRef bson.ObjectID) (*model.AccountBalance, error) { if s.records == nil { return nil, storage.ErrBalanceNotFound } @@ -199,14 +199,14 @@ func (s *memoryBalancesStore) Get(_ context.Context, accountRef primitive.Object func (s *memoryBalancesStore) Upsert(_ context.Context, balance *model.AccountBalance) error { if s.records == nil { - s.records = make(map[primitive.ObjectID]*model.AccountBalance) + s.records = make(map[bson.ObjectID]*model.AccountBalance) } copied := *balance s.records[balance.AccountRef] = &copied return nil } -func (s *memoryBalancesStore) IncrementBalance(context.Context, primitive.ObjectID, string) error { +func (s *memoryBalancesStore) IncrementBalance(context.Context, bson.ObjectID, string) error { return merrors.NotImplemented("increment balance") } @@ -216,13 +216,13 @@ func (memoryOutboxStore) Create(context.Context, *model.OutboxEvent) error { ret func (memoryOutboxStore) ListPending(context.Context, int) ([]*model.OutboxEvent, error) { return nil, merrors.NotImplemented("list outbox") } -func (memoryOutboxStore) MarkSent(context.Context, primitive.ObjectID, time.Time) error { +func (memoryOutboxStore) MarkSent(context.Context, bson.ObjectID, time.Time) error { return merrors.NotImplemented("mark sent") } -func (memoryOutboxStore) MarkFailed(context.Context, primitive.ObjectID) error { +func (memoryOutboxStore) MarkFailed(context.Context, bson.ObjectID) error { return merrors.NotImplemented("mark failed") } -func (memoryOutboxStore) IncrementAttempts(context.Context, primitive.ObjectID) error { +func (memoryOutboxStore) IncrementAttempts(context.Context, bson.ObjectID) error { return merrors.NotImplemented("increment attempts") } @@ -242,9 +242,9 @@ func newTestService() (*Service, *memoryRepository) { return svc, repo } -func newOrgAccount(orgRef primitive.ObjectID, currency string, role pmodel.AccountRole) *pmodel.LedgerAccount { +func newOrgAccount(orgRef bson.ObjectID, currency string, role pmodel.AccountRole) *pmodel.LedgerAccount { account := &pmodel.LedgerAccount{ - AccountCode: "test:" + strings.ToLower(currency) + ":" + primitive.NewObjectID().Hex(), + AccountCode: "test:" + strings.ToLower(currency) + ":" + bson.NewObjectID().Hex(), Currency: currency, AccountType: pmodel.LedgerAccountTypeAsset, Status: pmodel.LedgerAccountStatusActive, @@ -256,7 +256,7 @@ func newOrgAccount(orgRef primitive.ObjectID, currency string, role pmodel.Accou return account } -func balanceString(t *testing.T, balances *memoryBalancesStore, accountID primitive.ObjectID) string { +func balanceString(t *testing.T, balances *memoryBalancesStore, accountID bson.ObjectID) string { t.Helper() bal, err := balances.Get(context.Background(), accountID) if errors.Is(err, storage.ErrBalanceNotFound) { @@ -266,7 +266,7 @@ func balanceString(t *testing.T, balances *memoryBalancesStore, accountID primit return bal.Balance } -func balanceDecimal(t *testing.T, balances *memoryBalancesStore, accountID primitive.ObjectID) decimal.Decimal { +func balanceDecimal(t *testing.T, balances *memoryBalancesStore, accountID bson.ObjectID) decimal.Decimal { t.Helper() bal, err := balances.Get(context.Background(), accountID) if errors.Is(err, storage.ErrBalanceNotFound) { @@ -289,7 +289,7 @@ func TestExternalCreditAndDebit(t *testing.T) { svc, repo := newTestService() require.NoError(t, svc.ensureSystemAccounts(ctx)) - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() pending := newOrgAccount(orgRef, "USD", pmodel.AccountRolePending) require.NoError(t, repo.accounts.Create(ctx, pending)) @@ -333,7 +333,7 @@ func TestExternalCreditCurrencyMismatch(t *testing.T) { svc, repo := newTestService() require.NoError(t, svc.ensureSystemAccounts(ctx)) - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() pending := newOrgAccount(orgRef, "USD", pmodel.AccountRolePending) require.NoError(t, repo.accounts.Create(ctx, pending)) @@ -361,7 +361,7 @@ func TestExternalOperationsRejectSystemScopeTargets(t *testing.T) { svc, repo := newTestService() require.NoError(t, svc.ensureSystemAccounts(ctx)) - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() source, err := repo.accounts.GetSystemAccount(ctx, pmodel.SystemAccountPurposeExternalSource, "USD") require.NoError(t, err) sink, err := repo.accounts.GetSystemAccount(ctx, pmodel.SystemAccountPurposeExternalSink, "USD") @@ -395,7 +395,7 @@ func TestExternalFlowInvariant(t *testing.T) { svc, repo := newTestService() require.NoError(t, svc.ensureSystemAccounts(ctx)) - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() pending := newOrgAccount(orgRef, "USD", pmodel.AccountRolePending) transit := newOrgAccount(orgRef, "USD", pmodel.AccountRoleTransit) require.NoError(t, repo.accounts.Create(ctx, pending)) @@ -441,7 +441,7 @@ func TestExternalInvariantRandomSequence(t *testing.T) { svc, repo := newTestService() require.NoError(t, svc.ensureSystemAccounts(ctx)) - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() pending := newOrgAccount(orgRef, "USD", pmodel.AccountRolePending) transit := newOrgAccount(orgRef, "USD", pmodel.AccountRoleTransit) require.NoError(t, repo.accounts.Create(ctx, pending)) diff --git a/api/ledger/internal/service/ledger/helpers.go b/api/ledger/internal/service/ledger/helpers.go index de0b9b80..c5445c80 100644 --- a/api/ledger/internal/service/ledger/helpers.go +++ b/api/ledger/internal/service/ledger/helpers.go @@ -9,18 +9,18 @@ import ( "github.com/tech/sendico/pkg/merrors" moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1" ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "google.golang.org/protobuf/types/known/timestamppb" ) // parseObjectID converts a hex string to ObjectID -func parseObjectID(hexID string) (primitive.ObjectID, error) { +func parseObjectID(hexID string) (bson.ObjectID, error) { if hexID == "" { - return primitive.NilObjectID, merrors.InvalidArgument("empty object ID") + return bson.NilObjectID, merrors.InvalidArgument("empty object ID") } - oid, err := primitive.ObjectIDFromHex(hexID) + oid, err := bson.ObjectIDFromHex(hexID) if err != nil { - return primitive.NilObjectID, merrors.InvalidArgument(fmt.Sprintf("invalid object ID: %v", err)) + return bson.NilObjectID, merrors.InvalidArgument(fmt.Sprintf("invalid object ID: %v", err)) } return oid, nil } diff --git a/api/ledger/internal/service/ledger/helpers_test.go b/api/ledger/internal/service/ledger/helpers_test.go index ebeeb5e7..6872f808 100644 --- a/api/ledger/internal/service/ledger/helpers_test.go +++ b/api/ledger/internal/service/ledger/helpers_test.go @@ -10,13 +10,13 @@ import ( "github.com/tech/sendico/ledger/storage/model" moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1" ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "google.golang.org/protobuf/types/known/timestamppb" ) func TestParseObjectID(t *testing.T) { t.Run("ValidObjectID", func(t *testing.T) { - validID := primitive.NewObjectID() + validID := bson.NewObjectID() result, err := parseObjectID(validID.Hex()) require.NoError(t, err) @@ -27,7 +27,7 @@ func TestParseObjectID(t *testing.T) { result, err := parseObjectID("") require.Error(t, err) - assert.Equal(t, primitive.NilObjectID, result) + assert.Equal(t, bson.NilObjectID, result) assert.Contains(t, err.Error(), "empty object ID") }) @@ -35,7 +35,7 @@ func TestParseObjectID(t *testing.T) { result, err := parseObjectID("invalid-hex-string") require.Error(t, err) - assert.Equal(t, primitive.NilObjectID, result) + assert.Equal(t, bson.NilObjectID, result) assert.Contains(t, err.Error(), "invalid object ID") }) @@ -43,7 +43,7 @@ func TestParseObjectID(t *testing.T) { result, err := parseObjectID("abc123") require.Error(t, err) - assert.Equal(t, primitive.NilObjectID, result) + assert.Equal(t, bson.NilObjectID, result) }) } @@ -145,7 +145,7 @@ func TestValidatePostingLines(t *testing.T) { t.Run("ValidPostingLines", func(t *testing.T) { lines := []*ledgerv1.PostingLine{ { - LedgerAccountRef: primitive.NewObjectID().Hex(), + LedgerAccountRef: bson.NewObjectID().Hex(), Money: &moneyv1.Money{ Amount: "10.00", Currency: "USD", @@ -192,7 +192,7 @@ func TestValidatePostingLines(t *testing.T) { t.Run("NilMoney", func(t *testing.T) { lines := []*ledgerv1.PostingLine{ { - LedgerAccountRef: primitive.NewObjectID().Hex(), + LedgerAccountRef: bson.NewObjectID().Hex(), Money: nil, }, } @@ -206,7 +206,7 @@ func TestValidatePostingLines(t *testing.T) { t.Run("MainLineType", func(t *testing.T) { lines := []*ledgerv1.PostingLine{ { - LedgerAccountRef: primitive.NewObjectID().Hex(), + LedgerAccountRef: bson.NewObjectID().Hex(), Money: &moneyv1.Money{ Amount: "10.00", Currency: "USD", diff --git a/api/ledger/internal/service/ledger/invariant.go b/api/ledger/internal/service/ledger/invariant.go index 5e16669d..267e9e9e 100644 --- a/api/ledger/internal/service/ledger/invariant.go +++ b/api/ledger/internal/service/ledger/invariant.go @@ -12,7 +12,7 @@ import ( "github.com/tech/sendico/pkg/merrors" pmodel "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) // CheckExternalInvariant validates the external_source/external_sink invariant for a currency. diff --git a/api/ledger/internal/service/ledger/list_accounts.go b/api/ledger/internal/service/ledger/list_accounts.go index 591712ba..16b838ad 100644 --- a/api/ledger/internal/service/ledger/list_accounts.go +++ b/api/ledger/internal/service/ledger/list_accounts.go @@ -9,7 +9,7 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mutil/mzap" ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -35,7 +35,7 @@ func (s *Service) listAccountsResponder(_ context.Context, req *ledgerv1.ListAcc var filter *storage.AccountsFilter if req.GetOwnerRefFilter() != nil { ownerRefStr := strings.TrimSpace(req.GetOwnerRefFilter().GetValue()) - var ownerRef primitive.ObjectID + var ownerRef bson.ObjectID if ownerRefStr != "" { ownerRef, err = parseObjectID(ownerRefStr) if err != nil { diff --git a/api/ledger/internal/service/ledger/outbox_publisher_test.go b/api/ledger/internal/service/ledger/outbox_publisher_test.go index 47f2e2ff..1b0cc92a 100644 --- a/api/ledger/internal/service/ledger/outbox_publisher_test.go +++ b/api/ledger/internal/service/ledger/outbox_publisher_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tech/sendico/ledger/storage/model" me "github.com/tech/sendico/pkg/messaging/envelope" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -24,8 +24,8 @@ func TestOutboxPublisherDispatchSuccess(t *testing.T) { Payload: []byte(`{"journalEntryRef":"abc123"}`), Attempts: 0, } - event.SetID(primitive.NewObjectID()) - event.OrganizationRef = primitive.NewObjectID() + event.SetID(bson.NewObjectID()) + event.OrganizationRef = bson.NewObjectID() store := &recordingOutboxStore{ pending: []*model.OutboxEvent{event}, @@ -62,8 +62,8 @@ func TestOutboxPublisherDispatchFailureMarksAttempts(t *testing.T) { Payload: []byte(`{"journalEntryRef":"xyz789"}`), Attempts: maxOutboxDeliveryAttempts - 1, } - event.SetID(primitive.NewObjectID()) - event.OrganizationRef = primitive.NewObjectID() + event.SetID(bson.NewObjectID()) + event.OrganizationRef = bson.NewObjectID() store := &recordingOutboxStore{ pending: []*model.OutboxEvent{event}, @@ -89,9 +89,9 @@ type recordingOutboxStore struct { pending []*model.OutboxEvent - markedSent []primitive.ObjectID - markedFailed []primitive.ObjectID - incremented []primitive.ObjectID + markedSent []bson.ObjectID + markedFailed []bson.ObjectID + incremented []bson.ObjectID } func (s *recordingOutboxStore) Create(context.Context, *model.OutboxEvent) error { @@ -106,7 +106,7 @@ func (s *recordingOutboxStore) ListPending(context.Context, int) ([]*model.Outbo return events, nil } -func (s *recordingOutboxStore) MarkSent(_ context.Context, eventRef primitive.ObjectID, sentAt time.Time) error { +func (s *recordingOutboxStore) MarkSent(_ context.Context, eventRef bson.ObjectID, sentAt time.Time) error { _ = sentAt s.mu.Lock() defer s.mu.Unlock() @@ -114,14 +114,14 @@ func (s *recordingOutboxStore) MarkSent(_ context.Context, eventRef primitive.Ob return nil } -func (s *recordingOutboxStore) MarkFailed(_ context.Context, eventRef primitive.ObjectID) error { +func (s *recordingOutboxStore) MarkFailed(_ context.Context, eventRef bson.ObjectID) error { s.mu.Lock() defer s.mu.Unlock() s.markedFailed = append(s.markedFailed, eventRef) return nil } -func (s *recordingOutboxStore) IncrementAttempts(_ context.Context, eventRef primitive.ObjectID) error { +func (s *recordingOutboxStore) IncrementAttempts(_ context.Context, eventRef bson.ObjectID) error { s.mu.Lock() defer s.mu.Unlock() s.incremented = append(s.incremented, eventRef) diff --git a/api/ledger/internal/service/ledger/posting.go b/api/ledger/internal/service/ledger/posting.go index dca3276d..e8a222cd 100644 --- a/api/ledger/internal/service/ledger/posting.go +++ b/api/ledger/internal/service/ledger/posting.go @@ -13,7 +13,7 @@ import ( pmodel "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -89,7 +89,7 @@ func (s *Service) postCreditResponder(_ context.Context, req *ledgerv1.PostCredi return nil, err } - accountsByRef := map[primitive.ObjectID]*pmodel.LedgerAccount{accountRef: account} + accountsByRef := map[bson.ObjectID]*pmodel.LedgerAccount{accountRef: account} eventTime := getEventTime(req.EventTime) creditAmount, _ := parseDecimal(req.Money.Amount) @@ -109,7 +109,7 @@ func (s *Service) postCreditResponder(_ context.Context, req *ledgerv1.PostCredi postingLines := make([]*model.PostingLine, 0, 2+len(charges)) mainLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: accountRef, Amount: creditAmount.String(), Currency: req.Money.Currency, @@ -146,7 +146,7 @@ func (s *Service) postCreditResponder(_ context.Context, req *ledgerv1.PostCredi entryTotal = entryTotal.Add(chargeAmount) chargeLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: chargeAccountRef, Amount: chargeAmount.String(), Currency: charge.Money.Currency, @@ -170,7 +170,7 @@ func (s *Service) postCreditResponder(_ context.Context, req *ledgerv1.PostCredi contraAmount := entryTotal.Neg() if !contraAmount.IsZero() || len(postingLines) == 1 { contraLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: *contraAccountID, Amount: contraAmount.String(), Currency: req.Money.Currency, diff --git a/api/ledger/internal/service/ledger/posting_debit.go b/api/ledger/internal/service/ledger/posting_debit.go index a2572fc5..bd684642 100644 --- a/api/ledger/internal/service/ledger/posting_debit.go +++ b/api/ledger/internal/service/ledger/posting_debit.go @@ -13,7 +13,7 @@ import ( pmodel "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -86,7 +86,7 @@ func (s *Service) postDebitResponder(_ context.Context, req *ledgerv1.PostDebitR return nil, err } - accountsByRef := map[primitive.ObjectID]*pmodel.LedgerAccount{accountRef: account} + accountsByRef := map[bson.ObjectID]*pmodel.LedgerAccount{accountRef: account} eventTime := getEventTime(req.EventTime) debitAmount, _ := parseDecimal(req.Money.Amount) @@ -106,7 +106,7 @@ func (s *Service) postDebitResponder(_ context.Context, req *ledgerv1.PostDebitR postingLines := make([]*model.PostingLine, 0, 2+len(charges)) mainLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: accountRef, Amount: debitAmount.Neg().String(), Currency: req.Money.Currency, @@ -143,7 +143,7 @@ func (s *Service) postDebitResponder(_ context.Context, req *ledgerv1.PostDebitR entryTotal = entryTotal.Add(chargeAmount) chargeLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: chargeAccountRef, Amount: chargeAmount.String(), Currency: charge.Money.Currency, @@ -167,7 +167,7 @@ func (s *Service) postDebitResponder(_ context.Context, req *ledgerv1.PostDebitR contraAmount := entryTotal.Neg() if !contraAmount.IsZero() || len(postingLines) == 1 { contraLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: *contraAccountID, Amount: contraAmount.String(), Currency: req.Money.Currency, diff --git a/api/ledger/internal/service/ledger/posting_external.go b/api/ledger/internal/service/ledger/posting_external.go index 90f54b2f..acec8147 100644 --- a/api/ledger/internal/service/ledger/posting_external.go +++ b/api/ledger/internal/service/ledger/posting_external.go @@ -13,7 +13,7 @@ import ( pmodel "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -100,7 +100,7 @@ func (s *Service) postExternalCreditResponder(_ context.Context, req *ledgerv1.P return nil, merrors.Internal("system account missing identifier") } - accountsByRef := map[primitive.ObjectID]*pmodel.LedgerAccount{ + accountsByRef := map[bson.ObjectID]*pmodel.LedgerAccount{ accountRef: account, *systemAccountID: systemAccount, } @@ -123,7 +123,7 @@ func (s *Service) postExternalCreditResponder(_ context.Context, req *ledgerv1.P postingLines := make([]*model.PostingLine, 0, 2+len(charges)) mainLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: accountRef, Amount: creditAmount.String(), Currency: req.Money.Currency, @@ -160,7 +160,7 @@ func (s *Service) postExternalCreditResponder(_ context.Context, req *ledgerv1.P entryTotal = entryTotal.Add(chargeAmount) chargeLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: chargeAccountRef, Amount: chargeAmount.String(), Currency: charge.Money.Currency, @@ -173,7 +173,7 @@ func (s *Service) postExternalCreditResponder(_ context.Context, req *ledgerv1.P contraAmount := entryTotal.Neg() if !contraAmount.IsZero() || len(postingLines) == 1 { contraLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: *systemAccountID, Amount: contraAmount.String(), Currency: req.Money.Currency, @@ -333,7 +333,7 @@ func (s *Service) postExternalDebitResponder(_ context.Context, req *ledgerv1.Po return nil, merrors.Internal("system account missing identifier") } - accountsByRef := map[primitive.ObjectID]*pmodel.LedgerAccount{ + accountsByRef := map[bson.ObjectID]*pmodel.LedgerAccount{ accountRef: account, *systemAccountID: systemAccount, } @@ -356,7 +356,7 @@ func (s *Service) postExternalDebitResponder(_ context.Context, req *ledgerv1.Po postingLines := make([]*model.PostingLine, 0, 2+len(charges)) mainLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: accountRef, Amount: debitAmount.Neg().String(), Currency: req.Money.Currency, @@ -393,7 +393,7 @@ func (s *Service) postExternalDebitResponder(_ context.Context, req *ledgerv1.Po entryTotal = entryTotal.Add(chargeAmount) chargeLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: chargeAccountRef, Amount: chargeAmount.String(), Currency: charge.Money.Currency, @@ -406,7 +406,7 @@ func (s *Service) postExternalDebitResponder(_ context.Context, req *ledgerv1.Po contraAmount := entryTotal.Neg() if !contraAmount.IsZero() || len(postingLines) == 1 { contraLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: *systemAccountID, Amount: contraAmount.String(), Currency: req.Money.Currency, diff --git a/api/ledger/internal/service/ledger/posting_fx.go b/api/ledger/internal/service/ledger/posting_fx.go index 2f89c767..d967a8bc 100644 --- a/api/ledger/internal/service/ledger/posting_fx.go +++ b/api/ledger/internal/service/ledger/posting_fx.go @@ -12,7 +12,7 @@ import ( pmodel "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -115,7 +115,7 @@ func (s *Service) fxResponder(_ context.Context, req *ledgerv1.FXRequest) gsresp return nil, merrors.InvalidArgument(fmt.Sprintf("to_account: %s", err.Error())) } - accountsByRef := map[primitive.ObjectID]*pmodel.LedgerAccount{ + accountsByRef := map[bson.ObjectID]*pmodel.LedgerAccount{ fromAccountRef: fromAccount, toAccountRef: toAccount, } @@ -131,7 +131,7 @@ func (s *Service) fxResponder(_ context.Context, req *ledgerv1.FXRequest) gsresp // Debit from account fromLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: fromAccountRef, Amount: fromAmount.Neg().String(), // negative = debit Currency: req.FromMoney.Currency, @@ -142,7 +142,7 @@ func (s *Service) fxResponder(_ context.Context, req *ledgerv1.FXRequest) gsresp // Credit to account toLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: toAccountRef, Amount: toAmount.String(), // positive = credit Currency: req.ToMoney.Currency, @@ -175,7 +175,7 @@ func (s *Service) fxResponder(_ context.Context, req *ledgerv1.FXRequest) gsresp } chargeLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: chargeAccountRef, Amount: chargeAmount.String(), Currency: charge.Money.Currency, diff --git a/api/ledger/internal/service/ledger/posting_support.go b/api/ledger/internal/service/ledger/posting_support.go index 534c1187..80c00869 100644 --- a/api/ledger/internal/service/ledger/posting_support.go +++ b/api/ledger/internal/service/ledger/posting_support.go @@ -13,7 +13,7 @@ import ( "github.com/tech/sendico/pkg/merrors" pmodel "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -47,23 +47,23 @@ func validateAccountRole(account *pmodel.LedgerAccount, expected pmodel.AccountR // If accountRefStr is non-empty, it fetches by ID and optionally asserts the role. // If accountRefStr is empty and role is set, it resolves via GetByRole(orgRef, currency, role). // Returns the account and its ObjectID, or an error. -func (s *Service) resolveAccount(ctx context.Context, accountRefStr string, role pmodel.AccountRole, orgRef primitive.ObjectID, currency, label string) (*pmodel.LedgerAccount, primitive.ObjectID, error) { +func (s *Service) resolveAccount(ctx context.Context, accountRefStr string, role pmodel.AccountRole, orgRef bson.ObjectID, currency, label string) (*pmodel.LedgerAccount, bson.ObjectID, error) { if accountRefStr != "" { ref, err := parseObjectID(accountRefStr) if err != nil { - return nil, primitive.NilObjectID, err + return nil, bson.NilObjectID, err } account, err := s.storage.Accounts().Get(ctx, ref) if err != nil { if errors.Is(err, storage.ErrAccountNotFound) { - return nil, primitive.NilObjectID, merrors.NoData(label + " not found") + return nil, bson.NilObjectID, merrors.NoData(label + " not found") } - return nil, primitive.NilObjectID, merrors.Internal("failed to get " + label) + return nil, bson.NilObjectID, merrors.Internal("failed to get " + label) } // If role is also specified, assert it matches if role != "" { if err := validateAccountRole(account, role, label); err != nil { - return nil, primitive.NilObjectID, err + return nil, bson.NilObjectID, err } } return account, ref, nil @@ -71,25 +71,25 @@ func (s *Service) resolveAccount(ctx context.Context, accountRefStr string, role // No ref provided — resolve by role if role == "" { - return nil, primitive.NilObjectID, merrors.InvalidArgument(label + ": ledger_account_ref or role is required") + return nil, bson.NilObjectID, merrors.InvalidArgument(label + ": ledger_account_ref or role is required") } if orgRef.IsZero() { - return nil, primitive.NilObjectID, merrors.InvalidArgument(label + ": organization_ref is required for role resolution") + return nil, bson.NilObjectID, merrors.InvalidArgument(label + ": organization_ref is required for role resolution") } if currency == "" { - return nil, primitive.NilObjectID, merrors.InvalidArgument(label + ": currency is required for role resolution") + return nil, bson.NilObjectID, merrors.InvalidArgument(label + ": currency is required for role resolution") } account, err := s.storage.Accounts().GetByRole(ctx, orgRef, currency, role) if err != nil { if errors.Is(err, storage.ErrAccountNotFound) { - return nil, primitive.NilObjectID, merrors.NoData(fmt.Sprintf("%s: no account found with role %s", label, role)) + return nil, bson.NilObjectID, merrors.NoData(fmt.Sprintf("%s: no account found with role %s", label, role)) } - return nil, primitive.NilObjectID, merrors.Internal("failed to resolve " + label + " by role") + return nil, bson.NilObjectID, merrors.Internal("failed to resolve " + label + " by role") } return account, *account.GetID(), nil } -func validateAccountForOrg(account *pmodel.LedgerAccount, orgRef primitive.ObjectID, currency string) error { +func validateAccountForOrg(account *pmodel.LedgerAccount, orgRef bson.ObjectID, currency string) error { if account == nil { return merrors.InvalidArgument("account is required") } @@ -111,7 +111,7 @@ func validateAccountForOrg(account *pmodel.LedgerAccount, orgRef primitive.Objec return nil } -func (s *Service) getAccount(ctx context.Context, cache map[primitive.ObjectID]*pmodel.LedgerAccount, accountRef primitive.ObjectID) (*pmodel.LedgerAccount, error) { +func (s *Service) getAccount(ctx context.Context, cache map[bson.ObjectID]*pmodel.LedgerAccount, accountRef bson.ObjectID) (*pmodel.LedgerAccount, error) { if accountRef.IsZero() { return nil, merrors.InvalidArgument("account reference is required") } @@ -127,7 +127,7 @@ func (s *Service) getAccount(ctx context.Context, cache map[primitive.ObjectID]* return account, nil } -func (s *Service) resolveSettlementAccount(ctx context.Context, orgRef primitive.ObjectID, currency, override string, cache map[primitive.ObjectID]*pmodel.LedgerAccount) (*pmodel.LedgerAccount, error) { +func (s *Service) resolveSettlementAccount(ctx context.Context, orgRef bson.ObjectID, currency, override string, cache map[bson.ObjectID]*pmodel.LedgerAccount) (*pmodel.LedgerAccount, error) { if override != "" { overrideRef, err := parseObjectID(override) if err != nil { @@ -172,12 +172,12 @@ func (s *Service) resolveSettlementAccount(ctx context.Context, orgRef primitive return account, nil } -func (s *Service) upsertBalances(ctx context.Context, lines []*model.PostingLine, accounts map[primitive.ObjectID]*pmodel.LedgerAccount) error { +func (s *Service) upsertBalances(ctx context.Context, lines []*model.PostingLine, accounts map[bson.ObjectID]*pmodel.LedgerAccount) error { if len(lines) == 0 { return nil } - balanceDeltas := make(map[primitive.ObjectID]decimal.Decimal, len(lines)) + balanceDeltas := make(map[bson.ObjectID]decimal.Decimal, len(lines)) for _, line := range lines { delta, err := parseDecimal(line.Amount) if err != nil { @@ -233,7 +233,7 @@ func (s *Service) upsertBalances(ctx context.Context, lines []*model.PostingLine if account.OrganizationRef != nil { newBalance.OrganizationRef = *account.OrganizationRef } else { - newBalance.OrganizationRef = primitive.NilObjectID + newBalance.OrganizationRef = bson.NilObjectID } if err := balancesStore.Upsert(ctx, newBalance); err != nil { diff --git a/api/ledger/internal/service/ledger/posting_support_test.go b/api/ledger/internal/service/ledger/posting_support_test.go index 019d6e3d..59ba519f 100644 --- a/api/ledger/internal/service/ledger/posting_support_test.go +++ b/api/ledger/internal/service/ledger/posting_support_test.go @@ -13,7 +13,7 @@ import ( "github.com/tech/sendico/ledger/storage/model" "github.com/tech/sendico/pkg/merrors" pmodel "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -31,7 +31,7 @@ func (s *stubRepository) Balances() storage.BalancesStore { return s func (s *stubRepository) Outbox() storage.OutboxStore { return s.outbox } type stubAccountsStore struct { - getByID map[primitive.ObjectID]*pmodel.LedgerAccount + getByID map[bson.ObjectID]*pmodel.LedgerAccount defaultSettlement *pmodel.LedgerAccount getErr error defaultErr error @@ -40,7 +40,7 @@ type stubAccountsStore struct { func (s *stubAccountsStore) Create(context.Context, *pmodel.LedgerAccount) error { return merrors.NotImplemented("create") } -func (s *stubAccountsStore) Get(ctx context.Context, accountRef primitive.ObjectID) (*pmodel.LedgerAccount, error) { +func (s *stubAccountsStore) Get(ctx context.Context, accountRef bson.ObjectID) (*pmodel.LedgerAccount, error) { if s.getErr != nil { return nil, s.getErr } @@ -49,16 +49,16 @@ func (s *stubAccountsStore) Get(ctx context.Context, accountRef primitive.Object } return nil, storage.ErrAccountNotFound } -func (s *stubAccountsStore) GetByAccountCode(context.Context, primitive.ObjectID, string, string) (*pmodel.LedgerAccount, error) { +func (s *stubAccountsStore) GetByAccountCode(context.Context, bson.ObjectID, string, string) (*pmodel.LedgerAccount, error) { return nil, merrors.NotImplemented("get by code") } -func (s *stubAccountsStore) GetByRole(context.Context, primitive.ObjectID, string, pmodel.AccountRole) (*pmodel.LedgerAccount, error) { +func (s *stubAccountsStore) GetByRole(context.Context, bson.ObjectID, string, pmodel.AccountRole) (*pmodel.LedgerAccount, error) { return nil, merrors.NotImplemented("get by role") } func (s *stubAccountsStore) GetSystemAccount(context.Context, pmodel.SystemAccountPurpose, string) (*pmodel.LedgerAccount, error) { return nil, merrors.NotImplemented("get system account") } -func (s *stubAccountsStore) GetDefaultSettlement(context.Context, primitive.ObjectID, string) (*pmodel.LedgerAccount, error) { +func (s *stubAccountsStore) GetDefaultSettlement(context.Context, bson.ObjectID, string) (*pmodel.LedgerAccount, error) { if s.defaultErr != nil { return nil, s.defaultErr } @@ -67,21 +67,21 @@ func (s *stubAccountsStore) GetDefaultSettlement(context.Context, primitive.Obje } return s.defaultSettlement, nil } -func (s *stubAccountsStore) ListByOrganization(context.Context, primitive.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) { +func (s *stubAccountsStore) ListByOrganization(context.Context, bson.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) { return nil, merrors.NotImplemented("list") } -func (s *stubAccountsStore) UpdateStatus(context.Context, primitive.ObjectID, pmodel.LedgerAccountStatus) error { +func (s *stubAccountsStore) UpdateStatus(context.Context, bson.ObjectID, pmodel.LedgerAccountStatus) error { return merrors.NotImplemented("update status") } type stubBalancesStore struct { - records map[primitive.ObjectID]*model.AccountBalance + records map[bson.ObjectID]*model.AccountBalance upserts []*model.AccountBalance getErr error upErr error } -func (s *stubBalancesStore) Get(ctx context.Context, accountRef primitive.ObjectID) (*model.AccountBalance, error) { +func (s *stubBalancesStore) Get(ctx context.Context, accountRef bson.ObjectID) (*model.AccountBalance, error) { if s.getErr != nil { return nil, s.getErr } @@ -98,13 +98,13 @@ func (s *stubBalancesStore) Upsert(ctx context.Context, balance *model.AccountBa copied := *balance s.upserts = append(s.upserts, &copied) if s.records == nil { - s.records = make(map[primitive.ObjectID]*model.AccountBalance) + s.records = make(map[bson.ObjectID]*model.AccountBalance) } s.records[balance.AccountRef] = &copied return nil } -func (s *stubBalancesStore) IncrementBalance(context.Context, primitive.ObjectID, string) error { +func (s *stubBalancesStore) IncrementBalance(context.Context, bson.ObjectID, string) error { return merrors.NotImplemented("increment") } @@ -126,22 +126,22 @@ func (s *stubOutboxStore) ListPending(context.Context, int) ([]*model.OutboxEven return nil, merrors.NotImplemented("list") } -func (s *stubOutboxStore) MarkSent(context.Context, primitive.ObjectID, time.Time) error { +func (s *stubOutboxStore) MarkSent(context.Context, bson.ObjectID, time.Time) error { return merrors.NotImplemented("mark sent") } -func (s *stubOutboxStore) MarkFailed(context.Context, primitive.ObjectID) error { +func (s *stubOutboxStore) MarkFailed(context.Context, bson.ObjectID) error { return merrors.NotImplemented("mark failed") } -func (s *stubOutboxStore) IncrementAttempts(context.Context, primitive.ObjectID) error { +func (s *stubOutboxStore) IncrementAttempts(context.Context, bson.ObjectID) error { return merrors.NotImplemented("increment attempts") } func TestResolveSettlementAccount_Default(t *testing.T) { ctx := context.Background() - orgRef := primitive.NewObjectID() - settlementID := primitive.NewObjectID() + orgRef := bson.NewObjectID() + settlementID := bson.NewObjectID() settlement := &pmodel.LedgerAccount{} settlement.SetID(settlementID) settlement.OrganizationRef = &orgRef @@ -151,7 +151,7 @@ func TestResolveSettlementAccount_Default(t *testing.T) { accounts := &stubAccountsStore{defaultSettlement: settlement} repo := &stubRepository{accounts: accounts} service := &Service{logger: zap.NewNop(), storage: repo} - cache := make(map[primitive.ObjectID]*pmodel.LedgerAccount) + cache := make(map[bson.ObjectID]*pmodel.LedgerAccount) result, err := service.resolveSettlementAccount(ctx, orgRef, "USD", "", cache) @@ -162,18 +162,18 @@ func TestResolveSettlementAccount_Default(t *testing.T) { func TestResolveSettlementAccount_Override(t *testing.T) { ctx := context.Background() - orgRef := primitive.NewObjectID() - overrideID := primitive.NewObjectID() + orgRef := bson.NewObjectID() + overrideID := bson.NewObjectID() override := &pmodel.LedgerAccount{} override.SetID(overrideID) override.OrganizationRef = &orgRef override.Currency = "EUR" override.Status = pmodel.LedgerAccountStatusActive - accounts := &stubAccountsStore{getByID: map[primitive.ObjectID]*pmodel.LedgerAccount{overrideID: override}} + accounts := &stubAccountsStore{getByID: map[bson.ObjectID]*pmodel.LedgerAccount{overrideID: override}} repo := &stubRepository{accounts: accounts} service := &Service{logger: zap.NewNop(), storage: repo} - cache := make(map[primitive.ObjectID]*pmodel.LedgerAccount) + cache := make(map[bson.ObjectID]*pmodel.LedgerAccount) result, err := service.resolveSettlementAccount(ctx, orgRef, "EUR", overrideID.Hex(), cache) @@ -184,12 +184,12 @@ func TestResolveSettlementAccount_Override(t *testing.T) { func TestResolveSettlementAccount_NoDefault(t *testing.T) { ctx := context.Background() - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() accounts := &stubAccountsStore{defaultErr: storage.ErrAccountNotFound} repo := &stubRepository{accounts: accounts} service := &Service{logger: zap.NewNop(), storage: repo} - _, err := service.resolveSettlementAccount(ctx, orgRef, "USD", "", map[primitive.ObjectID]*pmodel.LedgerAccount{}) + _, err := service.resolveSettlementAccount(ctx, orgRef, "USD", "", map[bson.ObjectID]*pmodel.LedgerAccount{}) require.Error(t, err) assert.True(t, errors.Is(err, merrors.ErrInvalidArg)) @@ -197,8 +197,8 @@ func TestResolveSettlementAccount_NoDefault(t *testing.T) { func TestUpsertBalances_Succeeds(t *testing.T) { ctx := context.Background() - orgRef := primitive.NewObjectID() - accountRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() + accountRef := bson.NewObjectID() account := &pmodel.LedgerAccount{AllowNegative: false, Currency: "USD"} account.OrganizationRef = &orgRef @@ -213,7 +213,7 @@ func TestUpsertBalances_Succeeds(t *testing.T) { balances := &stubBalancesStore{} repo := &stubRepository{balances: balances} service := &Service{logger: zap.NewNop(), storage: repo} - accountCache := map[primitive.ObjectID]*pmodel.LedgerAccount{accountRef: account} + accountCache := map[bson.ObjectID]*pmodel.LedgerAccount{accountRef: account} require.NoError(t, service.upsertBalances(ctx, balanceLines, accountCache)) require.Len(t, balances.upserts, 1) @@ -224,8 +224,8 @@ func TestUpsertBalances_Succeeds(t *testing.T) { func TestUpsertBalances_DisallowNegative(t *testing.T) { ctx := context.Background() - orgRef := primitive.NewObjectID() - accountRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() + accountRef := bson.NewObjectID() account := &pmodel.LedgerAccount{AllowNegative: false, Currency: "USD"} account.OrganizationRef = &orgRef @@ -240,7 +240,7 @@ func TestUpsertBalances_DisallowNegative(t *testing.T) { balances := &stubBalancesStore{} repo := &stubRepository{balances: balances} service := &Service{logger: zap.NewNop(), storage: repo} - accountCache := map[primitive.ObjectID]*pmodel.LedgerAccount{accountRef: account} + accountCache := map[bson.ObjectID]*pmodel.LedgerAccount{accountRef: account} err := service.upsertBalances(ctx, balanceLines, accountCache) @@ -250,8 +250,8 @@ func TestUpsertBalances_DisallowNegative(t *testing.T) { func TestEnqueueOutbox_CreatesEvent(t *testing.T) { ctx := context.Background() - orgRef := primitive.NewObjectID() - entryID := primitive.NewObjectID() + orgRef := bson.NewObjectID() + entryID := bson.NewObjectID() entry := &model.JournalEntry{ IdempotencyKey: "idem", EventTime: time.Now().UTC(), @@ -263,7 +263,7 @@ func TestEnqueueOutbox_CreatesEvent(t *testing.T) { lines := []*model.PostingLine{ { - AccountRef: primitive.NewObjectID(), + AccountRef: bson.NewObjectID(), Amount: "100", Currency: "USD", LineType: model.LineTypeMain, diff --git a/api/ledger/internal/service/ledger/posting_transfer.go b/api/ledger/internal/service/ledger/posting_transfer.go index 40581112..4c5bfacd 100644 --- a/api/ledger/internal/service/ledger/posting_transfer.go +++ b/api/ledger/internal/service/ledger/posting_transfer.go @@ -13,7 +13,7 @@ import ( pmodel "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -121,7 +121,7 @@ func (s *Service) transferResponder(_ context.Context, req *ledgerv1.TransferReq return nil, merrors.InvalidArgument("cannot transfer to same account") } - accountsByRef := map[primitive.ObjectID]*pmodel.LedgerAccount{ + accountsByRef := map[bson.ObjectID]*pmodel.LedgerAccount{ fromAccountRef: fromAccount, toAccountRef: toAccount, } @@ -136,7 +136,7 @@ func (s *Service) transferResponder(_ context.Context, req *ledgerv1.TransferReq // Debit from account fromLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: fromAccountRef, Amount: transferAmount.Neg().String(), // negative = debit Currency: req.Money.Currency, @@ -147,7 +147,7 @@ func (s *Service) transferResponder(_ context.Context, req *ledgerv1.TransferReq // Credit to account toLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: toAccountRef, Amount: transferAmount.String(), // positive = credit Currency: req.Money.Currency, @@ -184,7 +184,7 @@ func (s *Service) transferResponder(_ context.Context, req *ledgerv1.TransferReq } chargeLine := &model.PostingLine{ - JournalEntryRef: primitive.NilObjectID, + JournalEntryRef: bson.NilObjectID, AccountRef: chargeAccountRef, Amount: chargeAmount.String(), Currency: charge.Money.Currency, diff --git a/api/ledger/internal/service/ledger/system_accounts.go b/api/ledger/internal/service/ledger/system_accounts.go index ab9efdf9..15cdaabe 100644 --- a/api/ledger/internal/service/ledger/system_accounts.go +++ b/api/ledger/internal/service/ledger/system_accounts.go @@ -8,7 +8,7 @@ import ( "github.com/tech/sendico/ledger/storage" "github.com/tech/sendico/pkg/merrors" pmodel "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // EnsureSystemAccounts initializes required system accounts once at startup. @@ -128,7 +128,7 @@ func (s *Service) cacheSystemAccount(purpose pmodel.SystemAccountPurpose, curren } func newExternalSystemAccount(purpose pmodel.SystemAccountPurpose, currency string) *pmodel.LedgerAccount { - ref := primitive.NewObjectID() + ref := bson.NewObjectID() purposeCopy := purpose account := &pmodel.LedgerAccount{ AccountCode: generateAccountCode(pmodel.LedgerAccountTypeAsset, currency, ref), diff --git a/api/ledger/internal/service/ledger/system_accounts_test.go b/api/ledger/internal/service/ledger/system_accounts_test.go index 4439c42a..dbe4234d 100644 --- a/api/ledger/internal/service/ledger/system_accounts_test.go +++ b/api/ledger/internal/service/ledger/system_accounts_test.go @@ -8,7 +8,7 @@ import ( "github.com/tech/sendico/ledger/storage" "github.com/tech/sendico/pkg/merrors" pmodel "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -19,7 +19,7 @@ type systemAccountsStoreStub struct { func (s *systemAccountsStoreStub) Create(_ context.Context, account *pmodel.LedgerAccount) error { if account.GetID() == nil || account.GetID().IsZero() { - account.SetID(primitive.NewObjectID()) + account.SetID(bson.NewObjectID()) } s.created = append(s.created, account) if s.existing == nil { @@ -32,15 +32,15 @@ func (s *systemAccountsStoreStub) Create(_ context.Context, account *pmodel.Ledg return nil } -func (s *systemAccountsStoreStub) Get(context.Context, primitive.ObjectID) (*pmodel.LedgerAccount, error) { +func (s *systemAccountsStoreStub) Get(context.Context, bson.ObjectID) (*pmodel.LedgerAccount, error) { return nil, storage.ErrAccountNotFound } -func (s *systemAccountsStoreStub) GetByAccountCode(context.Context, primitive.ObjectID, string, string) (*pmodel.LedgerAccount, error) { +func (s *systemAccountsStoreStub) GetByAccountCode(context.Context, bson.ObjectID, string, string) (*pmodel.LedgerAccount, error) { return nil, merrors.NotImplemented("get by code") } -func (s *systemAccountsStoreStub) GetByRole(context.Context, primitive.ObjectID, string, pmodel.AccountRole) (*pmodel.LedgerAccount, error) { +func (s *systemAccountsStoreStub) GetByRole(context.Context, bson.ObjectID, string, pmodel.AccountRole) (*pmodel.LedgerAccount, error) { return nil, merrors.NotImplemented("get by role") } @@ -55,15 +55,15 @@ func (s *systemAccountsStoreStub) GetSystemAccount(_ context.Context, purpose pm return nil, storage.ErrAccountNotFound } -func (s *systemAccountsStoreStub) GetDefaultSettlement(context.Context, primitive.ObjectID, string) (*pmodel.LedgerAccount, error) { +func (s *systemAccountsStoreStub) GetDefaultSettlement(context.Context, bson.ObjectID, string) (*pmodel.LedgerAccount, error) { return nil, merrors.NotImplemented("get default settlement") } -func (s *systemAccountsStoreStub) ListByOrganization(context.Context, primitive.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) { +func (s *systemAccountsStoreStub) ListByOrganization(context.Context, bson.ObjectID, *storage.AccountsFilter, int, int) ([]*pmodel.LedgerAccount, error) { return nil, merrors.NotImplemented("list") } -func (s *systemAccountsStoreStub) UpdateStatus(context.Context, primitive.ObjectID, pmodel.LedgerAccountStatus) error { +func (s *systemAccountsStoreStub) UpdateStatus(context.Context, bson.ObjectID, pmodel.LedgerAccountStatus) error { return merrors.NotImplemented("update status") } diff --git a/api/ledger/internal/service/ledger/topology.go b/api/ledger/internal/service/ledger/topology.go index 090bfcbe..53fbc5e7 100644 --- a/api/ledger/internal/service/ledger/topology.go +++ b/api/ledger/internal/service/ledger/topology.go @@ -9,7 +9,7 @@ import ( "github.com/tech/sendico/pkg/merrors" pmodel "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -32,7 +32,7 @@ func isRequiredTopologyRole(role pmodel.AccountRole) bool { return false } -func (s *Service) ensureLedgerTopology(ctx context.Context, orgRef primitive.ObjectID, currency string) error { +func (s *Service) ensureLedgerTopology(ctx context.Context, orgRef bson.ObjectID, currency string) error { if s.storage == nil || s.storage.Accounts() == nil { return errStorageNotInitialized } @@ -52,7 +52,7 @@ func (s *Service) ensureLedgerTopology(ctx context.Context, orgRef primitive.Obj return nil } -func (s *Service) ensureRoleAccount(ctx context.Context, orgRef primitive.ObjectID, currency string, role pmodel.AccountRole) (*pmodel.LedgerAccount, error) { +func (s *Service) ensureRoleAccount(ctx context.Context, orgRef bson.ObjectID, currency string, role pmodel.AccountRole) (*pmodel.LedgerAccount, error) { if s.storage == nil || s.storage.Accounts() == nil { return nil, errStorageNotInitialized } @@ -104,8 +104,8 @@ func (s *Service) ensureRoleAccount(ctx context.Context, orgRef primitive.Object return account, nil } -func newSystemAccount(orgRef primitive.ObjectID, currency string, role pmodel.AccountRole) *pmodel.LedgerAccount { - ref := primitive.NewObjectID() +func newSystemAccount(orgRef bson.ObjectID, currency string, role pmodel.AccountRole) *pmodel.LedgerAccount { + ref := bson.NewObjectID() account := &pmodel.LedgerAccount{ AccountCode: generateAccountCode(pmodel.LedgerAccountTypeAsset, currency, ref), AccountType: pmodel.LedgerAccountTypeAsset, diff --git a/api/ledger/storage/model/account_balance.go b/api/ledger/storage/model/account_balance.go index a1032b84..1dd145ab 100644 --- a/api/ledger/storage/model/account_balance.go +++ b/api/ledger/storage/model/account_balance.go @@ -5,7 +5,7 @@ import ( "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // AccountBalance represents the current balance of a ledger account. @@ -14,11 +14,11 @@ type AccountBalance struct { storable.Base `bson:",inline" json:",inline"` model.OrganizationBoundBase `bson:",inline" json:",inline"` - AccountRef primitive.ObjectID `bson:"accountRef" json:"accountRef"` // unique per account+currency - Balance string `bson:"balance" json:"balance"` // stored as string for exact decimal - Currency string `bson:"currency" json:"currency"` // ISO 4217 currency code - Version int64 `bson:"version" json:"version"` // for optimistic locking - LastUpdated time.Time `bson:"lastUpdated" json:"lastUpdated"` // timestamp of last balance update + AccountRef bson.ObjectID `bson:"accountRef" json:"accountRef"` // unique per account+currency + Balance string `bson:"balance" json:"balance"` // stored as string for exact decimal + Currency string `bson:"currency" json:"currency"` // ISO 4217 currency code + Version int64 `bson:"version" json:"version"` // for optimistic locking + LastUpdated time.Time `bson:"lastUpdated" json:"lastUpdated"` // timestamp of last balance update } // Collection implements storable.Storable. diff --git a/api/ledger/storage/model/posting_line.go b/api/ledger/storage/model/posting_line.go index 6427944a..74461cab 100644 --- a/api/ledger/storage/model/posting_line.go +++ b/api/ledger/storage/model/posting_line.go @@ -3,7 +3,7 @@ package model import ( "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // PostingLine represents a single debit or credit line in a journal entry. @@ -11,11 +11,11 @@ type PostingLine struct { storable.Base `bson:",inline" json:",inline"` model.OrganizationBoundBase `bson:",inline" json:",inline"` - JournalEntryRef primitive.ObjectID `bson:"journalEntryRef" json:"journalEntryRef"` - AccountRef primitive.ObjectID `bson:"accountRef" json:"accountRef"` - Amount string `bson:"amount" json:"amount"` // stored as string for exact decimal, positive = credit, negative = debit - Currency string `bson:"currency" json:"currency"` // ISO 4217 currency code - LineType LineType `bson:"lineType" json:"lineType"` // main, fee, spread, reversal + JournalEntryRef bson.ObjectID `bson:"journalEntryRef" json:"journalEntryRef"` + AccountRef bson.ObjectID `bson:"accountRef" json:"accountRef"` + Amount string `bson:"amount" json:"amount"` // stored as string for exact decimal, positive = credit, negative = debit + Currency string `bson:"currency" json:"currency"` // ISO 4217 currency code + LineType LineType `bson:"lineType" json:"lineType"` // main, fee, spread, reversal } // Collection implements storable.Storable. diff --git a/api/ledger/storage/mongo/repository.go b/api/ledger/storage/mongo/repository.go index 1ebee73e..c928bdb0 100644 --- a/api/ledger/storage/mongo/repository.go +++ b/api/ledger/storage/mongo/repository.go @@ -10,7 +10,7 @@ import ( "github.com/tech/sendico/pkg/db/transaction" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/ledger/storage/mongo/store/accounts.go b/api/ledger/storage/mongo/store/accounts.go index 2f3ea04c..1aa823f3 100644 --- a/api/ledger/storage/mongo/store/accounts.go +++ b/api/ledger/storage/mongo/store/accounts.go @@ -13,8 +13,8 @@ import ( pkm "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -114,7 +114,7 @@ func (a *accountsStore) Create(ctx context.Context, account *pkm.LedgerAccount) return nil } -func (a *accountsStore) Get(ctx context.Context, accountRef primitive.ObjectID) (*pkm.LedgerAccount, error) { +func (a *accountsStore) Get(ctx context.Context, accountRef bson.ObjectID) (*pkm.LedgerAccount, error) { if accountRef.IsZero() { a.logger.Warn("Attempt to get account with zero ID") return nil, merrors.InvalidArgument("accountsStore: zero account ID") @@ -134,7 +134,7 @@ func (a *accountsStore) Get(ctx context.Context, accountRef primitive.ObjectID) return result, nil } -func (a *accountsStore) GetByAccountCode(ctx context.Context, orgRef primitive.ObjectID, accountCode, currency string) (*pkm.LedgerAccount, error) { +func (a *accountsStore) GetByAccountCode(ctx context.Context, orgRef bson.ObjectID, accountCode, currency string) (*pkm.LedgerAccount, error) { if orgRef.IsZero() { a.logger.Warn("Attempt to get account with zero organization ID") return nil, merrors.InvalidArgument("accountsStore: zero organization ID") @@ -167,7 +167,7 @@ func (a *accountsStore) GetByAccountCode(ctx context.Context, orgRef primitive.O return result, nil } -func (a *accountsStore) GetByRole(ctx context.Context, orgRef primitive.ObjectID, currency string, role pkm.AccountRole) (*pkm.LedgerAccount, error) { +func (a *accountsStore) GetByRole(ctx context.Context, orgRef bson.ObjectID, currency string, role pkm.AccountRole) (*pkm.LedgerAccount, error) { if orgRef.IsZero() { a.logger.Warn("Attempt to get account with zero organization ID") return nil, merrors.InvalidArgument("accountsStore: zero organization ID") @@ -240,7 +240,7 @@ func (a *accountsStore) GetSystemAccount(ctx context.Context, purpose pkm.System return result, nil } -func (a *accountsStore) GetDefaultSettlement(ctx context.Context, orgRef primitive.ObjectID, currency string) (*pkm.LedgerAccount, error) { +func (a *accountsStore) GetDefaultSettlement(ctx context.Context, orgRef bson.ObjectID, currency string) (*pkm.LedgerAccount, error) { if orgRef.IsZero() { a.logger.Warn("Attempt to get default settlement with zero organization ID") return nil, merrors.InvalidArgument("accountsStore: zero organization ID") @@ -275,7 +275,7 @@ func (a *accountsStore) GetDefaultSettlement(ctx context.Context, orgRef primiti return result, nil } -func (a *accountsStore) ListByOrganization(ctx context.Context, orgRef primitive.ObjectID, filter *storage.AccountsFilter, limit int, offset int) ([]*pkm.LedgerAccount, error) { +func (a *accountsStore) ListByOrganization(ctx context.Context, orgRef bson.ObjectID, filter *storage.AccountsFilter, limit int, offset int) ([]*pkm.LedgerAccount, error) { if orgRef.IsZero() { a.logger.Warn("Attempt to list accounts with zero organization reference") return nil, merrors.InvalidArgument("accountsStore: zero organization reference") @@ -316,7 +316,7 @@ func (a *accountsStore) ListByOrganization(ctx context.Context, orgRef primitive return accounts, nil } -func (a *accountsStore) UpdateStatus(ctx context.Context, accountRef primitive.ObjectID, status pkm.LedgerAccountStatus) error { +func (a *accountsStore) UpdateStatus(ctx context.Context, accountRef bson.ObjectID, status pkm.LedgerAccountStatus) error { if accountRef.IsZero() { a.logger.Warn("Attempt to update account status with zero reference") return merrors.InvalidArgument("accountsStore: zero account reference") diff --git a/api/ledger/storage/mongo/store/accounts_test.go b/api/ledger/storage/mongo/store/accounts_test.go index 97db8df4..1e77917c 100644 --- a/api/ledger/storage/mongo/store/accounts_test.go +++ b/api/ledger/storage/mongo/store/accounts_test.go @@ -14,8 +14,8 @@ import ( "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/merrors" pkm "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -105,9 +105,9 @@ func TestAccountsStore_Get(t *testing.T) { logger := zap.NewNop() t.Run("Success", func(t *testing.T) { - accountRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() stub := &repositoryStub{ - GetFunc: func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error { + GetFunc: func(ctx context.Context, id bson.ObjectID, result storable.Storable) error { account := result.(*pkm.LedgerAccount) account.SetID(accountRef) account.AccountCode = "1000" @@ -129,7 +129,7 @@ func TestAccountsStore_Get(t *testing.T) { stub := &repositoryStub{} store := &accountsStore{logger: logger, repo: stub} - result, err := store.Get(ctx, primitive.NilObjectID) + result, err := store.Get(ctx, bson.NilObjectID) require.Error(t, err) assert.Nil(t, result) @@ -137,9 +137,9 @@ func TestAccountsStore_Get(t *testing.T) { }) t.Run("NotFound", func(t *testing.T) { - accountRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() stub := &repositoryStub{ - GetFunc: func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error { + GetFunc: func(ctx context.Context, id bson.ObjectID, result storable.Storable) error { return merrors.ErrNoData }, } @@ -153,10 +153,10 @@ func TestAccountsStore_Get(t *testing.T) { }) t.Run("GetError", func(t *testing.T) { - accountRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() expectedErr := errors.New("database error") stub := &repositoryStub{ - GetFunc: func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error { + GetFunc: func(ctx context.Context, id bson.ObjectID, result storable.Storable) error { return expectedErr }, } @@ -173,7 +173,7 @@ func TestAccountsStore_Get(t *testing.T) { func TestAccountsStore_GetByAccountCode(t *testing.T) { ctx := context.Background() logger := zap.NewNop() - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() t.Run("Success", func(t *testing.T) { stub := &repositoryStub{ @@ -198,7 +198,7 @@ func TestAccountsStore_GetByAccountCode(t *testing.T) { stub := &repositoryStub{} store := &accountsStore{logger: logger, repo: stub} - result, err := store.GetByAccountCode(ctx, primitive.NilObjectID, "1000", "USD") + result, err := store.GetByAccountCode(ctx, bson.NilObjectID, "1000", "USD") require.Error(t, err) assert.Nil(t, result) @@ -246,7 +246,7 @@ func TestAccountsStore_GetByAccountCode(t *testing.T) { func TestAccountsStore_GetByRole(t *testing.T) { ctx := context.Background() logger := zap.NewNop() - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() t.Run("Success", func(t *testing.T) { stub := &repositoryStub{ @@ -269,7 +269,7 @@ func TestAccountsStore_GetByRole(t *testing.T) { t.Run("ZeroOrganizationID", func(t *testing.T) { store := &accountsStore{logger: logger, repo: &repositoryStub{}} - result, err := store.GetByRole(ctx, primitive.NilObjectID, "USD", pkm.AccountRoleOperating) + result, err := store.GetByRole(ctx, bson.NilObjectID, "USD", pkm.AccountRoleOperating) require.Error(t, err) assert.Nil(t, result) @@ -329,13 +329,13 @@ func TestAccountsStore_GetByRole(t *testing.T) { func TestAccountsStore_GetDefaultSettlement(t *testing.T) { ctx := context.Background() logger := zap.NewNop() - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() t.Run("Success", func(t *testing.T) { stub := &repositoryStub{ FindOneByFilterFunc: func(ctx context.Context, _ builder.Query, result storable.Storable) error { account := result.(*pkm.LedgerAccount) - account.SetID(primitive.NewObjectID()) + account.SetID(bson.NewObjectID()) account.Currency = "USD" account.Role = pkm.AccountRoleSettlement return nil @@ -353,7 +353,7 @@ func TestAccountsStore_GetDefaultSettlement(t *testing.T) { t.Run("ZeroOrganizationID", func(t *testing.T) { store := &accountsStore{logger: logger, repo: &repositoryStub{}} - result, err := store.GetDefaultSettlement(ctx, primitive.NilObjectID, "USD") + result, err := store.GetDefaultSettlement(ctx, bson.NilObjectID, "USD") require.Error(t, err) assert.Nil(t, result) @@ -481,7 +481,7 @@ func TestAccountsStore_GetSystemAccount(t *testing.T) { func TestAccountsStore_ListByOrganization(t *testing.T) { ctx := context.Background() logger := zap.NewNop() - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() t.Run("Success", func(t *testing.T) { var calledWithQuery bool @@ -506,7 +506,7 @@ func TestAccountsStore_ListByOrganization(t *testing.T) { stub := &repositoryStub{} store := &accountsStore{logger: logger, repo: stub} - results, err := store.ListByOrganization(ctx, primitive.NilObjectID, nil, 10, 0) + results, err := store.ListByOrganization(ctx, bson.NilObjectID, nil, 10, 0) require.Error(t, err) assert.Nil(t, results) @@ -547,13 +547,13 @@ func TestAccountsStore_ListByOrganization(t *testing.T) { func TestAccountsStore_UpdateStatus(t *testing.T) { ctx := context.Background() logger := zap.NewNop() - accountRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() t.Run("Success", func(t *testing.T) { - var patchedID primitive.ObjectID + var patchedID bson.ObjectID var patchedStatus pkm.LedgerAccountStatus stub := &repositoryStub{ - PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error { + PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error { patchedID = id // In real test, we'd inspect patch builder but this is sufficient for stub patchedStatus = pkm.LedgerAccountStatusFrozen @@ -573,7 +573,7 @@ func TestAccountsStore_UpdateStatus(t *testing.T) { stub := &repositoryStub{} store := &accountsStore{logger: logger, repo: stub} - err := store.UpdateStatus(ctx, primitive.NilObjectID, pkm.LedgerAccountStatusFrozen) + err := store.UpdateStatus(ctx, bson.NilObjectID, pkm.LedgerAccountStatusFrozen) require.Error(t, err) assert.True(t, errors.Is(err, merrors.ErrInvalidArg)) @@ -582,7 +582,7 @@ func TestAccountsStore_UpdateStatus(t *testing.T) { t.Run("PatchError", func(t *testing.T) { expectedErr := errors.New("database error") stub := &repositoryStub{ - PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error { + PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error { return expectedErr }, } diff --git a/api/ledger/storage/mongo/store/balances.go b/api/ledger/storage/mongo/store/balances.go index b30f4bff..c47eb489 100644 --- a/api/ledger/storage/mongo/store/balances.go +++ b/api/ledger/storage/mongo/store/balances.go @@ -11,8 +11,8 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -45,7 +45,7 @@ func NewBalances(logger mlogger.Logger, db *mongo.Database) (storage.BalancesSto }, nil } -func (b *balancesStore) Get(ctx context.Context, accountRef primitive.ObjectID) (*model.AccountBalance, error) { +func (b *balancesStore) Get(ctx context.Context, accountRef bson.ObjectID) (*model.AccountBalance, error) { if accountRef.IsZero() { b.logger.Warn("attempt to get balance with zero account ID") return nil, merrors.InvalidArgument("balancesStore: zero account ID") @@ -98,7 +98,7 @@ func (b *balancesStore) Upsert(ctx context.Context, balance *model.AccountBalanc return b.repo.Update(ctx, balance) } -func (b *balancesStore) IncrementBalance(ctx context.Context, accountRef primitive.ObjectID, amount string) error { +func (b *balancesStore) IncrementBalance(ctx context.Context, accountRef bson.ObjectID, amount string) error { if accountRef.IsZero() { b.logger.Warn("attempt to increment balance with zero account ID") return merrors.InvalidArgument("balancesStore: zero account ID") diff --git a/api/ledger/storage/mongo/store/balances_test.go b/api/ledger/storage/mongo/store/balances_test.go index 03eab4e0..068a095b 100644 --- a/api/ledger/storage/mongo/store/balances_test.go +++ b/api/ledger/storage/mongo/store/balances_test.go @@ -5,14 +5,14 @@ import ( "errors" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tech/sendico/ledger/storage" "github.com/tech/sendico/ledger/storage/model" "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/merrors" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -21,7 +21,7 @@ func TestBalancesStore_Get(t *testing.T) { logger := zap.NewNop() t.Run("Success", func(t *testing.T) { - accountRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() stub := &repositoryStub{ FindOneByFilterFunc: func(ctx context.Context, _ builder.Query, result storable.Storable) error { balance := result.(*model.AccountBalance) @@ -46,7 +46,7 @@ func TestBalancesStore_Get(t *testing.T) { stub := &repositoryStub{} store := &balancesStore{logger: logger, repo: stub} - result, err := store.Get(ctx, primitive.NilObjectID) + result, err := store.Get(ctx, bson.NilObjectID) require.Error(t, err) assert.Nil(t, result) @@ -54,7 +54,7 @@ func TestBalancesStore_Get(t *testing.T) { }) t.Run("NotFound", func(t *testing.T) { - accountRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() stub := &repositoryStub{ FindOneByFilterFunc: func(ctx context.Context, _ builder.Query, result storable.Storable) error { return merrors.ErrNoData @@ -70,7 +70,7 @@ func TestBalancesStore_Get(t *testing.T) { }) t.Run("FindError", func(t *testing.T) { - accountRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() expectedErr := errors.New("database error") stub := &repositoryStub{ FindOneByFilterFunc: func(ctx context.Context, _ builder.Query, result storable.Storable) error { @@ -92,7 +92,7 @@ func TestBalancesStore_Upsert(t *testing.T) { logger := zap.NewNop() t.Run("Insert_NewBalance", func(t *testing.T) { - accountRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() var insertedBalance *model.AccountBalance stub := &repositoryStub{ @@ -120,8 +120,8 @@ func TestBalancesStore_Upsert(t *testing.T) { }) t.Run("Update_ExistingBalance", func(t *testing.T) { - accountRef := primitive.NewObjectID() - existingID := primitive.NewObjectID() + accountRef := bson.NewObjectID() + existingID := bson.NewObjectID() var updatedBalance *model.AccountBalance stub := &repositoryStub{ @@ -170,7 +170,7 @@ func TestBalancesStore_Upsert(t *testing.T) { store := &balancesStore{logger: logger, repo: stub} balance := &model.AccountBalance{ - AccountRef: primitive.NilObjectID, + AccountRef: bson.NilObjectID, Balance: "100.00", } @@ -181,7 +181,7 @@ func TestBalancesStore_Upsert(t *testing.T) { }) t.Run("FindError", func(t *testing.T) { - accountRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() expectedErr := errors.New("database error") stub := &repositoryStub{ @@ -203,7 +203,7 @@ func TestBalancesStore_Upsert(t *testing.T) { }) t.Run("InsertError", func(t *testing.T) { - accountRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() expectedErr := errors.New("insert error") stub := &repositoryStub{ @@ -228,8 +228,8 @@ func TestBalancesStore_Upsert(t *testing.T) { }) t.Run("UpdateError", func(t *testing.T) { - accountRef := primitive.NewObjectID() - existingID := primitive.NewObjectID() + accountRef := bson.NewObjectID() + existingID := bson.NewObjectID() expectedErr := errors.New("update error") stub := &repositoryStub{ @@ -263,7 +263,7 @@ func TestBalancesStore_IncrementBalance(t *testing.T) { logger := zap.NewNop() t.Run("NotImplemented", func(t *testing.T) { - accountRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() stub := &repositoryStub{} store := &balancesStore{logger: logger, repo: stub} @@ -277,7 +277,7 @@ func TestBalancesStore_IncrementBalance(t *testing.T) { stub := &repositoryStub{} store := &balancesStore{logger: logger, repo: stub} - err := store.IncrementBalance(ctx, primitive.NilObjectID, "100.00") + err := store.IncrementBalance(ctx, bson.NilObjectID, "100.00") require.Error(t, err) assert.True(t, errors.Is(err, merrors.ErrInvalidArg)) diff --git a/api/ledger/storage/mongo/store/journal_entries.go b/api/ledger/storage/mongo/store/journal_entries.go index 1dcb6215..e3f3d48c 100644 --- a/api/ledger/storage/mongo/store/journal_entries.go +++ b/api/ledger/storage/mongo/store/journal_entries.go @@ -11,8 +11,8 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -78,7 +78,7 @@ func (j *journalEntriesStore) Create(ctx context.Context, entry *model.JournalEn return nil } -func (j *journalEntriesStore) Get(ctx context.Context, entryRef primitive.ObjectID) (*model.JournalEntry, error) { +func (j *journalEntriesStore) Get(ctx context.Context, entryRef bson.ObjectID) (*model.JournalEntry, error) { if entryRef.IsZero() { j.logger.Warn("attempt to get journal entry with zero ID") return nil, merrors.InvalidArgument("journalEntriesStore: zero entry ID") @@ -99,7 +99,7 @@ func (j *journalEntriesStore) Get(ctx context.Context, entryRef primitive.Object return result, nil } -func (j *journalEntriesStore) GetByIdempotencyKey(ctx context.Context, orgRef primitive.ObjectID, idempotencyKey string) (*model.JournalEntry, error) { +func (j *journalEntriesStore) GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, idempotencyKey string) (*model.JournalEntry, error) { if orgRef.IsZero() { j.logger.Warn("attempt to get journal entry with zero organization ID") return nil, merrors.InvalidArgument("journalEntriesStore: zero organization ID") @@ -128,7 +128,7 @@ func (j *journalEntriesStore) GetByIdempotencyKey(ctx context.Context, orgRef pr return result, nil } -func (j *journalEntriesStore) ListByOrganization(ctx context.Context, orgRef primitive.ObjectID, limit int, offset int) ([]*model.JournalEntry, error) { +func (j *journalEntriesStore) ListByOrganization(ctx context.Context, orgRef bson.ObjectID, limit int, offset int) ([]*model.JournalEntry, error) { if orgRef.IsZero() { j.logger.Warn("attempt to list journal entries with zero organization ID") return nil, merrors.InvalidArgument("journalEntriesStore: zero organization ID") diff --git a/api/ledger/storage/mongo/store/journal_entries_test.go b/api/ledger/storage/mongo/store/journal_entries_test.go index 34b5318e..c7e7068e 100644 --- a/api/ledger/storage/mongo/store/journal_entries_test.go +++ b/api/ledger/storage/mongo/store/journal_entries_test.go @@ -6,16 +6,16 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tech/sendico/ledger/storage" "github.com/tech/sendico/ledger/storage/model" "github.com/tech/sendico/pkg/db/repository/builder" rd "github.com/tech/sendico/pkg/db/repository/decoder" "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/merrors" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -107,9 +107,9 @@ func TestJournalEntriesStore_Get(t *testing.T) { logger := zap.NewNop() t.Run("Success", func(t *testing.T) { - entryRef := primitive.NewObjectID() + entryRef := bson.NewObjectID() stub := &repositoryStub{ - GetFunc: func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error { + GetFunc: func(ctx context.Context, id bson.ObjectID, result storable.Storable) error { entry := result.(*model.JournalEntry) entry.SetID(entryRef) entry.IdempotencyKey = "test-key-123" @@ -131,7 +131,7 @@ func TestJournalEntriesStore_Get(t *testing.T) { stub := &repositoryStub{} store := &journalEntriesStore{logger: logger, repo: stub} - result, err := store.Get(ctx, primitive.NilObjectID) + result, err := store.Get(ctx, bson.NilObjectID) require.Error(t, err) assert.Nil(t, result) @@ -139,9 +139,9 @@ func TestJournalEntriesStore_Get(t *testing.T) { }) t.Run("NotFound", func(t *testing.T) { - entryRef := primitive.NewObjectID() + entryRef := bson.NewObjectID() stub := &repositoryStub{ - GetFunc: func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error { + GetFunc: func(ctx context.Context, id bson.ObjectID, result storable.Storable) error { return merrors.ErrNoData }, } @@ -158,7 +158,7 @@ func TestJournalEntriesStore_Get(t *testing.T) { func TestJournalEntriesStore_GetByIdempotencyKey(t *testing.T) { ctx := context.Background() logger := zap.NewNop() - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() t.Run("Success", func(t *testing.T) { stub := &repositoryStub{ @@ -183,7 +183,7 @@ func TestJournalEntriesStore_GetByIdempotencyKey(t *testing.T) { stub := &repositoryStub{} store := &journalEntriesStore{logger: logger, repo: stub} - result, err := store.GetByIdempotencyKey(ctx, primitive.NilObjectID, "test-key") + result, err := store.GetByIdempotencyKey(ctx, bson.NilObjectID, "test-key") require.Error(t, err) assert.Nil(t, result) @@ -220,7 +220,7 @@ func TestJournalEntriesStore_GetByIdempotencyKey(t *testing.T) { func TestJournalEntriesStore_ListByOrganization(t *testing.T) { ctx := context.Background() logger := zap.NewNop() - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() t.Run("Success", func(t *testing.T) { called := false @@ -243,7 +243,7 @@ func TestJournalEntriesStore_ListByOrganization(t *testing.T) { stub := &repositoryStub{} store := &journalEntriesStore{logger: logger, repo: stub} - results, err := store.ListByOrganization(ctx, primitive.NilObjectID, 10, 0) + results, err := store.ListByOrganization(ctx, bson.NilObjectID, 10, 0) require.Error(t, err) assert.Nil(t, results) diff --git a/api/ledger/storage/mongo/store/outbox.go b/api/ledger/storage/mongo/store/outbox.go index 4fb9bea8..c1048f8b 100644 --- a/api/ledger/storage/mongo/store/outbox.go +++ b/api/ledger/storage/mongo/store/outbox.go @@ -10,8 +10,8 @@ import ( ri "github.com/tech/sendico/pkg/db/repository/index" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -101,7 +101,7 @@ func (o *outboxStore) ListPending(ctx context.Context, limit int) ([]*model.Outb return events, nil } -func (o *outboxStore) MarkSent(ctx context.Context, eventRef primitive.ObjectID, sentAt time.Time) error { +func (o *outboxStore) MarkSent(ctx context.Context, eventRef bson.ObjectID, sentAt time.Time) error { if eventRef.IsZero() { o.logger.Warn("attempt to mark sent with zero event ID") return merrors.InvalidArgument("outboxStore: zero event ID") @@ -120,7 +120,7 @@ func (o *outboxStore) MarkSent(ctx context.Context, eventRef primitive.ObjectID, return nil } -func (o *outboxStore) MarkFailed(ctx context.Context, eventRef primitive.ObjectID) error { +func (o *outboxStore) MarkFailed(ctx context.Context, eventRef bson.ObjectID) error { if eventRef.IsZero() { o.logger.Warn("attempt to mark failed with zero event ID") return merrors.InvalidArgument("outboxStore: zero event ID") @@ -137,7 +137,7 @@ func (o *outboxStore) MarkFailed(ctx context.Context, eventRef primitive.ObjectI return nil } -func (o *outboxStore) IncrementAttempts(ctx context.Context, eventRef primitive.ObjectID) error { +func (o *outboxStore) IncrementAttempts(ctx context.Context, eventRef bson.ObjectID) error { if eventRef.IsZero() { o.logger.Warn("attempt to increment attempts with zero event ID") return merrors.InvalidArgument("outboxStore: zero event ID") diff --git a/api/ledger/storage/mongo/store/outbox_test.go b/api/ledger/storage/mongo/store/outbox_test.go index e0adc62f..a1e5f57e 100644 --- a/api/ledger/storage/mongo/store/outbox_test.go +++ b/api/ledger/storage/mongo/store/outbox_test.go @@ -6,16 +6,16 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tech/sendico/ledger/storage/model" "github.com/tech/sendico/pkg/db/repository" "github.com/tech/sendico/pkg/db/repository/builder" rd "github.com/tech/sendico/pkg/db/repository/decoder" "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/merrors" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -176,13 +176,13 @@ func TestOutboxStore_ListPending(t *testing.T) { func TestOutboxStore_MarkSent(t *testing.T) { ctx := context.Background() logger := zap.NewNop() - eventRef := primitive.NewObjectID() + eventRef := bson.NewObjectID() sentTime := time.Now() t.Run("Success", func(t *testing.T) { - var patchedID primitive.ObjectID + var patchedID bson.ObjectID stub := &repositoryStub{ - PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error { + PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error { patchedID = id return nil }, @@ -199,7 +199,7 @@ func TestOutboxStore_MarkSent(t *testing.T) { stub := &repositoryStub{} store := &outboxStore{logger: logger, repo: stub} - err := store.MarkSent(ctx, primitive.NilObjectID, sentTime) + err := store.MarkSent(ctx, bson.NilObjectID, sentTime) require.Error(t, err) assert.True(t, errors.Is(err, merrors.ErrInvalidArg)) @@ -208,7 +208,7 @@ func TestOutboxStore_MarkSent(t *testing.T) { t.Run("PatchError", func(t *testing.T) { expectedErr := errors.New("database error") stub := &repositoryStub{ - PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error { + PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error { return expectedErr }, } @@ -224,12 +224,12 @@ func TestOutboxStore_MarkSent(t *testing.T) { func TestOutboxStore_MarkFailed(t *testing.T) { ctx := context.Background() logger := zap.NewNop() - eventRef := primitive.NewObjectID() + eventRef := bson.NewObjectID() t.Run("Success", func(t *testing.T) { - var patchedID primitive.ObjectID + var patchedID bson.ObjectID stub := &repositoryStub{ - PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error { + PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error { patchedID = id return nil }, @@ -246,7 +246,7 @@ func TestOutboxStore_MarkFailed(t *testing.T) { stub := &repositoryStub{} store := &outboxStore{logger: logger, repo: stub} - err := store.MarkFailed(ctx, primitive.NilObjectID) + err := store.MarkFailed(ctx, bson.NilObjectID) require.Error(t, err) assert.True(t, errors.Is(err, merrors.ErrInvalidArg)) @@ -255,7 +255,7 @@ func TestOutboxStore_MarkFailed(t *testing.T) { t.Run("PatchError", func(t *testing.T) { expectedErr := errors.New("database error") stub := &repositoryStub{ - PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error { + PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error { return expectedErr }, } @@ -271,12 +271,12 @@ func TestOutboxStore_MarkFailed(t *testing.T) { func TestOutboxStore_IncrementAttempts(t *testing.T) { ctx := context.Background() logger := zap.NewNop() - eventRef := primitive.NewObjectID() + eventRef := bson.NewObjectID() t.Run("Success", func(t *testing.T) { - var patchedID primitive.ObjectID + var patchedID bson.ObjectID stub := &repositoryStub{ - PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error { + PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error { patchedID = id return nil }, @@ -293,7 +293,7 @@ func TestOutboxStore_IncrementAttempts(t *testing.T) { stub := &repositoryStub{} store := &outboxStore{logger: logger, repo: stub} - err := store.IncrementAttempts(ctx, primitive.NilObjectID) + err := store.IncrementAttempts(ctx, bson.NilObjectID) require.Error(t, err) assert.True(t, errors.Is(err, merrors.ErrInvalidArg)) @@ -302,7 +302,7 @@ func TestOutboxStore_IncrementAttempts(t *testing.T) { t.Run("PatchError", func(t *testing.T) { expectedErr := errors.New("database error") stub := &repositoryStub{ - PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error { + PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error { return expectedErr }, } @@ -317,7 +317,7 @@ func TestOutboxStore_IncrementAttempts(t *testing.T) { t.Run("MultipleIncrements", func(t *testing.T) { var callCount int stub := &repositoryStub{ - PatchFunc: func(ctx context.Context, id primitive.ObjectID, _ repository.PatchDoc) error { + PatchFunc: func(ctx context.Context, id bson.ObjectID, _ repository.PatchDoc) error { callCount++ return nil }, diff --git a/api/ledger/storage/mongo/store/posting_lines.go b/api/ledger/storage/mongo/store/posting_lines.go index cfe3c69b..54d31263 100644 --- a/api/ledger/storage/mongo/store/posting_lines.go +++ b/api/ledger/storage/mongo/store/posting_lines.go @@ -11,8 +11,8 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -80,7 +80,7 @@ func (p *postingLinesStore) CreateMany(ctx context.Context, lines []*model.Posti return nil } -func (p *postingLinesStore) ListByJournalEntry(ctx context.Context, entryRef primitive.ObjectID) ([]*model.PostingLine, error) { +func (p *postingLinesStore) ListByJournalEntry(ctx context.Context, entryRef bson.ObjectID) ([]*model.PostingLine, error) { if entryRef.IsZero() { p.logger.Warn("attempt to list posting lines with zero entry ID") return nil, merrors.InvalidArgument("postingLinesStore: zero entry ID") @@ -106,7 +106,7 @@ func (p *postingLinesStore) ListByJournalEntry(ctx context.Context, entryRef pri return lines, nil } -func (p *postingLinesStore) ListByAccount(ctx context.Context, accountRef primitive.ObjectID, limit int, offset int) ([]*model.PostingLine, error) { +func (p *postingLinesStore) ListByAccount(ctx context.Context, accountRef bson.ObjectID, limit int, offset int) ([]*model.PostingLine, error) { if accountRef.IsZero() { p.logger.Warn("attempt to list posting lines with zero account ID") return nil, merrors.InvalidArgument("postingLinesStore: zero account ID") diff --git a/api/ledger/storage/mongo/store/posting_lines_test.go b/api/ledger/storage/mongo/store/posting_lines_test.go index 777bfd38..ee4f0a29 100644 --- a/api/ledger/storage/mongo/store/posting_lines_test.go +++ b/api/ledger/storage/mongo/store/posting_lines_test.go @@ -5,14 +5,14 @@ import ( "errors" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tech/sendico/ledger/storage/model" "github.com/tech/sendico/pkg/db/repository/builder" rd "github.com/tech/sendico/pkg/db/repository/decoder" "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/merrors" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -32,14 +32,14 @@ func TestPostingLinesStore_CreateMany(t *testing.T) { store := &postingLinesStore{logger: logger, repo: stub} lines := []*model.PostingLine{ { - JournalEntryRef: primitive.NewObjectID(), - AccountRef: primitive.NewObjectID(), + JournalEntryRef: bson.NewObjectID(), + AccountRef: bson.NewObjectID(), LineType: model.LineTypeMain, Amount: "100.00", }, { - JournalEntryRef: primitive.NewObjectID(), - AccountRef: primitive.NewObjectID(), + JournalEntryRef: bson.NewObjectID(), + AccountRef: bson.NewObjectID(), LineType: model.LineTypeMain, Amount: "100.00", }, @@ -104,9 +104,9 @@ func TestPostingLinesStore_CreateMany(t *testing.T) { } store := &postingLinesStore{logger: logger, repo: stub} - entryRef := primitive.NewObjectID() - cashAccount := primitive.NewObjectID() - revenueAccount := primitive.NewObjectID() + entryRef := bson.NewObjectID() + cashAccount := bson.NewObjectID() + revenueAccount := bson.NewObjectID() lines := []*model.PostingLine{ { @@ -133,7 +133,7 @@ func TestPostingLinesStore_CreateMany(t *testing.T) { func TestPostingLinesStore_ListByJournalEntry(t *testing.T) { ctx := context.Background() logger := zap.NewNop() - entryRef := primitive.NewObjectID() + entryRef := bson.NewObjectID() t.Run("Success", func(t *testing.T) { called := false @@ -156,7 +156,7 @@ func TestPostingLinesStore_ListByJournalEntry(t *testing.T) { stub := &repositoryStub{} store := &postingLinesStore{logger: logger, repo: stub} - results, err := store.ListByJournalEntry(ctx, primitive.NilObjectID) + results, err := store.ListByJournalEntry(ctx, bson.NilObjectID) require.Error(t, err) assert.Nil(t, results) @@ -197,7 +197,7 @@ func TestPostingLinesStore_ListByJournalEntry(t *testing.T) { func TestPostingLinesStore_ListByAccount(t *testing.T) { ctx := context.Background() logger := zap.NewNop() - accountRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() t.Run("Success", func(t *testing.T) { called := false @@ -220,7 +220,7 @@ func TestPostingLinesStore_ListByAccount(t *testing.T) { stub := &repositoryStub{} store := &postingLinesStore{logger: logger, repo: stub} - results, err := store.ListByAccount(ctx, primitive.NilObjectID, 10, 0) + results, err := store.ListByAccount(ctx, bson.NilObjectID, 10, 0) require.Error(t, err) assert.Nil(t, results) diff --git a/api/ledger/storage/mongo/store/testing_helpers_test.go b/api/ledger/storage/mongo/store/testing_helpers_test.go index 492e322e..2ba30408 100644 --- a/api/ledger/storage/mongo/store/testing_helpers_test.go +++ b/api/ledger/storage/mongo/store/testing_helpers_test.go @@ -9,23 +9,23 @@ import ( ri "github.com/tech/sendico/pkg/db/repository/index" "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // repositoryStub provides a stub implementation of repository.Repository for testing type repositoryStub struct { AggregateFunc func(ctx context.Context, pipeline builder.Pipeline, decoder rd.DecodingFunc) error - GetFunc func(ctx context.Context, id primitive.ObjectID, result storable.Storable) error + GetFunc func(ctx context.Context, id bson.ObjectID, result storable.Storable) error InsertFunc func(ctx context.Context, object storable.Storable, filter builder.Query) error InsertManyFunc func(ctx context.Context, objects []storable.Storable) error UpdateFunc func(ctx context.Context, object storable.Storable) error - DeleteFunc func(ctx context.Context, id primitive.ObjectID) error + DeleteFunc func(ctx context.Context, id bson.ObjectID) error FindOneByFilterFunc func(ctx context.Context, filter builder.Query, result storable.Storable) error FindManyByFilterFunc func(ctx context.Context, filter builder.Query, decoder rd.DecodingFunc) error - PatchFunc func(ctx context.Context, id primitive.ObjectID, patch repository.PatchDoc) error + PatchFunc func(ctx context.Context, id bson.ObjectID, patch repository.PatchDoc) error PatchManyFunc func(ctx context.Context, filter repository.FilterQuery, patch repository.PatchDoc) (int, error) DeleteManyFunc func(ctx context.Context, query builder.Query) error - ListIDsFunc func(ctx context.Context, query builder.Query) ([]primitive.ObjectID, error) + ListIDsFunc func(ctx context.Context, query builder.Query) ([]bson.ObjectID, error) CreateIndexFunc func(def *ri.Definition) error } @@ -36,7 +36,7 @@ func (r *repositoryStub) Aggregate(ctx context.Context, pipeline builder.Pipelin return nil } -func (r *repositoryStub) Get(ctx context.Context, id primitive.ObjectID, result storable.Storable) error { +func (r *repositoryStub) Get(ctx context.Context, id bson.ObjectID, result storable.Storable) error { if r.GetFunc != nil { return r.GetFunc(ctx, id, result) } @@ -64,7 +64,7 @@ func (r *repositoryStub) Update(ctx context.Context, object storable.Storable) e return nil } -func (r *repositoryStub) Delete(ctx context.Context, id primitive.ObjectID) error { +func (r *repositoryStub) Delete(ctx context.Context, id bson.ObjectID) error { if r.DeleteFunc != nil { return r.DeleteFunc(ctx, id) } @@ -85,7 +85,7 @@ func (r *repositoryStub) FindManyByFilter(ctx context.Context, filter builder.Qu return nil } -func (r *repositoryStub) Patch(ctx context.Context, id primitive.ObjectID, patch repository.PatchDoc) error { +func (r *repositoryStub) Patch(ctx context.Context, id bson.ObjectID, patch repository.PatchDoc) error { if r.PatchFunc != nil { return r.PatchFunc(ctx, id, patch) } @@ -106,7 +106,7 @@ func (r *repositoryStub) DeleteMany(ctx context.Context, query builder.Query) er return nil } -func (r *repositoryStub) ListIDs(ctx context.Context, query builder.Query) ([]primitive.ObjectID, error) { +func (r *repositoryStub) ListIDs(ctx context.Context, query builder.Query) ([]bson.ObjectID, error) { if r.ListIDsFunc != nil { return r.ListIDsFunc(ctx, query) } diff --git a/api/ledger/storage/mongo/transaction.go b/api/ledger/storage/mongo/transaction.go index 64b7b652..52bad57e 100644 --- a/api/ledger/storage/mongo/transaction.go +++ b/api/ledger/storage/mongo/transaction.go @@ -4,7 +4,7 @@ import ( "context" "github.com/tech/sendico/pkg/db/transaction" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" ) type mongoTransactionFactory struct { @@ -26,7 +26,7 @@ func (t *mongoTransaction) Execute(ctx context.Context, cb transaction.Callback) } defer session.EndSession(ctx) - run := func(sessCtx mongo.SessionContext) (any, error) { + run := func(sessCtx context.Context) (any, error) { return cb(sessCtx) } diff --git a/api/ledger/storage/storage.go b/api/ledger/storage/storage.go index 4e711a84..3571f164 100644 --- a/api/ledger/storage/storage.go +++ b/api/ledger/storage/storage.go @@ -6,7 +6,7 @@ import ( "github.com/tech/sendico/ledger/storage/model" pkm "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type storageError string @@ -31,43 +31,43 @@ type AccountsFilter struct { // - nil: no filter on owner_ref (return all) // - pointer to zero ObjectID: filter for accounts where owner_ref is nil // - pointer to a value: filter for accounts where owner_ref matches - OwnerRefFilter *primitive.ObjectID + OwnerRefFilter *bson.ObjectID } type AccountsStore interface { Create(ctx context.Context, account *pkm.LedgerAccount) error - Get(ctx context.Context, accountRef primitive.ObjectID) (*pkm.LedgerAccount, error) - GetByAccountCode(ctx context.Context, orgRef primitive.ObjectID, accountCode, currency string) (*pkm.LedgerAccount, error) - GetByRole(ctx context.Context, orgRef primitive.ObjectID, currency string, role pkm.AccountRole) (*pkm.LedgerAccount, error) + Get(ctx context.Context, accountRef bson.ObjectID) (*pkm.LedgerAccount, error) + GetByAccountCode(ctx context.Context, orgRef bson.ObjectID, accountCode, currency string) (*pkm.LedgerAccount, error) + GetByRole(ctx context.Context, orgRef bson.ObjectID, currency string, role pkm.AccountRole) (*pkm.LedgerAccount, error) GetSystemAccount(ctx context.Context, purpose pkm.SystemAccountPurpose, currency string) (*pkm.LedgerAccount, error) - GetDefaultSettlement(ctx context.Context, orgRef primitive.ObjectID, currency string) (*pkm.LedgerAccount, error) - ListByOrganization(ctx context.Context, orgRef primitive.ObjectID, filter *AccountsFilter, limit int, offset int) ([]*pkm.LedgerAccount, error) - UpdateStatus(ctx context.Context, accountRef primitive.ObjectID, status pkm.LedgerAccountStatus) error + GetDefaultSettlement(ctx context.Context, orgRef bson.ObjectID, currency string) (*pkm.LedgerAccount, error) + ListByOrganization(ctx context.Context, orgRef bson.ObjectID, filter *AccountsFilter, limit int, offset int) ([]*pkm.LedgerAccount, error) + UpdateStatus(ctx context.Context, accountRef bson.ObjectID, status pkm.LedgerAccountStatus) error } type JournalEntriesStore interface { Create(ctx context.Context, entry *model.JournalEntry) error - Get(ctx context.Context, entryRef primitive.ObjectID) (*model.JournalEntry, error) - GetByIdempotencyKey(ctx context.Context, orgRef primitive.ObjectID, idempotencyKey string) (*model.JournalEntry, error) - ListByOrganization(ctx context.Context, orgRef primitive.ObjectID, limit int, offset int) ([]*model.JournalEntry, error) + Get(ctx context.Context, entryRef bson.ObjectID) (*model.JournalEntry, error) + GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, idempotencyKey string) (*model.JournalEntry, error) + ListByOrganization(ctx context.Context, orgRef bson.ObjectID, limit int, offset int) ([]*model.JournalEntry, error) } type PostingLinesStore interface { CreateMany(ctx context.Context, lines []*model.PostingLine) error - ListByJournalEntry(ctx context.Context, entryRef primitive.ObjectID) ([]*model.PostingLine, error) - ListByAccount(ctx context.Context, accountRef primitive.ObjectID, limit int, offset int) ([]*model.PostingLine, error) + ListByJournalEntry(ctx context.Context, entryRef bson.ObjectID) ([]*model.PostingLine, error) + ListByAccount(ctx context.Context, accountRef bson.ObjectID, limit int, offset int) ([]*model.PostingLine, error) } type BalancesStore interface { - Get(ctx context.Context, accountRef primitive.ObjectID) (*model.AccountBalance, error) + Get(ctx context.Context, accountRef bson.ObjectID) (*model.AccountBalance, error) Upsert(ctx context.Context, balance *model.AccountBalance) error - IncrementBalance(ctx context.Context, accountRef primitive.ObjectID, amount string) error + IncrementBalance(ctx context.Context, accountRef bson.ObjectID, amount string) error } type OutboxStore interface { Create(ctx context.Context, event *model.OutboxEvent) error ListPending(ctx context.Context, limit int) ([]*model.OutboxEvent, error) - MarkSent(ctx context.Context, eventRef primitive.ObjectID, sentAt time.Time) error - MarkFailed(ctx context.Context, eventRef primitive.ObjectID) error - IncrementAttempts(ctx context.Context, eventRef primitive.ObjectID) error + MarkSent(ctx context.Context, eventRef bson.ObjectID, sentAt time.Time) error + MarkFailed(ctx context.Context, eventRef bson.ObjectID) error + IncrementAttempts(ctx context.Context, eventRef bson.ObjectID) error } diff --git a/api/notification/go.mod b/api/notification/go.mod index c13ea4ba..d5ff1970 100644 --- a/api/notification/go.mod +++ b/api/notification/go.mod @@ -12,7 +12,7 @@ require ( github.com/sendgrid/sendgrid-go v3.16.1+incompatible github.com/tech/sendico/pkg v0.1.0 github.com/xhit/go-simple-mail/v2 v2.16.0 - go.mongodb.org/mongo-driver v1.17.8 + go.mongodb.org/mongo-driver/v2 v2.5.0 go.uber.org/zap v1.27.1 golang.org/x/text v0.33.0 gopkg.in/yaml.v3 v3.0.1 @@ -23,15 +23,13 @@ require ( github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect github.com/casbin/casbin/v2 v2.135.0 // indirect github.com/casbin/govaluate v1.10.0 // indirect - github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect + github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/go-test/deep v1.1.1 // indirect - github.com/golang/snappy v1.0.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/klauspost/compress v1.18.3 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/montanaflynn/stats v0.7.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nats-io/nats.go v1.48.0 // indirect github.com/nats-io/nkeys v0.4.15 // indirect diff --git a/api/notification/go.sum b/api/notification/go.sum index f098245c..895ba47d 100644 --- a/api/notification/go.sum +++ b/api/notification/go.sum @@ -18,8 +18,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0= github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= -github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E= -github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA= +github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ= +github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -59,8 +59,6 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs= -github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -93,8 +91,6 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= -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/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -165,8 +161,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM= -go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= diff --git a/api/notification/internal/server/notificationimp/notification_test.go b/api/notification/internal/server/notificationimp/notification_test.go index 23a38117..76fdbd61 100644 --- a/api/notification/internal/server/notificationimp/notification_test.go +++ b/api/notification/internal/server/notificationimp/notification_test.go @@ -9,9 +9,9 @@ import ( mmail "github.com/tech/sendico/notification/internal/server/notificationimp/mail/messagebuilder" "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/domainprovider" + mlogger "github.com/tech/sendico/pkg/mlogger/factory" "github.com/tech/sendico/pkg/model" - "github.com/tech/sendico/pkg/mlogger/factory" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // Mock implementations @@ -129,11 +129,11 @@ type mockMessage struct { parameters map[string]any } -func (m *mockMessage) AccountID() string { return m.accountID } -func (m *mockMessage) TemplateID() string { return m.templateID } -func (m *mockMessage) Locale() string { return m.locale } -func (m *mockMessage) Recipients() []string { return m.recipients } -func (m *mockMessage) Parameters() map[string]any { return m.parameters } +func (m *mockMessage) AccountID() string { return m.accountID } +func (m *mockMessage) TemplateID() string { return m.templateID } +func (m *mockMessage) Locale() string { return m.locale } +func (m *mockMessage) Recipients() []string { return m.recipients } +func (m *mockMessage) Parameters() map[string]any { return m.parameters } func (m *mockMessage) Body(l localizer.Localizer, dp domainprovider.DomainProvider) (string, error) { return "", nil } @@ -177,7 +177,7 @@ func TestOnAccount_ValidAccount_SendsWelcomeEmail(t *testing.T) { AccountPublic: model.AccountPublic{ AccountBase: model.AccountBase{ Base: storable.Base{ - ID: primitive.NewObjectID(), + ID: bson.NewObjectID(), }, Describable: model.Describable{ Name: "Test User", @@ -231,7 +231,7 @@ func TestOnAccount_LinkGenerationFails_ReturnsError(t *testing.T) { AccountPublic: model.AccountPublic{ AccountBase: model.AccountBase{ Base: storable.Base{ - ID: primitive.NewObjectID(), + ID: bson.NewObjectID(), }, Describable: model.Describable{ Name: "Test User", @@ -274,7 +274,7 @@ func TestOnAccount_SendFails_ReturnsError(t *testing.T) { AccountPublic: model.AccountPublic{ AccountBase: model.AccountBase{ Base: storable.Base{ - ID: primitive.NewObjectID(), + ID: bson.NewObjectID(), }, Describable: model.Describable{ Name: "Test User", @@ -311,7 +311,7 @@ func TestOnInvitation_ValidInvitation_SendsInvitationEmail(t *testing.T) { AccountPublic: model.AccountPublic{ AccountBase: model.AccountBase{ Base: storable.Base{ - ID: primitive.NewObjectID(), + ID: bson.NewObjectID(), }, Describable: model.Describable{ Name: "Inviter User", @@ -323,7 +323,7 @@ func TestOnInvitation_ValidInvitation_SendsInvitationEmail(t *testing.T) { }, } - invitationID := primitive.NewObjectID() + invitationID := bson.NewObjectID() invitation := &model.Invitation{} invitation.ID = invitationID invitation.Content.Email = "invitee@example.com" @@ -375,7 +375,7 @@ func TestOnInvitation_LinkGenerationFails_ReturnsError(t *testing.T) { AccountPublic: model.AccountPublic{ AccountBase: model.AccountBase{ Base: storable.Base{ - ID: primitive.NewObjectID(), + ID: bson.NewObjectID(), }, Describable: model.Describable{ Name: "Inviter User", @@ -387,7 +387,7 @@ func TestOnInvitation_LinkGenerationFails_ReturnsError(t *testing.T) { }, } - invitationID := primitive.NewObjectID() + invitationID := bson.NewObjectID() invitation := &model.Invitation{} invitation.ID = invitationID invitation.Content.Email = "invitee@example.com" @@ -420,7 +420,7 @@ func TestOnPasswordReset_ValidReset_SendsResetEmail(t *testing.T) { AccountPublic: model.AccountPublic{ AccountBase: model.AccountBase{ Base: storable.Base{ - ID: primitive.NewObjectID(), + ID: bson.NewObjectID(), }, Describable: model.Describable{ Name: "Test User", @@ -478,7 +478,7 @@ func TestOnPasswordReset_LinkGenerationFails_ReturnsError(t *testing.T) { AccountPublic: model.AccountPublic{ AccountBase: model.AccountBase{ Base: storable.Base{ - ID: primitive.NewObjectID(), + ID: bson.NewObjectID(), }, Describable: model.Describable{ Name: "Test User", @@ -520,7 +520,7 @@ func TestOnPasswordReset_SendFails_ReturnsError(t *testing.T) { AccountPublic: model.AccountPublic{ AccountBase: model.AccountBase{ Base: storable.Base{ - ID: primitive.NewObjectID(), + ID: bson.NewObjectID(), }, Describable: model.Describable{ Name: "Test User", diff --git a/api/payments/orchestrator/go.mod b/api/payments/orchestrator/go.mod index 32950a18..ea05f352 100644 --- a/api/payments/orchestrator/go.mod +++ b/api/payments/orchestrator/go.mod @@ -24,7 +24,7 @@ require ( github.com/tech/sendico/pkg v0.1.0 github.com/testcontainers/testcontainers-go v0.33.0 github.com/testcontainers/testcontainers-go/modules/mongodb v0.33.0 - go.mongodb.org/mongo-driver v1.17.8 + go.mongodb.org/mongo-driver/v2 v2.5.0 go.uber.org/zap v1.27.1 google.golang.org/grpc v1.78.0 google.golang.org/protobuf v1.36.11 @@ -39,7 +39,7 @@ require ( github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect github.com/casbin/casbin/v2 v2.135.0 // indirect github.com/casbin/govaluate v1.10.0 // indirect - github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect + github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/containerd/log v0.1.0 // indirect @@ -55,7 +55,6 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/snappy v1.0.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/klauspost/compress v1.18.3 // indirect github.com/lufia/plan9stats v0.0.0-20250827001030-24949be3fa54 // indirect diff --git a/api/payments/orchestrator/go.sum b/api/payments/orchestrator/go.sum index 7cac497c..efcb1e04 100644 --- a/api/payments/orchestrator/go.sum +++ b/api/payments/orchestrator/go.sum @@ -16,8 +16,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0= github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= -github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E= -github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA= +github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ= +github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -171,6 +171,8 @@ github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM= go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= diff --git a/api/payments/orchestrator/internal/service/orchestrator/card_payout_test.go b/api/payments/orchestrator/internal/service/orchestrator/card_payout_test.go index 3da1ee77..70a56850 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/card_payout_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/card_payout_test.go @@ -14,7 +14,7 @@ import ( chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1" mntxv1 "github.com/tech/sendico/pkg/proto/gateway/mntx/v1" orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -87,7 +87,7 @@ func TestSubmitCardFundingTransfers_PlansTopUpAndFunding(t *testing.T) { payment := &model.Payment{ PaymentRef: "pay-1", IdempotencyKey: "pay-1", - OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: primitive.NewObjectID()}, + OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: bson.NewObjectID()}, Intent: model.PaymentIntent{ Kind: model.PaymentKindPayout, Source: model.PaymentEndpoint{ @@ -249,7 +249,7 @@ func TestSubmitCardPayout_UsesSettlementAmount(t *testing.T) { payment := &model.Payment{ PaymentRef: "pay-2", IdempotencyKey: "pay-2", - OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: primitive.NewObjectID()}, + OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: bson.NewObjectID()}, Intent: model.PaymentIntent{ Kind: model.PaymentKindPayout, Source: model.PaymentEndpoint{ @@ -338,7 +338,7 @@ func TestSubmitCardFundingTransfers_RequiresFeeWalletRef(t *testing.T) { payment := &model.Payment{ PaymentRef: "pay-3", IdempotencyKey: "pay-3", - OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: primitive.NewObjectID()}, + OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: bson.NewObjectID()}, Intent: model.PaymentIntent{ Kind: model.PaymentKindPayout, Source: model.PaymentEndpoint{ diff --git a/api/payments/orchestrator/internal/service/orchestrator/handlers_commands.go b/api/payments/orchestrator/internal/service/orchestrator/handlers_commands.go index 6ce6925a..c5c3d399 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/handlers_commands.go +++ b/api/payments/orchestrator/internal/service/orchestrator/handlers_commands.go @@ -17,7 +17,7 @@ import ( "github.com/tech/sendico/pkg/mservice" "github.com/tech/sendico/pkg/mutil/mzap" orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "google.golang.org/protobuf/proto" ) @@ -35,7 +35,7 @@ var ( type quoteCtx struct { orgID string - orgRef primitive.ObjectID + orgRef bson.ObjectID intent *orchestratorv1.PaymentIntent previewOnly bool idempotencyKey string @@ -118,7 +118,7 @@ func (h *quotePaymentCommand) quotePayment( h.logger.Warn("Failed to build preview payment quote", zap.Error(err), zap.String("org_ref", qc.orgID)) return nil, err } - quote.QuoteRef = primitive.NewObjectID().Hex() + quote.QuoteRef = bson.NewObjectID().Hex() return quote, nil } @@ -153,7 +153,7 @@ func (h *quotePaymentCommand) quotePayment( return nil, err } - quoteRef := primitive.NewObjectID().Hex() + quoteRef := bson.NewObjectID().Hex() quote.QuoteRef = quoteRef record := &model.PaymentQuoteRecord{ @@ -164,7 +164,7 @@ func (h *quotePaymentCommand) quotePayment( Quote: quoteSnapshotToModel(quote), ExpiresAt: expiresAt, } - record.SetID(primitive.NewObjectID()) + record.SetID(bson.NewObjectID()) record.SetOrganizationRef(qc.orgRef) if err := quotesStore.Create(ctx, record); err != nil { @@ -231,7 +231,7 @@ var ( type quotePaymentsCtx struct { orgID string - orgRef primitive.ObjectID + orgRef bson.ObjectID previewOnly bool idempotencyKey string hash string @@ -293,7 +293,7 @@ func (h *quotePaymentsCommand) Execute( return gsresponse.Auto[orchestratorv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) } - quoteRef := primitive.NewObjectID().Hex() + quoteRef := bson.NewObjectID().Hex() for _, q := range quotes { if q != nil { q.QuoteRef = quoteRef @@ -466,7 +466,7 @@ func (h *quotePaymentsCommand) storeBatch( Quotes: quoteSnapshotsFromProto(quotes), ExpiresAt: expiresAt, } - record.SetID(primitive.NewObjectID()) + record.SetID(bson.NewObjectID()) record.SetOrganizationRef(qc.orgRef) if err := quotesStore.Create(ctx, record); err != nil { diff --git a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_executor_test.go b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_executor_test.go index 3bee7a80..044fa7c8 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_executor_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_executor_test.go @@ -16,7 +16,7 @@ import ( mntxv1 "github.com/tech/sendico/pkg/proto/gateway/mntx/v1" ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "google.golang.org/protobuf/types/known/structpb" ) @@ -102,7 +102,7 @@ func TestExecutePaymentPlan_SourceBeforeDestination(t *testing.T) { PaymentRef: "pay-plan-1", IdempotencyKey: "pay-plan-1", OrganizationBoundBase: mo.OrganizationBoundBase{ - OrganizationRef: primitive.NewObjectID(), + OrganizationRef: bson.NewObjectID(), }, Intent: model.PaymentIntent{ Kind: model.PaymentKindPayout, @@ -239,7 +239,7 @@ func TestExecutePaymentPlan_RejectsLegacyLedgerOperations(t *testing.T) { PaymentRef: "pay-legacy-1", IdempotencyKey: "pay-legacy-1", OrganizationBoundBase: mo.OrganizationBoundBase{ - OrganizationRef: primitive.NewObjectID(), + OrganizationRef: bson.NewObjectID(), }, Intent: model.PaymentIntent{ Kind: model.PaymentKindPayout, diff --git a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_ledger.go b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_ledger.go index 347234f2..42e4edda 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_ledger.go +++ b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_ledger.go @@ -14,7 +14,7 @@ import ( connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1" ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -84,7 +84,7 @@ func (p *paymentExecutor) postLedgerMove(ctx context.Context, payment *model.Pay if payment == nil { return "", merrors.InvalidArgument("ledger: payment is required") } - if payment.OrganizationRef == primitive.NilObjectID { + if payment.OrganizationRef == bson.NilObjectID { return "", merrors.InvalidArgument("ledger: organization_ref is required") } if step == nil { @@ -156,7 +156,7 @@ func (p *paymentExecutor) postLedgerBlock(ctx context.Context, payment *model.Pa if payment == nil { return "", merrors.InvalidArgument("ledger: payment is required") } - if payment.OrganizationRef == primitive.NilObjectID { + if payment.OrganizationRef == bson.NilObjectID { return "", merrors.InvalidArgument("ledger: organization_ref is required") } if amount == nil || strings.TrimSpace(amount.GetAmount()) == "" || strings.TrimSpace(amount.GetCurrency()) == "" { @@ -214,7 +214,7 @@ func (p *paymentExecutor) postLedgerRelease(ctx context.Context, payment *model. if payment == nil { return "", merrors.InvalidArgument("ledger: payment is required") } - if payment.OrganizationRef == primitive.NilObjectID { + if payment.OrganizationRef == bson.NilObjectID { return "", merrors.InvalidArgument("ledger: organization_ref is required") } if amount == nil || strings.TrimSpace(amount.GetAmount()) == "" || strings.TrimSpace(amount.GetCurrency()) == "" { @@ -264,7 +264,7 @@ func (p *paymentExecutor) ledgerTxForAction(ctx context.Context, payment *model. if payment == nil { return rail.LedgerTx{}, merrors.InvalidArgument("ledger: payment is required") } - if payment.OrganizationRef == primitive.NilObjectID { + if payment.OrganizationRef == bson.NilObjectID { return rail.LedgerTx{}, merrors.InvalidArgument("ledger: organization_ref is required") } if amount == nil || strings.TrimSpace(amount.GetAmount()) == "" || strings.TrimSpace(amount.GetCurrency()) == "" { @@ -454,7 +454,7 @@ func ledgerRoleFromAccountRole(role pmodel.AccountRole) ledgerv1.AccountRole { return ledgerv1.AccountRole_ACCOUNT_ROLE_UNSPECIFIED } -func (p *paymentExecutor) resolveAccount(ctx context.Context, orgRef primitive.ObjectID, asset string, rail model.Rail, role pmodel.AccountRole) (string, error) { +func (p *paymentExecutor) resolveAccount(ctx context.Context, orgRef bson.ObjectID, asset string, rail model.Rail, role pmodel.AccountRole) (string, error) { switch rail { case model.RailLedger: return p.resolveLedgerAccountByRole(ctx, orgRef, asset, role) @@ -463,11 +463,11 @@ func (p *paymentExecutor) resolveAccount(ctx context.Context, orgRef primitive.O } } -func (p *paymentExecutor) resolveLedgerAccountByRole(ctx context.Context, orgRef primitive.ObjectID, asset string, role pmodel.AccountRole) (string, error) { +func (p *paymentExecutor) resolveLedgerAccountByRole(ctx context.Context, orgRef bson.ObjectID, asset string, role pmodel.AccountRole) (string, error) { if p == nil || p.deps == nil || p.deps.ledger.client == nil { return "", merrors.Internal("ledger_client_unavailable") } - if orgRef == primitive.NilObjectID { + if orgRef == bson.NilObjectID { return "", merrors.InvalidArgument("ledger: organization_ref is required") } currency := strings.TrimSpace(asset) @@ -544,7 +544,7 @@ func (p *paymentExecutor) resolveOrgOwnedLedgerAccount(ctx context.Context, paym if payment == nil { return "", merrors.InvalidArgument("ledger: payment is required") } - if payment.OrganizationRef == primitive.NilObjectID { + if payment.OrganizationRef == bson.NilObjectID { return "", merrors.InvalidArgument("ledger: organization_ref is required") } if amount == nil || strings.TrimSpace(amount.GetCurrency()) == "" { diff --git a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_ledger_test.go b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_ledger_test.go index 65ad0c2f..186a3e81 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_ledger_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_ledger_test.go @@ -11,7 +11,7 @@ import ( connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1" ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "google.golang.org/protobuf/types/known/structpb" ) @@ -90,7 +90,7 @@ func TestLedgerAccountResolution_UsesRoleAccounts(t *testing.T) { }, }, } - payment.OrganizationRef = primitive.NewObjectID() + payment.OrganizationRef = bson.NewObjectID() store := newStubPaymentsStore() store.payments[payment.PaymentRef] = payment diff --git a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_release_test.go b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_release_test.go index 9f19d70f..2fe5c9db 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_release_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_release_test.go @@ -9,7 +9,7 @@ import ( "github.com/tech/sendico/payments/orchestrator/storage/model" mo "github.com/tech/sendico/pkg/model" paymenttypes "github.com/tech/sendico/pkg/payments/types" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -38,7 +38,7 @@ func TestReleasePaymentHold_RejectsLegacyLedgerRelease(t *testing.T) { PaymentRef: "pay-release-1", IdempotencyKey: "pay-release-1", OrganizationBoundBase: mo.OrganizationBoundBase{ - OrganizationRef: primitive.NewObjectID(), + OrganizationRef: bson.NewObjectID(), }, Intent: model.PaymentIntent{ Kind: model.PaymentKindPayout, diff --git a/api/payments/orchestrator/internal/service/orchestrator/quote_payment_idempotency_integration_test.go b/api/payments/orchestrator/internal/service/orchestrator/quote_payment_idempotency_integration_test.go index 02c77dfb..bf631cc6 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/quote_payment_idempotency_integration_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/quote_payment_idempotency_integration_test.go @@ -9,19 +9,18 @@ import ( "testing" "time" - storagemongo "github.com/tech/sendico/payments/orchestrator/storage/mongo" "github.com/tech/sendico/payments/orchestrator/storage/model" + storagemongo "github.com/tech/sendico/payments/orchestrator/storage/mongo" "github.com/tech/sendico/pkg/db/repository" moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1" orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mongodb" "github.com/testcontainers/testcontainers-go/wait" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" - "go.mongodb.org/mongo-driver/mongo/readpref" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" + "go.mongodb.org/mongo-driver/v2/mongo/readpref" "go.uber.org/zap" ) @@ -80,7 +79,7 @@ func TestQuotePayment_IdempotencyReuseAfterExpiry(t *testing.T) { now := time.Now() svc := NewService(zap.NewNop(), store, WithClock(testClock{now: now})) - orgID := primitive.NewObjectID() + orgID := bson.NewObjectID() req := &orchestratorv1.QuotePaymentRequest{ Meta: &orchestratorv1.RequestMeta{OrganizationRef: orgID.Hex()}, IdempotencyKey: "idem-expired-quote", diff --git a/api/payments/orchestrator/internal/service/orchestrator/service_helpers.go b/api/payments/orchestrator/internal/service/orchestrator/service_helpers.go index 994a8d03..7808aa38 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/service_helpers.go +++ b/api/payments/orchestrator/internal/service/orchestrator/service_helpers.go @@ -12,21 +12,21 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/mservice" orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "google.golang.org/protobuf/proto" ) -func validateMetaAndOrgRef(meta *orchestratorv1.RequestMeta) (string, primitive.ObjectID, error) { +func validateMetaAndOrgRef(meta *orchestratorv1.RequestMeta) (string, bson.ObjectID, error) { if meta == nil { - return "", primitive.NilObjectID, merrors.InvalidArgument("meta is required") + return "", bson.NilObjectID, merrors.InvalidArgument("meta is required") } orgRef := strings.TrimSpace(meta.GetOrganizationRef()) if orgRef == "" { - return "", primitive.NilObjectID, merrors.InvalidArgument("organization_ref is required") + return "", bson.NilObjectID, merrors.InvalidArgument("organization_ref is required") } - orgID, err := primitive.ObjectIDFromHex(orgRef) + orgID, err := bson.ObjectIDFromHex(orgRef) if err != nil { - return "", primitive.NilObjectID, merrors.InvalidArgument("organization_ref must be a valid objectID") + return "", bson.NilObjectID, merrors.InvalidArgument("organization_ref must be a valid objectID") } return orgRef, orgID, nil } @@ -82,7 +82,7 @@ func ensureQuotesStore(repo storage.Repository) (storage.QuotesStore, error) { return store, nil } -func getPaymentByIdempotencyKey(ctx context.Context, store storage.PaymentsStore, orgID primitive.ObjectID, key string) (*model.Payment, error) { +func getPaymentByIdempotencyKey(ctx context.Context, store storage.PaymentsStore, orgID bson.ObjectID, key string) (*model.Payment, error) { payment, err := store.GetByIdempotencyKey(ctx, orgID, key) if err != nil { return nil, err @@ -92,7 +92,7 @@ func getPaymentByIdempotencyKey(ctx context.Context, store storage.PaymentsStore type quoteResolutionInput struct { OrgRef string - OrgID primitive.ObjectID + OrgID bson.ObjectID Meta *orchestratorv1.RequestMeta Intent *orchestratorv1.PaymentIntent QuoteRef string @@ -185,9 +185,9 @@ func recordQuoteFromQuote(record *model.PaymentQuoteRecord) (*orchestratorv1.Pay return nil, merrors.InvalidArgument("stored quote is empty") } -func newPayment(orgID primitive.ObjectID, intent *orchestratorv1.PaymentIntent, idempotencyKey string, metadata map[string]string, quote *orchestratorv1.PaymentQuote) *model.Payment { +func newPayment(orgID bson.ObjectID, intent *orchestratorv1.PaymentIntent, idempotencyKey string, metadata map[string]string, quote *orchestratorv1.PaymentQuote) *model.Payment { entity := &model.Payment{} - entity.SetID(primitive.NewObjectID()) + entity.SetID(bson.NewObjectID()) entity.SetOrganizationRef(orgID) entity.PaymentRef = entity.GetID().Hex() entity.IdempotencyKey = idempotencyKey diff --git a/api/payments/orchestrator/internal/service/orchestrator/service_helpers_test.go b/api/payments/orchestrator/internal/service/orchestrator/service_helpers_test.go index d00497be..6b6a766f 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/service_helpers_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/service_helpers_test.go @@ -16,12 +16,12 @@ import ( connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1" ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "google.golang.org/protobuf/types/known/structpb" ) func TestValidateMetaAndOrgRef(t *testing.T) { - org := primitive.NewObjectID() + org := bson.NewObjectID() meta := &orchestratorv1.RequestMeta{OrganizationRef: org.Hex()} ref, id, err := validateMetaAndOrgRef(meta) if err != nil { @@ -52,7 +52,7 @@ func TestRequireIdempotencyKey(t *testing.T) { } func TestNewPayment(t *testing.T) { - org := primitive.NewObjectID() + org := bson.NewObjectID() intent := &orchestratorv1.PaymentIntent{ Amount: &moneyv1.Money{Currency: "USD", Amount: "10"}, SettlementMode: orchestratorv1.SettlementMode_SETTLEMENT_FIX_RECEIVED, @@ -75,7 +75,7 @@ func TestNewPayment(t *testing.T) { } func TestResolvePaymentQuote_NotFound(t *testing.T) { - org := primitive.NewObjectID() + org := bson.NewObjectID() svc := &Service{ storage: stubRepo{quotes: &helperQuotesStore{}}, clock: clockpkg.NewSystem(), @@ -93,7 +93,7 @@ func TestResolvePaymentQuote_NotFound(t *testing.T) { } func TestResolvePaymentQuote_Expired(t *testing.T) { - org := primitive.NewObjectID() + org := bson.NewObjectID() intent := &orchestratorv1.PaymentIntent{Amount: &moneyv1.Money{Currency: "USD", Amount: "1"}, SettlementCurrency: "USD"} record := &model.PaymentQuoteRecord{ QuoteRef: "q1", @@ -118,7 +118,7 @@ func TestResolvePaymentQuote_Expired(t *testing.T) { } func TestResolvePaymentQuote_QuoteRefUsesStoredIntent(t *testing.T) { - org := primitive.NewObjectID() + org := bson.NewObjectID() intent := &orchestratorv1.PaymentIntent{Amount: &moneyv1.Money{Currency: "USD", Amount: "1"}, SettlementCurrency: "USD"} record := &model.PaymentQuoteRecord{ QuoteRef: "q1", @@ -147,7 +147,7 @@ func TestResolvePaymentQuote_QuoteRefUsesStoredIntent(t *testing.T) { } func TestResolvePaymentQuote_QuoteRefSkipsQuoteRecompute(t *testing.T) { - org := primitive.NewObjectID() + org := bson.NewObjectID() intent := &orchestratorv1.PaymentIntent{ Amount: &moneyv1.Money{Currency: "USD", Amount: "1"}, SettlementCurrency: "USD", @@ -193,7 +193,7 @@ func TestResolvePaymentQuote_QuoteRefSkipsQuoteRecompute(t *testing.T) { func TestInitiatePaymentIdempotency(t *testing.T) { logger := mloggerfactory.NewLogger(false) - org := primitive.NewObjectID() + org := bson.NewObjectID() store := newHelperPaymentStore() ledgerFake := &ledgerclient.Fake{ ListConnectorAccountsFn: func(ctx context.Context, req *connectorv1.ListAccountsRequest) (*connectorv1.ListAccountsResponse, error) { @@ -264,7 +264,7 @@ func TestInitiatePaymentIdempotency(t *testing.T) { func TestInitiatePaymentByQuoteRef(t *testing.T) { logger := mloggerfactory.NewLogger(false) - org := primitive.NewObjectID() + org := bson.NewObjectID() store := newHelperPaymentStore() intent := &orchestratorv1.PaymentIntent{ Source: &orchestratorv1.PaymentEndpoint{ @@ -411,7 +411,7 @@ func (s *helperPaymentStore) GetByPaymentRef(_ context.Context, ref string) (*mo return nil, storage.ErrPaymentNotFound } -func (s *helperPaymentStore) GetByIdempotencyKey(_ context.Context, _ primitive.ObjectID, key string) (*model.Payment, error) { +func (s *helperPaymentStore) GetByIdempotencyKey(_ context.Context, _ bson.ObjectID, key string) (*model.Payment, error) { if p, ok := s.byIdem[key]; ok { return p, nil } @@ -435,7 +435,7 @@ type helperQuotesStore struct { func (s *helperQuotesStore) Create(_ context.Context, _ *model.PaymentQuoteRecord) error { return nil } -func (s *helperQuotesStore) GetByRef(_ context.Context, _ primitive.ObjectID, ref string) (*model.PaymentQuoteRecord, error) { +func (s *helperQuotesStore) GetByRef(_ context.Context, _ bson.ObjectID, ref string) (*model.PaymentQuoteRecord, error) { if s.records == nil { return nil, storage.ErrQuoteNotFound } @@ -445,7 +445,7 @@ func (s *helperQuotesStore) GetByRef(_ context.Context, _ primitive.ObjectID, re return nil, storage.ErrQuoteNotFound } -func (s *helperQuotesStore) GetByIdempotencyKey(_ context.Context, orgRef primitive.ObjectID, ref string) (*model.PaymentQuoteRecord, error) { +func (s *helperQuotesStore) GetByIdempotencyKey(_ context.Context, orgRef bson.ObjectID, ref string) (*model.PaymentQuoteRecord, error) { if s.records == nil { return nil, storage.ErrQuoteNotFound } diff --git a/api/payments/orchestrator/internal/service/orchestrator/service_test.go b/api/payments/orchestrator/internal/service/orchestrator/service_test.go index 79d8f41e..d6ec6684 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/service_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/service_test.go @@ -20,7 +20,7 @@ import ( ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1" orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -51,7 +51,7 @@ func TestExecutePayment_FXConversionSettled(t *testing.T) { payment := &model.Payment{ PaymentRef: "fx-1", IdempotencyKey: "fx-1", - OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: primitive.NewObjectID()}, + OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: bson.NewObjectID()}, Intent: model.PaymentIntent{ Kind: model.PaymentKindFXConversion, Source: model.PaymentEndpoint{ @@ -154,7 +154,7 @@ func TestExecutePayment_ChainFailure(t *testing.T) { payment := &model.Payment{ PaymentRef: "chain-1", IdempotencyKey: "chain-1", - OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: primitive.NewObjectID()}, + OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: bson.NewObjectID()}, Intent: model.PaymentIntent{ Kind: model.PaymentKindPayout, Source: model.PaymentEndpoint{ @@ -413,7 +413,7 @@ func (s *stubQuotesStore) Create(ctx context.Context, quote *model.PaymentQuoteR return nil } -func (s *stubQuotesStore) GetByRef(ctx context.Context, orgRef primitive.ObjectID, quoteRef string) (*model.PaymentQuoteRecord, error) { +func (s *stubQuotesStore) GetByRef(ctx context.Context, orgRef bson.ObjectID, quoteRef string) (*model.PaymentQuoteRecord, error) { if s.quotes == nil { return nil, storage.ErrQuoteNotFound } @@ -423,7 +423,7 @@ func (s *stubQuotesStore) GetByRef(ctx context.Context, orgRef primitive.ObjectI return nil, storage.ErrQuoteNotFound } -func (s *stubQuotesStore) GetByIdempotencyKey(ctx context.Context, orgRef primitive.ObjectID, idempotencyKey string) (*model.PaymentQuoteRecord, error) { +func (s *stubQuotesStore) GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, idempotencyKey string) (*model.PaymentQuoteRecord, error) { if s.quotes == nil { return nil, storage.ErrQuoteNotFound } @@ -450,7 +450,7 @@ func (s *stubRoutesStore) Update(ctx context.Context, route *model.PaymentRoute) return merrors.InvalidArgument("routes store not implemented") } -func (s *stubRoutesStore) GetByID(ctx context.Context, id primitive.ObjectID) (*model.PaymentRoute, error) { +func (s *stubRoutesStore) GetByID(ctx context.Context, id bson.ObjectID) (*model.PaymentRoute, error) { return nil, storage.ErrRouteNotFound } @@ -493,7 +493,7 @@ func (s *stubPlanTemplatesStore) Update(ctx context.Context, template *model.Pay return merrors.InvalidArgument("plan templates store not implemented") } -func (s *stubPlanTemplatesStore) GetByID(ctx context.Context, id primitive.ObjectID) (*model.PaymentPlanTemplate, error) { +func (s *stubPlanTemplatesStore) GetByID(ctx context.Context, id bson.ObjectID) (*model.PaymentPlanTemplate, error) { return nil, storage.ErrPlanTemplateNotFound } @@ -562,7 +562,7 @@ func (s *stubPaymentsStore) GetByPaymentRef(ctx context.Context, paymentRef stri return nil, storage.ErrPaymentNotFound } -func (s *stubPaymentsStore) GetByIdempotencyKey(ctx context.Context, orgRef primitive.ObjectID, key string) (*model.Payment, error) { +func (s *stubPaymentsStore) GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, key string) (*model.Payment, error) { for _, p := range s.payments { if p.OrganizationRef == orgRef && strings.TrimSpace(p.IdempotencyKey) == key { return p, nil diff --git a/api/payments/orchestrator/storage/mongo/store/payments.go b/api/payments/orchestrator/storage/mongo/store/payments.go index a7ae4c31..63b190e6 100644 --- a/api/payments/orchestrator/storage/mongo/store/payments.go +++ b/api/payments/orchestrator/storage/mongo/store/payments.go @@ -12,8 +12,8 @@ import ( ri "github.com/tech/sendico/pkg/db/repository/index" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -86,7 +86,7 @@ func (p *Payments) Create(ctx context.Context, payment *model.Payment) error { if strings.TrimSpace(payment.IdempotencyKey) == "" { return merrors.InvalidArgument("paymentsStore: empty idempotencyKey") } - if payment.OrganizationRef == primitive.NilObjectID { + if payment.OrganizationRef == bson.NilObjectID { return merrors.InvalidArgument("paymentsStore: organization_ref is required") } @@ -138,9 +138,9 @@ func (p *Payments) GetByPaymentRef(ctx context.Context, paymentRef string) (*mod return entity, nil } -func (p *Payments) GetByIdempotencyKey(ctx context.Context, orgRef primitive.ObjectID, idempotencyKey string) (*model.Payment, error) { +func (p *Payments) GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, idempotencyKey string) (*model.Payment, error) { idempotencyKey = strings.TrimSpace(idempotencyKey) - if orgRef == primitive.NilObjectID { + if orgRef == bson.NilObjectID { return nil, merrors.InvalidArgument("paymentsStore: organization_ref is required") } if idempotencyKey == "" { @@ -208,7 +208,7 @@ func (p *Payments) List(ctx context.Context, filter *model.PaymentFilter) (*mode } if cursor := strings.TrimSpace(filter.Cursor); cursor != "" { - if oid, err := primitive.ObjectIDFromHex(cursor); err == nil { + if oid, err := bson.ObjectIDFromHex(cursor); err == nil { query = query.Comparison(repository.IDField(), builder.Gt, oid) } else { p.logger.Warn("ignoring invalid payments cursor", zap.String("cursor", cursor), zap.Error(err)) diff --git a/api/payments/orchestrator/storage/mongo/store/plan_templates.go b/api/payments/orchestrator/storage/mongo/store/plan_templates.go index 84cc0283..6f058e9c 100644 --- a/api/payments/orchestrator/storage/mongo/store/plan_templates.go +++ b/api/payments/orchestrator/storage/mongo/store/plan_templates.go @@ -11,8 +11,8 @@ import ( ri "github.com/tech/sendico/pkg/db/repository/index" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -75,7 +75,7 @@ func (p *PlanTemplates) Create(ctx context.Context, template *model.PaymentPlanT return merrors.InvalidArgument("planTemplatesStore: steps are required") } if template.ID.IsZero() { - template.SetID(primitive.NewObjectID()) + template.SetID(bson.NewObjectID()) } else { template.Update() } @@ -112,8 +112,8 @@ func (p *PlanTemplates) Update(ctx context.Context, template *model.PaymentPlanT return nil } -func (p *PlanTemplates) GetByID(ctx context.Context, id primitive.ObjectID) (*model.PaymentPlanTemplate, error) { - if id == primitive.NilObjectID { +func (p *PlanTemplates) GetByID(ctx context.Context, id bson.ObjectID) (*model.PaymentPlanTemplate, error) { + if id == bson.NilObjectID { return nil, merrors.InvalidArgument("planTemplatesStore: template id is required") } entity := &model.PaymentPlanTemplate{} diff --git a/api/payments/orchestrator/storage/mongo/store/quotes.go b/api/payments/orchestrator/storage/mongo/store/quotes.go index aca865df..b0ea1676 100644 --- a/api/payments/orchestrator/storage/mongo/store/quotes.go +++ b/api/payments/orchestrator/storage/mongo/store/quotes.go @@ -14,7 +14,7 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -83,7 +83,7 @@ func (q *Quotes) Create(ctx context.Context, quote *model.PaymentQuoteRecord) er if quote.QuoteRef == "" { return merrors.InvalidArgument("quotesStore: empty quoteRef") } - if quote.OrganizationRef == primitive.NilObjectID { + if quote.OrganizationRef == bson.NilObjectID { return merrors.InvalidArgument("quotesStore: organization_ref is required") } quote.IdempotencyKey = strings.TrimSpace(quote.IdempotencyKey) @@ -127,12 +127,12 @@ func (q *Quotes) Create(ctx context.Context, quote *model.PaymentQuoteRecord) er return nil } -func (q *Quotes) GetByRef(ctx context.Context, orgRef primitive.ObjectID, quoteRef string) (*model.PaymentQuoteRecord, error) { +func (q *Quotes) GetByRef(ctx context.Context, orgRef bson.ObjectID, quoteRef string) (*model.PaymentQuoteRecord, error) { quoteRef = strings.TrimSpace(quoteRef) if quoteRef == "" { return nil, merrors.InvalidArgument("quotesStore: empty quoteRef") } - if orgRef == primitive.NilObjectID { + if orgRef == bson.NilObjectID { return nil, merrors.InvalidArgument("quotesStore: organization_ref is required") } entity := &model.PaymentQuoteRecord{} @@ -152,12 +152,12 @@ func (q *Quotes) GetByRef(ctx context.Context, orgRef primitive.ObjectID, quoteR return entity, nil } -func (q *Quotes) GetByIdempotencyKey(ctx context.Context, orgRef primitive.ObjectID, idempotencyKey string) (*model.PaymentQuoteRecord, error) { +func (q *Quotes) GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, idempotencyKey string) (*model.PaymentQuoteRecord, error) { idempotencyKey = strings.TrimSpace(idempotencyKey) if idempotencyKey == "" { return nil, merrors.InvalidArgument("quotesStore: empty idempotency key") } - if orgRef == primitive.NilObjectID { + if orgRef == bson.NilObjectID { return nil, merrors.InvalidArgument("quotesStore: organization_ref is required") } entity := &model.PaymentQuoteRecord{} diff --git a/api/payments/orchestrator/storage/mongo/store/routes.go b/api/payments/orchestrator/storage/mongo/store/routes.go index e66c5338..552622bc 100644 --- a/api/payments/orchestrator/storage/mongo/store/routes.go +++ b/api/payments/orchestrator/storage/mongo/store/routes.go @@ -11,8 +11,8 @@ import ( ri "github.com/tech/sendico/pkg/db/repository/index" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -72,7 +72,7 @@ func (r *Routes) Create(ctx context.Context, route *model.PaymentRoute) error { return merrors.InvalidArgument("routesStore: to_rail is required") } if route.ID.IsZero() { - route.SetID(primitive.NewObjectID()) + route.SetID(bson.NewObjectID()) } else { route.Update() } @@ -109,8 +109,8 @@ func (r *Routes) Update(ctx context.Context, route *model.PaymentRoute) error { return nil } -func (r *Routes) GetByID(ctx context.Context, id primitive.ObjectID) (*model.PaymentRoute, error) { - if id == primitive.NilObjectID { +func (r *Routes) GetByID(ctx context.Context, id bson.ObjectID) (*model.PaymentRoute, error) { + if id == bson.NilObjectID { return nil, merrors.InvalidArgument("routesStore: route id is required") } entity := &model.PaymentRoute{} diff --git a/api/payments/orchestrator/storage/storage.go b/api/payments/orchestrator/storage/storage.go index 5b05576c..a64b94cb 100644 --- a/api/payments/orchestrator/storage/storage.go +++ b/api/payments/orchestrator/storage/storage.go @@ -4,7 +4,7 @@ import ( "context" "github.com/tech/sendico/payments/orchestrator/storage/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type storageError string @@ -46,7 +46,7 @@ type PaymentsStore interface { Create(ctx context.Context, payment *model.Payment) error Update(ctx context.Context, payment *model.Payment) error GetByPaymentRef(ctx context.Context, paymentRef string) (*model.Payment, error) - GetByIdempotencyKey(ctx context.Context, orgRef primitive.ObjectID, idempotencyKey string) (*model.Payment, error) + GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, idempotencyKey string) (*model.Payment, error) GetByChainTransferRef(ctx context.Context, transferRef string) (*model.Payment, error) List(ctx context.Context, filter *model.PaymentFilter) (*model.PaymentList, error) } @@ -54,15 +54,15 @@ type PaymentsStore interface { // QuotesStore manages temporary stored payment quotes. type QuotesStore interface { Create(ctx context.Context, quote *model.PaymentQuoteRecord) error - GetByRef(ctx context.Context, orgRef primitive.ObjectID, quoteRef string) (*model.PaymentQuoteRecord, error) - GetByIdempotencyKey(ctx context.Context, orgRef primitive.ObjectID, idempotencyKey string) (*model.PaymentQuoteRecord, error) + GetByRef(ctx context.Context, orgRef bson.ObjectID, quoteRef string) (*model.PaymentQuoteRecord, error) + GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, idempotencyKey string) (*model.PaymentQuoteRecord, error) } // RoutesStore manages allowed routing transitions. type RoutesStore interface { Create(ctx context.Context, route *model.PaymentRoute) error Update(ctx context.Context, route *model.PaymentRoute) error - GetByID(ctx context.Context, id primitive.ObjectID) (*model.PaymentRoute, error) + GetByID(ctx context.Context, id bson.ObjectID) (*model.PaymentRoute, error) List(ctx context.Context, filter *model.PaymentRouteFilter) (*model.PaymentRouteList, error) } @@ -70,6 +70,6 @@ type RoutesStore interface { type PlanTemplatesStore interface { Create(ctx context.Context, template *model.PaymentPlanTemplate) error Update(ctx context.Context, template *model.PaymentPlanTemplate) error - GetByID(ctx context.Context, id primitive.ObjectID) (*model.PaymentPlanTemplate, error) + GetByID(ctx context.Context, id bson.ObjectID) (*model.PaymentPlanTemplate, error) List(ctx context.Context, filter *model.PaymentPlanTemplateFilter) (*model.PaymentPlanTemplateList, error) } diff --git a/api/pkg/api/routers/gsresponse/response_test.go b/api/pkg/api/routers/gsresponse/response_test.go index 852f666b..8e5b7f64 100644 --- a/api/pkg/api/routers/gsresponse/response_test.go +++ b/api/pkg/api/routers/gsresponse/response_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -49,7 +49,7 @@ func TestAutoMappings(t *testing.T) { code codes.Code }{ {"invalid_argument", merrors.InvalidArgument("bad"), codes.InvalidArgument}, - {"access_denied", merrors.AccessDenied("object", "action", primitive.NilObjectID), codes.PermissionDenied}, + {"access_denied", merrors.AccessDenied("object", "action", bson.NilObjectID), codes.PermissionDenied}, {"not_found", merrors.NoData("missing"), codes.NotFound}, {"unauthorized", fmt.Errorf("%w: %s", merrors.ErrUnauthorized, "bad"), codes.Unauthenticated}, {"conflict", merrors.DataConflict("conflict"), codes.Aborted}, diff --git a/api/pkg/auth/USAGE.md b/api/pkg/auth/USAGE.md index aab79aeb..23d799c6 100644 --- a/api/pkg/auth/USAGE.md +++ b/api/pkg/auth/USAGE.md @@ -162,7 +162,7 @@ if err != nil { mockEnforcer := &MockEnforcer{} // Grant all permissions -permissions := map[primitive.ObjectID]bool{ +permissions := map[bson.ObjectID]bool{ objectID1: true, objectID2: true, } diff --git a/api/pkg/auth/archivable.go b/api/pkg/auth/archivable.go index e099fec8..e770edc4 100644 --- a/api/pkg/auth/archivable.go +++ b/api/pkg/auth/archivable.go @@ -6,21 +6,21 @@ import ( "github.com/tech/sendico/pkg/db/template" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // ArchivableDB implements archive operations with permission checking type ArchivableDB[T model.PermissionBoundStorable] interface { // SetArchived sets the archived status of an entity with permission checking - SetArchived(ctx context.Context, accountRef, objectRef primitive.ObjectID, archived bool) error + SetArchived(ctx context.Context, accountRef, objectRef bson.ObjectID, archived bool) error // IsArchived checks if an entity is archived with permission checking - IsArchived(ctx context.Context, accountRef, objectRef primitive.ObjectID) (bool, error) + IsArchived(ctx context.Context, accountRef, objectRef bson.ObjectID) (bool, error) // Archive archives an entity with permission checking (sets archived to true) - Archive(ctx context.Context, accountRef, objectRef primitive.ObjectID) error + Archive(ctx context.Context, accountRef, objectRef bson.ObjectID) error // Unarchive unarchives an entity with permission checking (sets archived to false) - Unarchive(ctx context.Context, accountRef, objectRef primitive.ObjectID) error + Unarchive(ctx context.Context, accountRef, objectRef bson.ObjectID) error } // NewArchivableDB creates a new auth.ArchivableDB instance diff --git a/api/pkg/auth/archivableimp.go b/api/pkg/auth/archivableimp.go index 114e2cad..c2a2f3e2 100644 --- a/api/pkg/auth/archivableimp.go +++ b/api/pkg/auth/archivableimp.go @@ -9,7 +9,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -40,7 +40,7 @@ func newArchivableDBImp[T model.PermissionBoundStorable]( } // SetArchived sets the archived status of an entity with permission checking -func (db *ArchivableDBImp[T]) SetArchived(ctx context.Context, accountRef, objectRef primitive.ObjectID, archived bool) error { +func (db *ArchivableDBImp[T]) SetArchived(ctx context.Context, accountRef, objectRef bson.ObjectID, archived bool) error { // Check permissions using enforceObject helper if err := enforceObjectByRef(ctx, db.dbImp, db.enforcer, model.ActionUpdate, accountRef, objectRef); err != nil { db.logger.Warn("Failed to enforce object permission", zap.Error(err), @@ -79,7 +79,7 @@ func (db *ArchivableDBImp[T]) SetArchived(ctx context.Context, accountRef, objec } // IsArchived checks if an entity is archived with permission checking -func (db *ArchivableDBImp[T]) IsArchived(ctx context.Context, accountRef, objectRef primitive.ObjectID) (bool, error) { +func (db *ArchivableDBImp[T]) IsArchived(ctx context.Context, accountRef, objectRef bson.ObjectID) (bool, error) { // // Check permissions using single Enforce if err := enforceObjectByRef(ctx, db.dbImp, db.enforcer, model.ActionRead, accountRef, objectRef); err != nil { db.logger.Debug("Permission denied for checking archived status", mzap.ObjRef("account_ref", accountRef), @@ -97,11 +97,11 @@ func (db *ArchivableDBImp[T]) IsArchived(ctx context.Context, accountRef, object } // Archive archives an entity with permission checking (sets archived to true) -func (db *ArchivableDBImp[T]) Archive(ctx context.Context, accountRef, objectRef primitive.ObjectID) error { +func (db *ArchivableDBImp[T]) Archive(ctx context.Context, accountRef, objectRef bson.ObjectID) error { return db.SetArchived(ctx, accountRef, objectRef, true) } // Unarchive unarchives an entity with permission checking (sets archived to false) -func (db *ArchivableDBImp[T]) Unarchive(ctx context.Context, accountRef, objectRef primitive.ObjectID) error { +func (db *ArchivableDBImp[T]) Unarchive(ctx context.Context, accountRef, objectRef bson.ObjectID) error { return db.SetArchived(ctx, accountRef, objectRef, false) } diff --git a/api/pkg/auth/db.go b/api/pkg/auth/db.go index a6667c6e..9ccd3fd3 100644 --- a/api/pkg/auth/db.go +++ b/api/pkg/auth/db.go @@ -9,21 +9,21 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" ) type ProtectedDB[T model.PermissionBoundStorable] interface { - Create(ctx context.Context, accountRef, organizationRef primitive.ObjectID, object T) error - InsertMany(ctx context.Context, accountRef, organizationRef primitive.ObjectID, objects []T) error - Get(ctx context.Context, accountRef, objectRef primitive.ObjectID, result T) error - Update(ctx context.Context, accountRef primitive.ObjectID, object T) error - Delete(ctx context.Context, accountRef, objectRef primitive.ObjectID) error - DeleteCascadeAuth(ctx context.Context, accountRef, objectRef primitive.ObjectID) error - Patch(ctx context.Context, accountRef, objectRef primitive.ObjectID, patch builder.Patch) error - PatchMany(ctx context.Context, accountRef primitive.ObjectID, query builder.Query, patch builder.Patch) (int, error) + Create(ctx context.Context, accountRef, organizationRef bson.ObjectID, object T) error + InsertMany(ctx context.Context, accountRef, organizationRef bson.ObjectID, objects []T) error + Get(ctx context.Context, accountRef, objectRef bson.ObjectID, result T) error + Update(ctx context.Context, accountRef bson.ObjectID, object T) error + Delete(ctx context.Context, accountRef, objectRef bson.ObjectID) error + DeleteCascadeAuth(ctx context.Context, accountRef, objectRef bson.ObjectID) error + Patch(ctx context.Context, accountRef, objectRef bson.ObjectID, patch builder.Patch) error + PatchMany(ctx context.Context, accountRef bson.ObjectID, query builder.Query, patch builder.Patch) (int, error) Unprotected() template.DB[T] - ListIDs(ctx context.Context, action model.Action, accountRef primitive.ObjectID, query builder.Query) ([]primitive.ObjectID, error) + ListIDs(ctx context.Context, action model.Action, accountRef bson.ObjectID, query builder.Query) ([]bson.ObjectID, error) } func CreateDB[T model.PermissionBoundStorable]( diff --git a/api/pkg/auth/dbab.go b/api/pkg/auth/dbab.go index a72a4eab..b8fa72ab 100644 --- a/api/pkg/auth/dbab.go +++ b/api/pkg/auth/dbab.go @@ -9,21 +9,21 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) type AccountBoundDB[T model.AccountBoundStorable] interface { - Create(ctx context.Context, accountRef primitive.ObjectID, object T) error - Get(ctx context.Context, accountRef, objectRef primitive.ObjectID, result T) error - Update(ctx context.Context, accountRef primitive.ObjectID, object T) error - Patch(ctx context.Context, accountRef, objectRef primitive.ObjectID, patch builder.Patch) error - Delete(ctx context.Context, accountRef, objectRef primitive.ObjectID) error - DeleteMany(ctx context.Context, accountRef primitive.ObjectID, query builder.Query) error - FindOne(ctx context.Context, accountRef primitive.ObjectID, query builder.Query, result T) error - ListIDs(ctx context.Context, accountRef primitive.ObjectID, query builder.Query) ([]primitive.ObjectID, error) - ListAccountBound(ctx context.Context, accountRef, organizationRef primitive.ObjectID, query builder.Query) ([]model.AccountBoundStorable, error) + Create(ctx context.Context, accountRef bson.ObjectID, object T) error + Get(ctx context.Context, accountRef, objectRef bson.ObjectID, result T) error + Update(ctx context.Context, accountRef bson.ObjectID, object T) error + Patch(ctx context.Context, accountRef, objectRef bson.ObjectID, patch builder.Patch) error + Delete(ctx context.Context, accountRef, objectRef bson.ObjectID) error + DeleteMany(ctx context.Context, accountRef bson.ObjectID, query builder.Query) error + FindOne(ctx context.Context, accountRef bson.ObjectID, query builder.Query, result T) error + ListIDs(ctx context.Context, accountRef bson.ObjectID, query builder.Query) ([]bson.ObjectID, error) + ListAccountBound(ctx context.Context, accountRef, organizationRef bson.ObjectID, query builder.Query) ([]model.AccountBoundStorable, error) } func CreateAccountBound[T model.AccountBoundStorable]( diff --git a/api/pkg/auth/dbimp.go b/api/pkg/auth/dbimp.go index 40e9c2ae..a9e4b132 100644 --- a/api/pkg/auth/dbimp.go +++ b/api/pkg/auth/dbimp.go @@ -16,19 +16,19 @@ import ( "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) type ProtectedDBImp[T model.PermissionBoundStorable] struct { DBImp *template.DBImp[T] Enforcer Enforcer - PermissionRef primitive.ObjectID + PermissionRef bson.ObjectID Collection mservice.Type } -func (db *ProtectedDBImp[T]) enforce(ctx context.Context, action model.Action, object model.PermissionBoundStorable, accountRef, objectRef primitive.ObjectID) error { +func (db *ProtectedDBImp[T]) enforce(ctx context.Context, action model.Action, object model.PermissionBoundStorable, accountRef, objectRef bson.ObjectID) error { res, err := db.Enforcer.Enforce(ctx, object.GetPermissionRef(), accountRef, object.GetOrganizationRef(), objectRef, action) if err != nil { db.DBImp.Logger.Warn("Failed to enforce permission", @@ -46,16 +46,16 @@ func (db *ProtectedDBImp[T]) enforce(ctx context.Context, action model.Action, o return nil } -func (db *ProtectedDBImp[T]) Create(ctx context.Context, accountRef, organizationRef primitive.ObjectID, object T) error { +func (db *ProtectedDBImp[T]) Create(ctx context.Context, accountRef, organizationRef bson.ObjectID, object T) error { db.DBImp.Logger.Debug("Attempting to create object", mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("organization_ref", organizationRef), zap.String("collection", string(db.Collection))) - if object.GetPermissionRef() == primitive.NilObjectID { + if object.GetPermissionRef() == bson.NilObjectID { object.SetPermissionRef(db.PermissionRef) } object.SetOrganizationRef(organizationRef) - if err := db.enforce(ctx, model.ActionCreate, object, accountRef, primitive.NilObjectID); err != nil { + if err := db.enforce(ctx, model.ActionCreate, object, accountRef, bson.NilObjectID); err != nil { return err } @@ -70,7 +70,7 @@ func (db *ProtectedDBImp[T]) Create(ctx context.Context, accountRef, organizatio return nil } -func (db *ProtectedDBImp[T]) InsertMany(ctx context.Context, accountRef, organizationRef primitive.ObjectID, objects []T) error { +func (db *ProtectedDBImp[T]) InsertMany(ctx context.Context, accountRef, organizationRef bson.ObjectID, objects []T) error { if len(objects) == 0 { return nil } @@ -81,12 +81,12 @@ func (db *ProtectedDBImp[T]) InsertMany(ctx context.Context, accountRef, organiz // Set permission and organization refs for all objects and enforce permissions for _, object := range objects { - if object.GetPermissionRef() == primitive.NilObjectID { + if object.GetPermissionRef() == bson.NilObjectID { object.SetPermissionRef(db.PermissionRef) } object.SetOrganizationRef(organizationRef) - if err := db.enforce(ctx, model.ActionCreate, object, accountRef, primitive.NilObjectID); err != nil { + if err := db.enforce(ctx, model.ActionCreate, object, accountRef, bson.NilObjectID); err != nil { return err } } @@ -104,7 +104,7 @@ func (db *ProtectedDBImp[T]) InsertMany(ctx context.Context, accountRef, organiz return nil } -func (db *ProtectedDBImp[T]) enforceObject(ctx context.Context, action model.Action, accountRef, objectRef primitive.ObjectID) error { +func (db *ProtectedDBImp[T]) enforceObject(ctx context.Context, action model.Action, accountRef, objectRef bson.ObjectID) error { l, err := db.ListIDs(ctx, action, accountRef, repository.IDFilter(objectRef)) if err != nil { db.DBImp.Logger.Warn("Error occured while checking access rights", zap.Error(err), @@ -118,7 +118,7 @@ func (db *ProtectedDBImp[T]) enforceObject(ctx context.Context, action model.Act return nil } -func (db *ProtectedDBImp[T]) Get(ctx context.Context, accountRef, objectRef primitive.ObjectID, result T) error { +func (db *ProtectedDBImp[T]) Get(ctx context.Context, accountRef, objectRef bson.ObjectID, result T) error { db.DBImp.Logger.Debug("Attempting to get object", mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("object_ref", objectRef)) if err := db.enforceObject(ctx, model.ActionRead, accountRef, objectRef); err != nil { @@ -137,7 +137,7 @@ func (db *ProtectedDBImp[T]) Get(ctx context.Context, accountRef, objectRef prim return nil } -func (db *ProtectedDBImp[T]) Update(ctx context.Context, accountRef primitive.ObjectID, object T) error { +func (db *ProtectedDBImp[T]) Update(ctx context.Context, accountRef bson.ObjectID, object T) error { db.DBImp.Logger.Debug("Attempting to update object", mzap.ObjRef("account_ref", accountRef), mzap.StorableRef(object)) if err := db.enforceObject(ctx, model.ActionUpdate, accountRef, *object.GetID()); err != nil { @@ -156,7 +156,7 @@ func (db *ProtectedDBImp[T]) Update(ctx context.Context, accountRef primitive.Ob return nil } -func (db *ProtectedDBImp[T]) Delete(ctx context.Context, accountRef, objectRef primitive.ObjectID) error { +func (db *ProtectedDBImp[T]) Delete(ctx context.Context, accountRef, objectRef bson.ObjectID) error { db.DBImp.Logger.Debug("Attempting to delete object", mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("object_ref", objectRef)) @@ -178,9 +178,9 @@ func (db *ProtectedDBImp[T]) Delete(ctx context.Context, accountRef, objectRef p func (db *ProtectedDBImp[T]) ListIDs( ctx context.Context, action model.Action, - accountRef primitive.ObjectID, + accountRef bson.ObjectID, query builder.Query, -) ([]primitive.ObjectID, error) { +) ([]bson.ObjectID, error) { db.DBImp.Logger.Debug("Attempting to list object IDs", mzap.ObjRef("account_ref", accountRef), zap.String("collection", string(db.Collection)), zap.Any("filter", query.BuildQuery())) @@ -194,11 +194,11 @@ func (db *ProtectedDBImp[T]) ListIDs( if len(allIDs) == 0 { db.DBImp.Logger.Debug("No objects found matching filter", mzap.ObjRef("account_ref", accountRef), zap.String("collection", string(db.Collection)), zap.Any("filter", query.BuildQuery())) - return []primitive.ObjectID{}, merrors.NoData(fmt.Sprintf("no %s found", db.Collection)) + return []bson.ObjectID{}, merrors.NoData(fmt.Sprintf("no %s found", db.Collection)) } // 2. Check read permission for each ID - var allowedIDs []primitive.ObjectID + var allowedIDs []bson.ObjectID for _, desc := range allIDs { enforceErr := db.enforce(ctx, action, desc, accountRef, *desc.GetID()) if enforceErr == nil { @@ -227,7 +227,7 @@ func (db *ProtectedDBImp[T]) Unprotected() template.DB[T] { return db.DBImp } -func (db *ProtectedDBImp[T]) DeleteCascadeAuth(ctx context.Context, accountRef, objectRef primitive.ObjectID) error { +func (db *ProtectedDBImp[T]) DeleteCascadeAuth(ctx context.Context, accountRef, objectRef bson.ObjectID) error { if err := db.enforceObject(ctx, model.ActionDelete, accountRef, objectRef); err != nil { return err } @@ -268,7 +268,7 @@ func CreateDBImp[T model.PermissionBoundStorable]( return p, nil } -func (db *ProtectedDBImp[T]) Patch(ctx context.Context, accountRef, objectRef primitive.ObjectID, patch builder.Patch) error { +func (db *ProtectedDBImp[T]) Patch(ctx context.Context, accountRef, objectRef bson.ObjectID, patch builder.Patch) error { db.DBImp.Logger.Debug("Attempting to patch object", mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("object_ref", objectRef)) @@ -287,7 +287,7 @@ func (db *ProtectedDBImp[T]) Patch(ctx context.Context, accountRef, objectRef pr return nil } -func (db *ProtectedDBImp[T]) PatchMany(ctx context.Context, accountRef primitive.ObjectID, query builder.Query, patch builder.Patch) (int, error) { +func (db *ProtectedDBImp[T]) PatchMany(ctx context.Context, accountRef bson.ObjectID, query builder.Query, patch builder.Patch) (int, error) { db.DBImp.Logger.Debug("Attempting to patch many objects", mzap.ObjRef("account_ref", accountRef), zap.Any("filter", query.BuildQuery())) diff --git a/api/pkg/auth/dbimpab.go b/api/pkg/auth/dbimpab.go index 44f64892..418b61a2 100644 --- a/api/pkg/auth/dbimpab.go +++ b/api/pkg/auth/dbimpab.go @@ -13,8 +13,8 @@ import ( "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -22,11 +22,11 @@ type AccountBoundDBImp[T model.AccountBoundStorable] struct { Logger mlogger.Logger DBImp *template.DBImp[T] Enforcer Enforcer - PermissionRef primitive.ObjectID + PermissionRef bson.ObjectID Collection mservice.Type } -func (db *AccountBoundDBImp[T]) enforce(ctx context.Context, action model.Action, object model.AccountBoundStorable, accountRef primitive.ObjectID) error { +func (db *AccountBoundDBImp[T]) enforce(ctx context.Context, action model.Action, object model.AccountBoundStorable, accountRef bson.ObjectID) error { // FIRST: Check if the object's AccountRef equals the calling accountRef - if so, ALLOW objectAccountRef := object.GetAccountRef() if objectAccountRef != nil && *objectAccountRef == accountRef { @@ -51,12 +51,12 @@ func (db *AccountBoundDBImp[T]) enforce(ctx context.Context, action model.Action db.Logger.Debug("Access denied", mzap.ObjRef("permission_ref", db.PermissionRef), mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("organization_ref", organizationRef), zap.String("action", string(action))) - return merrors.AccessDenied(db.Collection, string(action), primitive.NilObjectID) + return merrors.AccessDenied(db.Collection, string(action), bson.NilObjectID) } return nil } -func (db *AccountBoundDBImp[T]) enforceInterface(ctx context.Context, action model.Action, object model.AccountBoundStorable, accountRef primitive.ObjectID) error { +func (db *AccountBoundDBImp[T]) enforceInterface(ctx context.Context, action model.Action, object model.AccountBoundStorable, accountRef bson.ObjectID) error { // FIRST: Check if the object's AccountRef equals the calling accountRef - if so, ALLOW objectAccountRef := object.GetAccountRef() if objectAccountRef != nil && *objectAccountRef == accountRef { @@ -81,12 +81,12 @@ func (db *AccountBoundDBImp[T]) enforceInterface(ctx context.Context, action mod db.Logger.Debug("Access denied", mzap.ObjRef("permission_ref", db.PermissionRef), mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("organization_ref", organizationRef), zap.String("action", string(action))) - return merrors.AccessDenied(db.Collection, string(action), primitive.NilObjectID) + return merrors.AccessDenied(db.Collection, string(action), bson.NilObjectID) } return nil } -func (db *AccountBoundDBImp[T]) Create(ctx context.Context, accountRef primitive.ObjectID, object T) error { +func (db *AccountBoundDBImp[T]) Create(ctx context.Context, accountRef bson.ObjectID, object T) error { orgRef := object.GetOrganizationRef() db.Logger.Debug("Attempting to create object", mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("organization_ref", orgRef), zap.String("collection", string(db.Collection))) @@ -107,7 +107,7 @@ func (db *AccountBoundDBImp[T]) Create(ctx context.Context, accountRef primitive return nil } -func (db *AccountBoundDBImp[T]) Get(ctx context.Context, accountRef, objectRef primitive.ObjectID, result T) error { +func (db *AccountBoundDBImp[T]) Get(ctx context.Context, accountRef, objectRef bson.ObjectID, result T) error { db.Logger.Debug("Attempting to get object", mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("object_ref", objectRef)) // First get the object to check its organization @@ -127,7 +127,7 @@ func (db *AccountBoundDBImp[T]) Get(ctx context.Context, accountRef, objectRef p return nil } -func (db *AccountBoundDBImp[T]) Update(ctx context.Context, accountRef primitive.ObjectID, object T) error { +func (db *AccountBoundDBImp[T]) Update(ctx context.Context, accountRef bson.ObjectID, object T) error { db.Logger.Debug("Attempting to update object", mzap.ObjRef("account_ref", accountRef), mzap.StorableRef(object)) // Check organization update permission @@ -146,7 +146,7 @@ func (db *AccountBoundDBImp[T]) Update(ctx context.Context, accountRef primitive return nil } -func (db *AccountBoundDBImp[T]) Patch(ctx context.Context, accountRef, objectRef primitive.ObjectID, patch builder.Patch) error { +func (db *AccountBoundDBImp[T]) Patch(ctx context.Context, accountRef, objectRef bson.ObjectID, patch builder.Patch) error { db.Logger.Debug("Attempting to patch object", mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("object_ref", objectRef)) // First get the object to check its organization @@ -175,7 +175,7 @@ func (db *AccountBoundDBImp[T]) Patch(ctx context.Context, accountRef, objectRef return nil } -func (db *AccountBoundDBImp[T]) Delete(ctx context.Context, accountRef, objectRef primitive.ObjectID) error { +func (db *AccountBoundDBImp[T]) Delete(ctx context.Context, accountRef, objectRef bson.ObjectID) error { db.Logger.Debug("Attempting to delete object", mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("object_ref", objectRef)) // First get the object to check its organization @@ -203,7 +203,7 @@ func (db *AccountBoundDBImp[T]) Delete(ctx context.Context, accountRef, objectRe return nil } -func (db *AccountBoundDBImp[T]) DeleteMany(ctx context.Context, accountRef primitive.ObjectID, query builder.Query) error { +func (db *AccountBoundDBImp[T]) DeleteMany(ctx context.Context, accountRef bson.ObjectID, query builder.Query) error { db.Logger.Debug("Attempting to delete many objects", mzap.ObjRef("account_ref", accountRef), zap.String("collection", string(db.Collection))) // Get all candidate objects for batch permission checking @@ -221,7 +221,7 @@ func (db *AccountBoundDBImp[T]) DeleteMany(ctx context.Context, accountRef primi } // Build query for objects that passed permission check - var allowedIDs []primitive.ObjectID + var allowedIDs []bson.ObjectID for _, obj := range allObjects { if allowedResults[*obj.GetID()] { allowedIDs = append(allowedIDs, *obj.GetID()) @@ -244,7 +244,7 @@ func (db *AccountBoundDBImp[T]) DeleteMany(ctx context.Context, accountRef primi return nil } -func (db *AccountBoundDBImp[T]) FindOne(ctx context.Context, accountRef primitive.ObjectID, query builder.Query, result T) error { +func (db *AccountBoundDBImp[T]) FindOne(ctx context.Context, accountRef bson.ObjectID, query builder.Query, result T) error { db.Logger.Debug("Attempting to find one object", mzap.ObjRef("account_ref", accountRef), zap.String("collection", string(db.Collection))) // For FindOne, we need to check read permission after finding the object @@ -263,7 +263,7 @@ func (db *AccountBoundDBImp[T]) FindOne(ctx context.Context, accountRef primitiv return nil } -func (db *AccountBoundDBImp[T]) ListIDs(ctx context.Context, accountRef primitive.ObjectID, query builder.Query) ([]primitive.ObjectID, error) { +func (db *AccountBoundDBImp[T]) ListIDs(ctx context.Context, accountRef bson.ObjectID, query builder.Query) ([]bson.ObjectID, error) { db.Logger.Debug("Attempting to list object IDs", mzap.ObjRef("account_ref", accountRef), zap.String("collection", string(db.Collection))) // Get all candidate objects for batch permission checking @@ -281,7 +281,7 @@ func (db *AccountBoundDBImp[T]) ListIDs(ctx context.Context, accountRef primitiv } // Filter to only allowed object IDs - var allowedIDs []primitive.ObjectID + var allowedIDs []bson.ObjectID for _, obj := range allObjects { if allowedResults[*obj.GetID()] { allowedIDs = append(allowedIDs, *obj.GetID()) @@ -293,7 +293,7 @@ func (db *AccountBoundDBImp[T]) ListIDs(ctx context.Context, accountRef primitiv return allowedIDs, nil } -func (db *AccountBoundDBImp[T]) ListAccountBound(ctx context.Context, accountRef, organizationRef primitive.ObjectID, query builder.Query) ([]model.AccountBoundStorable, error) { +func (db *AccountBoundDBImp[T]) ListAccountBound(ctx context.Context, accountRef, organizationRef bson.ObjectID, query builder.Query) ([]model.AccountBoundStorable, error) { db.Logger.Debug("Attempting to list account bound objects", mzap.ObjRef("account_ref", accountRef), zap.String("collection", string(db.Collection))) // Build query to find objects where accountRef matches OR is null/absent @@ -327,7 +327,7 @@ func (db *AccountBoundDBImp[T]) ListAccountBound(ctx context.Context, accountRef return allowedObjects, nil } -func (db *AccountBoundDBImp[T]) GetByAccountRef(ctx context.Context, accountRef primitive.ObjectID, result T) error { +func (db *AccountBoundDBImp[T]) GetByAccountRef(ctx context.Context, accountRef bson.ObjectID, result T) error { db.Logger.Debug("Attempting to get object by account ref", mzap.ObjRef("account_ref", accountRef)) // Build query to find objects where accountRef matches OR is null/absent @@ -348,7 +348,7 @@ func (db *AccountBoundDBImp[T]) GetByAccountRef(ctx context.Context, accountRef return nil } -func (db *AccountBoundDBImp[T]) DeleteByAccountRef(ctx context.Context, accountRef primitive.ObjectID) error { +func (db *AccountBoundDBImp[T]) DeleteByAccountRef(ctx context.Context, accountRef bson.ObjectID) error { db.Logger.Debug("Attempting to delete objects by account ref", mzap.ObjRef("account_ref", accountRef)) // Build query to find objects where accountRef matches OR is null/absent @@ -362,7 +362,7 @@ func (db *AccountBoundDBImp[T]) DeleteByAccountRef(ctx context.Context, accountR } // Check permissions for each object individually (AccountBoundStorable doesn't have permission info) - var allowedIDs []primitive.ObjectID + var allowedIDs []bson.ObjectID for _, obj := range allObjects { if err := db.enforceInterface(ctx, model.ActionUpdate, obj, accountRef); err == nil { allowedIDs = append(allowedIDs, *obj.GetID()) @@ -390,7 +390,7 @@ func (db *AccountBoundDBImp[T]) DeleteByAccountRef(ctx context.Context, accountR return nil } -func (db *AccountBoundDBImp[T]) DeleteCascade(ctx context.Context, objectRef primitive.ObjectID) error { +func (db *AccountBoundDBImp[T]) DeleteCascade(ctx context.Context, objectRef bson.ObjectID) error { return db.DBImp.DeleteCascade(ctx, objectRef) } diff --git a/api/pkg/auth/dbimpab_test.go b/api/pkg/auth/dbimpab_test.go index 1ccdb9c8..711058b2 100644 --- a/api/pkg/auth/dbimpab_test.go +++ b/api/pkg/auth/dbimpab_test.go @@ -4,11 +4,11 @@ import ( "errors" "testing" + "github.com/stretchr/testify/assert" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" - "github.com/stretchr/testify/assert" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -17,7 +17,7 @@ func TestAccountBoundDBImp_Enforce(t *testing.T) { logger := mlogger.Logger(zap.NewNop()) db := &AccountBoundDBImp[model.AccountBoundStorable]{ Logger: logger, - PermissionRef: primitive.NewObjectID(), + PermissionRef: bson.NewObjectID(), Collection: "test_collection", } @@ -29,7 +29,7 @@ func TestAccountBoundDBImp_Enforce(t *testing.T) { t.Run("PermissionRefSet", func(t *testing.T) { // Test that PermissionRef is properly set - assert.NotEqual(t, primitive.NilObjectID, db.PermissionRef) + assert.NotEqual(t, bson.NilObjectID, db.PermissionRef) }) t.Run("CollectionSet", func(t *testing.T) { @@ -43,7 +43,7 @@ func TestAccountBoundDBImp_InterfaceCompliance(t *testing.T) { logger := mlogger.Logger(zap.NewNop()) db := &AccountBoundDBImp[model.AccountBoundStorable]{ Logger: logger, - PermissionRef: primitive.NewObjectID(), + PermissionRef: bson.NewObjectID(), Collection: "test_collection", } @@ -51,7 +51,7 @@ func TestAccountBoundDBImp_InterfaceCompliance(t *testing.T) { // Test that the struct can be initialized assert.NotNil(t, db) assert.NotNil(t, db.Logger) - assert.NotEqual(t, primitive.NilObjectID, db.PermissionRef) + assert.NotEqual(t, bson.NilObjectID, db.PermissionRef) assert.NotEmpty(t, db.Collection) }) @@ -65,14 +65,14 @@ func TestAccountBoundDBImp_InterfaceCompliance(t *testing.T) { func TestAccountBoundDBImp_ErrorHandling(t *testing.T) { t.Run("AccessDeniedError", func(t *testing.T) { // Test that AccessDenied error is properly created - err := merrors.AccessDenied("test_collection", "read", primitive.NilObjectID) + err := merrors.AccessDenied("test_collection", "read", bson.NilObjectID) assert.Error(t, err) assert.True(t, errors.Is(err, merrors.ErrAccessDenied)) }) t.Run("ErrorTypeChecking", func(t *testing.T) { // Test error type checking - accessDeniedErr := merrors.AccessDenied("test", "read", primitive.NilObjectID) + accessDeniedErr := merrors.AccessDenied("test", "read", bson.NilObjectID) otherErr := errors.New("other error") assert.True(t, errors.Is(accessDeniedErr, merrors.ErrAccessDenied)) diff --git a/api/pkg/auth/enforcer.go b/api/pkg/auth/enforcer.go index eb0c0b37..487c3b22 100644 --- a/api/pkg/auth/enforcer.go +++ b/api/pkg/auth/enforcer.go @@ -4,14 +4,14 @@ import ( "context" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type Enforcer interface { // Enforce checks if accountRef can do `action` on objectRef in an org (domainRef). Enforce( ctx context.Context, - permissionRef, accountRef, orgRef, objectRef primitive.ObjectID, + permissionRef, accountRef, orgRef, objectRef bson.ObjectID, action model.Action, ) (bool, error) @@ -19,14 +19,14 @@ type Enforcer interface { EnforceBatch( ctx context.Context, objectRefs []model.PermissionBoundStorable, - accountRef primitive.ObjectID, + accountRef bson.ObjectID, action model.Action, - ) (map[primitive.ObjectID]bool, error) + ) (map[bson.ObjectID]bool, error) // GetRoles returns the user's roles in a given org domain, plus any partial scopes if relevant. - GetRoles(ctx context.Context, accountRef, orgRef primitive.ObjectID) ([]model.Role, error) + GetRoles(ctx context.Context, accountRef, orgRef bson.ObjectID) ([]model.Role, error) // GetPermissions returns all effective permissions (with effect, object scoping) for a user in org domain. // Merges from all roles the user holds, plus any denies/exceptions. - GetPermissions(ctx context.Context, accountRef, orgRef primitive.ObjectID) ([]model.Role, []model.Permission, error) + GetPermissions(ctx context.Context, accountRef, orgRef bson.ObjectID) ([]model.Role, []model.Permission, error) } diff --git a/api/pkg/auth/factory.go b/api/pkg/auth/factory.go index c054e567..9efa1c9b 100644 --- a/api/pkg/auth/factory.go +++ b/api/pkg/auth/factory.go @@ -7,7 +7,7 @@ import ( "github.com/tech/sendico/pkg/db/role" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/pkg/auth/helper.go b/api/pkg/auth/helper.go index 4d448fc3..78f27ef1 100644 --- a/api/pkg/auth/helper.go +++ b/api/pkg/auth/helper.go @@ -10,11 +10,11 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) -func enforceObject[T model.PermissionBoundStorable](ctx context.Context, db *template.DBImp[T], enforcer Enforcer, action model.Action, accountRef primitive.ObjectID, query builder.Query) error { +func enforceObject[T model.PermissionBoundStorable](ctx context.Context, db *template.DBImp[T], enforcer Enforcer, action model.Action, accountRef bson.ObjectID, query builder.Query) error { l, err := db.ListPermissionBound(ctx, query) if err != nil { db.Logger.Warn("Error occured while checking access rights", zap.Error(err), @@ -23,7 +23,7 @@ func enforceObject[T model.PermissionBoundStorable](ctx context.Context, db *tem } if len(l) == 0 { db.Logger.Debug("Access denied", mzap.ObjRef("account_ref", accountRef), zap.String("action", string(action))) - return merrors.AccessDenied(db.Repository.Collection(), string(action), primitive.NilObjectID) + return merrors.AccessDenied(db.Repository.Collection(), string(action), bson.NilObjectID) } for _, item := range l { db.Logger.Debug("Object found", mzap.ObjRef("object_ref", *item.GetID()), @@ -46,7 +46,7 @@ func enforceObject[T model.PermissionBoundStorable](ctx context.Context, db *tem return nil } -func enforceObjectByRef[T model.PermissionBoundStorable](ctx context.Context, db *template.DBImp[T], enforcer Enforcer, action model.Action, accountRef, objectRef primitive.ObjectID) error { +func enforceObjectByRef[T model.PermissionBoundStorable](ctx context.Context, db *template.DBImp[T], enforcer Enforcer, action model.Action, accountRef, objectRef bson.ObjectID) error { err := enforceObject(ctx, db, enforcer, action, accountRef, repository.IDFilter(objectRef)) if err != nil { if errors.Is(err, merrors.ErrAccessDenied) { diff --git a/api/pkg/auth/indexable.go b/api/pkg/auth/indexable.go index a0e620b9..4ba65ec9 100644 --- a/api/pkg/auth/indexable.go +++ b/api/pkg/auth/indexable.go @@ -8,13 +8,13 @@ import ( "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // IndexableDB implements reordering with permission checking type IndexableDB[T storable.Storable] interface { // Reorder implements reordering with permission checking using EnforceBatch - Reorder(ctx context.Context, accountRef, objectRef primitive.ObjectID, newIndex int, filter builder.Query) error + Reorder(ctx context.Context, accountRef, objectRef bson.ObjectID, newIndex int, filter builder.Query) error } // NewIndexableDB creates a new auth.IndexableDB instance diff --git a/api/pkg/auth/indexableimp.go b/api/pkg/auth/indexableimp.go index ec03cb38..d7169cc8 100644 --- a/api/pkg/auth/indexableimp.go +++ b/api/pkg/auth/indexableimp.go @@ -10,7 +10,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -41,7 +41,7 @@ func newIndexableDBImp[T storable.Storable]( } // Reorder implements reordering with permission checking using EnforceBatch -func (db *indexableDBImp[T]) Reorder(ctx context.Context, accountRef, objectRef primitive.ObjectID, newIndex int, filter builder.Query) error { +func (db *indexableDBImp[T]) Reorder(ctx context.Context, accountRef, objectRef bson.ObjectID, newIndex int, filter builder.Query) error { // Get current object to find its index obj := db.createEmpty() if err := db.repo.Get(ctx, objectRef, obj); err != nil { diff --git a/api/pkg/auth/internal/casbin/config/config.go b/api/pkg/auth/internal/casbin/config/config.go index 4984fef7..c28bed4c 100644 --- a/api/pkg/auth/internal/casbin/config/config.go +++ b/api/pkg/auth/internal/casbin/config/config.go @@ -4,7 +4,7 @@ import ( "os" "time" - mongodbadapter "github.com/casbin/mongodb-adapter/v3" + mongodbadapter "github.com/casbin/mongodb-adapter/v4" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" "go.uber.org/zap" diff --git a/api/pkg/auth/internal/casbin/enforcer.go b/api/pkg/auth/internal/casbin/enforcer.go index ba2fe6ca..e68e6e95 100644 --- a/api/pkg/auth/internal/casbin/enforcer.go +++ b/api/pkg/auth/internal/casbin/enforcer.go @@ -5,6 +5,7 @@ import ( "context" "github.com/casbin/casbin/v2" + "github.com/mitchellh/mapstructure" "github.com/tech/sendico/pkg/auth/anyobject" cc "github.com/tech/sendico/pkg/auth/internal/casbin/config" "github.com/tech/sendico/pkg/auth/internal/casbin/serialization" @@ -12,9 +13,8 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" - "github.com/mitchellh/mapstructure" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -59,7 +59,7 @@ func NewEnforcer( // Enforce checks if a user has the specified action permission on an object within a domain. func (c *CasbinEnforcer) Enforce( _ context.Context, - permissionRef, accountRef, organizationRef, objectRef primitive.ObjectID, + permissionRef, accountRef, organizationRef, objectRef bson.ObjectID, action model.Action, ) (bool, error) { // Convert ObjectIDs to strings for Casbin @@ -67,7 +67,7 @@ func (c *CasbinEnforcer) Enforce( organization := organizationRef.Hex() permission := permissionRef.Hex() object := anyobject.ID - if objectRef != primitive.NilObjectID { + if objectRef != bson.NilObjectID { object = objectRef.Hex() } act := string(action) @@ -96,10 +96,10 @@ func (c *CasbinEnforcer) Enforce( func (c *CasbinEnforcer) EnforceBatch( ctx context.Context, objectRefs []model.PermissionBoundStorable, - accountRef primitive.ObjectID, + accountRef bson.ObjectID, action model.Action, -) (map[primitive.ObjectID]bool, error) { - results := make(map[primitive.ObjectID]bool, len(objectRefs)) +) (map[bson.ObjectID]bool, error) { + results := make(map[bson.ObjectID]bool, len(objectRefs)) for _, desc := range objectRefs { ok, err := c.Enforce(ctx, desc.GetPermissionRef(), accountRef, desc.GetOrganizationRef(), *desc.GetID(), action) if err != nil { @@ -115,7 +115,7 @@ func (c *CasbinEnforcer) EnforceBatch( } // GetRoles retrieves all roles assigned to the user within the domain. -func (c *CasbinEnforcer) GetRoles(ctx context.Context, accountRef, orgRef primitive.ObjectID) ([]model.Role, error) { +func (c *CasbinEnforcer) GetRoles(ctx context.Context, accountRef, orgRef bson.ObjectID) ([]model.Role, error) { sub := accountRef.Hex() dom := orgRef.Hex() @@ -145,7 +145,7 @@ func (c *CasbinEnforcer) GetRoles(ctx context.Context, accountRef, orgRef primit } // GetPermissions retrieves all effective policies for the user within the domain. -func (c *CasbinEnforcer) GetPermissions(ctx context.Context, accountRef, orgRef primitive.ObjectID) ([]model.Role, []model.Permission, error) { +func (c *CasbinEnforcer) GetPermissions(ctx context.Context, accountRef, orgRef bson.ObjectID) ([]model.Role, []model.Permission, error) { c.logger.Debug("Fetching policies for user", mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("organization_ref", orgRef)) // Step 1: Retrieve all roles assigned to the user within the domain diff --git a/api/pkg/auth/internal/casbin/factory.go b/api/pkg/auth/internal/casbin/factory.go index 82de7d18..705c76bf 100644 --- a/api/pkg/auth/internal/casbin/factory.go +++ b/api/pkg/auth/internal/casbin/factory.go @@ -2,10 +2,10 @@ package casbin import ( "github.com/casbin/casbin/v2" - mongodbadapter "github.com/casbin/mongodb-adapter/v3" + mongodbadapter "github.com/casbin/mongodb-adapter/v4" cc "github.com/tech/sendico/pkg/auth/internal/casbin/config" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/pkg/auth/internal/casbin/permissions.go b/api/pkg/auth/internal/casbin/permissions.go index 62407652..76cced0a 100644 --- a/api/pkg/auth/internal/casbin/permissions.go +++ b/api/pkg/auth/internal/casbin/permissions.go @@ -9,7 +9,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -23,7 +23,7 @@ type CasbinPermissionManager struct { // GrantToRole adds a permission to a role in Casbin. func (m *CasbinPermissionManager) GrantToRole(ctx context.Context, policy *model.RolePolicy) error { objRef := anyobject.ID - if (policy.ObjectRef != nil) && (*policy.ObjectRef != primitive.NilObjectID) { + if (policy.ObjectRef != nil) && (*policy.ObjectRef != bson.NilObjectID) { objRef = policy.ObjectRef.Hex() } @@ -118,7 +118,7 @@ func (m *CasbinPermissionManager) RevokeFromRole(ctx context.Context, policy *mo // GetPolicies retrieves all policies for a specific role. func (m *CasbinPermissionManager) GetPolicies( ctx context.Context, - roleRef primitive.ObjectID, + roleRef bson.ObjectID, ) ([]model.RolePolicy, error) { m.logger.Debug("Fetching policies for role", mzap.ObjRef("role_ref", roleRef)) diff --git a/api/pkg/auth/internal/casbin/role.go b/api/pkg/auth/internal/casbin/role.go index 7c0811e4..21e01283 100644 --- a/api/pkg/auth/internal/casbin/role.go +++ b/api/pkg/auth/internal/casbin/role.go @@ -9,7 +9,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -18,11 +18,11 @@ type RoleManager struct { logger mlogger.Logger enforcer *CasbinEnforcer rdb role.DB - rolePermissionRef primitive.ObjectID + rolePermissionRef bson.ObjectID } // NewRoleManager creates a new RoleManager. -func NewRoleManager(logger mlogger.Logger, enforcer *CasbinEnforcer, rolePermissionRef primitive.ObjectID, rdb role.DB) *RoleManager { +func NewRoleManager(logger mlogger.Logger, enforcer *CasbinEnforcer, rolePermissionRef bson.ObjectID, rdb role.DB) *RoleManager { return &RoleManager{ logger: logger.Named("role"), enforcer: enforcer, @@ -32,7 +32,7 @@ func NewRoleManager(logger mlogger.Logger, enforcer *CasbinEnforcer, rolePermiss } // validateObjectIDs ensures that all provided ObjectIDs are non-zero. -func (rm *RoleManager) validateObjectIDs(ids ...primitive.ObjectID) error { +func (rm *RoleManager) validateObjectIDs(ids ...bson.ObjectID) error { for _, id := range ids { if id.IsZero() { return merrors.InvalidArgument("Object references cannot be zero", "objectRef") @@ -42,7 +42,7 @@ func (rm *RoleManager) validateObjectIDs(ids ...primitive.ObjectID) error { } // removePolicies removes policies based on the provided filter and logs the results. -func (rm *RoleManager) removePolicies(policyType, role string, roleRef primitive.ObjectID) error { +func (rm *RoleManager) removePolicies(policyType, role string, roleRef bson.ObjectID) error { filterIndex := 1 if policyType == "permission" { filterIndex = 0 @@ -78,14 +78,14 @@ func (rm *RoleManager) removePolicies(policyType, role string, roleRef primitive } // fetchRolesFromPolicies retrieves and converts policies to roles. -func (rm *RoleManager) fetchRolesFromPolicies(policies [][]string, orgRef primitive.ObjectID) []model.RoleDescription { +func (rm *RoleManager) fetchRolesFromPolicies(policies [][]string, orgRef bson.ObjectID) []model.RoleDescription { roles := make([]model.RoleDescription, 0, len(policies)) for _, policy := range policies { if len(policy) < 2 { continue } - roleID, err := primitive.ObjectIDFromHex(policy[1]) + roleID, err := bson.ObjectIDFromHex(policy[1]) if err != nil { rm.logger.Warn("Invalid role ID", zap.String("roleID", policy[1])) continue @@ -96,7 +96,7 @@ func (rm *RoleManager) fetchRolesFromPolicies(policies [][]string, orgRef primit } // Create creates a new role in an organization. -func (rm *RoleManager) Create(ctx context.Context, orgRef primitive.ObjectID, description *model.Describable) (*model.RoleDescription, error) { +func (rm *RoleManager) Create(ctx context.Context, orgRef bson.ObjectID, description *model.Describable) (*model.RoleDescription, error) { if err := rm.validateObjectIDs(orgRef); err != nil { return nil, err } @@ -129,7 +129,7 @@ func (rm *RoleManager) Assign(ctx context.Context, role *model.Role) error { } // Delete removes a role entirely and cleans up associated Casbin policies. -func (rm *RoleManager) Delete(ctx context.Context, roleRef primitive.ObjectID) error { +func (rm *RoleManager) Delete(ctx context.Context, roleRef bson.ObjectID) error { if err := rm.validateObjectIDs(roleRef); err != nil { rm.logger.Warn("Failed to delete role", mzap.ObjRef("role_ref", roleRef)) return err @@ -166,7 +166,7 @@ func (rm *RoleManager) Delete(ctx context.Context, roleRef primitive.ObjectID) e } // Revoke removes a role from a user. -func (rm *RoleManager) Revoke(ctx context.Context, roleRef, accountRef, orgRef primitive.ObjectID) error { +func (rm *RoleManager) Revoke(ctx context.Context, roleRef, accountRef, orgRef bson.ObjectID) error { if err := rm.validateObjectIDs(roleRef, accountRef, orgRef); err != nil { return err } @@ -180,7 +180,7 @@ func (rm *RoleManager) Revoke(ctx context.Context, roleRef, accountRef, orgRef p } // logPolicyResult logs results for Assign and Revoke. -func (rm *RoleManager) logPolicyResult(action string, result bool, err error, roleRef, accountRef, orgRef primitive.ObjectID) error { +func (rm *RoleManager) logPolicyResult(action string, result bool, err error, roleRef, accountRef, orgRef bson.ObjectID) error { if err != nil { rm.logger.Warn("Failed to "+action+" role", zap.Error(err), mzap.ObjRef("role_ref", roleRef), mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("organization_ref", orgRef)) return err @@ -194,7 +194,7 @@ func (rm *RoleManager) logPolicyResult(action string, result bool, err error, ro } // List retrieves all roles in an organization or all roles if orgRef is zero. -func (rm *RoleManager) List(ctx context.Context, orgRef primitive.ObjectID) ([]model.RoleDescription, error) { +func (rm *RoleManager) List(ctx context.Context, orgRef bson.ObjectID) ([]model.RoleDescription, error) { domain := orgRef.Hex() groupingPolicies, err := rm.enforcer.enforcer.GetFilteredGroupingPolicy(2, domain) if err != nil { diff --git a/api/pkg/auth/internal/casbin/serialization/internal/policy.go b/api/pkg/auth/internal/casbin/serialization/internal/policy.go index 65b7ab57..e119f976 100644 --- a/api/pkg/auth/internal/casbin/serialization/internal/policy.go +++ b/api/pkg/auth/internal/casbin/serialization/internal/policy.go @@ -4,7 +4,7 @@ import ( "github.com/tech/sendico/pkg/auth/anyobject" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // PolicySerializer implements CasbinSerializer for Permission. @@ -41,25 +41,25 @@ func (s *PolicySerializer) Deserialize(policy []string) (*model.RolePolicy, erro return nil, merrors.Internal("invalid policy format") } - roleRef, err := primitive.ObjectIDFromHex(policy[0]) + roleRef, err := bson.ObjectIDFromHex(policy[0]) if err != nil { return nil, merrors.InvalidArgument("invalid roleRef in policy") } - organizationRef, err := primitive.ObjectIDFromHex(policy[1]) + organizationRef, err := bson.ObjectIDFromHex(policy[1]) if err != nil { return nil, merrors.InvalidArgument("invalid organizationRef in policy") } - permissionRef, err := primitive.ObjectIDFromHex(policy[2]) + permissionRef, err := bson.ObjectIDFromHex(policy[2]) if err != nil { return nil, merrors.InvalidArgument("invalid permissionRef in policy") } // Handle wildcard for ObjectRef - var objectRef *primitive.ObjectID + var objectRef *bson.ObjectID if policy[3] != anyobject.ID { - ref, err := primitive.ObjectIDFromHex(policy[3]) + ref, err := bson.ObjectIDFromHex(policy[3]) if err != nil { return nil, merrors.InvalidArgument("invalid objectRef in policy") } diff --git a/api/pkg/auth/internal/casbin/serialization/internal/role.go b/api/pkg/auth/internal/casbin/serialization/internal/role.go index e58c36b1..796914fd 100644 --- a/api/pkg/auth/internal/casbin/serialization/internal/role.go +++ b/api/pkg/auth/internal/casbin/serialization/internal/role.go @@ -3,7 +3,7 @@ package serializationimp import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // RoleSerializer implements CasbinSerializer for Role. @@ -31,19 +31,19 @@ func (s *RoleSerializer) Deserialize(policy []string) (*model.Role, error) { } // Parse accountRef - accountRef, err := primitive.ObjectIDFromHex(policy[0]) + accountRef, err := bson.ObjectIDFromHex(policy[0]) if err != nil { return nil, merrors.InvalidArgument("invalid accountRef in grouping policy") } // Parse roleDescriptionRef (roleRef) - roleDescriptionRef, err := primitive.ObjectIDFromHex(policy[1]) + roleDescriptionRef, err := bson.ObjectIDFromHex(policy[1]) if err != nil { return nil, merrors.InvalidArgument("invalid roleRef in grouping policy") } // Parse organizationRef - organizationRef, err := primitive.ObjectIDFromHex(policy[2]) + organizationRef, err := bson.ObjectIDFromHex(policy[2]) if err != nil { return nil, merrors.InvalidArgument("invalid organizationRef in grouping policy") } diff --git a/api/pkg/auth/internal/native/db/policies.go b/api/pkg/auth/internal/native/db/policies.go index 778f6093..00d1221c 100644 --- a/api/pkg/auth/internal/native/db/policies.go +++ b/api/pkg/auth/internal/native/db/policies.go @@ -11,8 +11,8 @@ import ( "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" mutil "github.com/tech/sendico/pkg/mutil/db" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -38,7 +38,7 @@ func (db *PermissionsDBImp) Policies(ctx context.Context, object model.Permissio ) } -func (db *PermissionsDBImp) PoliciesForPermissionAction(ctx context.Context, roleRef, permissionRef primitive.ObjectID, action model.Action) ([]nstructures.PolicyAssignment, error) { +func (db *PermissionsDBImp) PoliciesForPermissionAction(ctx context.Context, roleRef, permissionRef bson.ObjectID, action model.Action) ([]nstructures.PolicyAssignment, error) { return mutil.GetObjects[nstructures.PolicyAssignment]( ctx, db.Logger, @@ -55,7 +55,7 @@ func (db *PermissionsDBImp) PoliciesForPermissionAction(ctx context.Context, rol func (db *PermissionsDBImp) Remove(ctx context.Context, policy *model.RolePolicy) error { objRefFilter := repository.Query().Or( repository.Filter("policy.objectRef", nil), - repository.Filter("policy.objectRef", primitive.NilObjectID), + repository.Filter("policy.objectRef", bson.NilObjectID), ) if policy.ObjectRef != nil { objRefFilter = repository.Filter("policy.objectRef", *policy.ObjectRef) @@ -73,7 +73,7 @@ func (db *PermissionsDBImp) Remove(ctx context.Context, policy *model.RolePolicy ) } -func (db *PermissionsDBImp) PoliciesForRole(ctx context.Context, roleRef primitive.ObjectID) ([]nstructures.PolicyAssignment, error) { +func (db *PermissionsDBImp) PoliciesForRole(ctx context.Context, roleRef bson.ObjectID) ([]nstructures.PolicyAssignment, error) { return mutil.GetObjects[nstructures.PolicyAssignment]( ctx, db.Logger, @@ -83,7 +83,7 @@ func (db *PermissionsDBImp) PoliciesForRole(ctx context.Context, roleRef primiti ) } -func (db *PermissionsDBImp) PoliciesForRoles(ctx context.Context, roleRefs []primitive.ObjectID, action model.Action) ([]nstructures.PolicyAssignment, error) { +func (db *PermissionsDBImp) PoliciesForRoles(ctx context.Context, roleRefs []bson.ObjectID, action model.Action) ([]nstructures.PolicyAssignment, error) { if len(roleRefs) == 0 { db.Logger.Debug("Empty role references list provided, returning empty resposnse") return []nstructures.PolicyAssignment{}, nil diff --git a/api/pkg/auth/internal/native/db/roles.go b/api/pkg/auth/internal/native/db/roles.go index 8ad37d56..9019b769 100644 --- a/api/pkg/auth/internal/native/db/roles.go +++ b/api/pkg/auth/internal/native/db/roles.go @@ -9,8 +9,8 @@ import ( "github.com/tech/sendico/pkg/db/template" "github.com/tech/sendico/pkg/mlogger" mutil "github.com/tech/sendico/pkg/mutil/db" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -18,7 +18,7 @@ type RolesDBImp struct { template.DBImp[*nstructures.RoleAssignment] } -func (db *RolesDBImp) Roles(ctx context.Context, accountRef, organizationRef primitive.ObjectID) ([]nstructures.RoleAssignment, error) { +func (db *RolesDBImp) Roles(ctx context.Context, accountRef, organizationRef bson.ObjectID) ([]nstructures.RoleAssignment, error) { return mutil.GetObjects[nstructures.RoleAssignment]( ctx, db.Logger, @@ -31,7 +31,7 @@ func (db *RolesDBImp) Roles(ctx context.Context, accountRef, organizationRef pri ) } -func (db *RolesDBImp) RolesForVenue(ctx context.Context, organizationRef primitive.ObjectID) ([]nstructures.RoleAssignment, error) { +func (db *RolesDBImp) RolesForVenue(ctx context.Context, organizationRef bson.ObjectID) ([]nstructures.RoleAssignment, error) { return mutil.GetObjects[nstructures.RoleAssignment]( ctx, db.Logger, @@ -43,7 +43,7 @@ func (db *RolesDBImp) RolesForVenue(ctx context.Context, organizationRef primiti ) } -func (db *RolesDBImp) DeleteRole(ctx context.Context, roleRef primitive.ObjectID) error { +func (db *RolesDBImp) DeleteRole(ctx context.Context, roleRef bson.ObjectID) error { return db.DeleteMany( ctx, repository.Query().And( @@ -52,7 +52,7 @@ func (db *RolesDBImp) DeleteRole(ctx context.Context, roleRef primitive.ObjectID ) } -func (db *RolesDBImp) RemoveRole(ctx context.Context, roleRef, organizationRef, accountRef primitive.ObjectID) error { +func (db *RolesDBImp) RemoveRole(ctx context.Context, roleRef, organizationRef, accountRef bson.ObjectID) error { return db.DeleteMany( ctx, repository.Query().And( diff --git a/api/pkg/auth/internal/native/dbpolicies.go b/api/pkg/auth/internal/native/dbpolicies.go index 663a7fd2..35958c0c 100644 --- a/api/pkg/auth/internal/native/dbpolicies.go +++ b/api/pkg/auth/internal/native/dbpolicies.go @@ -8,17 +8,17 @@ import ( "github.com/tech/sendico/pkg/db/template" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" ) type PoliciesDB interface { template.DB[*nstructures.PolicyAssignment] // plenty of interfaces for performance reasons Policies(ctx context.Context, object model.PermissionBoundStorable, action model.Action) ([]nstructures.PolicyAssignment, error) - PoliciesForPermissionAction(ctx context.Context, roleRef, permissionRef primitive.ObjectID, action model.Action) ([]nstructures.PolicyAssignment, error) - PoliciesForRole(ctx context.Context, roleRef primitive.ObjectID) ([]nstructures.PolicyAssignment, error) - PoliciesForRoles(ctx context.Context, roleRefs []primitive.ObjectID, action model.Action) ([]nstructures.PolicyAssignment, error) + PoliciesForPermissionAction(ctx context.Context, roleRef, permissionRef bson.ObjectID, action model.Action) ([]nstructures.PolicyAssignment, error) + PoliciesForRole(ctx context.Context, roleRef bson.ObjectID) ([]nstructures.PolicyAssignment, error) + PoliciesForRoles(ctx context.Context, roleRefs []bson.ObjectID, action model.Action) ([]nstructures.PolicyAssignment, error) Remove(ctx context.Context, policy *model.RolePolicy) error } diff --git a/api/pkg/auth/internal/native/dbroles.go b/api/pkg/auth/internal/native/dbroles.go index 104daddf..72b98ab1 100644 --- a/api/pkg/auth/internal/native/dbroles.go +++ b/api/pkg/auth/internal/native/dbroles.go @@ -7,16 +7,16 @@ import ( "github.com/tech/sendico/pkg/auth/internal/native/nstructures" "github.com/tech/sendico/pkg/db/template" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" ) type RolesDB interface { template.DB[*nstructures.RoleAssignment] - Roles(ctx context.Context, accountRef, organizationRef primitive.ObjectID) ([]nstructures.RoleAssignment, error) - RolesForVenue(ctx context.Context, organizationRef primitive.ObjectID) ([]nstructures.RoleAssignment, error) - RemoveRole(ctx context.Context, roleRef, organizationRef, accountRef primitive.ObjectID) error - DeleteRole(ctx context.Context, roleRef primitive.ObjectID) error + Roles(ctx context.Context, accountRef, organizationRef bson.ObjectID) ([]nstructures.RoleAssignment, error) + RolesForVenue(ctx context.Context, organizationRef bson.ObjectID) ([]nstructures.RoleAssignment, error) + RemoveRole(ctx context.Context, roleRef, organizationRef, accountRef bson.ObjectID) error + DeleteRole(ctx context.Context, roleRef bson.ObjectID) error } func NewRolesDB(logger mlogger.Logger, conn *mongo.Database) (RolesDB, error) { diff --git a/api/pkg/auth/internal/native/enforcer.go b/api/pkg/auth/internal/native/enforcer.go index 974309de..bf6b8153 100644 --- a/api/pkg/auth/internal/native/enforcer.go +++ b/api/pkg/auth/internal/native/enforcer.go @@ -9,8 +9,8 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) @@ -44,7 +44,7 @@ func NewEnforcer( // Enforce checks if a user has the specified action permission on an object within a domain. func (n *Enforcer) Enforce( ctx context.Context, - permissionRef, accountRef, organizationRef, objectRef primitive.ObjectID, + permissionRef, accountRef, organizationRef, objectRef bson.ObjectID, action model.Action, ) (bool, error) { if organizationRef.IsZero() { @@ -118,13 +118,13 @@ func (n *Enforcer) Enforce( func (n *Enforcer) EnforceBatch( ctx context.Context, objectRefs []model.PermissionBoundStorable, - accountRef primitive.ObjectID, + accountRef bson.ObjectID, action model.Action, -) (map[primitive.ObjectID]bool, error) { - results := make(map[primitive.ObjectID]bool, len(objectRefs)) +) (map[bson.ObjectID]bool, error) { + results := make(map[bson.ObjectID]bool, len(objectRefs)) // Group objectRefs by organizationRef. - objectsByVenue := make(map[primitive.ObjectID][]model.PermissionBoundStorable) + objectsByVenue := make(map[bson.ObjectID][]model.PermissionBoundStorable) for _, obj := range objectRefs { organizationRef := obj.GetOrganizationRef() objectsByVenue[organizationRef] = append(objectsByVenue[organizationRef], obj) @@ -151,7 +151,7 @@ func (n *Enforcer) EnforceBatch( } // 2. Extract role description references - var roleRefs []primitive.ObjectID + var roleRefs []bson.ObjectID for _, role := range roles { roleRefs = append(roleRefs, role.DescriptionRef) } @@ -164,7 +164,7 @@ func (n *Enforcer) EnforceBatch( } // 4. Build a lookup map keyed by PermissionRef. - policyMap := make(map[primitive.ObjectID][]nstructures.PolicyAssignment) + policyMap := make(map[bson.ObjectID][]nstructures.PolicyAssignment) for _, policy := range allPolicies { policyMap[policy.DescriptionRef] = append(policyMap[policy.DescriptionRef], policy) } @@ -197,7 +197,7 @@ func (n *Enforcer) EnforceBatch( } // GetRoles retrieves all roles assigned to the user within the domain. -func (n *Enforcer) GetRoles(ctx context.Context, accountRef, organizationRef primitive.ObjectID) ([]model.Role, error) { +func (n *Enforcer) GetRoles(ctx context.Context, accountRef, organizationRef bson.ObjectID) ([]model.Role, error) { n.logger.Debug("Fetching roles for user", mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("organization_ref", organizationRef)) ra, err := n.rdb.Roles(ctx, accountRef, organizationRef) if errors.Is(err, merrors.ErrNoData) { @@ -224,7 +224,7 @@ func (n *Enforcer) Reload() error { } // GetPermissions retrieves all effective policies for the user within the domain. -func (n *Enforcer) GetPermissions(ctx context.Context, accountRef, organizationRef primitive.ObjectID) ([]model.Role, []model.Permission, error) { +func (n *Enforcer) GetPermissions(ctx context.Context, accountRef, organizationRef bson.ObjectID) ([]model.Role, []model.Permission, error) { n.logger.Debug("Fetching policies for user", mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("organization_ref", organizationRef)) roles, err := n.GetRoles(ctx, accountRef, organizationRef) @@ -233,7 +233,7 @@ func (n *Enforcer) GetPermissions(ctx context.Context, accountRef, organizationR return nil, nil, err } - uniquePermissions := make(map[primitive.ObjectID]model.Permission) + uniquePermissions := make(map[bson.ObjectID]model.Permission) for _, role := range roles { perms, err := n.pdb.PoliciesForRole(ctx, role.DescriptionRef) if err != nil { diff --git a/api/pkg/auth/internal/native/enforcer_test.go b/api/pkg/auth/internal/native/enforcer_test.go index 0fea3f24..cd7bb03c 100644 --- a/api/pkg/auth/internal/native/enforcer_test.go +++ b/api/pkg/auth/internal/native/enforcer_test.go @@ -5,15 +5,15 @@ import ( "errors" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" "github.com/tech/sendico/pkg/auth/internal/native/nstructures" "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/merrors" factory "github.com/tech/sendico/pkg/mlogger/factory" "github.com/tech/sendico/pkg/model" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // Mock implementations for testing @@ -21,17 +21,17 @@ type MockPoliciesDB struct { mock.Mock } -func (m *MockPoliciesDB) PoliciesForPermissionAction(ctx context.Context, roleRef, permissionRef primitive.ObjectID, action model.Action) ([]nstructures.PolicyAssignment, error) { +func (m *MockPoliciesDB) PoliciesForPermissionAction(ctx context.Context, roleRef, permissionRef bson.ObjectID, action model.Action) ([]nstructures.PolicyAssignment, error) { args := m.Called(ctx, roleRef, permissionRef, action) return args.Get(0).([]nstructures.PolicyAssignment), args.Error(1) } -func (m *MockPoliciesDB) PoliciesForRole(ctx context.Context, roleRef primitive.ObjectID) ([]nstructures.PolicyAssignment, error) { +func (m *MockPoliciesDB) PoliciesForRole(ctx context.Context, roleRef bson.ObjectID) ([]nstructures.PolicyAssignment, error) { args := m.Called(ctx, roleRef) return args.Get(0).([]nstructures.PolicyAssignment), args.Error(1) } -func (m *MockPoliciesDB) PoliciesForRoles(ctx context.Context, roleRefs []primitive.ObjectID, action model.Action) ([]nstructures.PolicyAssignment, error) { +func (m *MockPoliciesDB) PoliciesForRoles(ctx context.Context, roleRefs []bson.ObjectID, action model.Action) ([]nstructures.PolicyAssignment, error) { args := m.Called(ctx, roleRefs, action) return args.Get(0).([]nstructures.PolicyAssignment), args.Error(1) } @@ -52,7 +52,7 @@ func (m *MockPoliciesDB) Create(ctx context.Context, assignment *nstructures.Pol return args.Error(0) } -func (m *MockPoliciesDB) Get(ctx context.Context, id primitive.ObjectID, assignment *nstructures.PolicyAssignment) error { +func (m *MockPoliciesDB) Get(ctx context.Context, id bson.ObjectID, assignment *nstructures.PolicyAssignment) error { args := m.Called(ctx, id, assignment) return args.Error(0) } @@ -62,12 +62,12 @@ func (m *MockPoliciesDB) Update(ctx context.Context, assignment *nstructures.Pol return args.Error(0) } -func (m *MockPoliciesDB) Patch(ctx context.Context, objectRef primitive.ObjectID, patch builder.Patch) error { +func (m *MockPoliciesDB) Patch(ctx context.Context, objectRef bson.ObjectID, patch builder.Patch) error { args := m.Called(ctx, objectRef, patch) return args.Error(0) } -func (m *MockPoliciesDB) Delete(ctx context.Context, id primitive.ObjectID) error { +func (m *MockPoliciesDB) Delete(ctx context.Context, id bson.ObjectID) error { args := m.Called(ctx, id) return args.Error(0) } @@ -77,14 +77,14 @@ func (m *MockPoliciesDB) DeleteMany(ctx context.Context, query builder.Query) er return args.Error(0) } -func (m *MockPoliciesDB) ListPermissionBound(ctx context.Context, accountRef, organizationRef primitive.ObjectID) ([]nstructures.PolicyAssignment, error) { +func (m *MockPoliciesDB) ListPermissionBound(ctx context.Context, accountRef, organizationRef bson.ObjectID) ([]nstructures.PolicyAssignment, error) { args := m.Called(ctx, accountRef, organizationRef) return args.Get(0).([]nstructures.PolicyAssignment), args.Error(1) } -func (m *MockPoliciesDB) ListIDs(ctx context.Context, query interface{}) ([]primitive.ObjectID, error) { +func (m *MockPoliciesDB) ListIDs(ctx context.Context, query interface{}) ([]bson.ObjectID, error) { args := m.Called(ctx, query) - return args.Get(0).([]primitive.ObjectID), args.Error(1) + return args.Get(0).([]bson.ObjectID), args.Error(1) } func (m *MockPoliciesDB) FindOne(ctx context.Context, query builder.Query, assignment *nstructures.PolicyAssignment) error { @@ -101,7 +101,7 @@ func (m *MockPoliciesDB) Name() string { return "mock_policies" } -func (m *MockPoliciesDB) DeleteCascade(ctx context.Context, id primitive.ObjectID) error { +func (m *MockPoliciesDB) DeleteCascade(ctx context.Context, id bson.ObjectID) error { args := m.Called(ctx, id) return args.Error(0) } @@ -115,22 +115,22 @@ type MockRolesDB struct { mock.Mock } -func (m *MockRolesDB) Roles(ctx context.Context, accountRef, organizationRef primitive.ObjectID) ([]nstructures.RoleAssignment, error) { +func (m *MockRolesDB) Roles(ctx context.Context, accountRef, organizationRef bson.ObjectID) ([]nstructures.RoleAssignment, error) { args := m.Called(ctx, accountRef, organizationRef) return args.Get(0).([]nstructures.RoleAssignment), args.Error(1) } -func (m *MockRolesDB) RolesForVenue(ctx context.Context, organizationRef primitive.ObjectID) ([]nstructures.RoleAssignment, error) { +func (m *MockRolesDB) RolesForVenue(ctx context.Context, organizationRef bson.ObjectID) ([]nstructures.RoleAssignment, error) { args := m.Called(ctx, organizationRef) return args.Get(0).([]nstructures.RoleAssignment), args.Error(1) } -func (m *MockRolesDB) RemoveRole(ctx context.Context, roleRef, organizationRef, accountRef primitive.ObjectID) error { +func (m *MockRolesDB) RemoveRole(ctx context.Context, roleRef, organizationRef, accountRef bson.ObjectID) error { args := m.Called(ctx, roleRef, organizationRef, accountRef) return args.Error(0) } -func (m *MockRolesDB) DeleteRole(ctx context.Context, roleRef primitive.ObjectID) error { +func (m *MockRolesDB) DeleteRole(ctx context.Context, roleRef bson.ObjectID) error { args := m.Called(ctx, roleRef) return args.Error(0) } @@ -141,7 +141,7 @@ func (m *MockRolesDB) Create(ctx context.Context, assignment *nstructures.RoleAs return args.Error(0) } -func (m *MockRolesDB) Get(ctx context.Context, id primitive.ObjectID, assignment *nstructures.RoleAssignment) error { +func (m *MockRolesDB) Get(ctx context.Context, id bson.ObjectID, assignment *nstructures.RoleAssignment) error { args := m.Called(ctx, id, assignment) return args.Error(0) } @@ -151,12 +151,12 @@ func (m *MockRolesDB) Update(ctx context.Context, assignment *nstructures.RoleAs return args.Error(0) } -func (m *MockRolesDB) Patch(ctx context.Context, objectRef primitive.ObjectID, patch builder.Patch) error { +func (m *MockRolesDB) Patch(ctx context.Context, objectRef bson.ObjectID, patch builder.Patch) error { args := m.Called(ctx, objectRef, patch) return args.Error(0) } -func (m *MockRolesDB) Delete(ctx context.Context, id primitive.ObjectID) error { +func (m *MockRolesDB) Delete(ctx context.Context, id bson.ObjectID) error { args := m.Called(ctx, id) return args.Error(0) } @@ -166,14 +166,14 @@ func (m *MockRolesDB) DeleteMany(ctx context.Context, query builder.Query) error return args.Error(0) } -func (m *MockRolesDB) ListPermissionBound(ctx context.Context, accountRef, organizationRef primitive.ObjectID) ([]nstructures.RoleAssignment, error) { +func (m *MockRolesDB) ListPermissionBound(ctx context.Context, accountRef, organizationRef bson.ObjectID) ([]nstructures.RoleAssignment, error) { args := m.Called(ctx, accountRef, organizationRef) return args.Get(0).([]nstructures.RoleAssignment), args.Error(1) } -func (m *MockRolesDB) ListIDs(ctx context.Context, query interface{}) ([]primitive.ObjectID, error) { +func (m *MockRolesDB) ListIDs(ctx context.Context, query interface{}) ([]bson.ObjectID, error) { args := m.Called(ctx, query) - return args.Get(0).([]primitive.ObjectID), args.Error(1) + return args.Get(0).([]bson.ObjectID), args.Error(1) } func (m *MockRolesDB) FindOne(ctx context.Context, query builder.Query, assignment *nstructures.RoleAssignment) error { @@ -190,7 +190,7 @@ func (m *MockRolesDB) Name() string { return "mock_roles" } -func (m *MockRolesDB) DeleteCascade(ctx context.Context, id primitive.ObjectID) error { +func (m *MockRolesDB) DeleteCascade(ctx context.Context, id bson.ObjectID) error { args := m.Called(ctx, id) return args.Error(0) } @@ -201,11 +201,11 @@ func (m *MockRolesDB) InsertMany(ctx context.Context, objects []*nstructures.Rol } // Test helper functions -func createTestObjectID() primitive.ObjectID { - return primitive.NewObjectID() +func createTestObjectID() bson.ObjectID { + return bson.NewObjectID() } -func createTestRoleAssignment(roleRef, accountRef, organizationRef primitive.ObjectID) nstructures.RoleAssignment { +func createTestRoleAssignment(roleRef, accountRef, organizationRef bson.ObjectID) nstructures.RoleAssignment { return nstructures.RoleAssignment{ Role: model.Role{ AccountRef: accountRef, @@ -215,7 +215,7 @@ func createTestRoleAssignment(roleRef, accountRef, organizationRef primitive.Obj } } -func createTestPolicyAssignment(roleRef primitive.ObjectID, action model.Action, effect model.Effect, organizationRef, descriptionRef primitive.ObjectID, objectRef *primitive.ObjectID) nstructures.PolicyAssignment { +func createTestPolicyAssignment(roleRef bson.ObjectID, action model.Action, effect model.Effect, organizationRef, descriptionRef bson.ObjectID, objectRef *bson.ObjectID) nstructures.PolicyAssignment { return nstructures.PolicyAssignment{ Policy: model.Policy{ OrganizationRef: organizationRef, @@ -464,20 +464,20 @@ func TestEnforcer_Enforce(t *testing.T) { // Mock implementation for PermissionBoundStorable type MockPermissionBoundStorable struct { - id primitive.ObjectID - permissionRef primitive.ObjectID - organizationRef primitive.ObjectID + id bson.ObjectID + permissionRef bson.ObjectID + organizationRef bson.ObjectID } -func (m *MockPermissionBoundStorable) GetID() *primitive.ObjectID { +func (m *MockPermissionBoundStorable) GetID() *bson.ObjectID { return &m.id } -func (m *MockPermissionBoundStorable) GetPermissionRef() primitive.ObjectID { +func (m *MockPermissionBoundStorable) GetPermissionRef() bson.ObjectID { return m.permissionRef } -func (m *MockPermissionBoundStorable) GetOrganizationRef() primitive.ObjectID { +func (m *MockPermissionBoundStorable) GetOrganizationRef() bson.ObjectID { return m.organizationRef } @@ -485,7 +485,7 @@ func (m *MockPermissionBoundStorable) Collection() string { return "test_objects" } -func (m *MockPermissionBoundStorable) SetID(objID primitive.ObjectID) { +func (m *MockPermissionBoundStorable) SetID(objID bson.ObjectID) { m.id = objID } @@ -493,11 +493,11 @@ func (m *MockPermissionBoundStorable) Update() { // Do nothing for mock } -func (m *MockPermissionBoundStorable) SetPermissionRef(permissionRef primitive.ObjectID) { +func (m *MockPermissionBoundStorable) SetPermissionRef(permissionRef bson.ObjectID) { m.permissionRef = permissionRef } -func (m *MockPermissionBoundStorable) SetOrganizationRef(organizationRef primitive.ObjectID) { +func (m *MockPermissionBoundStorable) SetOrganizationRef(organizationRef bson.ObjectID) { m.organizationRef = organizationRef } @@ -540,7 +540,7 @@ func TestEnforcer_EnforceBatch(t *testing.T) { // Mock policy assignment with ALLOW effect policyAssignment := createTestPolicyAssignment(roleRef, model.ActionRead, model.EffectAllow, organizationRef, permissionRef, nil) - mockPDB.On("PoliciesForRoles", ctx, []primitive.ObjectID{roleRef}, model.ActionRead).Return([]nstructures.PolicyAssignment{policyAssignment}, nil) + mockPDB.On("PoliciesForRoles", ctx, []bson.ObjectID{roleRef}, model.ActionRead).Return([]nstructures.PolicyAssignment{policyAssignment}, nil) enforcer := createTestEnforcer(mockPDB, mockRDB) diff --git a/api/pkg/auth/internal/native/nstructures/policies.go b/api/pkg/auth/internal/native/nstructures/policies.go index 272ce53a..a6791ab0 100644 --- a/api/pkg/auth/internal/native/nstructures/policies.go +++ b/api/pkg/auth/internal/native/nstructures/policies.go @@ -3,13 +3,13 @@ package nstructures import ( "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type PolicyAssignment struct { storable.Base `bson:",inline" json:",inline"` model.Policy `bson:"policy" json:"policy"` - RoleRef primitive.ObjectID `bson:"roleRef" json:"roleRef"` + RoleRef bson.ObjectID `bson:"roleRef" json:"roleRef"` } func (*PolicyAssignment) Collection() string { diff --git a/api/pkg/auth/internal/native/permission.go b/api/pkg/auth/internal/native/permission.go index 726bf9cd..886a3315 100644 --- a/api/pkg/auth/internal/native/permission.go +++ b/api/pkg/auth/internal/native/permission.go @@ -9,7 +9,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -22,7 +22,7 @@ type PermissionManager struct { // GrantToRole adds a permission to a role in Casbin. func (m *PermissionManager) GrantToRole(ctx context.Context, policy *model.RolePolicy) error { objRef := "any" - if (policy.ObjectRef != nil) && (*policy.ObjectRef != primitive.NilObjectID) { + if (policy.ObjectRef != nil) && (*policy.ObjectRef != bson.NilObjectID) { objRef = policy.ObjectRef.Hex() } @@ -67,7 +67,7 @@ func (m *PermissionManager) RevokeFromRole(ctx context.Context, policy *model.Ro // GetPolicies retrieves all policies for a specific role. func (m *PermissionManager) GetPolicies( ctx context.Context, - roleRef primitive.ObjectID, + roleRef bson.ObjectID, ) ([]model.RolePolicy, error) { m.logger.Debug("Fetching policies for role", mzap.ObjRef("role_ref", roleRef)) diff --git a/api/pkg/auth/internal/native/role.go b/api/pkg/auth/internal/native/role.go index f50eaa6b..7926dbc7 100644 --- a/api/pkg/auth/internal/native/role.go +++ b/api/pkg/auth/internal/native/role.go @@ -10,7 +10,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -19,11 +19,11 @@ type RoleManager struct { logger mlogger.Logger enforcer *Enforcer rdb role.DB - rolePermissionRef primitive.ObjectID + rolePermissionRef bson.ObjectID } // NewRoleManager creates a new RoleManager. -func NewRoleManager(logger mlogger.Logger, enforcer *Enforcer, rolePermissionRef primitive.ObjectID, rdb role.DB) *RoleManager { +func NewRoleManager(logger mlogger.Logger, enforcer *Enforcer, rolePermissionRef bson.ObjectID, rdb role.DB) *RoleManager { return &RoleManager{ logger: logger.Named("role"), enforcer: enforcer, @@ -33,7 +33,7 @@ func NewRoleManager(logger mlogger.Logger, enforcer *Enforcer, rolePermissionRef } // validateObjectIDs ensures that all provided ObjectIDs are non-zero. -func (rm *RoleManager) validateObjectIDs(ids ...primitive.ObjectID) error { +func (rm *RoleManager) validateObjectIDs(ids ...bson.ObjectID) error { for _, id := range ids { if id.IsZero() { return merrors.InvalidArgument("Object references cannot be zero", "objectRef") @@ -43,7 +43,7 @@ func (rm *RoleManager) validateObjectIDs(ids ...primitive.ObjectID) error { } // fetchRolesFromPolicies retrieves and converts policies to roles. -func (rm *RoleManager) fetchRolesFromPolicies(roles []nstructures.RoleAssignment, organizationRef primitive.ObjectID) []model.RoleDescription { +func (rm *RoleManager) fetchRolesFromPolicies(roles []nstructures.RoleAssignment, organizationRef bson.ObjectID) []model.RoleDescription { result := make([]model.RoleDescription, len(roles)) for i, role := range roles { result[i] = model.RoleDescription{ @@ -55,7 +55,7 @@ func (rm *RoleManager) fetchRolesFromPolicies(roles []nstructures.RoleAssignment } // Create creates a new role in an organization. -func (rm *RoleManager) Create(ctx context.Context, organizationRef primitive.ObjectID, description *model.Describable) (*model.RoleDescription, error) { +func (rm *RoleManager) Create(ctx context.Context, organizationRef bson.ObjectID, description *model.Describable) (*model.RoleDescription, error) { if err := rm.validateObjectIDs(organizationRef); err != nil { return nil, err } @@ -84,7 +84,7 @@ func (rm *RoleManager) Assign(ctx context.Context, role *model.Role) error { } // Delete removes a role entirely and cleans up associated Casbin policies. -func (rm *RoleManager) Delete(ctx context.Context, roleRef primitive.ObjectID) error { +func (rm *RoleManager) Delete(ctx context.Context, roleRef bson.ObjectID) error { if err := rm.validateObjectIDs(roleRef); err != nil { rm.logger.Warn("Failed to delete role", mzap.ObjRef("role_ref", roleRef)) return err @@ -105,7 +105,7 @@ func (rm *RoleManager) Delete(ctx context.Context, roleRef primitive.ObjectID) e } // Revoke removes a role from a user. -func (rm *RoleManager) Revoke(ctx context.Context, roleRef, accountRef, organizationRef primitive.ObjectID) error { +func (rm *RoleManager) Revoke(ctx context.Context, roleRef, accountRef, organizationRef bson.ObjectID) error { if err := rm.validateObjectIDs(roleRef, accountRef, organizationRef); err != nil { return err } @@ -115,7 +115,7 @@ func (rm *RoleManager) Revoke(ctx context.Context, roleRef, accountRef, organiza } // logPolicyResult logs results for Assign and Revoke. -func (rm *RoleManager) logPolicyResult(action string, result bool, err error, roleRef, accountRef, organizationRef primitive.ObjectID) error { +func (rm *RoleManager) logPolicyResult(action string, result bool, err error, roleRef, accountRef, organizationRef bson.ObjectID) error { if err != nil { rm.logger.Warn("Failed to "+action+" role", zap.Error(err), mzap.ObjRef("role_ref", roleRef), mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("organization_ref", organizationRef)) return err @@ -129,7 +129,7 @@ func (rm *RoleManager) logPolicyResult(action string, result bool, err error, ro } // List retrieves all roles in an organization or all roles if organizationRef is zero. -func (rm *RoleManager) List(ctx context.Context, organizationRef primitive.ObjectID) ([]model.RoleDescription, error) { +func (rm *RoleManager) List(ctx context.Context, organizationRef bson.ObjectID) ([]model.RoleDescription, error) { roles4Venues, err := rm.enforcer.rdb.RolesForVenue(ctx, organizationRef) if err != nil { rm.logger.Warn("Failed to fetch grouping policies", zap.Error(err), mzap.ObjRef("organization_ref", organizationRef)) diff --git a/api/pkg/auth/management/permission.go b/api/pkg/auth/management/permission.go index a880972d..35ea4729 100644 --- a/api/pkg/auth/management/permission.go +++ b/api/pkg/auth/management/permission.go @@ -4,22 +4,22 @@ import ( "context" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type Permission interface { // Grant a permission to a role with an optional object scope and specified effect. - // Use primitive.NilObjectID for 'any' objectRef. + // Use bson.NilObjectID for 'any' objectRef. GrantToRole(ctx context.Context, policy *model.RolePolicy) error // Revoke a permission from a role with an optional object scope and specified effect. - // Use primitive.NilObjectID for 'any' objectRef. + // Use bson.NilObjectID for 'any' objectRef. RevokeFromRole(ctx context.Context, policy *model.RolePolicy) error // Retrieve all policies assigned to a specific role, including scope and effects. GetPolicies( ctx context.Context, - roleRef primitive.ObjectID, + roleRef bson.ObjectID, ) ([]model.RolePolicy, error) // Persist any changes made to permissions. diff --git a/api/pkg/auth/management/role.go b/api/pkg/auth/management/role.go index 0cc1366d..ea3b902e 100644 --- a/api/pkg/auth/management/role.go +++ b/api/pkg/auth/management/role.go @@ -4,21 +4,21 @@ import ( "context" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type Role interface { // Create a new role in an organization (returns the created Role with its ID). Create( ctx context.Context, - orgRef primitive.ObjectID, + orgRef bson.ObjectID, description *model.Describable, ) (*model.RoleDescription, error) // Delete a role entirely. This will cascade and remove all associated Delete( ctx context.Context, - roleRef primitive.ObjectID, + roleRef bson.ObjectID, ) error // Assign a role to a user in a specific organization. @@ -30,12 +30,12 @@ type Role interface { // Revoke a role from a user in a specific organization. Revoke( ctx context.Context, - roleRef, accountRef, orgRef primitive.ObjectID, + roleRef, accountRef, orgRef bson.ObjectID, ) error - // List all roles in an organization or globally if orgRef is primitive.NilObjectID. + // List all roles in an organization or globally if orgRef is bson.NilObjectID. List( ctx context.Context, - orgRef primitive.ObjectID, + orgRef bson.ObjectID, ) ([]model.RoleDescription, error) } diff --git a/api/pkg/db/account/account.go b/api/pkg/db/account/account.go index a22fa33d..fb705bda 100755 --- a/api/pkg/db/account/account.go +++ b/api/pkg/db/account/account.go @@ -5,7 +5,7 @@ import ( "github.com/tech/sendico/pkg/db/template" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // DB is the interface which must be implemented by all db drivers @@ -13,5 +13,5 @@ type DB interface { template.DB[*model.Account] GetByEmail(ctx context.Context, email string) (*model.Account, error) GetByToken(ctx context.Context, email string) (*model.Account, error) - GetAccountsByRefs(ctx context.Context, orgRef primitive.ObjectID, refs []primitive.ObjectID) ([]model.Account, error) + GetAccountsByRefs(ctx context.Context, orgRef bson.ObjectID, refs []bson.ObjectID) ([]model.Account, error) } diff --git a/api/pkg/db/confirmation/confirmation.go b/api/pkg/db/confirmation/confirmation.go index 7f5d510b..61bc79fc 100644 --- a/api/pkg/db/confirmation/confirmation.go +++ b/api/pkg/db/confirmation/confirmation.go @@ -5,12 +5,12 @@ import ( "github.com/tech/sendico/pkg/db/template" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type DB interface { template.DB[*model.ConfirmationCode] - FindActive(ctx context.Context, accountRef primitive.ObjectID, destination string, target model.ConfirmationTarget, now int64) (*model.ConfirmationCode, error) - DeleteTuple(ctx context.Context, accountRef primitive.ObjectID, destination string, target model.ConfirmationTarget) error + FindActive(ctx context.Context, accountRef bson.ObjectID, destination string, target model.ConfirmationTarget, now int64) (*model.ConfirmationCode, error) + DeleteTuple(ctx context.Context, accountRef bson.ObjectID, destination string, target model.ConfirmationTarget) error } diff --git a/api/pkg/db/connection.go b/api/pkg/db/connection.go index de00fbfe..a9874817 100644 --- a/api/pkg/db/connection.go +++ b/api/pkg/db/connection.go @@ -6,8 +6,8 @@ import ( mongoimpl "github.com/tech/sendico/pkg/db/internal/mongo" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mlogger" - mongoDriver "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/readpref" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/readpref" ) // Connection represents a low-level database connection lifecycle. @@ -18,15 +18,15 @@ type Connection interface { // MongoConnection provides direct access to the underlying mongo client. type MongoConnection struct { - client *mongoDriver.Client + client *mongo.Client database string } -func (c *MongoConnection) Client() *mongoDriver.Client { +func (c *MongoConnection) Client() *mongo.Client { return c.client } -func (c *MongoConnection) Database() *mongoDriver.Database { +func (c *MongoConnection) Database() *mongo.Database { return c.client.Database(c.database) } diff --git a/api/pkg/db/indexable/indexable.go b/api/pkg/db/indexable/indexable.go index 368a0488..7fb50443 100644 --- a/api/pkg/db/indexable/indexable.go +++ b/api/pkg/db/indexable/indexable.go @@ -4,9 +4,9 @@ import ( "context" "github.com/tech/sendico/pkg/db/repository/builder" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type DB interface { - Reorder(ctx context.Context, objectRef primitive.ObjectID, newIndex int, filter builder.Query) error + Reorder(ctx context.Context, objectRef bson.ObjectID, newIndex int, filter builder.Query) error } diff --git a/api/pkg/db/internal/mongo/accountdb/db.go b/api/pkg/db/internal/mongo/accountdb/db.go index 4e51c326..d5136bc4 100644 --- a/api/pkg/db/internal/mongo/accountdb/db.go +++ b/api/pkg/db/internal/mongo/accountdb/db.go @@ -6,7 +6,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/pkg/db/internal/mongo/accountdb/user.go b/api/pkg/db/internal/mongo/accountdb/user.go index df52d22a..22d68e5e 100755 --- a/api/pkg/db/internal/mongo/accountdb/user.go +++ b/api/pkg/db/internal/mongo/accountdb/user.go @@ -7,10 +7,10 @@ import ( "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/model" mutil "github.com/tech/sendico/pkg/mutil/db" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *AccountDB) GetAccountsByRefs(ctx context.Context, orgRef primitive.ObjectID, refs []primitive.ObjectID) ([]model.Account, error) { +func (db *AccountDB) GetAccountsByRefs(ctx context.Context, orgRef bson.ObjectID, refs []bson.ObjectID) ([]model.Account, error) { filter := repository.Query().Comparison(repository.IDField(), builder.In, refs) return mutil.GetObjects[model.Account](ctx, db.Logger, filter, nil, db.Repository) } diff --git a/api/pkg/db/internal/mongo/archivable/archivable.go b/api/pkg/db/internal/mongo/archivable/archivable.go index 133dd6de..2f2954e8 100644 --- a/api/pkg/db/internal/mongo/archivable/archivable.go +++ b/api/pkg/db/internal/mongo/archivable/archivable.go @@ -8,7 +8,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -36,7 +36,7 @@ func NewArchivableDB[T storable.Storable]( } // SetArchived sets the archived status of an entity -func (db *ArchivableDB[T]) SetArchived(ctx context.Context, objectRef primitive.ObjectID, archived bool) error { +func (db *ArchivableDB[T]) SetArchived(ctx context.Context, objectRef bson.ObjectID, archived bool) error { // Get current object to check current archived status obj := db.createEmpty() if err := db.repo.Get(ctx, objectRef, obj); err != nil { @@ -74,7 +74,7 @@ func (db *ArchivableDB[T]) SetArchived(ctx context.Context, objectRef primitive. } // IsArchived checks if an entity is archived -func (db *ArchivableDB[T]) IsArchived(ctx context.Context, objectRef primitive.ObjectID) (bool, error) { +func (db *ArchivableDB[T]) IsArchived(ctx context.Context, objectRef bson.ObjectID) (bool, error) { obj := db.createEmpty() if err := db.repo.Get(ctx, objectRef, obj); err != nil { @@ -89,11 +89,11 @@ func (db *ArchivableDB[T]) IsArchived(ctx context.Context, objectRef primitive.O } // Archive archives an entity (sets archived to true) -func (db *ArchivableDB[T]) Archive(ctx context.Context, objectRef primitive.ObjectID) error { +func (db *ArchivableDB[T]) Archive(ctx context.Context, objectRef bson.ObjectID) error { return db.SetArchived(ctx, objectRef, true) } // Unarchive unarchives an entity (sets archived to false) -func (db *ArchivableDB[T]) Unarchive(ctx context.Context, objectRef primitive.ObjectID) error { +func (db *ArchivableDB[T]) Unarchive(ctx context.Context, objectRef bson.ObjectID) error { return db.SetArchived(ctx, objectRef, false) } diff --git a/api/pkg/db/internal/mongo/archivable/archivable_test.go b/api/pkg/db/internal/mongo/archivable/archivable_test.go index 789e2222..265c4743 100644 --- a/api/pkg/db/internal/mongo/archivable/archivable_test.go +++ b/api/pkg/db/internal/mongo/archivable/archivable_test.go @@ -8,16 +8,16 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tech/sendico/pkg/db/internal/mongo/repositoryimp" "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/model" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mongodb" "github.com/testcontainers/testcontainers-go/wait" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" "go.uber.org/zap" ) diff --git a/api/pkg/db/internal/mongo/chainassetsdb/db.go b/api/pkg/db/internal/mongo/chainassetsdb/db.go index 50b5c38d..e437492a 100644 --- a/api/pkg/db/internal/mongo/chainassetsdb/db.go +++ b/api/pkg/db/internal/mongo/chainassetsdb/db.go @@ -6,7 +6,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/pkg/db/internal/mongo/confirmationdb/db.go b/api/pkg/db/internal/mongo/confirmationdb/db.go index 27cf5714..5e97b046 100644 --- a/api/pkg/db/internal/mongo/confirmationdb/db.go +++ b/api/pkg/db/internal/mongo/confirmationdb/db.go @@ -7,7 +7,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/pkg/db/internal/mongo/confirmationdb/delete.go b/api/pkg/db/internal/mongo/confirmationdb/delete.go index c1744357..fa04153f 100644 --- a/api/pkg/db/internal/mongo/confirmationdb/delete.go +++ b/api/pkg/db/internal/mongo/confirmationdb/delete.go @@ -5,10 +5,10 @@ import ( "github.com/tech/sendico/pkg/db/repository" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *ConfirmationDB) DeleteTuple(ctx context.Context, accountRef primitive.ObjectID, destination string, target model.ConfirmationTarget) error { +func (db *ConfirmationDB) DeleteTuple(ctx context.Context, accountRef bson.ObjectID, destination string, target model.ConfirmationTarget) error { query := repository.Query(). Filter(repository.Field(fieldAccountRef), accountRef). Filter(repository.Field(fieldDestination), destination). diff --git a/api/pkg/db/internal/mongo/confirmationdb/find.go b/api/pkg/db/internal/mongo/confirmationdb/find.go index 3be2f63e..7737c0c6 100644 --- a/api/pkg/db/internal/mongo/confirmationdb/find.go +++ b/api/pkg/db/internal/mongo/confirmationdb/find.go @@ -7,10 +7,10 @@ import ( "github.com/tech/sendico/pkg/db/repository" "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *ConfirmationDB) FindActive(ctx context.Context, accountRef primitive.ObjectID, destination string, target model.ConfirmationTarget, now int64) (*model.ConfirmationCode, error) { +func (db *ConfirmationDB) FindActive(ctx context.Context, accountRef bson.ObjectID, destination string, target model.ConfirmationTarget, now int64) (*model.ConfirmationCode, error) { var res model.ConfirmationCode query := repository.Query(). Filter(repository.Field(fieldAccountRef), accountRef). diff --git a/api/pkg/db/internal/mongo/db.go b/api/pkg/db/internal/mongo/db.go index ceeba721..00139039 100755 --- a/api/pkg/db/internal/mongo/db.go +++ b/api/pkg/db/internal/mongo/db.go @@ -36,8 +36,8 @@ import ( "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" mutil "github.com/tech/sendico/pkg/mutil/config" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/readpref" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/readpref" "go.uber.org/zap" ) @@ -133,7 +133,7 @@ func decodeConfig(logger mlogger.Logger, settings model.SettingsT) (*Config, *DB func dialMongo(logger mlogger.Logger, dbSettings *DBSettings) (*mongo.Client, error) { opts := buildOptions(dbSettings) - client, err := mongo.Connect(context.Background(), opts) + client, err := mongo.Connect(opts) if err != nil { logger.Error("Unable to connect to database", zap.Error(err)) return nil, err diff --git a/api/pkg/db/internal/mongo/indexable/USAGE.md b/api/pkg/db/internal/mongo/indexable/USAGE.md index 682838d0..5629f29d 100644 --- a/api/pkg/db/internal/mongo/indexable/USAGE.md +++ b/api/pkg/db/internal/mongo/indexable/USAGE.md @@ -160,7 +160,7 @@ type IndexableDB[T storable.Storable] struct { } // Single filter parameter - clean and simple -func (db *IndexableDB[T]) Reorder(ctx context.Context, objectRef primitive.ObjectID, newIndex int, filter builder.Query) error +func (db *IndexableDB[T]) Reorder(ctx context.Context, objectRef bson.ObjectID, newIndex int, filter builder.Query) error ``` ## Benefits diff --git a/api/pkg/db/internal/mongo/indexable/indexable.go b/api/pkg/db/internal/mongo/indexable/indexable.go index 874c79b7..4cbdbcea 100644 --- a/api/pkg/db/internal/mongo/indexable/indexable.go +++ b/api/pkg/db/internal/mongo/indexable/indexable.go @@ -8,7 +8,7 @@ import ( "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -36,7 +36,7 @@ func NewIndexableDB[T storable.Storable]( } // Reorder implements the db.IndexableDB interface with single filter parameter -func (db *IndexableDB[T]) Reorder(ctx context.Context, objectRef primitive.ObjectID, newIndex int, filter builder.Query) error { +func (db *IndexableDB[T]) Reorder(ctx context.Context, objectRef bson.ObjectID, newIndex int, filter builder.Query) error { // Get current object to find its index obj := db.createEmpty() err := db.repo.Get(ctx, objectRef, obj) diff --git a/api/pkg/db/internal/mongo/invitationdb/accept.go b/api/pkg/db/internal/mongo/invitationdb/accept.go index 01ac0912..8b22999c 100644 --- a/api/pkg/db/internal/mongo/invitationdb/accept.go +++ b/api/pkg/db/internal/mongo/invitationdb/accept.go @@ -4,9 +4,9 @@ import ( "context" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *InvitationDB) Accept(ctx context.Context, invitationRef primitive.ObjectID) error { +func (db *InvitationDB) Accept(ctx context.Context, invitationRef bson.ObjectID) error { return db.updateStatus(ctx, invitationRef, model.InvitationAccepted) } diff --git a/api/pkg/db/internal/mongo/invitationdb/archived.go b/api/pkg/db/internal/mongo/invitationdb/archived.go index 546b0045..c899d1ae 100644 --- a/api/pkg/db/internal/mongo/invitationdb/archived.go +++ b/api/pkg/db/internal/mongo/invitationdb/archived.go @@ -6,13 +6,13 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) // SetArchived sets the archived status of an invitation // Invitation supports archiving through PermissionBound embedding ArchivableBase -func (db *InvitationDB) SetArchived(ctx context.Context, accountRef, organizationRef, invitationRef primitive.ObjectID, archived, cascade bool) error { +func (db *InvitationDB) SetArchived(ctx context.Context, accountRef, organizationRef, invitationRef bson.ObjectID, archived, cascade bool) error { db.DBImp.Logger.Debug("Setting invitation archived status", mzap.ObjRef("invitation_ref", invitationRef), zap.Bool("archived", archived), zap.Bool("cascade", cascade)) res, err := db.Enforcer.Enforce(ctx, db.PermissionRef, accountRef, organizationRef, invitationRef, model.ActionUpdate) if err != nil { diff --git a/api/pkg/db/internal/mongo/invitationdb/cascade.go b/api/pkg/db/internal/mongo/invitationdb/cascade.go index 6b3fa866..6ec580bf 100644 --- a/api/pkg/db/internal/mongo/invitationdb/cascade.go +++ b/api/pkg/db/internal/mongo/invitationdb/cascade.go @@ -4,13 +4,13 @@ import ( "context" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) // DeleteCascade deletes an invitation // Invitations don't have cascade dependencies, so this is a simple deletion -func (db *InvitationDB) DeleteCascade(ctx context.Context, accountRef, invitationRef primitive.ObjectID) error { +func (db *InvitationDB) DeleteCascade(ctx context.Context, accountRef, invitationRef bson.ObjectID) error { db.DBImp.Logger.Debug("Starting invitation cascade deletion", mzap.ObjRef("invitation_ref", invitationRef)) // Delete the invitation itself (no dependencies to cascade delete) diff --git a/api/pkg/db/internal/mongo/invitationdb/db.go b/api/pkg/db/internal/mongo/invitationdb/db.go index c9afc3c3..7221fff1 100644 --- a/api/pkg/db/internal/mongo/invitationdb/db.go +++ b/api/pkg/db/internal/mongo/invitationdb/db.go @@ -10,7 +10,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/pkg/db/internal/mongo/invitationdb/decline.go b/api/pkg/db/internal/mongo/invitationdb/decline.go index d6fadae5..0cd0b989 100644 --- a/api/pkg/db/internal/mongo/invitationdb/decline.go +++ b/api/pkg/db/internal/mongo/invitationdb/decline.go @@ -4,9 +4,9 @@ import ( "context" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *InvitationDB) Decline(ctx context.Context, invitationRef primitive.ObjectID) error { +func (db *InvitationDB) Decline(ctx context.Context, invitationRef bson.ObjectID) error { return db.updateStatus(ctx, invitationRef, model.InvitationDeclined) } diff --git a/api/pkg/db/internal/mongo/invitationdb/getpublic.go b/api/pkg/db/internal/mongo/invitationdb/getpublic.go index 072f9291..d072f157 100644 --- a/api/pkg/db/internal/mongo/invitationdb/getpublic.go +++ b/api/pkg/db/internal/mongo/invitationdb/getpublic.go @@ -9,12 +9,12 @@ import ( "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) -func (db *InvitationDB) GetPublic(ctx context.Context, invitationRef primitive.ObjectID) (*model.PublicInvitation, error) { +func (db *InvitationDB) GetPublic(ctx context.Context, invitationRef bson.ObjectID) (*model.PublicInvitation, error) { roleField := repository.Field("role") orgField := repository.Field("organization") accField := repository.Field("account") diff --git a/api/pkg/db/internal/mongo/invitationdb/list.go b/api/pkg/db/internal/mongo/invitationdb/list.go index 0e8aa5fb..4eb61b8a 100644 --- a/api/pkg/db/internal/mongo/invitationdb/list.go +++ b/api/pkg/db/internal/mongo/invitationdb/list.go @@ -8,10 +8,10 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/model" mauth "github.com/tech/sendico/pkg/mutil/db/auth" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *InvitationDB) List(ctx context.Context, accountRef, organizationRef, _ primitive.ObjectID, cursor *model.ViewCursor) ([]model.Invitation, error) { +func (db *InvitationDB) List(ctx context.Context, accountRef, organizationRef, _ bson.ObjectID, cursor *model.ViewCursor) ([]model.Invitation, error) { res, err := mauth.GetProtectedObjects[model.Invitation]( ctx, db.DBImp.Logger, diff --git a/api/pkg/db/internal/mongo/invitationdb/updatestatus.go b/api/pkg/db/internal/mongo/invitationdb/updatestatus.go index 966d3a61..a55ba460 100644 --- a/api/pkg/db/internal/mongo/invitationdb/updatestatus.go +++ b/api/pkg/db/internal/mongo/invitationdb/updatestatus.go @@ -6,11 +6,11 @@ import ( "github.com/tech/sendico/pkg/db/repository" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) -func (db *InvitationDB) updateStatus(ctx context.Context, invitationRef primitive.ObjectID, newStatus model.InvitationStatus) error { +func (db *InvitationDB) updateStatus(ctx context.Context, invitationRef bson.ObjectID, newStatus model.InvitationStatus) error { // db.DBImp.Up var inv model.Invitation if err := db.DBImp.FindOne(ctx, repository.IDFilter(invitationRef), &inv); err != nil { diff --git a/api/pkg/db/internal/mongo/mongo.go b/api/pkg/db/internal/mongo/mongo.go index 60d3c1cf..45915bc5 100644 --- a/api/pkg/db/internal/mongo/mongo.go +++ b/api/pkg/db/internal/mongo/mongo.go @@ -4,7 +4,7 @@ import ( "net" "strings" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/mongo/options" ) func buildOptions(s *DBSettings) *options.ClientOptions { diff --git a/api/pkg/db/internal/mongo/organizationdb/archived.go b/api/pkg/db/internal/mongo/organizationdb/archived.go index 0d2acaed..bae2d893 100644 --- a/api/pkg/db/internal/mongo/organizationdb/archived.go +++ b/api/pkg/db/internal/mongo/organizationdb/archived.go @@ -5,12 +5,12 @@ import ( "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) // SetArchived sets the archived status of an organization and optionally cascades to projects, tasks, comments, and reactions -func (db *OrganizationDB) SetArchived(ctx context.Context, accountRef, organizationRef primitive.ObjectID, archived, cascade bool) error { +func (db *OrganizationDB) SetArchived(ctx context.Context, accountRef, organizationRef bson.ObjectID, archived, cascade bool) error { db.DBImp.Logger.Debug("Setting organization archived status", mzap.ObjRef("organization_ref", organizationRef), zap.Bool("archived", archived), zap.Bool("cascade", cascade)) // Get the organization first diff --git a/api/pkg/db/internal/mongo/organizationdb/cascade.go b/api/pkg/db/internal/mongo/organizationdb/cascade.go index d5bbff3c..5dc47aa8 100644 --- a/api/pkg/db/internal/mongo/organizationdb/cascade.go +++ b/api/pkg/db/internal/mongo/organizationdb/cascade.go @@ -4,12 +4,12 @@ import ( "context" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) // DeleteCascade deletes an organization and all its related data (projects, tasks, comments, reactions, statuses) -func (db *OrganizationDB) DeleteCascade(ctx context.Context, organizationRef primitive.ObjectID) error { +func (db *OrganizationDB) DeleteCascade(ctx context.Context, organizationRef bson.ObjectID) error { db.DBImp.Logger.Debug("Starting organization deletion with projects", mzap.ObjRef("organization_ref", organizationRef)) // Delete the organization itself diff --git a/api/pkg/db/internal/mongo/organizationdb/create.go b/api/pkg/db/internal/mongo/organizationdb/create.go index 2be8cd2e..4107dd16 100644 --- a/api/pkg/db/internal/mongo/organizationdb/create.go +++ b/api/pkg/db/internal/mongo/organizationdb/create.go @@ -5,14 +5,14 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *OrganizationDB) Create(ctx context.Context, _, _ primitive.ObjectID, org *model.Organization) error { +func (db *OrganizationDB) Create(ctx context.Context, _, _ bson.ObjectID, org *model.Organization) error { if org == nil { return merrors.InvalidArgument("Organization object is nil", "organization") } - org.SetID(primitive.NewObjectID()) + org.SetID(bson.NewObjectID()) // Organizaiton reference must be set to the same value as own organization reference org.SetOrganizationRef(*org.GetID()) return db.DBImp.Create(ctx, org) diff --git a/api/pkg/db/internal/mongo/organizationdb/db.go b/api/pkg/db/internal/mongo/organizationdb/db.go index 4ae81766..fa4f7a07 100644 --- a/api/pkg/db/internal/mongo/organizationdb/db.go +++ b/api/pkg/db/internal/mongo/organizationdb/db.go @@ -8,7 +8,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" ) type OrganizationDB struct { diff --git a/api/pkg/db/internal/mongo/organizationdb/get.go b/api/pkg/db/internal/mongo/organizationdb/get.go index 0a3a7ec9..4202d047 100644 --- a/api/pkg/db/internal/mongo/organizationdb/get.go +++ b/api/pkg/db/internal/mongo/organizationdb/get.go @@ -4,9 +4,9 @@ import ( "context" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *OrganizationDB) GetByRef(ctx context.Context, organizationRef primitive.ObjectID, org *model.Organization) error { +func (db *OrganizationDB) GetByRef(ctx context.Context, organizationRef bson.ObjectID, org *model.Organization) error { return db.Unprotected().Get(ctx, organizationRef, org) } diff --git a/api/pkg/db/internal/mongo/organizationdb/list.go b/api/pkg/db/internal/mongo/organizationdb/list.go index 4b1e691d..c445d7c4 100644 --- a/api/pkg/db/internal/mongo/organizationdb/list.go +++ b/api/pkg/db/internal/mongo/organizationdb/list.go @@ -7,10 +7,10 @@ import ( "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/model" mutil "github.com/tech/sendico/pkg/mutil/db" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *OrganizationDB) List(ctx context.Context, accountRef primitive.ObjectID, cursor *model.ViewCursor) ([]model.Organization, error) { +func (db *OrganizationDB) List(ctx context.Context, accountRef bson.ObjectID, cursor *model.ViewCursor) ([]model.Organization, error) { filter := repository.Query().Comparison(repository.Field("members"), builder.Eq, accountRef) return mutil.GetObjects[model.Organization](ctx, db.DBImp.Logger, filter, cursor, db.DBImp.Repository) } diff --git a/api/pkg/db/internal/mongo/organizationdb/owned.go b/api/pkg/db/internal/mongo/organizationdb/owned.go index 87ebdfc0..1f2e7176 100644 --- a/api/pkg/db/internal/mongo/organizationdb/owned.go +++ b/api/pkg/db/internal/mongo/organizationdb/owned.go @@ -6,9 +6,9 @@ import ( "github.com/tech/sendico/pkg/db/repository" "github.com/tech/sendico/pkg/model" mutil "github.com/tech/sendico/pkg/mutil/db" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *OrganizationDB) ListOwned(ctx context.Context, accountRef primitive.ObjectID) ([]model.Organization, error) { +func (db *OrganizationDB) ListOwned(ctx context.Context, accountRef bson.ObjectID) ([]model.Organization, error) { return mutil.GetObjects[model.Organization](ctx, db.DBImp.Logger, repository.Filter("ownerRef", accountRef), nil, db.DBImp.Repository) } diff --git a/api/pkg/db/internal/mongo/organizationdb/setarchived_test.go b/api/pkg/db/internal/mongo/organizationdb/setarchived_test.go index cdfb27e7..fa895164 100644 --- a/api/pkg/db/internal/mongo/organizationdb/setarchived_test.go +++ b/api/pkg/db/internal/mongo/organizationdb/setarchived_test.go @@ -17,13 +17,13 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) func TestOrganizationDB_SetArchived_TogglesState(t *testing.T) { ctx := context.Background() - accountRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() orgDB := newTestOrganizationDB(t) org := &model.Organization{ @@ -32,7 +32,7 @@ func TestOrganizationDB_SetArchived_TogglesState(t *testing.T) { TimeZone: "UTC", }, } - org.SetID(primitive.NewObjectID()) + org.SetID(bson.NewObjectID()) require.NoError(t, orgDB.Create(ctx, accountRef, *org.GetID(), org)) @@ -51,10 +51,10 @@ func TestOrganizationDB_SetArchived_TogglesState(t *testing.T) { func TestOrganizationDB_SetArchived_UnknownOrganization(t *testing.T) { ctx := context.Background() - accountRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() orgDB := newTestOrganizationDB(t) - err := orgDB.SetArchived(ctx, accountRef, primitive.NewObjectID(), true, false) + err := orgDB.SetArchived(ctx, accountRef, bson.NewObjectID(), true, false) require.Error(t, err) assert.True(t, errors.Is(err, merrors.ErrNoData)) } @@ -71,7 +71,7 @@ func newTestOrganizationDB(t *testing.T) *OrganizationDB { Logger: logger, Repository: repo, } - dbImp.SetDeleter(func(ctx context.Context, objectRef primitive.ObjectID) error { + dbImp.SetDeleter(func(ctx context.Context, objectRef bson.ObjectID) error { return repo.Delete(ctx, objectRef) }) @@ -79,7 +79,7 @@ func newTestOrganizationDB(t *testing.T) *OrganizationDB { ProtectedDBImp: auth.ProtectedDBImp[*model.Organization]{ DBImp: dbImp, Enforcer: allowAllEnforcer{}, - PermissionRef: primitive.NewObjectID(), + PermissionRef: bson.NewObjectID(), Collection: mservice.Organizations, }, } @@ -87,35 +87,35 @@ func newTestOrganizationDB(t *testing.T) *OrganizationDB { type allowAllEnforcer struct{} -func (allowAllEnforcer) Enforce(context.Context, primitive.ObjectID, primitive.ObjectID, primitive.ObjectID, primitive.ObjectID, model.Action) (bool, error) { +func (allowAllEnforcer) Enforce(context.Context, bson.ObjectID, bson.ObjectID, bson.ObjectID, bson.ObjectID, model.Action) (bool, error) { return true, nil } -func (allowAllEnforcer) EnforceBatch(_ context.Context, objects []model.PermissionBoundStorable, _ primitive.ObjectID, _ model.Action) (map[primitive.ObjectID]bool, error) { - result := make(map[primitive.ObjectID]bool, len(objects)) +func (allowAllEnforcer) EnforceBatch(_ context.Context, objects []model.PermissionBoundStorable, _ bson.ObjectID, _ model.Action) (map[bson.ObjectID]bool, error) { + result := make(map[bson.ObjectID]bool, len(objects)) for _, obj := range objects { result[*obj.GetID()] = true } return result, nil } -func (allowAllEnforcer) GetRoles(context.Context, primitive.ObjectID, primitive.ObjectID) ([]model.Role, error) { +func (allowAllEnforcer) GetRoles(context.Context, bson.ObjectID, bson.ObjectID) ([]model.Role, error) { return nil, nil } -func (allowAllEnforcer) GetPermissions(context.Context, primitive.ObjectID, primitive.ObjectID) ([]model.Role, []model.Permission, error) { +func (allowAllEnforcer) GetPermissions(context.Context, bson.ObjectID, bson.ObjectID) ([]model.Role, []model.Permission, error) { return nil, nil, nil } type memoryOrganizationRepository struct { mu sync.RWMutex - data map[primitive.ObjectID]*model.Organization - order []primitive.ObjectID + data map[bson.ObjectID]*model.Organization + order []bson.ObjectID } func newMemoryOrganizationRepository() *memoryOrganizationRepository { return &memoryOrganizationRepository{ - data: make(map[primitive.ObjectID]*model.Organization), + data: make(map[bson.ObjectID]*model.Organization), } } @@ -132,7 +132,7 @@ func (m *memoryOrganizationRepository) Insert(_ context.Context, obj storable.St return merrors.InvalidDataType("expected organization") } id := org.GetID() - if id == nil || *id == primitive.NilObjectID { + if id == nil || *id == bson.NilObjectID { return merrors.InvalidArgument("organization ID must be set") } if _, exists := m.data[*id]; exists { @@ -152,7 +152,7 @@ func (m *memoryOrganizationRepository) InsertMany(ctx context.Context, objects [ return nil } -func (m *memoryOrganizationRepository) Get(_ context.Context, id primitive.ObjectID, result storable.Storable) error { +func (m *memoryOrganizationRepository) Get(_ context.Context, id bson.ObjectID, result storable.Storable) error { m.mu.RLock() defer m.mu.RUnlock() @@ -207,7 +207,7 @@ func (m *memoryOrganizationRepository) Update(_ context.Context, obj storable.St return nil } -func (m *memoryOrganizationRepository) Patch(context.Context, primitive.ObjectID, builder.Patch) error { +func (m *memoryOrganizationRepository) Patch(context.Context, bson.ObjectID, builder.Patch) error { return merrors.NotImplemented("Patch is not supported in memory repository") } @@ -215,7 +215,7 @@ func (m *memoryOrganizationRepository) PatchMany(context.Context, builder.Query, return 0, merrors.NotImplemented("PatchMany is not supported in memory repository") } -func (m *memoryOrganizationRepository) Delete(_ context.Context, id primitive.ObjectID) error { +func (m *memoryOrganizationRepository) Delete(_ context.Context, id bson.ObjectID) error { m.mu.Lock() defer m.mu.Unlock() if _, exists := m.data[id]; !exists { @@ -233,11 +233,11 @@ func (m *memoryOrganizationRepository) CreateIndex(*ri.Definition) error { return nil } -func (m *memoryOrganizationRepository) ListIDs(_ context.Context, query builder.Query) ([]primitive.ObjectID, error) { +func (m *memoryOrganizationRepository) ListIDs(_ context.Context, query builder.Query) ([]bson.ObjectID, error) { m.mu.RLock() defer m.mu.RUnlock() - var ids []primitive.ObjectID + var ids []bson.ObjectID for _, id := range m.order { if org, ok := m.data[id]; ok && m.matchesQuery(query, org) { ids = append(ids, id) @@ -277,7 +277,7 @@ func (m *memoryOrganizationRepository) matchesQuery(query builder.Query, org *mo for _, elem := range query.BuildQuery() { switch elem.Key { case storable.IDField: - id, ok := elem.Value.(primitive.ObjectID) + id, ok := elem.Value.(bson.ObjectID) if !ok || *org.GetID() != id { return false } @@ -294,7 +294,7 @@ func (m *memoryOrganizationRepository) matchesQuery(query builder.Query, org *mo func cloneOrganization(src *model.Organization) *model.Organization { dst := *src if len(src.Members) > 0 { - dst.Members = append([]primitive.ObjectID{}, src.Members...) + dst.Members = append([]bson.ObjectID{}, src.Members...) } return &dst } diff --git a/api/pkg/db/internal/mongo/paymethoddb/archived.go b/api/pkg/db/internal/mongo/paymethoddb/archived.go index 13c8e35f..9bcef783 100644 --- a/api/pkg/db/internal/mongo/paymethoddb/archived.go +++ b/api/pkg/db/internal/mongo/paymethoddb/archived.go @@ -4,11 +4,11 @@ import ( "context" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) -func (db *PaymentMethodsDB) SetArchived(ctx context.Context, accountRef, organizationRef, objectRef primitive.ObjectID, isArchived, cascade bool) error { +func (db *PaymentMethodsDB) SetArchived(ctx context.Context, accountRef, organizationRef, objectRef bson.ObjectID, isArchived, cascade bool) error { // Use the ArchivableDB for the main archiving logic if err := db.ArchivableDB.SetArchived(ctx, accountRef, objectRef, isArchived); err != nil { db.DBImp.Logger.Warn("Failed to chnage object archive status", zap.Error(err), diff --git a/api/pkg/db/internal/mongo/paymethoddb/db.go b/api/pkg/db/internal/mongo/paymethoddb/db.go index 57917dfd..03fd6656 100644 --- a/api/pkg/db/internal/mongo/paymethoddb/db.go +++ b/api/pkg/db/internal/mongo/paymethoddb/db.go @@ -9,7 +9,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/pkg/db/internal/mongo/paymethoddb/list.go b/api/pkg/db/internal/mongo/paymethoddb/list.go index 772c3b51..63be7a6e 100644 --- a/api/pkg/db/internal/mongo/paymethoddb/list.go +++ b/api/pkg/db/internal/mongo/paymethoddb/list.go @@ -8,10 +8,10 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/model" mauth "github.com/tech/sendico/pkg/mutil/db/auth" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *PaymentMethodsDB) List(ctx context.Context, accountRef, organizationRef, recipientRef primitive.ObjectID, cursor *model.ViewCursor) ([]model.PaymentMethod, error) { +func (db *PaymentMethodsDB) List(ctx context.Context, accountRef, organizationRef, recipientRef bson.ObjectID, cursor *model.ViewCursor) ([]model.PaymentMethod, error) { res, err := mauth.GetProtectedObjects[model.PaymentMethod]( ctx, db.DBImp.Logger, diff --git a/api/pkg/db/internal/mongo/policiesdb/all.go b/api/pkg/db/internal/mongo/policiesdb/all.go index a74c1abb..d944be21 100644 --- a/api/pkg/db/internal/mongo/policiesdb/all.go +++ b/api/pkg/db/internal/mongo/policiesdb/all.go @@ -7,10 +7,10 @@ import ( "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/model" mutil "github.com/tech/sendico/pkg/mutil/db" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *PoliciesDB) All(ctx context.Context, organizationRef primitive.ObjectID) ([]model.PolicyDescription, error) { +func (db *PoliciesDB) All(ctx context.Context, organizationRef bson.ObjectID) ([]model.PolicyDescription, error) { // all documents filter := repository.Query().Or( repository.Filter(storable.OrganizationRefField, nil), diff --git a/api/pkg/db/internal/mongo/policiesdb/db.go b/api/pkg/db/internal/mongo/policiesdb/db.go index 425e395d..b4c0e973 100644 --- a/api/pkg/db/internal/mongo/policiesdb/db.go +++ b/api/pkg/db/internal/mongo/policiesdb/db.go @@ -5,7 +5,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" ) type PoliciesDB struct { diff --git a/api/pkg/db/internal/mongo/policiesdb/db_test.go b/api/pkg/db/internal/mongo/policiesdb/db_test.go index 2bf6827c..5089eec6 100644 --- a/api/pkg/db/internal/mongo/policiesdb/db_test.go +++ b/api/pkg/db/internal/mongo/policiesdb/db_test.go @@ -14,17 +14,19 @@ import ( "github.com/tech/sendico/pkg/db/repository" "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/merrors" + // Model package (contains PolicyDescription + Describable) - "github.com/tech/sendico/pkg/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/tech/sendico/pkg/model" + // Testcontainers "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mongodb" "github.com/testcontainers/testcontainers-go/wait" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" "go.uber.org/zap" ) @@ -114,7 +116,7 @@ func TestPoliciesDB(t *testing.T) { cleanupCollection(t, ctx, db) // Attempt to get a non-existent ID - nonExistentID := primitive.NewObjectID() + nonExistentID := bson.NewObjectID() result := &model.PolicyDescription{} err := pdb.Get(ctx, nonExistentID, result) assert.Error(t, err) @@ -234,8 +236,8 @@ func TestPoliciesDB(t *testing.T) { cleanupCollection(t, ctx, db) // Insert some policies (orgA, orgB, nil org) - orgA := primitive.NewObjectID() - orgB := primitive.NewObjectID() + orgA := bson.NewObjectID() + orgB := bson.NewObjectID() descA := "Org A policy" policyA := &model.PolicyDescription{ @@ -272,7 +274,7 @@ func TestPoliciesDB(t *testing.T) { require.NoError(t, err) require.Len(t, resultsA, 2) // orgA + built-in - var idsA []primitive.ObjectID + var idsA []bson.ObjectID for _, r := range resultsA { idsA = append(idsA, r.ID) } @@ -284,7 +286,7 @@ func TestPoliciesDB(t *testing.T) { require.NoError(t, err) require.Len(t, resultsB, 2) // orgB + built-in - var idsB []primitive.ObjectID + var idsB []bson.ObjectID for _, r := range resultsB { idsB = append(idsB, r.ID) } @@ -322,11 +324,11 @@ func TestPoliciesDB(t *testing.T) { require.NoError(t, pdb.Create(ctx, pol3)) // 1) Request pol1, pol2 - results12, err := pdb.Policies(ctx, []primitive.ObjectID{pol1.ID, pol2.ID}) + results12, err := pdb.Policies(ctx, []bson.ObjectID{pol1.ID, pol2.ID}) require.NoError(t, err) require.Len(t, results12, 2) // IDs might be out of order, so we do a set-like check - var set12 []primitive.ObjectID + var set12 []bson.ObjectID for _, r := range results12 { set12 = append(set12, r.ID) } @@ -334,11 +336,11 @@ func TestPoliciesDB(t *testing.T) { assert.Contains(t, set12, pol2.ID) // 2) Request pol1, pol3, plus a random ID - fakeID := primitive.NewObjectID() - results13Fake, err := pdb.Policies(ctx, []primitive.ObjectID{pol1.ID, pol3.ID, fakeID}) + fakeID := bson.NewObjectID() + results13Fake, err := pdb.Policies(ctx, []bson.ObjectID{pol1.ID, pol3.ID, fakeID}) require.NoError(t, err) require.Len(t, results13Fake, 2) // pol1 + pol3 only - var set13Fake []primitive.ObjectID + var set13Fake []bson.ObjectID for _, r := range results13Fake { set13Fake = append(set13Fake, r.ID) } @@ -346,7 +348,7 @@ func TestPoliciesDB(t *testing.T) { assert.Contains(t, set13Fake, pol3.ID) // 3) Request with empty slice => expect no results - resultsEmpty, err := pdb.Policies(ctx, []primitive.ObjectID{}) + resultsEmpty, err := pdb.Policies(ctx, []bson.ObjectID{}) require.NoError(t, err) assert.Len(t, resultsEmpty, 0) }) diff --git a/api/pkg/db/internal/mongo/policiesdb/policies.go b/api/pkg/db/internal/mongo/policiesdb/policies.go index 3e809434..b802cb5d 100644 --- a/api/pkg/db/internal/mongo/policiesdb/policies.go +++ b/api/pkg/db/internal/mongo/policiesdb/policies.go @@ -6,10 +6,10 @@ import ( "github.com/tech/sendico/pkg/db/repository" "github.com/tech/sendico/pkg/model" mutil "github.com/tech/sendico/pkg/mutil/db" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *PoliciesDB) Policies(ctx context.Context, refs []primitive.ObjectID) ([]model.PolicyDescription, error) { +func (db *PoliciesDB) Policies(ctx context.Context, refs []bson.ObjectID) ([]model.PolicyDescription, error) { if len(refs) == 0 { return []model.PolicyDescription{}, nil } diff --git a/api/pkg/db/internal/mongo/recipientdb/archived.go b/api/pkg/db/internal/mongo/recipientdb/archived.go index c0af4dcd..8a7c56b2 100644 --- a/api/pkg/db/internal/mongo/recipientdb/archived.go +++ b/api/pkg/db/internal/mongo/recipientdb/archived.go @@ -6,11 +6,11 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) -func (db *RecipientDB) SetArchived(ctx context.Context, accountRef, organizationRef, objectRef primitive.ObjectID, isArchived, cascade bool) error { +func (db *RecipientDB) SetArchived(ctx context.Context, accountRef, organizationRef, objectRef bson.ObjectID, isArchived, cascade bool) error { // Use the ArchivableDB for the main archiving logic if err := db.ArchivableDB.SetArchived(ctx, accountRef, objectRef, isArchived); err != nil { db.DBImp.Logger.Warn("Failed to change recipient archive status", zap.Error(err), @@ -32,7 +32,7 @@ func (db *RecipientDB) SetArchived(ctx context.Context, accountRef, organization return nil } -func (db *RecipientDB) setArchivedPaymentMethods(ctx context.Context, accountRef, organizationRef, recipientRef primitive.ObjectID, archived bool) error { +func (db *RecipientDB) setArchivedPaymentMethods(ctx context.Context, accountRef, organizationRef, recipientRef bson.ObjectID, archived bool) error { db.DBImp.Logger.Debug("Setting archived status for recipient payment methods", mzap.ObjRef("recipient_ref", recipientRef), zap.Bool("archived", archived)) db.DBImp.Logger.Debug("Applying archived status to payment methods for recipient", mzap.ObjRef("recipient_ref", recipientRef)) diff --git a/api/pkg/db/internal/mongo/recipientdb/db.go b/api/pkg/db/internal/mongo/recipientdb/db.go index c9fcc77b..4135c73f 100644 --- a/api/pkg/db/internal/mongo/recipientdb/db.go +++ b/api/pkg/db/internal/mongo/recipientdb/db.go @@ -9,7 +9,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" ) type RecipientDB struct { diff --git a/api/pkg/db/internal/mongo/recipientdb/list.go b/api/pkg/db/internal/mongo/recipientdb/list.go index 29c1fc70..ba7d1243 100644 --- a/api/pkg/db/internal/mongo/recipientdb/list.go +++ b/api/pkg/db/internal/mongo/recipientdb/list.go @@ -8,10 +8,10 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/model" mauth "github.com/tech/sendico/pkg/mutil/db/auth" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *RecipientDB) List(ctx context.Context, accountRef, organizationRef, _ primitive.ObjectID, cursor *model.ViewCursor) ([]model.Recipient, error) { +func (db *RecipientDB) List(ctx context.Context, accountRef, organizationRef, _ bson.ObjectID, cursor *model.ViewCursor) ([]model.Recipient, error) { res, err := mauth.GetProtectedObjects[model.Recipient]( ctx, db.DBImp.Logger, diff --git a/api/pkg/db/internal/mongo/refreshtokensdb/crud.go b/api/pkg/db/internal/mongo/refreshtokensdb/crud.go index 92699f31..4cfc039b 100644 --- a/api/pkg/db/internal/mongo/refreshtokensdb/crud.go +++ b/api/pkg/db/internal/mongo/refreshtokensdb/crud.go @@ -10,7 +10,7 @@ import ( "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -67,12 +67,12 @@ func (db *RefreshTokenDB) Update(ctx context.Context, rt *model.RefreshToken) er return db.Patch(ctx, *rt.GetID(), patch) } -func (db *RefreshTokenDB) Delete(ctx context.Context, tokenRef primitive.ObjectID) error { +func (db *RefreshTokenDB) Delete(ctx context.Context, tokenRef bson.ObjectID) error { db.Logger.Info("Deleting refresh token", mzap.ObjRef("refresh_token_ref", tokenRef)) return db.DBImp.Delete(ctx, tokenRef) } -func (db *RefreshTokenDB) Revoke(ctx context.Context, accountRef primitive.ObjectID, session *model.SessionIdentifier) error { +func (db *RefreshTokenDB) Revoke(ctx context.Context, accountRef bson.ObjectID, session *model.SessionIdentifier) error { var rt model.RefreshToken f := filterByAccount(accountRef, session) if err := db.Repository.FindOneByFilter(ctx, f, &rt); err != nil { diff --git a/api/pkg/db/internal/mongo/refreshtokensdb/db.go b/api/pkg/db/internal/mongo/refreshtokensdb/db.go index 06d232d4..d116fc42 100644 --- a/api/pkg/db/internal/mongo/refreshtokensdb/db.go +++ b/api/pkg/db/internal/mongo/refreshtokensdb/db.go @@ -7,7 +7,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/pkg/db/internal/mongo/refreshtokensdb/filters.go b/api/pkg/db/internal/mongo/refreshtokensdb/filters.go index ad67faba..eb875da2 100644 --- a/api/pkg/db/internal/mongo/refreshtokensdb/filters.go +++ b/api/pkg/db/internal/mongo/refreshtokensdb/filters.go @@ -4,7 +4,7 @@ import ( "github.com/tech/sendico/pkg/db/repository" "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) func filterByClientId(clientID string) builder.Query { @@ -20,6 +20,6 @@ func filter(session *model.SessionIdentifier) builder.Query { return filter } -func filterByAccount(accountRef primitive.ObjectID, session *model.SessionIdentifier) builder.Query { +func filterByAccount(accountRef bson.ObjectID, session *model.SessionIdentifier) builder.Query { return filter(session).And(repository.Query().Comparison(repository.AccountField(), builder.Eq, accountRef)) } diff --git a/api/pkg/db/internal/mongo/refreshtokensdb/refreshtokensdb_test.go b/api/pkg/db/internal/mongo/refreshtokensdb/refreshtokensdb_test.go index b5e57a61..e0f22bae 100644 --- a/api/pkg/db/internal/mongo/refreshtokensdb/refreshtokensdb_test.go +++ b/api/pkg/db/internal/mongo/refreshtokensdb/refreshtokensdb_test.go @@ -21,10 +21,9 @@ import ( "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mongodb" "github.com/testcontainers/testcontainers-go/wait" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" ) func setupTestDB(t *testing.T) (*refreshtokensdb.RefreshTokenDB, func()) { @@ -71,7 +70,7 @@ func setupTestDBWithMongo(t *testing.T) (*refreshtokensdb.RefreshTokenDB, *mongo return db, database, cleanup } -func createTestRefreshToken(accountRef primitive.ObjectID, clientID, deviceID, token string) *model.RefreshToken { +func createTestRefreshToken(accountRef bson.ObjectID, clientID, deviceID, token string) *model.RefreshToken { return &model.RefreshToken{ ClientRefreshToken: model.ClientRefreshToken{ SessionIdentifier: model.SessionIdentifier{ @@ -99,7 +98,7 @@ func TestRefreshTokenDB_AuthenticationFlow(t *testing.T) { t.Run("Complete_User_Authentication_Flow", func(t *testing.T) { // Setup: Create user and client - userID := primitive.NewObjectID() + userID := bson.NewObjectID() clientID := "web-app" deviceID := "user-desktop-chrome" token := "refresh_token_12345" @@ -141,7 +140,7 @@ func TestRefreshTokenDB_AuthenticationFlow(t *testing.T) { t.Run("Manual_Token_Revocation_Workaround", func(t *testing.T) { // Test manual revocation by directly updating the token - userID := primitive.NewObjectID() + userID := bson.NewObjectID() clientID := "web-app" deviceID := "user-desktop-chrome" token := "manual_revoke_token_123" @@ -178,7 +177,7 @@ func TestRefreshTokenDB_MultiDeviceManagement(t *testing.T) { ctx := context.Background() t.Run("User_With_Multiple_Devices", func(t *testing.T) { - userID := primitive.NewObjectID() + userID := bson.NewObjectID() clientID := "mobile-app" // User logs in from phone @@ -241,7 +240,7 @@ func TestRefreshTokenDB_TokenRotation(t *testing.T) { ctx := context.Background() t.Run("Token_Rotation_On_Use", func(t *testing.T) { - userID := primitive.NewObjectID() + userID := bson.NewObjectID() clientID := "web-app" deviceID := "user-browser" initialToken := "initial_token_123" @@ -298,7 +297,7 @@ func TestRefreshTokenDB_SessionReplacement(t *testing.T) { ctx := context.Background() t.Run("User_Login_From_Same_Device_Twice", func(t *testing.T) { - userID := primitive.NewObjectID() + userID := bson.NewObjectID() clientID := "web-app" deviceID := "user-laptop" @@ -340,7 +339,7 @@ func TestRefreshTokenDB_SessionReplacement(t *testing.T) { }) t.Run("Create_After_GlobalRevocation_AllowsNewActive", func(t *testing.T) { - userID := primitive.NewObjectID() + userID := bson.NewObjectID() clientID := "web-app" deviceID := "user-laptop" @@ -407,7 +406,7 @@ func TestRefreshTokenDB_ClientManagement(t *testing.T) { // Note: Client management is handled by a separate client database // This test verifies that refresh tokens work with different client IDs - userID := primitive.NewObjectID() + userID := bson.NewObjectID() // Create refresh tokens for different clients webToken := createTestRefreshToken(userID, "web-app", "device1", "token1") @@ -454,7 +453,7 @@ func TestRefreshTokenDB_SecurityScenarios(t *testing.T) { ctx := context.Background() t.Run("Token_Hijacking_Prevention", func(t *testing.T) { - userID := primitive.NewObjectID() + userID := bson.NewObjectID() clientID := "web-app" deviceID := "user-browser" token := "hijacked_token_123" @@ -509,7 +508,7 @@ func TestRefreshTokenDB_ExpiredTokenHandling(t *testing.T) { ctx := context.Background() t.Run("Expired_Token_Cleanup", func(t *testing.T) { - userID := primitive.NewObjectID() + userID := bson.NewObjectID() clientID := "web-app" deviceID := "user-device" token := "expired_token_123" @@ -548,7 +547,7 @@ func TestRefreshTokenDB_ConcurrentAccess(t *testing.T) { ctx := context.Background() t.Run("Concurrent_Token_Usage", func(t *testing.T) { - userID := primitive.NewObjectID() + userID := bson.NewObjectID() clientID := "web-app" deviceID := "user-device" token := "concurrent_token_123" @@ -594,7 +593,7 @@ func TestRefreshTokenDB_EdgeCases(t *testing.T) { ctx := context.Background() t.Run("Delete_Token_By_ID", func(t *testing.T) { - userID := primitive.NewObjectID() + userID := bson.NewObjectID() refreshToken := createTestRefreshToken(userID, "web-app", "device-1", "token_123") err := db.Create(ctx, refreshToken) require.NoError(t, err) @@ -613,7 +612,7 @@ func TestRefreshTokenDB_EdgeCases(t *testing.T) { }) t.Run("Revoke_Non_Existent_Token", func(t *testing.T) { - userID := primitive.NewObjectID() + userID := bson.NewObjectID() session := &model.SessionIdentifier{ ClientID: "non-existent-client", DeviceID: "non-existent-device", @@ -625,7 +624,7 @@ func TestRefreshTokenDB_EdgeCases(t *testing.T) { }) t.Run("RevokeAll_No_Other_Devices", func(t *testing.T) { - userID := primitive.NewObjectID() + userID := bson.NewObjectID() clientID := "web-app" deviceID := "only-device" @@ -659,8 +658,8 @@ func TestRefreshTokenDB_DatabaseIndexes(t *testing.T) { ctx := context.Background() t.Run("Unique_Token_Constraint", func(t *testing.T) { - userID1 := primitive.NewObjectID() - userID2 := primitive.NewObjectID() + userID1 := bson.NewObjectID() + userID2 := bson.NewObjectID() token := "duplicate_token_123" // Create first token @@ -676,7 +675,7 @@ func TestRefreshTokenDB_DatabaseIndexes(t *testing.T) { }) t.Run("Query_Performance_By_Revocation_Status", func(t *testing.T) { - userID := primitive.NewObjectID() + userID := bson.NewObjectID() clientID := "web-app" // Create multiple tokens diff --git a/api/pkg/db/internal/mongo/refreshtokensdb/revoke.go b/api/pkg/db/internal/mongo/refreshtokensdb/revoke.go index 8adc61e6..efc73e01 100644 --- a/api/pkg/db/internal/mongo/refreshtokensdb/revoke.go +++ b/api/pkg/db/internal/mongo/refreshtokensdb/revoke.go @@ -6,10 +6,10 @@ import ( "github.com/tech/sendico/pkg/db/repository" "github.com/tech/sendico/pkg/db/repository/builder" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *RefreshTokenDB) RevokeAll(ctx context.Context, accountRef primitive.ObjectID, deviceID string) error { +func (db *RefreshTokenDB) RevokeAll(ctx context.Context, accountRef bson.ObjectID, deviceID string) error { query := repository.Query(). Filter(repository.AccountField(), accountRef). And(repository.Query().Comparison(repository.Field("deviceId"), builder.Ne, deviceID)). diff --git a/api/pkg/db/internal/mongo/repositoryimp/builderimp/accumulator.go b/api/pkg/db/internal/mongo/repositoryimp/builderimp/accumulator.go index 85853505..09ff732b 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/builderimp/accumulator.go +++ b/api/pkg/db/internal/mongo/repositoryimp/builderimp/accumulator.go @@ -2,7 +2,7 @@ package builderimp import ( "github.com/tech/sendico/pkg/db/repository/builder" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) type literalAccumulatorImp struct { diff --git a/api/pkg/db/internal/mongo/repositoryimp/builderimp/alias.go b/api/pkg/db/internal/mongo/repositoryimp/builderimp/alias.go index 52ab07fc..546f64ef 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/builderimp/alias.go +++ b/api/pkg/db/internal/mongo/repositoryimp/builderimp/alias.go @@ -2,7 +2,7 @@ package builderimp import ( "github.com/tech/sendico/pkg/db/repository/builder" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) type aliasImp struct { diff --git a/api/pkg/db/internal/mongo/repositoryimp/builderimp/array.go b/api/pkg/db/internal/mongo/repositoryimp/builderimp/array.go index 44473752..738fc9e1 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/builderimp/array.go +++ b/api/pkg/db/internal/mongo/repositoryimp/builderimp/array.go @@ -2,7 +2,7 @@ package builderimp import ( "github.com/tech/sendico/pkg/db/repository/builder" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) type arrayImp struct { diff --git a/api/pkg/db/internal/mongo/repositoryimp/builderimp/expression.go b/api/pkg/db/internal/mongo/repositoryimp/builderimp/expression.go index fa0cfe2b..376a2fb8 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/builderimp/expression.go +++ b/api/pkg/db/internal/mongo/repositoryimp/builderimp/expression.go @@ -4,7 +4,7 @@ import ( "reflect" "github.com/tech/sendico/pkg/db/repository/builder" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) type literalExpression struct { diff --git a/api/pkg/db/internal/mongo/repositoryimp/builderimp/func.go b/api/pkg/db/internal/mongo/repositoryimp/builderimp/func.go index 5ed8f3dc..d2516994 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/builderimp/func.go +++ b/api/pkg/db/internal/mongo/repositoryimp/builderimp/func.go @@ -2,7 +2,7 @@ package builderimp import ( "github.com/tech/sendico/pkg/db/repository/builder" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) type condImp struct { diff --git a/api/pkg/db/internal/mongo/repositoryimp/builderimp/gaccumulator.go b/api/pkg/db/internal/mongo/repositoryimp/builderimp/gaccumulator.go index 88a5975e..762a5da2 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/builderimp/gaccumulator.go +++ b/api/pkg/db/internal/mongo/repositoryimp/builderimp/gaccumulator.go @@ -2,7 +2,7 @@ package builderimp import ( "github.com/tech/sendico/pkg/db/repository/builder" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) type groupAccumulatorImp struct { diff --git a/api/pkg/db/internal/mongo/repositoryimp/builderimp/patch.go b/api/pkg/db/internal/mongo/repositoryimp/builderimp/patch.go index 399e5b49..cf98f748 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/builderimp/patch.go +++ b/api/pkg/db/internal/mongo/repositoryimp/builderimp/patch.go @@ -5,7 +5,7 @@ import ( "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/db/storable" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) type patchBuilder struct { diff --git a/api/pkg/db/internal/mongo/repositoryimp/builderimp/pipeline.go b/api/pkg/db/internal/mongo/repositoryimp/builderimp/pipeline.go index 668efbe8..bac45d3a 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/builderimp/pipeline.go +++ b/api/pkg/db/internal/mongo/repositoryimp/builderimp/pipeline.go @@ -3,8 +3,8 @@ package builderimp import ( "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" ) type unwindOpts = builder.UnwindOpts diff --git a/api/pkg/db/internal/mongo/repositoryimp/builderimp/pipeline_test.go b/api/pkg/db/internal/mongo/repositoryimp/builderimp/pipeline_test.go index 129f34ae..5728d726 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/builderimp/pipeline_test.go +++ b/api/pkg/db/internal/mongo/repositoryimp/builderimp/pipeline_test.go @@ -6,9 +6,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" ) func TestNewPipelineImp(t *testing.T) { @@ -454,7 +454,7 @@ func (m *MockQuery) Offset(offset *int64) builder.Query func (m *MockQuery) Archived(isArchived *bool) builder.Query { return m } func (m *MockQuery) BuildPipeline() bson.D { return m.buildPipeline } func (m *MockQuery) BuildQuery() bson.D { return bson.D{} } -func (m *MockQuery) BuildOptions() *options.FindOptions { return &options.FindOptions{} } +func (m *MockQuery) BuildOptions() *options.FindOptionsBuilder { return &options.FindOptionsBuilder{} } type MockField struct { build string diff --git a/api/pkg/db/internal/mongo/repositoryimp/builderimp/projection.go b/api/pkg/db/internal/mongo/repositoryimp/builderimp/projection.go index 1f4a8a47..e53ec47b 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/builderimp/projection.go +++ b/api/pkg/db/internal/mongo/repositoryimp/builderimp/projection.go @@ -2,7 +2,7 @@ package builderimp import ( "github.com/tech/sendico/pkg/db/repository/builder" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) // projectionExprImp is a concrete implementation of builder.Projection diff --git a/api/pkg/db/internal/mongo/repositoryimp/builderimp/query.go b/api/pkg/db/internal/mongo/repositoryimp/builderimp/query.go index c42f0527..045ca4e5 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/builderimp/query.go +++ b/api/pkg/db/internal/mongo/repositoryimp/builderimp/query.go @@ -5,9 +5,8 @@ import ( "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/db/storable" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo/options" ) type QueryImp struct { @@ -51,7 +50,7 @@ func (b *QueryImp) Expression(value builder.Expression) builder.Query { } func (b *QueryImp) RegEx(field builder.Field, pattern, options string) builder.Query { - b.filter = append(b.filter, bson.E{Key: field.Build(), Value: primitive.Regex{Pattern: pattern, Options: options}}) + b.filter = append(b.filter, bson.E{Key: field.Build(), Value: bson.Regex{Pattern: pattern, Options: options}}) return b } @@ -134,7 +133,7 @@ func (b *QueryImp) Offset(offset *int64) builder.Query { return b } -func (b *QueryImp) BuildOptions() *options.FindOptions { +func (b *QueryImp) BuildOptions() *options.FindOptionsBuilder { opts := options.Find() if b.limit != nil { opts.SetLimit(*b.limit) diff --git a/api/pkg/db/internal/mongo/repositoryimp/index.go b/api/pkg/db/internal/mongo/repositoryimp/index.go index 50ac3bff..add340ac 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/index.go +++ b/api/pkg/db/internal/mongo/repositoryimp/index.go @@ -5,9 +5,9 @@ import ( ri "github.com/tech/sendico/pkg/db/repository/index" "github.com/tech/sendico/pkg/merrors" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" ) func (r *MongoRepository) CreateIndex(def *ri.Definition) error { diff --git a/api/pkg/db/internal/mongo/repositoryimp/index_integration_test.go b/api/pkg/db/internal/mongo/repositoryimp/index_integration_test.go index 54efca4d..056b4136 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/index_integration_test.go +++ b/api/pkg/db/internal/mongo/repositoryimp/index_integration_test.go @@ -15,9 +15,9 @@ import ( "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mongodb" "github.com/testcontainers/testcontainers-go/wait" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" ) func TestCreateIndex_WithPartialFilter(t *testing.T) { diff --git a/api/pkg/db/internal/mongo/repositoryimp/repository.go b/api/pkg/db/internal/mongo/repositoryimp/repository.go index 81e2cc47..2042dad6 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/repository.go +++ b/api/pkg/db/internal/mongo/repositoryimp/repository.go @@ -10,10 +10,9 @@ import ( "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" ) type MongoRepository struct { @@ -21,7 +20,7 @@ type MongoRepository struct { collection *mongo.Collection } -func idFilter(id primitive.ObjectID) bson.D { +func idFilter(id bson.ObjectID) bson.D { return bson.D{ {Key: storable.IDField, Value: id}, } @@ -40,7 +39,7 @@ func (r *MongoRepository) Collection() string { func (r *MongoRepository) Insert(ctx context.Context, obj storable.Storable, getFilter builder.Query) error { if (obj.GetID() == nil) || (obj.GetID().IsZero()) { - obj.SetID(primitive.NewObjectID()) + obj.SetID(bson.NewObjectID()) } obj.Update() _, err := r.collection.InsertOne(ctx, obj) @@ -63,7 +62,7 @@ func (r *MongoRepository) InsertMany(ctx context.Context, objects []storable.Sto docs := make([]interface{}, len(objects)) for i, obj := range objects { if (obj.GetID() == nil) || (obj.GetID().IsZero()) { - obj.SetID(primitive.NewObjectID()) + obj.SetID(bson.NewObjectID()) } obj.Update() docs[i] = obj @@ -81,7 +80,7 @@ func (r *MongoRepository) findOneByFilterImp(ctx context.Context, filter bson.D, return err } -func (r *MongoRepository) Get(ctx context.Context, id primitive.ObjectID, result storable.Storable) error { +func (r *MongoRepository) Get(ctx context.Context, id bson.ObjectID, result storable.Storable) error { if id.IsZero() { return merrors.InvalidArgument("zero id provided while fetching "+result.Collection(), "id") } @@ -132,7 +131,7 @@ func (r *MongoRepository) Update(ctx context.Context, obj storable.Storable) err return r.collection.FindOneAndReplace(ctx, idFilter(*obj.GetID()), obj).Err() } -func (r *MongoRepository) Patch(ctx context.Context, id primitive.ObjectID, patch builder.Patch) error { +func (r *MongoRepository) Patch(ctx context.Context, id bson.ObjectID, patch builder.Patch) error { if id.IsZero() { return merrors.InvalidArgument("zero id provided while patching", "id") } @@ -148,7 +147,7 @@ func (r *MongoRepository) PatchMany(ctx context.Context, query builder.Query, pa return int(result.ModifiedCount), nil } -func (r *MongoRepository) ListIDs(ctx context.Context, query builder.Query) ([]primitive.ObjectID, error) { +func (r *MongoRepository) ListIDs(ctx context.Context, query builder.Query) ([]bson.ObjectID, error) { filter := query.BuildQuery() findOptions := options.Find().SetProjection(bson.M{storable.IDField: 1}) @@ -158,10 +157,10 @@ func (r *MongoRepository) ListIDs(ctx context.Context, query builder.Query) ([]p } defer cursor.Close(ctx) - var ids []primitive.ObjectID + var ids []bson.ObjectID for cursor.Next(ctx) { var doc struct { - ID primitive.ObjectID `bson:"_id"` + ID bson.ObjectID `bson:"_id"` } if err := cursor.Decode(&doc); err != nil { return nil, err @@ -235,7 +234,7 @@ func (r *MongoRepository) ListAccountBound(ctx context.Context, query builder.Qu return result, nil } -func (r *MongoRepository) Delete(ctx context.Context, id primitive.ObjectID) error { +func (r *MongoRepository) Delete(ctx context.Context, id bson.ObjectID) error { _, err := r.collection.DeleteOne(ctx, idFilter(id)) return err } diff --git a/api/pkg/db/internal/mongo/repositoryimp/repository_comprehensive_test.go b/api/pkg/db/internal/mongo/repositoryimp/repository_comprehensive_test.go index 97efd4aa..277df8f3 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/repository_comprehensive_test.go +++ b/api/pkg/db/internal/mongo/repositoryimp/repository_comprehensive_test.go @@ -9,19 +9,18 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tech/sendico/pkg/db/internal/mongo/repositoryimp" "github.com/tech/sendico/pkg/db/internal/mongo/repositoryimp/builderimp" "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/merrors" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mongodb" "github.com/testcontainers/testcontainers-go/wait" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" ) func TestMongoRepository_Insert(t *testing.T) { @@ -63,7 +62,7 @@ func TestMongoRepository_Insert(t *testing.T) { }) t.Run("Insert_WithExistingID", func(t *testing.T) { - existingID := primitive.NewObjectID() + existingID := bson.NewObjectID() testObj := &TestObject{Name: "testInsertWithID"} testObj.SetID(existingID) @@ -158,7 +157,7 @@ func TestMongoRepository_Update(t *testing.T) { }) t.Run("Update_NonExistentObject", func(t *testing.T) { - nonExistentID := primitive.NewObjectID() + nonExistentID := bson.NewObjectID() testObj := &TestObject{Name: "nonExistent"} testObj.SetID(nonExistentID) @@ -210,7 +209,7 @@ func TestMongoRepository_Delete(t *testing.T) { }) t.Run("Delete_NonExistentObject", func(t *testing.T) { - nonExistentID := primitive.NewObjectID() + nonExistentID := bson.NewObjectID() err := repository.Delete(ctx, nonExistentID) // Delete should not return error even if object doesn't exist @@ -473,19 +472,19 @@ func TestMongoRepository_ListPermissionBound(t *testing.T) { t.Run("ListPermissionBound_WithData", func(t *testing.T) { // Insert test objects with permission bound data - orgID := primitive.NewObjectID() + orgID := bson.NewObjectID() // Insert documents directly with permission bound fields _, err := db.Collection("testcollection").InsertMany(ctx, []interface{}{ bson.M{ - "_id": primitive.NewObjectID(), + "_id": bson.NewObjectID(), "organizationRef": orgID, - "permissionRef": primitive.NewObjectID(), + "permissionRef": bson.NewObjectID(), }, bson.M{ - "_id": primitive.NewObjectID(), + "_id": bson.NewObjectID(), "organizationRef": orgID, - "permissionRef": primitive.NewObjectID(), + "permissionRef": bson.NewObjectID(), }, }) require.NoError(t, err) @@ -504,7 +503,7 @@ func TestMongoRepository_ListPermissionBound(t *testing.T) { }) t.Run("ListPermissionBound_EmptyResult", func(t *testing.T) { - nonExistentOrgID := primitive.NewObjectID() + nonExistentOrgID := bson.NewObjectID() query := builderimp.NewQueryImp().Comparison(builderimp.NewFieldImp("organizationRef"), builder.Eq, nonExistentOrgID) results, err := repository.ListPermissionBound(ctx, query) @@ -544,7 +543,7 @@ func TestMongoRepository_UpdateTimestamp(t *testing.T) { } // Set ID and initial timestamps - obj.SetID(primitive.NewObjectID()) + obj.SetID(bson.NewObjectID()) originalCreatedAt := obj.CreatedAt originalUpdatedAt := obj.UpdatedAt diff --git a/api/pkg/db/internal/mongo/repositoryimp/repository_insertmany_test.go b/api/pkg/db/internal/mongo/repositoryimp/repository_insertmany_test.go index 44dc3c7d..cd808839 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/repository_insertmany_test.go +++ b/api/pkg/db/internal/mongo/repositoryimp/repository_insertmany_test.go @@ -8,16 +8,15 @@ import ( "testing" "time" - "github.com/tech/sendico/pkg/db/internal/mongo/repositoryimp" - "github.com/tech/sendico/pkg/db/storable" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/tech/sendico/pkg/db/internal/mongo/repositoryimp" + "github.com/tech/sendico/pkg/db/storable" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mongodb" "github.com/testcontainers/testcontainers-go/wait" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" ) func TestMongoRepository_InsertMany(t *testing.T) { @@ -75,8 +74,8 @@ func TestMongoRepository_InsertMany(t *testing.T) { }) t.Run("InsertMany_WithExistingIDs", func(t *testing.T) { - id1 := primitive.NewObjectID() - id2 := primitive.NewObjectID() + id1 := bson.NewObjectID() + id2 := bson.NewObjectID() objects := []storable.Storable{ &TestObject{Base: storable.Base{ID: id1}, Name: "preassigned1"}, @@ -116,7 +115,7 @@ func TestMongoRepository_InsertMany(t *testing.T) { }) t.Run("InsertMany_DuplicateKey", func(t *testing.T) { - id := primitive.NewObjectID() + id := bson.NewObjectID() // Insert first object obj1 := &TestObject{Base: storable.Base{ID: id}, Name: "original"} diff --git a/api/pkg/db/internal/mongo/repositoryimp/repository_patch_test.go b/api/pkg/db/internal/mongo/repositoryimp/repository_patch_test.go index 57309ebb..031b2f52 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/repository_patch_test.go +++ b/api/pkg/db/internal/mongo/repositoryimp/repository_patch_test.go @@ -8,16 +8,16 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tech/sendico/pkg/db/internal/mongo/repositoryimp" "github.com/tech/sendico/pkg/db/repository" "github.com/tech/sendico/pkg/db/repository/builder" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mongodb" "github.com/testcontainers/testcontainers-go/wait" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" ) func TestMongoRepository_PatchOperations(t *testing.T) { diff --git a/api/pkg/db/internal/mongo/repositoryimp/repository_test.go b/api/pkg/db/internal/mongo/repositoryimp/repository_test.go index 14161355..45baa388 100644 --- a/api/pkg/db/internal/mongo/repositoryimp/repository_test.go +++ b/api/pkg/db/internal/mongo/repositoryimp/repository_test.go @@ -9,19 +9,19 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tech/sendico/pkg/db/internal/mongo/repositoryimp" "github.com/tech/sendico/pkg/db/internal/mongo/repositoryimp/builderimp" "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/merrors" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mongodb" "github.com/testcontainers/testcontainers-go/wait" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" ) type TestObject struct { @@ -92,7 +92,7 @@ func TestMongoRepository_Get(t *testing.T) { }) t.Run("Get_NotFound", func(t *testing.T) { - nonExistentID := primitive.NewObjectID() + nonExistentID := bson.NewObjectID() result := &TestObject{} err := repository.Get(ctx, nonExistentID, result) @@ -101,7 +101,7 @@ func TestMongoRepository_Get(t *testing.T) { }) t.Run("Get_InvalidID", func(t *testing.T) { - invalidID := primitive.ObjectID{} // zero value + invalidID := bson.ObjectID{} // zero value result := &TestObject{} err := repository.Get(ctx, invalidID, result) diff --git a/api/pkg/db/internal/mongo/rolesdb/db.go b/api/pkg/db/internal/mongo/rolesdb/db.go index 7ce4014d..2f5f3848 100644 --- a/api/pkg/db/internal/mongo/rolesdb/db.go +++ b/api/pkg/db/internal/mongo/rolesdb/db.go @@ -5,7 +5,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" ) type RolesDB struct { diff --git a/api/pkg/db/internal/mongo/rolesdb/list.go b/api/pkg/db/internal/mongo/rolesdb/list.go index 4b9435f3..54a993da 100644 --- a/api/pkg/db/internal/mongo/rolesdb/list.go +++ b/api/pkg/db/internal/mongo/rolesdb/list.go @@ -6,10 +6,10 @@ import ( "github.com/tech/sendico/pkg/db/repository" "github.com/tech/sendico/pkg/model" mutil "github.com/tech/sendico/pkg/mutil/db" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *RolesDB) List(ctx context.Context, organizationRef primitive.ObjectID, cursor *model.ViewCursor) ([]model.RoleDescription, error) { +func (db *RolesDB) List(ctx context.Context, organizationRef bson.ObjectID, cursor *model.ViewCursor) ([]model.RoleDescription, error) { filter := repository.OrgFilter(organizationRef) return mutil.GetObjects[model.RoleDescription](ctx, db.Logger, filter, cursor, db.Repository) } diff --git a/api/pkg/db/internal/mongo/rolesdb/roles.go b/api/pkg/db/internal/mongo/rolesdb/roles.go index e68e0a91..4d070ce5 100644 --- a/api/pkg/db/internal/mongo/rolesdb/roles.go +++ b/api/pkg/db/internal/mongo/rolesdb/roles.go @@ -6,10 +6,10 @@ import ( "github.com/tech/sendico/pkg/db/repository" "github.com/tech/sendico/pkg/model" mutil "github.com/tech/sendico/pkg/mutil/db" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func (db *RolesDB) Roles(ctx context.Context, refs []primitive.ObjectID) ([]model.RoleDescription, error) { +func (db *RolesDB) Roles(ctx context.Context, refs []bson.ObjectID) ([]model.RoleDescription, error) { filter := repository.Query().In(repository.IDField(), refs) return mutil.GetObjects[model.RoleDescription](ctx, db.Logger, filter, nil, db.Repository) } diff --git a/api/pkg/db/internal/mongo/transactionimp/factory.go b/api/pkg/db/internal/mongo/transactionimp/factory.go index e0671b95..6b5c0424 100644 --- a/api/pkg/db/internal/mongo/transactionimp/factory.go +++ b/api/pkg/db/internal/mongo/transactionimp/factory.go @@ -2,7 +2,7 @@ package transactionimp import ( "github.com/tech/sendico/pkg/db/transaction" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" ) type MongoTransactionFactory struct { diff --git a/api/pkg/db/internal/mongo/transactionimp/transaction.go b/api/pkg/db/internal/mongo/transactionimp/transaction.go index b85f6a8d..266feed6 100644 --- a/api/pkg/db/internal/mongo/transactionimp/transaction.go +++ b/api/pkg/db/internal/mongo/transactionimp/transaction.go @@ -4,7 +4,7 @@ import ( "context" "github.com/tech/sendico/pkg/db/transaction" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" ) type MongoTransaction struct { @@ -18,8 +18,8 @@ func (mt *MongoTransaction) Execute(ctx context.Context, cb transaction.Callback } defer session.EndSession(ctx) - callback := func(sessCtx mongo.SessionContext) (any, error) { - return cb(sessCtx) + callback := func(c context.Context) (any, error) { + return cb(c) } return session.WithTransaction(ctx, callback) diff --git a/api/pkg/db/internal/mongo/tseriesimp/tseries.go b/api/pkg/db/internal/mongo/tseriesimp/tseries.go index ed1a5ba8..e30ef135 100644 --- a/api/pkg/db/internal/mongo/tseriesimp/tseries.go +++ b/api/pkg/db/internal/mongo/tseriesimp/tseries.go @@ -11,8 +11,8 @@ import ( tsoptions "github.com/tech/sendico/pkg/db/tseries/options" tspoint "github.com/tech/sendico/pkg/db/tseries/point" "github.com/tech/sendico/pkg/merrors" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" ) type TimeSeries struct { @@ -26,12 +26,13 @@ func NewMongoTimeSeriesCollection(ctx context.Context, db *mongo.Database, tsOpt } // Configure time-series options granularity := tsOpts.Granularity.String() - ts := &options.TimeSeriesOptions{ - TimeField: tsOpts.TimeField, - Granularity: &granularity, - } + ts := &options.TimeSeriesOptionsBuilder{} + // TimeField: tsOpts.TimeField, + // Granularity: &granularity, + ts.SetTimeField(tsOpts.TimeField) + ts.SetGranularity(granularity) if tsOpts.MetaField != "" { - ts.MetaField = &tsOpts.MetaField + ts.SetMetaField(tsOpts.MetaField) } // Collection options diff --git a/api/pkg/db/invitation/invitation.go b/api/pkg/db/invitation/invitation.go index d1229b70..3097375d 100644 --- a/api/pkg/db/invitation/invitation.go +++ b/api/pkg/db/invitation/invitation.go @@ -5,15 +5,15 @@ import ( "github.com/tech/sendico/pkg/auth" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type DB interface { auth.ProtectedDB[*model.Invitation] - GetPublic(ctx context.Context, invitationRef primitive.ObjectID) (*model.PublicInvitation, error) - Accept(ctx context.Context, invitationRef primitive.ObjectID) error - Decline(ctx context.Context, invitationRef primitive.ObjectID) error - List(ctx context.Context, accountRef, organizationRef, _ primitive.ObjectID, cursor *model.ViewCursor) ([]model.Invitation, error) - DeleteCascade(ctx context.Context, accountRef, statusRef primitive.ObjectID) error - SetArchived(ctx context.Context, accountRef, organizationRef, invitationRef primitive.ObjectID, archived, cascade bool) error + GetPublic(ctx context.Context, invitationRef bson.ObjectID) (*model.PublicInvitation, error) + Accept(ctx context.Context, invitationRef bson.ObjectID) error + Decline(ctx context.Context, invitationRef bson.ObjectID) error + List(ctx context.Context, accountRef, organizationRef, _ bson.ObjectID, cursor *model.ViewCursor) ([]model.Invitation, error) + DeleteCascade(ctx context.Context, accountRef, statusRef bson.ObjectID) error + SetArchived(ctx context.Context, accountRef, organizationRef, invitationRef bson.ObjectID, archived, cascade bool) error } diff --git a/api/pkg/db/organization/organization.go b/api/pkg/db/organization/organization.go index 6cd1ff7e..7c26680e 100644 --- a/api/pkg/db/organization/organization.go +++ b/api/pkg/db/organization/organization.go @@ -5,13 +5,13 @@ import ( "github.com/tech/sendico/pkg/auth" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // DB is the interface which must be implemented by all db drivers type DB interface { auth.ProtectedDB[*model.Organization] - List(ctx context.Context, accountRef primitive.ObjectID, cursor *model.ViewCursor) ([]model.Organization, error) - ListOwned(ctx context.Context, accountRef primitive.ObjectID) ([]model.Organization, error) - SetArchived(ctx context.Context, accountRef, organizationRef primitive.ObjectID, archived, cascade bool) error + List(ctx context.Context, accountRef bson.ObjectID, cursor *model.ViewCursor) ([]model.Organization, error) + ListOwned(ctx context.Context, accountRef bson.ObjectID) ([]model.Organization, error) + SetArchived(ctx context.Context, accountRef, organizationRef bson.ObjectID, archived, cascade bool) error } diff --git a/api/pkg/db/paymethod/db.go b/api/pkg/db/paymethod/db.go index 163845a4..8a915b1c 100644 --- a/api/pkg/db/paymethod/db.go +++ b/api/pkg/db/paymethod/db.go @@ -5,11 +5,11 @@ import ( "github.com/tech/sendico/pkg/auth" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type DB interface { auth.ProtectedDB[*model.PaymentMethod] - SetArchived(ctx context.Context, accountRef, organizationRef, methodRef primitive.ObjectID, archived, cascade bool) error - List(ctx context.Context, accountRef, organizationRef, recipientRef primitive.ObjectID, cursor *model.ViewCursor) ([]model.PaymentMethod, error) + SetArchived(ctx context.Context, accountRef, organizationRef, methodRef bson.ObjectID, archived, cascade bool) error + List(ctx context.Context, accountRef, organizationRef, recipientRef bson.ObjectID, cursor *model.ViewCursor) ([]model.PaymentMethod, error) } diff --git a/api/pkg/db/policy/policy.go b/api/pkg/db/policy/policy.go index 15c658af..30b0eeaa 100644 --- a/api/pkg/db/policy/policy.go +++ b/api/pkg/db/policy/policy.go @@ -6,12 +6,12 @@ import ( "github.com/tech/sendico/pkg/db/template" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type DB interface { template.DB[*model.PolicyDescription] - All(ctx context.Context, organizationRef primitive.ObjectID) ([]model.PolicyDescription, error) - Policies(ctx context.Context, refs []primitive.ObjectID) ([]model.PolicyDescription, error) + All(ctx context.Context, organizationRef bson.ObjectID) ([]model.PolicyDescription, error) + Policies(ctx context.Context, refs []bson.ObjectID) ([]model.PolicyDescription, error) GetBuiltInPolicy(ctx context.Context, resourceType mservice.Type, policy *model.PolicyDescription) error } diff --git a/api/pkg/db/recipient/db.go b/api/pkg/db/recipient/db.go index 3b8ad0a7..97caa1f0 100644 --- a/api/pkg/db/recipient/db.go +++ b/api/pkg/db/recipient/db.go @@ -5,11 +5,11 @@ import ( "github.com/tech/sendico/pkg/auth" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type DB interface { auth.ProtectedDB[*model.Recipient] - SetArchived(ctx context.Context, accountRef, organizationRef, recipientRef primitive.ObjectID, archived, cascade bool) error - List(ctx context.Context, accountRef, organizationRef, _ primitive.ObjectID, cursor *model.ViewCursor) ([]model.Recipient, error) + SetArchived(ctx context.Context, accountRef, organizationRef, recipientRef bson.ObjectID, archived, cascade bool) error + List(ctx context.Context, accountRef, organizationRef, _ bson.ObjectID, cursor *model.ViewCursor) ([]model.Recipient, error) } diff --git a/api/pkg/db/refreshtokens/refreshtokens.go b/api/pkg/db/refreshtokens/refreshtokens.go index b039560b..b612def0 100644 --- a/api/pkg/db/refreshtokens/refreshtokens.go +++ b/api/pkg/db/refreshtokens/refreshtokens.go @@ -5,13 +5,13 @@ import ( "github.com/tech/sendico/pkg/db/template" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type DB interface { template.DB[*model.RefreshToken] - Revoke(ctx context.Context, accountRef primitive.ObjectID, session *model.SessionIdentifier) error - RevokeAll(ctx context.Context, accountRef primitive.ObjectID, deviceID string) error + Revoke(ctx context.Context, accountRef bson.ObjectID, session *model.SessionIdentifier) error + RevokeAll(ctx context.Context, accountRef bson.ObjectID, deviceID string) error GetByCRT(ctx context.Context, t *model.ClientRefreshToken) (*model.RefreshToken, error) GetClient(ctx context.Context, clientID string) (*model.Client, error) } diff --git a/api/pkg/db/repository/abfilter.go b/api/pkg/db/repository/abfilter.go index 759c9f0d..8e09216e 100644 --- a/api/pkg/db/repository/abfilter.go +++ b/api/pkg/db/repository/abfilter.go @@ -3,7 +3,7 @@ package repository import ( "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // AccountBoundFilter provides factory methods for creating account-bound filters @@ -19,7 +19,7 @@ func NewAccountBoundFilter() *AccountBoundFilter { // - accountRef matches the provided accountRef, OR // - accountRef is nil/null, OR // - accountRef field doesn't exist -func (f *AccountBoundFilter) WithoutOrg(accountRef primitive.ObjectID) builder.Query { +func (f *AccountBoundFilter) WithoutOrg(accountRef bson.ObjectID) builder.Query { return Query().Or( AccountFilter(accountRef), Filter(model.AccountRefField, nil), @@ -33,7 +33,7 @@ func (f *AccountBoundFilter) WithoutOrg(accountRef primitive.ObjectID) builder.Q // - accountRef is nil/null, OR // - accountRef field doesn't exist // AND combines with organization filter -func (f *AccountBoundFilter) WithOrg(accountRef, organizationRef primitive.ObjectID) builder.Query { +func (f *AccountBoundFilter) WithOrg(accountRef, organizationRef bson.ObjectID) builder.Query { return Query().And( OrgFilter(organizationRef), f.WithoutOrg(accountRef), @@ -41,13 +41,13 @@ func (f *AccountBoundFilter) WithOrg(accountRef, organizationRef primitive.Objec } // WithQuery creates a filter for account-bound objects with additional query and organization filter -func (f *AccountBoundFilter) WithQuery(accountRef, organizationRef primitive.ObjectID, additionalQuery builder.Query) builder.Query { +func (f *AccountBoundFilter) WithQuery(accountRef, organizationRef bson.ObjectID, additionalQuery builder.Query) builder.Query { accountQuery := f.WithOrg(accountRef, organizationRef) return additionalQuery.And(accountQuery) } // WithQueryNoOrg creates a filter for account-bound objects with additional query but no org filter -func (f *AccountBoundFilter) WithQueryNoOrg(accountRef primitive.ObjectID, additionalQuery builder.Query) builder.Query { +func (f *AccountBoundFilter) WithQueryNoOrg(accountRef bson.ObjectID, additionalQuery builder.Query) builder.Query { accountQuery := f.WithoutOrg(accountRef) return additionalQuery.And(accountQuery) } @@ -58,21 +58,21 @@ var DefaultAccountBoundFilter = NewAccountBoundFilter() // Convenience functions that use the global factory instance // WithOrg is a convenience function that uses the default factory -func WithOrg(accountRef, organizationRef primitive.ObjectID) builder.Query { +func WithOrg(accountRef, organizationRef bson.ObjectID) builder.Query { return DefaultAccountBoundFilter.WithOrg(accountRef, organizationRef) } // WithoutOrg is a convenience function that uses the default factory -func WithoutOrg(accountRef primitive.ObjectID) builder.Query { +func WithoutOrg(accountRef bson.ObjectID) builder.Query { return DefaultAccountBoundFilter.WithoutOrg(accountRef) } // WithQuery is a convenience function that uses the default factory -func WithQuery(accountRef, organizationRef primitive.ObjectID, additionalQuery builder.Query) builder.Query { +func WithQuery(accountRef, organizationRef bson.ObjectID, additionalQuery builder.Query) builder.Query { return DefaultAccountBoundFilter.WithQuery(accountRef, organizationRef, additionalQuery) } // WithQueryNoOrg is a convenience function that uses the default factory -func WithQueryNoOrg(accountRef primitive.ObjectID, additionalQuery builder.Query) builder.Query { +func WithQueryNoOrg(accountRef bson.ObjectID, additionalQuery builder.Query) builder.Query { return DefaultAccountBoundFilter.WithQueryNoOrg(accountRef, additionalQuery) } diff --git a/api/pkg/db/repository/builder/accumulator.go b/api/pkg/db/repository/builder/accumulator.go index d22b9088..7d2729a4 100644 --- a/api/pkg/db/repository/builder/accumulator.go +++ b/api/pkg/db/repository/builder/accumulator.go @@ -1,6 +1,6 @@ package builder -import "go.mongodb.org/mongo-driver/bson" +import "go.mongodb.org/mongo-driver/v2/bson" type Accumulator interface { Build() bson.D diff --git a/api/pkg/db/repository/builder/alias.go b/api/pkg/db/repository/builder/alias.go index 9f9cea1e..ba587bc8 100644 --- a/api/pkg/db/repository/builder/alias.go +++ b/api/pkg/db/repository/builder/alias.go @@ -1,6 +1,6 @@ package builder -import "go.mongodb.org/mongo-driver/bson" +import "go.mongodb.org/mongo-driver/v2/bson" type Alias interface { Field() Field diff --git a/api/pkg/db/repository/builder/array.go b/api/pkg/db/repository/builder/array.go index 77260392..59e78a3b 100644 --- a/api/pkg/db/repository/builder/array.go +++ b/api/pkg/db/repository/builder/array.go @@ -1,6 +1,6 @@ package builder -import "go.mongodb.org/mongo-driver/bson" +import "go.mongodb.org/mongo-driver/v2/bson" type Array interface { Build() bson.A diff --git a/api/pkg/db/repository/builder/patch.go b/api/pkg/db/repository/builder/patch.go index 8d98ba6f..5da3eeeb 100644 --- a/api/pkg/db/repository/builder/patch.go +++ b/api/pkg/db/repository/builder/patch.go @@ -1,6 +1,6 @@ package builder -import "go.mongodb.org/mongo-driver/bson" +import "go.mongodb.org/mongo-driver/v2/bson" // Patch defines operations for constructing partial update documents. // Each builder method returns the same Patch instance to allow chaining. diff --git a/api/pkg/db/repository/builder/pipeline.go b/api/pkg/db/repository/builder/pipeline.go index 572d3200..47350e0d 100644 --- a/api/pkg/db/repository/builder/pipeline.go +++ b/api/pkg/db/repository/builder/pipeline.go @@ -2,7 +2,7 @@ package builder import ( "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" ) type Pipeline interface { diff --git a/api/pkg/db/repository/builder/projection.go b/api/pkg/db/repository/builder/projection.go index 8e3c31eb..466f07a7 100644 --- a/api/pkg/db/repository/builder/projection.go +++ b/api/pkg/db/repository/builder/projection.go @@ -1,6 +1,6 @@ package builder -import "go.mongodb.org/mongo-driver/bson" +import "go.mongodb.org/mongo-driver/v2/bson" type Projection interface { Build() bson.D diff --git a/api/pkg/db/repository/builder/query.go b/api/pkg/db/repository/builder/query.go index 0700dc54..1fc397a0 100644 --- a/api/pkg/db/repository/builder/query.go +++ b/api/pkg/db/repository/builder/query.go @@ -1,8 +1,8 @@ package builder import ( - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo/options" ) type Query interface { @@ -20,5 +20,5 @@ type Query interface { Archived(isArchived *bool) Query BuildPipeline() bson.D BuildQuery() bson.D - BuildOptions() *options.FindOptions + BuildOptions() *options.FindOptionsBuilder } diff --git a/api/pkg/db/repository/builders.go b/api/pkg/db/repository/builders.go index 6035329f..b044df14 100644 --- a/api/pkg/db/repository/builders.go +++ b/api/pkg/db/repository/builders.go @@ -5,7 +5,7 @@ import ( "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) func Query() builder.Query { @@ -52,7 +52,7 @@ func IsArchivedField() builder.Field { return Field(storable.IsArchivedField) } -func IDFilter(ref primitive.ObjectID) builder.Query { +func IDFilter(ref bson.ObjectID) builder.Query { return Query().Filter(IDField(), ref) } @@ -72,7 +72,7 @@ func OrgField() builder.Field { return Field(storable.OrganizationRefField) } -func OrgFilter(ref primitive.ObjectID) builder.Query { +func OrgFilter(ref bson.ObjectID) builder.Query { return Query().Filter(OrgField(), ref) } @@ -80,7 +80,7 @@ func ProjectField() builder.Field { return Field("projectRef") } -func ProjectFilter(ref primitive.ObjectID) builder.Query { +func ProjectFilter(ref bson.ObjectID) builder.Query { return Query().Filter(ProjectField(), ref) } @@ -88,7 +88,7 @@ func AccountField() builder.Field { return Field(model.AccountRefField) } -func AccountFilter(ref primitive.ObjectID) builder.Query { +func AccountFilter(ref bson.ObjectID) builder.Query { return Query().Filter(AccountField(), ref) } @@ -96,7 +96,7 @@ func StatusRefField() builder.Field { return Field("statusRef") } -func StatusRefFilter(ref primitive.ObjectID) builder.Query { +func StatusRefFilter(ref bson.ObjectID) builder.Query { return Query().Filter(StatusRefField(), ref) } @@ -104,7 +104,7 @@ func PriorityRefField() builder.Field { return Field("priorityRef") } -func PriorityRefFilter(ref primitive.ObjectID) builder.Query { +func PriorityRefFilter(ref bson.ObjectID) builder.Query { return Query().Filter(PriorityRefField(), ref) } diff --git a/api/pkg/db/repository/decoder/decoder.go b/api/pkg/db/repository/decoder/decoder.go index 46e9e4ac..3a5fb78e 100644 --- a/api/pkg/db/repository/decoder/decoder.go +++ b/api/pkg/db/repository/decoder/decoder.go @@ -1,5 +1,5 @@ package repository -import "go.mongodb.org/mongo-driver/mongo" +import "go.mongodb.org/mongo-driver/v2/mongo" type DecodingFunc = func(r *mongo.Cursor) error diff --git a/api/pkg/db/repository/filter_factory_test.go b/api/pkg/db/repository/filter_factory_test.go index e8384a3a..9ba32e80 100644 --- a/api/pkg/db/repository/filter_factory_test.go +++ b/api/pkg/db/repository/filter_factory_test.go @@ -4,13 +4,13 @@ import ( "testing" "github.com/stretchr/testify/assert" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) func TestAccountBoundFilter_WithOrg(t *testing.T) { factory := NewAccountBoundFilter() - accountRef := primitive.NewObjectID() - orgRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() + orgRef := bson.NewObjectID() query := factory.WithOrg(accountRef, orgRef) @@ -20,7 +20,7 @@ func TestAccountBoundFilter_WithOrg(t *testing.T) { func TestAccountBoundFilter_WithoutOrg(t *testing.T) { factory := NewAccountBoundFilter() - accountRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() query := factory.WithoutOrg(accountRef) @@ -30,8 +30,8 @@ func TestAccountBoundFilter_WithoutOrg(t *testing.T) { func TestAccountBoundFilter_WithQuery(t *testing.T) { factory := NewAccountBoundFilter() - accountRef := primitive.NewObjectID() - orgRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() + orgRef := bson.NewObjectID() additionalQuery := Query().Filter(Field("status"), "active") query := factory.WithQuery(accountRef, orgRef, additionalQuery) @@ -42,7 +42,7 @@ func TestAccountBoundFilter_WithQuery(t *testing.T) { func TestAccountBoundFilter_WithQueryNoOrg(t *testing.T) { factory := NewAccountBoundFilter() - accountRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() additionalQuery := Query().Filter(Field("status"), "active") query := factory.WithQueryNoOrg(accountRef, additionalQuery) @@ -60,8 +60,8 @@ func TestDefaultAccountBoundFilter(t *testing.T) { } func TestConvenienceFunctions(t *testing.T) { - accountRef := primitive.NewObjectID() - orgRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() + orgRef := bson.NewObjectID() additionalQuery := Query().Filter(Field("status"), "active") // Test convenience functions @@ -80,8 +80,8 @@ func TestConvenienceFunctions(t *testing.T) { func TestFilterFactoryConsistency(t *testing.T) { factory := NewAccountBoundFilter() - accountRef := primitive.NewObjectID() - orgRef := primitive.NewObjectID() + accountRef := bson.NewObjectID() + orgRef := bson.NewObjectID() // Test that factory methods and convenience functions produce the same result query1 := factory.WithOrg(accountRef, orgRef) diff --git a/api/pkg/db/repository/repository.go b/api/pkg/db/repository/repository.go index a2a28390..a3e7e739 100644 --- a/api/pkg/db/repository/repository.go +++ b/api/pkg/db/repository/repository.go @@ -9,8 +9,8 @@ import ( ri "github.com/tech/sendico/pkg/db/repository/index" "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" ) type ( @@ -24,18 +24,18 @@ type Repository interface { Aggregate(ctx context.Context, builder builder.Pipeline, decoder rd.DecodingFunc) error Insert(ctx context.Context, obj storable.Storable, getFilter builder.Query) error InsertMany(ctx context.Context, objects []storable.Storable) error - Get(ctx context.Context, id primitive.ObjectID, result storable.Storable) error + Get(ctx context.Context, id bson.ObjectID, result storable.Storable) error FindOneByFilter(ctx context.Context, builder builder.Query, result storable.Storable) error FindManyByFilter(ctx context.Context, builder builder.Query, decoder rd.DecodingFunc) error Update(ctx context.Context, obj storable.Storable) error // Patch applies partial updates defined by patch to the document identified by id. - Patch(ctx context.Context, id primitive.ObjectID, patch PatchDoc) error + Patch(ctx context.Context, id bson.ObjectID, patch PatchDoc) error // PatchMany applies partial updates defined by patch to all documents matching filter and returns the number of updated documents. PatchMany(ctx context.Context, filter FilterQuery, patch PatchDoc) (int, error) - Delete(ctx context.Context, id primitive.ObjectID) error + Delete(ctx context.Context, id bson.ObjectID) error DeleteMany(ctx context.Context, query builder.Query) error CreateIndex(def *ri.Definition) error - ListIDs(ctx context.Context, query builder.Query) ([]primitive.ObjectID, error) + ListIDs(ctx context.Context, query builder.Query) ([]bson.ObjectID, error) ListPermissionBound(ctx context.Context, query builder.Query) ([]model.PermissionBoundStorable, error) ListAccountBound(ctx context.Context, query builder.Query) ([]model.AccountBoundStorable, error) Collection() string diff --git a/api/pkg/db/role/role.go b/api/pkg/db/role/role.go index 9c5837b5..30a4e4e1 100644 --- a/api/pkg/db/role/role.go +++ b/api/pkg/db/role/role.go @@ -5,11 +5,11 @@ import ( "github.com/tech/sendico/pkg/db/template" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type DB interface { template.DB[*model.RoleDescription] - Roles(ctx context.Context, refs []primitive.ObjectID) ([]model.RoleDescription, error) - List(ctx context.Context, organizationRef primitive.ObjectID, cursor *model.ViewCursor) ([]model.RoleDescription, error) + Roles(ctx context.Context, refs []bson.ObjectID) ([]model.RoleDescription, error) + List(ctx context.Context, organizationRef bson.ObjectID, cursor *model.ViewCursor) ([]model.RoleDescription, error) } diff --git a/api/pkg/db/storable/id.go b/api/pkg/db/storable/id.go index 13b01ecf..58d06374 100644 --- a/api/pkg/db/storable/id.go +++ b/api/pkg/db/storable/id.go @@ -3,7 +3,7 @@ package storable import ( "time" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) const ( @@ -15,16 +15,16 @@ const ( ) type Base struct { - ID primitive.ObjectID `bson:"_id" json:"id"` - CreatedAt time.Time `bson:"createdAt" json:"createdAt"` // Timestamp for when the comment was created - UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"` // Timestamp for when the comment was last updated (optional) + ID bson.ObjectID `bson:"_id" json:"id"` + CreatedAt time.Time `bson:"createdAt" json:"createdAt"` // Timestamp for when the comment was created + UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"` // Timestamp for when the comment was last updated (optional) } -func (b *Base) GetID() *primitive.ObjectID { +func (b *Base) GetID() *bson.ObjectID { return &b.ID } -func (b *Base) SetID(objID primitive.ObjectID) { +func (b *Base) SetID(objID bson.ObjectID) { b.ID = objID b.CreatedAt = time.Now() b.UpdatedAt = time.Now() diff --git a/api/pkg/db/storable/ref.go b/api/pkg/db/storable/ref.go index 17b59470..58e34684 100644 --- a/api/pkg/db/storable/ref.go +++ b/api/pkg/db/storable/ref.go @@ -1,11 +1,11 @@ package storable -import "go.mongodb.org/mongo-driver/bson/primitive" +import "go.mongodb.org/mongo-driver/v2/bson" const ( RefField = "ref" ) type Ref struct { - Ref primitive.ObjectID `bson:"ref" json:"ref"` + Ref bson.ObjectID `bson:"ref" json:"ref"` } diff --git a/api/pkg/db/storable/storable.go b/api/pkg/db/storable/storable.go index 57a764d3..e048582b 100644 --- a/api/pkg/db/storable/storable.go +++ b/api/pkg/db/storable/storable.go @@ -1,10 +1,10 @@ package storable -import "go.mongodb.org/mongo-driver/bson/primitive" +import "go.mongodb.org/mongo-driver/v2/bson" type Storable interface { - GetID() *primitive.ObjectID - SetID(objID primitive.ObjectID) + GetID() *bson.ObjectID + SetID(objID bson.ObjectID) Update() Collection() string } diff --git a/api/pkg/db/template/interface.go b/api/pkg/db/template/interface.go index 1558978e..cbf16571 100644 --- a/api/pkg/db/template/interface.go +++ b/api/pkg/db/template/interface.go @@ -5,17 +5,17 @@ import ( "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/db/storable" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type DB[T storable.Storable] interface { Create(ctx context.Context, object T) error InsertMany(ctx context.Context, objects []T) error - Get(ctx context.Context, objectRef primitive.ObjectID, result T) error + Get(ctx context.Context, objectRef bson.ObjectID, result T) error Update(ctx context.Context, object T) error - Patch(ctx context.Context, objectRef primitive.ObjectID, patch builder.Patch) error - Delete(ctx context.Context, objectRef primitive.ObjectID) error + Patch(ctx context.Context, objectRef bson.ObjectID, patch builder.Patch) error + Delete(ctx context.Context, objectRef bson.ObjectID) error DeleteMany(ctx context.Context, query builder.Query) error - DeleteCascade(ctx context.Context, objectRef primitive.ObjectID) error + DeleteCascade(ctx context.Context, objectRef bson.ObjectID) error FindOne(ctx context.Context, query builder.Query, result T) error } diff --git a/api/pkg/db/template/template.go b/api/pkg/db/template/template.go index f4461e0c..abe24d42 100644 --- a/api/pkg/db/template/template.go +++ b/api/pkg/db/template/template.go @@ -11,11 +11,11 @@ import ( "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mservice" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" ) -type CascadeDeleterT = func(ctx context.Context, objectRef primitive.ObjectID) error +type CascadeDeleterT = func(ctx context.Context, objectRef bson.ObjectID) error type DBImp[T storable.Storable] struct { Logger mlogger.Logger @@ -40,7 +40,7 @@ func (db *DBImp[T]) InsertMany(ctx context.Context, objects []T) error { return db.Repository.InsertMany(ctx, storables) } -func (db *DBImp[T]) Get(ctx context.Context, objectRef primitive.ObjectID, result T) error { +func (db *DBImp[T]) Get(ctx context.Context, objectRef bson.ObjectID, result T) error { return db.Repository.Get(ctx, objectRef, result) } @@ -48,7 +48,7 @@ func (db *DBImp[T]) Update(ctx context.Context, object T) error { return db.Repository.Update(ctx, object) } -func (db *DBImp[T]) Patch(ctx context.Context, objectRef primitive.ObjectID, patch builder.Patch) error { +func (db *DBImp[T]) Patch(ctx context.Context, objectRef bson.ObjectID, patch builder.Patch) error { return db.Repository.Patch(ctx, objectRef, patch) } @@ -56,7 +56,7 @@ func (db *DBImp[T]) PatchMany(ctx context.Context, query builder.Query, patch bu return db.Repository.PatchMany(ctx, query, patch) } -func (db *DBImp[T]) Delete(ctx context.Context, objectRef primitive.ObjectID) error { +func (db *DBImp[T]) Delete(ctx context.Context, objectRef bson.ObjectID) error { return db.Repository.Delete(ctx, objectRef) } @@ -68,7 +68,7 @@ func (db *DBImp[T]) FindOne(ctx context.Context, query builder.Query, result T) return db.Repository.FindOneByFilter(ctx, query, result) } -func (db *DBImp[T]) ListIDs(ctx context.Context, query builder.Query) ([]primitive.ObjectID, error) { +func (db *DBImp[T]) ListIDs(ctx context.Context, query builder.Query) ([]bson.ObjectID, error) { return db.Repository.ListIDs(ctx, query) } @@ -81,12 +81,12 @@ func (db *DBImp[T]) SetDeleter(deleter CascadeDeleterT) { db.cdeleter = deleter } -func (db *DBImp[T]) deleteCascadeStub(_ context.Context, objectRef primitive.ObjectID) error { +func (db *DBImp[T]) deleteCascadeStub(_ context.Context, objectRef bson.ObjectID) error { db.Logger.Warn("Unimplemented cascade delete call", mzap.ObjRef("object_ref", objectRef)) return merrors.NotImplemented("custom implementation required") } -func (db *DBImp[T]) DeleteCascade(ctx context.Context, objectRef primitive.ObjectID) error { +func (db *DBImp[T]) DeleteCascade(ctx context.Context, objectRef bson.ObjectID) error { return db.cdeleter(ctx, objectRef) } diff --git a/api/pkg/db/tseries/factory.go b/api/pkg/db/tseries/factory.go index ce3691e8..ad95cd26 100644 --- a/api/pkg/db/tseries/factory.go +++ b/api/pkg/db/tseries/factory.go @@ -5,7 +5,7 @@ import ( "github.com/tech/sendico/pkg/db/internal/mongo/tseriesimp" tsoptions "github.com/tech/sendico/pkg/db/tseries/options" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" ) func CreateMongoTimeSeries(ctx context.Context, db *mongo.Database, tsOpts *tsoptions.Options) (TimeSeries, error) { diff --git a/api/pkg/go.mod b/api/pkg/go.mod index f580c5b1..2556aa0e 100644 --- a/api/pkg/go.mod +++ b/api/pkg/go.mod @@ -4,7 +4,7 @@ go 1.24.0 require ( github.com/casbin/casbin/v2 v2.135.0 - github.com/casbin/mongodb-adapter/v3 v3.7.0 + github.com/casbin/mongodb-adapter/v4 v4.3.0 github.com/go-chi/chi/v5 v5.2.4 github.com/google/uuid v1.6.0 github.com/mattn/go-colorable v0.1.14 @@ -14,7 +14,7 @@ require ( github.com/stretchr/testify v1.11.1 github.com/testcontainers/testcontainers-go v0.33.0 github.com/testcontainers/testcontainers-go/modules/mongodb v0.33.0 - go.mongodb.org/mongo-driver v1.17.8 + go.mongodb.org/mongo-driver/v2 v2.5.0 go.uber.org/zap v1.27.1 golang.org/x/crypto v0.47.0 google.golang.org/grpc v1.78.0 @@ -45,7 +45,6 @@ require ( github.com/go-ole/go-ole v1.3.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/mock v1.6.0 // indirect - github.com/golang/snappy v1.0.0 // indirect github.com/klauspost/compress v1.18.3 // indirect github.com/lufia/plan9stats v0.0.0-20250827001030-24949be3fa54 // indirect github.com/magiconair/properties v1.8.7 // indirect @@ -56,7 +55,6 @@ require ( github.com/moby/sys/user v0.3.0 // indirect github.com/moby/sys/userns v0.1.0 // indirect github.com/moby/term v0.5.0 // indirect - github.com/montanaflynn/stats v0.7.1 // indirect github.com/morikuni/aec v1.0.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nats-io/nkeys v0.4.15 // indirect @@ -80,6 +78,7 @@ require ( github.com/xdg-go/stringprep v1.0.4 // indirect github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect + go.mongodb.org/mongo-driver v1.17.8 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect go.opentelemetry.io/otel v1.38.0 // indirect diff --git a/api/pkg/go.sum b/api/pkg/go.sum index 2ed7bd39..608b40ea 100644 --- a/api/pkg/go.sum +++ b/api/pkg/go.sum @@ -16,8 +16,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0= github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= -github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E= -github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA= +github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ= +github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -170,6 +170,8 @@ github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM= go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= diff --git a/api/pkg/merrors/errors.go b/api/pkg/merrors/errors.go index 754db562..3deef52d 100644 --- a/api/pkg/merrors/errors.go +++ b/api/pkg/merrors/errors.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) var ErrNotImplemented = errors.New("notImplemented") @@ -40,8 +40,8 @@ func DataConflict(msg string) error { var ErrAccessDenied = errors.New("accessDenied") -func AccessDenied(object, action string, objectRef primitive.ObjectID) error { - if objectRef != primitive.NilObjectID { +func AccessDenied(object, action string, objectRef bson.ObjectID) error { + if objectRef != bson.NilObjectID { return fmt.Errorf("%w: cannot %s object of type '%s' with ID '%s'", ErrAccessDenied, action, object, objectRef.Hex()) } return fmt.Errorf("%w: cannot %s object of type '%s'", ErrAccessDenied, action, object) diff --git a/api/pkg/messaging/internal/notifications/account/notification.go b/api/pkg/messaging/internal/notifications/account/notification.go index 5a5e675b..363b078a 100644 --- a/api/pkg/messaging/internal/notifications/account/notification.go +++ b/api/pkg/messaging/internal/notifications/account/notification.go @@ -1,18 +1,18 @@ package notifications import ( - messaging "github.com/tech/sendico/pkg/messaging/envelope" gmessaging "github.com/tech/sendico/pkg/generated/gmessaging" + messaging "github.com/tech/sendico/pkg/messaging/envelope" "github.com/tech/sendico/pkg/model" nm "github.com/tech/sendico/pkg/model/notification" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "google.golang.org/protobuf/proto" ) type AccountNotification struct { messaging.Envelope - accountRef primitive.ObjectID + accountRef bson.ObjectID } func (acn *AccountNotification) Serialize() ([]byte, error) { @@ -29,7 +29,7 @@ func NewAccountNotification(action nm.NotificationAction) model.NotificationEven return model.NewNotification(mservice.Accounts, action) } -func NewAccountImp(sender string, accountRef primitive.ObjectID, action nm.NotificationAction) messaging.Envelope { +func NewAccountImp(sender string, accountRef bson.ObjectID, action nm.NotificationAction) messaging.Envelope { return &AccountNotification{ Envelope: messaging.CreateEnvelope(sender, NewAccountNotification(action)), accountRef: accountRef, diff --git a/api/pkg/messaging/internal/notifications/account/password_reset.go b/api/pkg/messaging/internal/notifications/account/password_reset.go index 115ec0a7..bd5fe763 100644 --- a/api/pkg/messaging/internal/notifications/account/password_reset.go +++ b/api/pkg/messaging/internal/notifications/account/password_reset.go @@ -1,18 +1,18 @@ package notifications import ( - messaging "github.com/tech/sendico/pkg/messaging/envelope" gmessaging "github.com/tech/sendico/pkg/generated/gmessaging" + messaging "github.com/tech/sendico/pkg/messaging/envelope" "github.com/tech/sendico/pkg/model" nm "github.com/tech/sendico/pkg/model/notification" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "google.golang.org/protobuf/proto" ) type PasswordResetNotification struct { messaging.Envelope - accountRef primitive.ObjectID + accountRef bson.ObjectID resetToken string } @@ -31,7 +31,7 @@ func NewPasswordResetNotification(action nm.NotificationAction) model.Notificati return model.NewNotification(mservice.Accounts, action) } -func NewPasswordResetImp(sender string, accountRef primitive.ObjectID, resetToken string, action nm.NotificationAction) messaging.Envelope { +func NewPasswordResetImp(sender string, accountRef bson.ObjectID, resetToken string, action nm.NotificationAction) messaging.Envelope { return &PasswordResetNotification{ Envelope: messaging.CreateEnvelope(sender, NewPasswordResetNotification(action)), accountRef: accountRef, diff --git a/api/pkg/messaging/internal/notifications/account/password_reset_processor.go b/api/pkg/messaging/internal/notifications/account/password_reset_processor.go index 214795e0..48008d27 100644 --- a/api/pkg/messaging/internal/notifications/account/password_reset_processor.go +++ b/api/pkg/messaging/internal/notifications/account/password_reset_processor.go @@ -4,14 +4,14 @@ import ( "context" "github.com/tech/sendico/pkg/db/account" - me "github.com/tech/sendico/pkg/messaging/envelope" gmessaging "github.com/tech/sendico/pkg/generated/gmessaging" + me "github.com/tech/sendico/pkg/messaging/envelope" mah "github.com/tech/sendico/pkg/messaging/notifications/account/handler" np "github.com/tech/sendico/pkg/messaging/notifications/processor" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" nm "github.com/tech/sendico/pkg/model/notification" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "google.golang.org/protobuf/proto" ) @@ -29,7 +29,7 @@ func (prnp *PasswordResetNotificationProcessor) Process(ctx context.Context, env prnp.logger.Warn("Failed to unmarshall envelope", zap.Error(err), zap.String("topic", prnp.event.ToString())) return err } - accountRef, err := primitive.ObjectIDFromHex(msg.AccountRef) + accountRef, err := bson.ObjectIDFromHex(msg.AccountRef) if err != nil { prnp.logger.Warn("Failed to restore object ID", zap.Error(err), zap.String("topic", prnp.event.ToString()), zap.String("account_ref", msg.AccountRef)) return err diff --git a/api/pkg/messaging/internal/notifications/account/processor.go b/api/pkg/messaging/internal/notifications/account/processor.go index 4cc701be..1abb07f1 100644 --- a/api/pkg/messaging/internal/notifications/account/processor.go +++ b/api/pkg/messaging/internal/notifications/account/processor.go @@ -4,14 +4,14 @@ import ( "context" "github.com/tech/sendico/pkg/db/account" - me "github.com/tech/sendico/pkg/messaging/envelope" gmessaging "github.com/tech/sendico/pkg/generated/gmessaging" + me "github.com/tech/sendico/pkg/messaging/envelope" mah "github.com/tech/sendico/pkg/messaging/notifications/account/handler" np "github.com/tech/sendico/pkg/messaging/notifications/processor" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" nm "github.com/tech/sendico/pkg/model/notification" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "google.golang.org/protobuf/proto" ) @@ -29,7 +29,7 @@ func (acnp *AccoountNotificaionProcessor) Process(ctx context.Context, envelope acnp.logger.Warn("Failed to unmarshall envelope", zap.Error(err), zap.String("topic", acnp.event.ToString())) return err } - accountRef, err := primitive.ObjectIDFromHex(msg.AccountRef) + accountRef, err := bson.ObjectIDFromHex(msg.AccountRef) if err != nil { acnp.logger.Warn("Failed to restore object ID", zap.Error(err), zap.String("topic", acnp.event.ToString()), zap.String("account_ref", msg.AccountRef)) return err diff --git a/api/pkg/messaging/internal/notifications/confirmation/notification.go b/api/pkg/messaging/internal/notifications/confirmation/notification.go index c45f5aea..ccd25e4d 100644 --- a/api/pkg/messaging/internal/notifications/confirmation/notification.go +++ b/api/pkg/messaging/internal/notifications/confirmation/notification.go @@ -7,7 +7,7 @@ import ( "github.com/tech/sendico/pkg/model" nm "github.com/tech/sendico/pkg/model/notification" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type confirmationCodePayload struct { @@ -34,7 +34,7 @@ func newConfirmationEvent(action nm.NotificationAction) model.NotificationEvent return model.NewNotification(mservice.Confirmations, action) } -func NewConfirmationCodeEnvelope(sender string, accountRef primitive.ObjectID, destination string, target model.ConfirmationTarget, code string) messaging.Envelope { +func NewConfirmationCodeEnvelope(sender string, accountRef bson.ObjectID, destination string, target model.ConfirmationTarget, code string) messaging.Envelope { return &ConfirmationCodeNotification{ Envelope: messaging.CreateEnvelope(sender, newConfirmationEvent(nm.NAPending)), payload: confirmationCodePayload{ diff --git a/api/pkg/messaging/internal/notifications/confirmation/processor.go b/api/pkg/messaging/internal/notifications/confirmation/processor.go index c0857122..e93d999e 100644 --- a/api/pkg/messaging/internal/notifications/confirmation/processor.go +++ b/api/pkg/messaging/internal/notifications/confirmation/processor.go @@ -12,7 +12,7 @@ import ( "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" nm "github.com/tech/sendico/pkg/model/notification" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -30,7 +30,7 @@ func (ccp *ConfirmationCodeProcessor) Process(ctx context.Context, envelope me.E return err } - accountRef, err := primitive.ObjectIDFromHex(msg.AccountRef) + accountRef, err := bson.ObjectIDFromHex(msg.AccountRef) if err != nil { ccp.logger.Warn("Failed to restore account id from envelope", zap.Error(err), zap.String("topic", ccp.event.ToString()), zap.String("account_ref", msg.AccountRef)) return err diff --git a/api/pkg/messaging/internal/notifications/invitation/processor.go b/api/pkg/messaging/internal/notifications/invitation/processor.go index bc05a4e1..20bf1f77 100644 --- a/api/pkg/messaging/internal/notifications/invitation/processor.go +++ b/api/pkg/messaging/internal/notifications/invitation/processor.go @@ -13,7 +13,7 @@ import ( nm "github.com/tech/sendico/pkg/model/notification" "github.com/tech/sendico/pkg/mservice" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -28,7 +28,7 @@ type InvitationNotificaionProcessor struct { func (ianp *InvitationNotificaionProcessor) onInvitation( ctx context.Context, objectType mservice.Type, - objectRef, actorAccountRef primitive.ObjectID, + objectRef, actorAccountRef bson.ObjectID, action nm.NotificationAction, ) error { var invitation model.Invitation diff --git a/api/pkg/messaging/internal/notifications/object/object.go b/api/pkg/messaging/internal/notifications/object/object.go index 43670e22..689a68dc 100644 --- a/api/pkg/messaging/internal/notifications/object/object.go +++ b/api/pkg/messaging/internal/notifications/object/object.go @@ -1,19 +1,19 @@ package notifications import ( - messaging "github.com/tech/sendico/pkg/messaging/envelope" gmessaging "github.com/tech/sendico/pkg/generated/gmessaging" + messaging "github.com/tech/sendico/pkg/messaging/envelope" "github.com/tech/sendico/pkg/model" nm "github.com/tech/sendico/pkg/model/notification" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "google.golang.org/protobuf/proto" ) type ObjectNotification struct { messaging.Envelope - actorAccountRef primitive.ObjectID - objectRef primitive.ObjectID + actorAccountRef bson.ObjectID + objectRef bson.ObjectID } func (acn *ObjectNotification) Serialize() ([]byte, error) { @@ -33,9 +33,9 @@ func NewObjectNotification(t mservice.Type, action nm.NotificationAction) model. func NewObjectImp( sender string, - actorAccountRef primitive.ObjectID, + actorAccountRef bson.ObjectID, objectType mservice.Type, - objectRef primitive.ObjectID, + objectRef bson.ObjectID, action nm.NotificationAction, ) messaging.Envelope { return &ObjectNotification{ diff --git a/api/pkg/messaging/internal/notifications/object/processor.go b/api/pkg/messaging/internal/notifications/object/processor.go index 20d260b6..b9ce7282 100644 --- a/api/pkg/messaging/internal/notifications/object/processor.go +++ b/api/pkg/messaging/internal/notifications/object/processor.go @@ -3,15 +3,15 @@ package notifications import ( "context" - me "github.com/tech/sendico/pkg/messaging/envelope" gmessaging "github.com/tech/sendico/pkg/generated/gmessaging" + me "github.com/tech/sendico/pkg/messaging/envelope" moh "github.com/tech/sendico/pkg/messaging/notifications/object/handler" np "github.com/tech/sendico/pkg/messaging/notifications/processor" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" nm "github.com/tech/sendico/pkg/model/notification" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "google.golang.org/protobuf/proto" ) @@ -28,12 +28,12 @@ func (ounp *ObjectNotificaionProcessor) Process(ctx context.Context, envelope me ounp.logger.Warn("Failed to unmarshall envelope", zap.Error(err), zap.String("topic", ounp.event.ToString())) return err } - actorAccountRef, err := primitive.ObjectIDFromHex(msg.ActorAccountRef) + actorAccountRef, err := bson.ObjectIDFromHex(msg.ActorAccountRef) if err != nil { ounp.logger.Warn("Failed to restore actor account reference", zap.Error(err), zap.String("topic", ounp.event.ToString()), zap.String("actor_account_ref", msg.ActorAccountRef)) return err } - objectRef, err := primitive.ObjectIDFromHex(msg.ObjectRef) + objectRef, err := bson.ObjectIDFromHex(msg.ObjectRef) if err != nil { ounp.logger.Warn("Failed to restore object reference", zap.Error(err), zap.String("topic", ounp.event.ToString()), zap.String("object_ref", msg.ObjectRef)) return err diff --git a/api/pkg/messaging/notifications/account/created.go b/api/pkg/messaging/notifications/account/created.go index 8b3045c5..fed5a6cb 100644 --- a/api/pkg/messaging/notifications/account/created.go +++ b/api/pkg/messaging/notifications/account/created.go @@ -1,16 +1,16 @@ package notifications import ( - an "github.com/tech/sendico/pkg/messaging/internal/notifications/account" messaging "github.com/tech/sendico/pkg/messaging/envelope" + an "github.com/tech/sendico/pkg/messaging/internal/notifications/account" nm "github.com/tech/sendico/pkg/model/notification" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func Account(sender string, accountRef primitive.ObjectID, action nm.NotificationAction) messaging.Envelope { +func Account(sender string, accountRef bson.ObjectID, action nm.NotificationAction) messaging.Envelope { return an.NewAccountImp(sender, accountRef, action) } -func AccountCreated(sender string, accountRef primitive.ObjectID) messaging.Envelope { +func AccountCreated(sender string, accountRef bson.ObjectID) messaging.Envelope { return Account(sender, accountRef, nm.NACreated) } diff --git a/api/pkg/messaging/notifications/account/password_reset.go b/api/pkg/messaging/notifications/account/password_reset.go index 44d0b703..b3eefcb2 100644 --- a/api/pkg/messaging/notifications/account/password_reset.go +++ b/api/pkg/messaging/notifications/account/password_reset.go @@ -8,14 +8,14 @@ import ( np "github.com/tech/sendico/pkg/messaging/notifications/processor" "github.com/tech/sendico/pkg/mlogger" nm "github.com/tech/sendico/pkg/model/notification" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func PasswordReset(sender string, accountRef primitive.ObjectID, resetToken string, action nm.NotificationAction) messaging.Envelope { +func PasswordReset(sender string, accountRef bson.ObjectID, resetToken string, action nm.NotificationAction) messaging.Envelope { return an.NewPasswordResetImp(sender, accountRef, resetToken, action) } -func PasswordResetRequested(sender string, accountRef primitive.ObjectID, resetToken string) messaging.Envelope { +func PasswordResetRequested(sender string, accountRef bson.ObjectID, resetToken string) messaging.Envelope { return PasswordReset(sender, accountRef, resetToken, nm.NAPasswordReset) } diff --git a/api/pkg/messaging/notifications/confirmation/confirmation.go b/api/pkg/messaging/notifications/confirmation/confirmation.go index 23ec6db1..c43d6f70 100644 --- a/api/pkg/messaging/notifications/confirmation/confirmation.go +++ b/api/pkg/messaging/notifications/confirmation/confirmation.go @@ -8,10 +8,10 @@ import ( np "github.com/tech/sendico/pkg/messaging/notifications/processor" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func Code(sender string, accountRef primitive.ObjectID, destination string, target model.ConfirmationTarget, code string) messaging.Envelope { +func Code(sender string, accountRef bson.ObjectID, destination string, target model.ConfirmationTarget, code string) messaging.Envelope { return cinternal.NewConfirmationCodeEnvelope(sender, accountRef, destination, target, code) } diff --git a/api/pkg/messaging/notifications/invitation/invitation.go b/api/pkg/messaging/notifications/invitation/invitation.go index fb12afaa..3f641381 100644 --- a/api/pkg/messaging/notifications/invitation/invitation.go +++ b/api/pkg/messaging/notifications/invitation/invitation.go @@ -5,38 +5,38 @@ import ( on "github.com/tech/sendico/pkg/messaging/notifications/object" nm "github.com/tech/sendico/pkg/model/notification" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) func InvitationCreated( sender string, - actorAccountRef primitive.ObjectID, + actorAccountRef bson.ObjectID, objectType mservice.Type, - objectRef primitive.ObjectID, + objectRef bson.ObjectID, ) messaging.Envelope { return on.ObjectCreated(sender, actorAccountRef, mservice.Invitations, objectRef) } func InvitationUpdated( sender string, - actorAccountRef primitive.ObjectID, - objectRef primitive.ObjectID, + actorAccountRef bson.ObjectID, + objectRef bson.ObjectID, ) messaging.Envelope { return on.ObjectUpdated(sender, actorAccountRef, mservice.Invitations, objectRef) } func InvitationDeleted( sender string, - actorAccountRef primitive.ObjectID, - objectRef primitive.ObjectID, + actorAccountRef bson.ObjectID, + objectRef bson.ObjectID, ) messaging.Envelope { return on.ObjectDeleted(sender, actorAccountRef, mservice.Invitations, objectRef) } func Invitation( sender string, - actorAccountRef primitive.ObjectID, - objectRef primitive.ObjectID, + actorAccountRef bson.ObjectID, + objectRef bson.ObjectID, action nm.NotificationAction, ) messaging.Envelope { return on.Object(sender, actorAccountRef, mservice.Invitations, objectRef, action) diff --git a/api/pkg/messaging/notifications/object/handler/interface.go b/api/pkg/messaging/notifications/object/handler/interface.go index c61a552a..4153f279 100644 --- a/api/pkg/messaging/notifications/object/handler/interface.go +++ b/api/pkg/messaging/notifications/object/handler/interface.go @@ -5,12 +5,12 @@ import ( nm "github.com/tech/sendico/pkg/model/notification" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type ObjectUpdateHandler = func( ctx context.Context, objectType mservice.Type, - objectRef, actorAccountRef primitive.ObjectID, + objectRef, actorAccountRef bson.ObjectID, action nm.NotificationAction, ) error diff --git a/api/pkg/messaging/notifications/object/object.go b/api/pkg/messaging/notifications/object/object.go index fd38239f..fa552a1c 100644 --- a/api/pkg/messaging/notifications/object/object.go +++ b/api/pkg/messaging/notifications/object/object.go @@ -5,14 +5,14 @@ import ( on "github.com/tech/sendico/pkg/messaging/internal/notifications/object" nm "github.com/tech/sendico/pkg/model/notification" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) func Object( sender string, - actorAccountRef primitive.ObjectID, + actorAccountRef bson.ObjectID, objectType mservice.Type, - objectRef primitive.ObjectID, + objectRef bson.ObjectID, action nm.NotificationAction, ) messaging.Envelope { return on.NewObjectImp(sender, actorAccountRef, objectType, objectRef, action) @@ -20,27 +20,27 @@ func Object( func ObjectCreated( sender string, - actorAccountRef primitive.ObjectID, + actorAccountRef bson.ObjectID, objectType mservice.Type, - objectRef primitive.ObjectID, + objectRef bson.ObjectID, ) messaging.Envelope { return Object(sender, actorAccountRef, objectType, objectRef, nm.NACreated) } func ObjectUpdated( sender string, - actorAccountRef primitive.ObjectID, + actorAccountRef bson.ObjectID, objectType mservice.Type, - objectRef primitive.ObjectID, + objectRef bson.ObjectID, ) messaging.Envelope { return Object(sender, actorAccountRef, objectType, objectRef, nm.NAUpdated) } func ObjectDeleted( sender string, - actorAccountRef primitive.ObjectID, + actorAccountRef bson.ObjectID, objectType mservice.Type, - objectRef primitive.ObjectID, + objectRef bson.ObjectID, ) messaging.Envelope { return Object(sender, actorAccountRef, objectType, objectRef, nm.NADeleted) } diff --git a/api/pkg/model/account.go b/api/pkg/model/account.go index 271f8439..ea0d41ff 100755 --- a/api/pkg/model/account.go +++ b/api/pkg/model/account.go @@ -3,7 +3,7 @@ package model import ( "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "golang.org/x/crypto/bcrypt" ) @@ -49,11 +49,11 @@ func (a *Account) MatchPassword(password string) bool { return err == nil } -func AnonymousUserName(orgRef primitive.ObjectID) string { +func AnonymousUserName(orgRef bson.ObjectID) string { return "anonymous@" + orgRef.Hex() } -func AccountIsAnonymous(account *UserDataBase, orgRef primitive.ObjectID) bool { +func AccountIsAnonymous(account *UserDataBase, orgRef bson.ObjectID) bool { if account == nil { return false } @@ -61,13 +61,13 @@ func AccountIsAnonymous(account *UserDataBase, orgRef primitive.ObjectID) bool { } type AccountBound interface { - GetAccountRef() primitive.ObjectID + GetAccountRef() bson.ObjectID } type AccountBoundStorable interface { storable.Storable OrganizationBound - GetAccountRef() *primitive.ObjectID + GetAccountRef() *bson.ObjectID } const ( @@ -77,9 +77,9 @@ const ( type AccountBoundBase struct { storable.Base `bson:",inline" json:",inline"` OrganizationBoundBase `bson:",inline" json:",inline"` - AccountRef *primitive.ObjectID `bson:"accountRef,omitempty" json:"accountRef,omitempty"` + AccountRef *bson.ObjectID `bson:"accountRef,omitempty" json:"accountRef,omitempty"` } -func (a *AccountBoundBase) GetAccountRef() *primitive.ObjectID { +func (a *AccountBoundBase) GetAccountRef() *bson.ObjectID { return a.AccountRef } diff --git a/api/pkg/model/auth.go b/api/pkg/model/auth.go index fc08735e..2c6bda15 100644 --- a/api/pkg/model/auth.go +++ b/api/pkg/model/auth.go @@ -3,7 +3,7 @@ package model import ( "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // Action represents a permissible action on a resource. @@ -29,7 +29,7 @@ const ( type RoleDescription struct { storable.Base `bson:",inline" json:",inline"` // Base fields for MongoDB documents Describable `bson:",inline" json:",inline"` // Name and description fields - OrganizationRef primitive.ObjectID `bson:"organizationRef" json:"organizationRef"` // Organization associated with the role + OrganizationRef bson.ObjectID `bson:"organizationRef" json:"organizationRef"` // Organization associated with the role } // Collection specifies the MongoDB collection for RoleDescription. @@ -39,9 +39,9 @@ func (*RoleDescription) Collection() string { // Role represents a role assignment for an account within an organization. type Role struct { - AccountRef primitive.ObjectID `bson:"accountRef" json:"accountRef"` // Account assigned to the role - DescriptionRef primitive.ObjectID `bson:"descriptionRef" json:"descriptionRef"` // Reference to the role's description - OrganizationRef primitive.ObjectID `bson:"organizationRef" json:"organizationRef"` // Organization where the role is applicable + AccountRef bson.ObjectID `bson:"accountRef" json:"accountRef"` // Account assigned to the role + DescriptionRef bson.ObjectID `bson:"descriptionRef" json:"descriptionRef"` // Reference to the role's description + OrganizationRef bson.ObjectID `bson:"organizationRef" json:"organizationRef"` // Organization where the role is applicable } // ActionEffect represents a combination of an action and its effect (allow/deny). @@ -52,16 +52,16 @@ type ActionEffect struct { // Policy defines access control rules for a role within an organization. type Policy struct { - OrganizationRef primitive.ObjectID `bson:"organizationRef" json:"organizationRef"` // Organization associated with the policy - DescriptionRef primitive.ObjectID `bson:"descriptionRef" json:"descriptionRef"` // Reference to the policy's metadata - ObjectRef *primitive.ObjectID `bson:"objectRef,omitempty" json:"objectRef,omitempty"` // Target object (NilObjectID for all objects) - Effect ActionEffect `bson:"effect" json:"effect"` // Action and effect for the policy + OrganizationRef bson.ObjectID `bson:"organizationRef" json:"organizationRef"` // Organization associated with the policy + DescriptionRef bson.ObjectID `bson:"descriptionRef" json:"descriptionRef"` // Reference to the policy's metadata + ObjectRef *bson.ObjectID `bson:"objectRef,omitempty" json:"objectRef,omitempty"` // Target object (NilObjectID for all objects) + Effect ActionEffect `bson:"effect" json:"effect"` // Action and effect for the policy } // RolePolicy defines access control rules for a role within an organization. type RolePolicy struct { Policy `bson:",inline" json:",inline"` - RoleDescriptionRef primitive.ObjectID `bson:"roleDescriptionRef" json:"roleDescriptionRef"` // Reference to the associated role + RoleDescriptionRef bson.ObjectID `bson:"roleDescriptionRef" json:"roleDescriptionRef"` // Reference to the associated role } // PolicyDescription provides metadata for policies. @@ -69,7 +69,7 @@ type PolicyDescription struct { storable.Base `bson:",inline" json:",inline"` // Base fields for MongoDB documents Describable `bson:",inline" json:",inline"` // Name and description fields ResourceTypes *[]mservice.Type `bson:"resourceTypes,omitempty" json:"resourceTypes,omitempty"` // nil for custom policies, non-nil for built-in permissisons - OrganizationRef *primitive.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"` // nil for built-in policies, non-nil for custom + OrganizationRef *bson.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"` // nil for built-in policies, non-nil for custom } // Collection specifies the MongoDB collection for PolicyDescription. @@ -80,5 +80,5 @@ func (*PolicyDescription) Collection() string { // Permission ties a policy to a specific account. type Permission struct { RolePolicy `bson:",inline" json:",inline"` // Embedded policy definition - AccountRef primitive.ObjectID `bson:"accountRef" json:"accountRef"` // Account assigned the permission + AccountRef bson.ObjectID `bson:"accountRef" json:"accountRef"` // Account assigned the permission } diff --git a/api/pkg/model/card.go b/api/pkg/model/card.go index 500c3348..931a549b 100644 --- a/api/pkg/model/card.go +++ b/api/pkg/model/card.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/tech/sendico/pkg/merrors" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) type CardPaymentData struct { diff --git a/api/pkg/model/client.go b/api/pkg/model/client.go index b93a637c..cbc22b3e 100644 --- a/api/pkg/model/client.go +++ b/api/pkg/model/client.go @@ -3,20 +3,20 @@ package model import ( "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type Client struct { storable.Base `bson:",inline" json:",inline"` - ClientID string `bson:"clientId"` - ClientName string `bson:"clientName"` - ClientSecret string `bson:"clientSecret,omitempty"` - AllowedScopes []string `bson:"allowedScopes"` - RedirectURIs []string `bson:"redirectURIs"` - GrantTypes []string `bson:"grantTypes"` - TokenEndpointAuthMethod string `bson:"tokenEndpointAuthMethod"` - AccountRef *primitive.ObjectID `bson:"accountRef,omitempty"` // owner reference - IsRevoked bool `bson:"isRevoked"` + ClientID string `bson:"clientId"` + ClientName string `bson:"clientName"` + ClientSecret string `bson:"clientSecret,omitempty"` + AllowedScopes []string `bson:"allowedScopes"` + RedirectURIs []string `bson:"redirectURIs"` + GrantTypes []string `bson:"grantTypes"` + TokenEndpointAuthMethod string `bson:"tokenEndpointAuthMethod"` + AccountRef *bson.ObjectID `bson:"accountRef,omitempty"` // owner reference + IsRevoked bool `bson:"isRevoked"` } func (*Client) Collection() string { diff --git a/api/pkg/model/confirmation_code.go b/api/pkg/model/confirmation_code.go index 326a080a..ce794b26 100644 --- a/api/pkg/model/confirmation_code.go +++ b/api/pkg/model/confirmation_code.go @@ -5,7 +5,7 @@ import ( "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type ConfirmationTarget string @@ -17,7 +17,7 @@ const ( type ConfirmationCode struct { storable.Base `bson:",inline" json:",inline"` - AccountRef primitive.ObjectID `bson:"accountRef" json:"accountRef"` + AccountRef bson.ObjectID `bson:"accountRef" json:"accountRef"` Destination string `bson:"destination" json:"destination"` Target ConfirmationTarget `bson:"target" json:"target"` CodeHash []byte `bson:"codeHash" json:"codeHash,omitempty"` diff --git a/api/pkg/model/cryptoaddress.go b/api/pkg/model/cryptoaddress.go index 67478691..3fa2c52b 100644 --- a/api/pkg/model/cryptoaddress.go +++ b/api/pkg/model/cryptoaddress.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/tech/sendico/pkg/merrors" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) type CryptoAddressPaymentData struct { diff --git a/api/pkg/model/ctoken.go b/api/pkg/model/ctoken.go index 89b0adb7..bac6b675 100644 --- a/api/pkg/model/ctoken.go +++ b/api/pkg/model/ctoken.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/tech/sendico/pkg/merrors" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) // TokenPaymentData represents a network or gateway-issued card token. diff --git a/api/pkg/model/iban.go b/api/pkg/model/iban.go index a729c4a1..6a2550b3 100644 --- a/api/pkg/model/iban.go +++ b/api/pkg/model/iban.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/tech/sendico/pkg/merrors" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) type IbanPaymentData struct { diff --git a/api/pkg/model/invitation.go b/api/pkg/model/invitation.go index d9c1c7a5..e3003258 100644 --- a/api/pkg/model/invitation.go +++ b/api/pkg/model/invitation.go @@ -5,7 +5,7 @@ import ( "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type InvitationStatus string @@ -31,12 +31,12 @@ func (id *invitationDesc) Collection() string { type Invitation struct { PermissionBound `bson:",inline" json:",inline"` - OrganizationRef primitive.ObjectID `bson:"organizationRef" json:"organizationRef"` - RoleRef primitive.ObjectID `bson:"roleRef" json:"roleRef"` - InviterRef primitive.ObjectID `bson:"inviterRef" json:"inviterRef"` - Status InvitationStatus `bson:"status" json:"status"` - ExpiresAt time.Time `bson:"expiresAt" json:"expiresAt"` - Content invitationDesc `bson:"description" json:"description"` + OrganizationRef bson.ObjectID `bson:"organizationRef" json:"organizationRef"` + RoleRef bson.ObjectID `bson:"roleRef" json:"roleRef"` + InviterRef bson.ObjectID `bson:"inviterRef" json:"inviterRef"` + Status InvitationStatus `bson:"status" json:"status"` + ExpiresAt time.Time `bson:"expiresAt" json:"expiresAt"` + Content invitationDesc `bson:"description" json:"description"` } func (*Invitation) Collection() string { diff --git a/api/pkg/model/ledger.go b/api/pkg/model/ledger.go index 11f6fb4a..7a1634fb 100644 --- a/api/pkg/model/ledger.go +++ b/api/pkg/model/ledger.go @@ -6,7 +6,7 @@ import ( "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // AccountType defines the category of account (asset, liability, revenue, expense). @@ -58,7 +58,7 @@ type LedgerAccount struct { // OrganizationRef links the account to an organization. // Must be set for organization accounts and nil for system accounts. - OrganizationRef *primitive.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"` + OrganizationRef *bson.ObjectID `bson:"organizationRef,omitempty" json:"organizationRef,omitempty"` // Role defines the functional purpose of the account within an organization // (e.g., pending, operating, settlement, hold, etc.). @@ -85,7 +85,7 @@ type LedgerAccount struct { // OwnerRef optionally links the account to a specific owner entity // (e.g., user or sub-entity within the organization). - OwnerRef *primitive.ObjectID `bson:"ownerRef,omitempty" json:"ownerRef,omitempty"` + OwnerRef *bson.ObjectID `bson:"ownerRef,omitempty" json:"ownerRef,omitempty"` // Metadata holds additional arbitrary key-value attributes. Metadata map[string]string `bson:"metadata,omitempty" json:"metadata,omitempty"` diff --git a/api/pkg/model/link.go b/api/pkg/model/link.go index c564b823..94d76c09 100644 --- a/api/pkg/model/link.go +++ b/api/pkg/model/link.go @@ -2,10 +2,10 @@ package model import ( "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type Link struct { - ObjectRef primitive.ObjectID `bson:"objectRef" json:"objectRef"` - Type mservice.Type `bson:"type" json:"type"` + ObjectRef bson.ObjectID `bson:"objectRef" json:"objectRef"` + Type mservice.Type `bson:"type" json:"type"` } diff --git a/api/pkg/model/object.go b/api/pkg/model/object.go index a69f0828..32b43c85 100644 --- a/api/pkg/model/object.go +++ b/api/pkg/model/object.go @@ -2,7 +2,7 @@ package model import ( "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type TypeBound struct { @@ -11,10 +11,10 @@ type TypeBound struct { type ObjectRefs struct { TypeBound `bson:"inline" json:"inline"` - Refs []primitive.ObjectID `bson:"refs,omitempty" json:"refs,omitempty"` + Refs []bson.ObjectID `bson:"refs,omitempty" json:"refs,omitempty"` } type ObjectRef struct { TypeBound `bson:"inline" json:"inline"` - Ref primitive.ObjectID `bson:"ref,omitempty" json:"ref,omitempty"` + Ref bson.ObjectID `bson:"ref,omitempty" json:"ref,omitempty"` } diff --git a/api/pkg/model/organization.go b/api/pkg/model/organization.go index 14dc20db..612ada07 100644 --- a/api/pkg/model/organization.go +++ b/api/pkg/model/organization.go @@ -2,15 +2,15 @@ package model import ( "github.com/tech/sendico/pkg/mservice" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type OrganizationBase struct { PermissionBound `bson:",inline" json:",inline"` Describable `bson:",inline" json:",inline"` - TenantRef primitive.ObjectID `bson:"tenantRef" json:"tenantRef"` - TimeZone string `bson:"timeZone" json:"timeZone"` - LogoURL *string `bson:"logoUrl,omitempty" json:"logoUrl,omitempty"` + TenantRef bson.ObjectID `bson:"tenantRef" json:"tenantRef"` + TimeZone string `bson:"timeZone" json:"timeZone"` + LogoURL *string `bson:"logoUrl,omitempty" json:"logoUrl,omitempty"` } func (*OrganizationBase) Collection() string { @@ -19,12 +19,12 @@ func (*OrganizationBase) Collection() string { type Organization struct { OrganizationBase `bson:",inline" json:",inline"` - Members []primitive.ObjectID `bson:"members" json:"members"` + Members []bson.ObjectID `bson:"members" json:"members"` } type OrganizationBound interface { - GetOrganizationRef() primitive.ObjectID - SetOrganizationRef(organizationRef primitive.ObjectID) + GetOrganizationRef() bson.ObjectID + SetOrganizationRef(organizationRef bson.ObjectID) } const ( @@ -32,13 +32,13 @@ const ( ) type OrganizationBoundBase struct { - OrganizationRef primitive.ObjectID `bson:"organizationRef" json:"organizationRef"` + OrganizationRef bson.ObjectID `bson:"organizationRef" json:"organizationRef"` } -func (a *OrganizationBoundBase) GetOrganizationRef() primitive.ObjectID { +func (a *OrganizationBoundBase) GetOrganizationRef() bson.ObjectID { return a.OrganizationRef } -func (a *OrganizationBoundBase) SetOrganizationRef(organizationRef primitive.ObjectID) { +func (a *OrganizationBoundBase) SetOrganizationRef(organizationRef bson.ObjectID) { a.OrganizationRef = organizationRef } diff --git a/api/pkg/model/payment.go b/api/pkg/model/payment.go index 0c2f2270..6caa2472 100644 --- a/api/pkg/model/payment.go +++ b/api/pkg/model/payment.go @@ -6,8 +6,7 @@ import ( "fmt" "github.com/tech/sendico/pkg/merrors" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type PaymentType int @@ -70,20 +69,20 @@ type PaymentMethod struct { PermissionBound `bson:",inline" json:",inline"` Describable `bson:",inline" json:",inline"` - RecipientRef primitive.ObjectID `bson:"recipientRef" json:"recipientRef"` - Type PaymentType `bson:"type" json:"type"` - Data bson.Raw `bson:"data" json:"data"` - IsMain bool `bson:"isMain" json:"isMain"` + RecipientRef bson.ObjectID `bson:"recipientRef" json:"recipientRef"` + Type PaymentType `bson:"type" json:"type"` + Data bson.Raw `bson:"data" json:"data"` + IsMain bool `bson:"isMain" json:"isMain"` } type paymentMethodJSON struct { PermissionBound `json:",inline"` Describable `json:",inline"` - RecipientRef primitive.ObjectID `json:"recipientRef"` - Type PaymentType `json:"type"` - Data json.RawMessage `json:"data"` - IsMain bool `json:"isMain"` + RecipientRef bson.ObjectID `json:"recipientRef"` + Type PaymentType `json:"type"` + Data json.RawMessage `json:"data"` + IsMain bool `json:"isMain"` } func (m PaymentMethod) MarshalJSON() ([]byte, error) { diff --git a/api/pkg/model/permission.go b/api/pkg/model/permission.go index 2d8d6af3..2b80f1bb 100644 --- a/api/pkg/model/permission.go +++ b/api/pkg/model/permission.go @@ -2,32 +2,32 @@ package model import ( "github.com/tech/sendico/pkg/db/storable" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type PermissionBoundStorable interface { storable.Storable OrganizationBound Archivable - GetPermissionRef() primitive.ObjectID - SetPermissionRef(permissionRef primitive.ObjectID) + GetPermissionRef() bson.ObjectID + SetPermissionRef(permissionRef bson.ObjectID) } type PermissionBound struct { storable.Base `bson:",inline" json:",inline"` ArchivableBase `bson:",inline" json:",inline"` OrganizationBoundBase `bson:",inline" json:",inline"` - PermissionRef primitive.ObjectID `bson:"permissionRef" json:"permissionRef"` + PermissionRef bson.ObjectID `bson:"permissionRef" json:"permissionRef"` } -func (b *PermissionBound) GetPermissionRef() primitive.ObjectID { +func (b *PermissionBound) GetPermissionRef() bson.ObjectID { return b.PermissionRef } -func (b *PermissionBound) GetOrganizationRef() primitive.ObjectID { +func (b *PermissionBound) GetOrganizationRef() bson.ObjectID { return b.OrganizationRef } -func (b *PermissionBound) SetPermissionRef(permissionRef primitive.ObjectID) { +func (b *PermissionBound) SetPermissionRef(permissionRef bson.ObjectID) { b.PermissionRef = permissionRef } diff --git a/api/pkg/model/rba.go b/api/pkg/model/rba.go index fc4f0310..ff6aa7b4 100644 --- a/api/pkg/model/rba.go +++ b/api/pkg/model/rba.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/tech/sendico/pkg/merrors" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) type RussianBankAccountPaymentData struct { diff --git a/api/pkg/model/wallet.go b/api/pkg/model/wallet.go index cf46f140..b8ab2254 100644 --- a/api/pkg/model/wallet.go +++ b/api/pkg/model/wallet.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/tech/sendico/pkg/merrors" - "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/v2/bson" ) type WalletPaymentData struct { diff --git a/api/pkg/mutil/db/archive.go b/api/pkg/mutil/db/archive.go index 8daf19a1..d4205a5d 100644 --- a/api/pkg/mutil/db/archive.go +++ b/api/pkg/mutil/db/archive.go @@ -7,11 +7,11 @@ import ( "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) -func SetArchived[T storable.Storable](ctx context.Context, logger mlogger.Logger, newArchived bool, objectRef primitive.ObjectID, repo repository.Repository) error { +func SetArchived[T storable.Storable](ctx context.Context, logger mlogger.Logger, newArchived bool, objectRef bson.ObjectID, repo repository.Repository) error { objs, err := GetObjects[T](ctx, logger, repository.IDFilter(objectRef), nil, repo) if err != nil { logger.Warn("Failed to fetch object", zap.Error(err), mzap.ObjRef("object_ref", objectRef)) diff --git a/api/pkg/mutil/db/array.go b/api/pkg/mutil/db/array.go index 0cbfdaca..b0fb240c 100644 --- a/api/pkg/mutil/db/array.go +++ b/api/pkg/mutil/db/array.go @@ -7,7 +7,7 @@ import ( "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/v2/mongo" "go.uber.org/zap" ) diff --git a/api/pkg/mutil/db/auth/accountbound.go b/api/pkg/mutil/db/auth/accountbound.go index c375f5ba..25ada631 100644 --- a/api/pkg/mutil/db/auth/accountbound.go +++ b/api/pkg/mutil/db/auth/accountbound.go @@ -28,7 +28,7 @@ import ( "github.com/tech/sendico/pkg/model" mutil "github.com/tech/sendico/pkg/mutil/db" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -40,7 +40,7 @@ import ( func GetAccountBoundObjects[T any]( ctx context.Context, logger mlogger.Logger, - accountRef, organizationRef primitive.ObjectID, + accountRef, organizationRef bson.ObjectID, filter builder.Query, cursor *model.ViewCursor, enforcer auth.Enforcer, @@ -70,7 +70,7 @@ func GetAccountBoundObjects[T any]( return nil, merrors.NoData("no_account_bound_objects_found") } - allowed := make([]primitive.ObjectID, 0, len(allObjects)) + allowed := make([]bson.ObjectID, 0, len(allObjects)) for _, ref := range allObjects { allowed = append(allowed, *ref.GetID()) } diff --git a/api/pkg/mutil/db/auth/protected.go b/api/pkg/mutil/db/auth/protected.go index 222e18b9..248b1dd7 100644 --- a/api/pkg/mutil/db/auth/protected.go +++ b/api/pkg/mutil/db/auth/protected.go @@ -12,14 +12,14 @@ import ( "github.com/tech/sendico/pkg/model" mutil "github.com/tech/sendico/pkg/mutil/db" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) func GetProtectedObjects[T any]( ctx context.Context, logger mlogger.Logger, - accountRef, organizationRef primitive.ObjectID, + accountRef, organizationRef bson.ObjectID, action model.Action, filter builder.Query, cursor *model.ViewCursor, @@ -44,7 +44,7 @@ func GetProtectedObjects[T any]( return nil, err } - allowed := make([]primitive.ObjectID, 0, len(res)) + allowed := make([]bson.ObjectID, 0, len(res)) for _, ref := range refs { if ok := res[*ref.GetID()]; ok { allowed = append(allowed, *ref.GetID()) diff --git a/api/pkg/mutil/db/db.go b/api/pkg/mutil/db/db.go index 1dc161d0..d29855c9 100644 --- a/api/pkg/mutil/db/db.go +++ b/api/pkg/mutil/db/db.go @@ -6,12 +6,12 @@ import ( "github.com/tech/sendico/pkg/db/repository" "github.com/tech/sendico/pkg/db/storable" "github.com/tech/sendico/pkg/mlogger" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) func GetObjectByID(ctx context.Context, logger mlogger.Logger, id string, val storable.Storable, repo repository.Repository) error { - p, err := primitive.ObjectIDFromHex(id) + p, err := bson.ObjectIDFromHex(id) if err != nil { logger.Warn("Failed to decode object reference", zap.String("reference", id), zap.String("collection", val.Collection())) return err diff --git a/api/pkg/mutil/helpers/accountmanager.go b/api/pkg/mutil/helpers/accountmanager.go index 19eeff82..d7f64b5c 100644 --- a/api/pkg/mutil/helpers/accountmanager.go +++ b/api/pkg/mutil/helpers/accountmanager.go @@ -3,20 +3,20 @@ package helpers import ( "context" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // AccountManager defines the interface for account management operations type AccountManager interface { // DeleteOrganization deletes an organization and all its associated data // The caller is responsible for wrapping this in a transaction - DeleteOrganization(ctx context.Context, orgRef primitive.ObjectID) error + DeleteOrganization(ctx context.Context, orgRef bson.ObjectID) error // DeleteAccount deletes an account and all its associated data // The caller is responsible for wrapping this in a transaction - DeleteAccount(ctx context.Context, accountRef primitive.ObjectID) error + DeleteAccount(ctx context.Context, accountRef bson.ObjectID) error // DeleteAll deletes all data for a given account and organization // The caller is responsible for wrapping this in a transaction - DeleteAll(ctx context.Context, accountRef, organizationRef primitive.ObjectID) error + DeleteAll(ctx context.Context, accountRef, organizationRef bson.ObjectID) error } diff --git a/api/pkg/mutil/helpers/internal/accountmanager.go b/api/pkg/mutil/helpers/internal/accountmanager.go index 1968a904..e09e5c55 100644 --- a/api/pkg/mutil/helpers/internal/accountmanager.go +++ b/api/pkg/mutil/helpers/internal/accountmanager.go @@ -9,7 +9,7 @@ import ( "github.com/tech/sendico/pkg/db/policy" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -45,7 +45,7 @@ func NewAccountManager( // DeleteOrganization deletes an organization and all its associated data // The caller is responsible for wrapping this in a transaction -func (m *AccountManager) DeleteOrganization(ctx context.Context, orgRef primitive.ObjectID) error { +func (m *AccountManager) DeleteOrganization(ctx context.Context, orgRef bson.ObjectID) error { m.logger.Debug("Deleting organization", mzap.ObjRef("org_ref", orgRef)) // Delete organization roles @@ -61,7 +61,7 @@ func (m *AccountManager) DeleteOrganization(ctx context.Context, orgRef primitiv } // Finally delete the organization itself - if err := m.orgDB.Delete(ctx, primitive.NilObjectID, orgRef); err != nil { + if err := m.orgDB.Delete(ctx, bson.NilObjectID, orgRef); err != nil { m.logger.Warn("Failed to delete organization", zap.Error(err), mzap.ObjRef("org_ref", orgRef)) return err } @@ -72,7 +72,7 @@ func (m *AccountManager) DeleteOrganization(ctx context.Context, orgRef primitiv // DeleteAccount deletes an account and all its associated data // The caller is responsible for wrapping this in a transaction -func (m *AccountManager) DeleteAccount(ctx context.Context, accountRef primitive.ObjectID) error { +func (m *AccountManager) DeleteAccount(ctx context.Context, accountRef bson.ObjectID) error { m.logger.Debug("Deleting account", mzap.ObjRef("account_ref", accountRef)) // Delete the account @@ -87,7 +87,7 @@ func (m *AccountManager) DeleteAccount(ctx context.Context, accountRef primitive // DeleteAll deletes all data for a given account and organization // The caller is responsible for wrapping this in a transaction -func (m *AccountManager) DeleteAll(ctx context.Context, accountRef, organizationRef primitive.ObjectID) error { +func (m *AccountManager) DeleteAll(ctx context.Context, accountRef, organizationRef bson.ObjectID) error { m.logger.Debug("Deleting all data", mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("organization_ref", organizationRef)) // Delete organization first (which will cascade delete all related data) @@ -107,7 +107,7 @@ func (m *AccountManager) DeleteAll(ctx context.Context, accountRef, organization } // deleteOrganizationRoles deletes all roles for an organization -func (m *AccountManager) deleteOrganizationRoles(ctx context.Context, orgRef primitive.ObjectID) error { +func (m *AccountManager) deleteOrganizationRoles(ctx context.Context, orgRef bson.ObjectID) error { // Get all roles for the organization roles, err := m.authManager.Role().List(ctx, orgRef) if err != nil { @@ -128,7 +128,7 @@ func (m *AccountManager) deleteOrganizationRoles(ctx context.Context, orgRef pri } // deleteOrganizationPolicies deletes all policies for an organization -func (m *AccountManager) deleteOrganizationPolicies(_ context.Context, _ primitive.ObjectID) error { +func (m *AccountManager) deleteOrganizationPolicies(_ context.Context, _ bson.ObjectID) error { // Note: PolicyDB is used for both roles and policies, but the interface is unclear // This would need to be implemented differently or skipped for now m.logger.Warn("Policy deletion not implemented - interface unclear") diff --git a/api/pkg/mutil/mzap/object.go b/api/pkg/mutil/mzap/object.go index 8e47bbdc..fac4b695 100644 --- a/api/pkg/mutil/mzap/object.go +++ b/api/pkg/mutil/mzap/object.go @@ -2,11 +2,11 @@ package mzap import ( "github.com/tech/sendico/pkg/db/storable" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) -func ObjRef(name string, objRef primitive.ObjectID) zap.Field { +func ObjRef(name string, objRef bson.ObjectID) zap.Field { return zap.String(name, objRef.Hex()) } diff --git a/api/server/go.mod b/api/server/go.mod index bd5b4efc..738a3c05 100644 --- a/api/server/go.mod +++ b/api/server/go.mod @@ -29,7 +29,7 @@ require ( github.com/tech/sendico/pkg v0.1.0 github.com/testcontainers/testcontainers-go v0.33.0 github.com/testcontainers/testcontainers-go/modules/mongodb v0.33.0 - go.mongodb.org/mongo-driver v1.17.8 + go.mongodb.org/mongo-driver/v2 v2.5.0 go.uber.org/zap v1.27.1 golang.org/x/net v0.49.0 google.golang.org/grpc v1.78.0 @@ -64,7 +64,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/sts v1.41.6 // indirect github.com/aws/smithy-go v1.24.0 // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect + github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/containerd/log v0.1.0 // indirect @@ -83,7 +83,6 @@ require ( github.com/go-ole/go-ole v1.3.0 // indirect github.com/goccy/go-json v0.10.5 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/snappy v1.0.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect github.com/klauspost/compress v1.18.3 // indirect github.com/lestrrat-go/blackmagic v1.0.4 // indirect @@ -102,7 +101,6 @@ require ( github.com/moby/sys/user v0.3.0 // indirect github.com/moby/sys/userns v0.1.0 // indirect github.com/moby/term v0.5.0 // indirect - github.com/montanaflynn/stats v0.7.1 // indirect github.com/morikuni/aec v1.0.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nats-io/nats.go v1.48.0 // indirect diff --git a/api/server/go.sum b/api/server/go.sum index 7d4569ce..8a256d60 100644 --- a/api/server/go.sum +++ b/api/server/go.sum @@ -55,8 +55,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0= github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A= -github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E= -github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA= +github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ= +github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -252,6 +252,8 @@ github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM= go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= diff --git a/api/server/interface/accountservice/internal/service.go b/api/server/interface/accountservice/internal/service.go index 07d35792..051788b9 100644 --- a/api/server/interface/accountservice/internal/service.go +++ b/api/server/interface/accountservice/internal/service.go @@ -20,7 +20,7 @@ import ( "github.com/tech/sendico/pkg/mutil/mzap" "github.com/tech/sendico/server/interface/middleware" "github.com/tech/sendico/server/internal/mutil/flrstring" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -120,7 +120,7 @@ func (s *service) CreateAccount( ctx context.Context, org *model.Organization, acct *model.Account, - roleDescID primitive.ObjectID, + roleDescID bson.ObjectID, ) error { if org == nil { return merrors.InvalidArgument("Organization must not be nil") @@ -128,7 +128,7 @@ func (s *service) CreateAccount( if acct == nil || len(acct.Login) == 0 { return merrors.InvalidArgument("Account must have a non-empty login") } - if roleDescID == primitive.NilObjectID { + if roleDescID == bson.NilObjectID { return merrors.InvalidArgument("Role description must be provided") } // 1) Create the account @@ -152,7 +152,7 @@ func (s *service) CreateAccount( func (s *service) DeleteAccount( ctx context.Context, org *model.Organization, - accountRef primitive.ObjectID, + accountRef bson.ObjectID, ) error { // Check if this is the only member in the organization if len(org.Members) <= 1 { @@ -178,7 +178,7 @@ func (s *service) DeleteAccount( func (s *service) RemoveAccountFromOrganization( ctx context.Context, org *model.Organization, - accountRef primitive.ObjectID, + accountRef bson.ObjectID, ) error { if org == nil { return merrors.InvalidArgument("Organization must not be nil") @@ -233,7 +233,7 @@ func (s *service) JoinOrganization( ctx context.Context, org *model.Organization, account *model.Account, - roleDescID primitive.ObjectID, + roleDescID bson.ObjectID, ) error { if slices.Contains(org.Members, account.ID) { s.logger.Debug("Account is already a member", mzap.StorableRef(org), mzap.StorableRef(account)) @@ -260,7 +260,7 @@ func (s *service) JoinOrganization( return nil } -func (s *service) deleteOrganizationRoles(ctx context.Context, orgRef primitive.ObjectID) error { +func (s *service) deleteOrganizationRoles(ctx context.Context, orgRef bson.ObjectID) error { s.logger.Info("Deleting roles for organization", mzap.ObjRef("organization_ref", orgRef)) // Get all roles for the organization @@ -282,7 +282,7 @@ func (s *service) deleteOrganizationRoles(ctx context.Context, orgRef primitive. return nil } -func (s *service) deleteOrganizationPolicies(ctx context.Context, orgRef primitive.ObjectID) error { +func (s *service) deleteOrganizationPolicies(ctx context.Context, orgRef bson.ObjectID) error { s.logger.Info("Deleting policies for organization", mzap.ObjRef("organization_ref", orgRef)) // Get all policies for the organization @@ -323,7 +323,7 @@ func (s *service) DeleteOrganization( } // 10. Finally, delete the organization itself - if err := s.orgDB.Delete(ctx, primitive.NilObjectID, org.ID); err != nil { + if err := s.orgDB.Delete(ctx, bson.NilObjectID, org.ID); err != nil { s.logger.Warn("Failed to delete organization", zap.Error(err), mzap.StorableRef(org)) return nil, err } @@ -342,7 +342,7 @@ func (s *service) DeleteOrganization( func (s *service) DeleteAll( ctx context.Context, org *model.Organization, - accountRef primitive.ObjectID, + accountRef bson.ObjectID, ) error { s.logger.Info("Starting complete deletion (organization + account)", mzap.StorableRef(org), mzap.ObjRef("account_ref", accountRef)) diff --git a/api/server/interface/accountservice/internal/service_deletion_test.go b/api/server/interface/accountservice/internal/service_deletion_test.go index 881c3292..0100b9aa 100644 --- a/api/server/interface/accountservice/internal/service_deletion_test.go +++ b/api/server/interface/accountservice/internal/service_deletion_test.go @@ -3,23 +3,23 @@ package accountserviceimp import ( "testing" - "github.com/tech/sendico/pkg/merrors" - "github.com/tech/sendico/pkg/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.mongodb.org/mongo-driver/bson/primitive" + "github.com/tech/sendico/pkg/merrors" + "github.com/tech/sendico/pkg/model" + "go.mongodb.org/mongo-driver/v2/bson" ) func TestDeleteAccount_Validation(t *testing.T) { t.Run("DeleteAccount_LastMemberFails", func(t *testing.T) { - orgID := primitive.NewObjectID() - accountID := primitive.NewObjectID() + orgID := bson.NewObjectID() + accountID := bson.NewObjectID() org := &model.Organization{ OrganizationBase: model.OrganizationBase{ Describable: model.Describable{Name: "Single Member Org"}, }, - Members: []primitive.ObjectID{accountID}, // Only one member + Members: []bson.ObjectID{accountID}, // Only one member } org.ID = orgID @@ -30,15 +30,15 @@ func TestDeleteAccount_Validation(t *testing.T) { }) t.Run("DeleteAccount_MultipleMembersSuccess", func(t *testing.T) { - orgID := primitive.NewObjectID() - accountID := primitive.NewObjectID() - otherAccountID := primitive.NewObjectID() + orgID := bson.NewObjectID() + accountID := bson.NewObjectID() + otherAccountID := bson.NewObjectID() org := &model.Organization{ OrganizationBase: model.OrganizationBase{ Describable: model.Describable{Name: "Multi Member Org"}, }, - Members: []primitive.ObjectID{accountID, otherAccountID}, // Multiple members + Members: []bson.ObjectID{accountID, otherAccountID}, // Multiple members } org.ID = orgID @@ -48,13 +48,13 @@ func TestDeleteAccount_Validation(t *testing.T) { }) t.Run("DeleteAccount_EmptyMembersList", func(t *testing.T) { - orgID := primitive.NewObjectID() + orgID := bson.NewObjectID() org := &model.Organization{ OrganizationBase: model.OrganizationBase{ Describable: model.Describable{Name: "Empty Org"}, }, - Members: []primitive.ObjectID{}, // No members + Members: []bson.ObjectID{}, // No members } org.ID = orgID @@ -85,7 +85,7 @@ func TestDeleteOrganization_Validation(t *testing.T) { Describable: model.Describable{Name: "Valid Organization"}, }, } - org.ID = primitive.NewObjectID() + org.ID = bson.NewObjectID() err := validateDeleteOrganization(org) require.NoError(t, err) @@ -94,7 +94,7 @@ func TestDeleteOrganization_Validation(t *testing.T) { func TestDeleteAll_Validation(t *testing.T) { t.Run("DeleteAll_NilOrganization", func(t *testing.T) { - accountID := primitive.NewObjectID() + accountID := bson.NewObjectID() err := validateDeleteAll(nil, accountID) require.Error(t, err) assert.Contains(t, err.Error(), "organization cannot be nil") @@ -106,9 +106,9 @@ func TestDeleteAll_Validation(t *testing.T) { Describable: model.Describable{Name: "Valid Organization"}, }, } - org.ID = primitive.NewObjectID() + org.ID = bson.NewObjectID() - err := validateDeleteAll(org, primitive.NilObjectID) + err := validateDeleteAll(org, bson.NilObjectID) require.Error(t, err) assert.Contains(t, err.Error(), "account ID cannot be empty") }) @@ -119,8 +119,8 @@ func TestDeleteAll_Validation(t *testing.T) { Describable: model.Describable{Name: "Valid Organization"}, }, } - org.ID = primitive.NewObjectID() - accountID := primitive.NewObjectID() + org.ID = bson.NewObjectID() + accountID := bson.NewObjectID() err := validateDeleteAll(org, accountID) require.NoError(t, err) @@ -139,17 +139,17 @@ func validateDeleteOrganization(org *model.Organization) error { if org == nil { return merrors.InvalidArgument("organization cannot be nil") } - if org.ID == primitive.NilObjectID { + if org.ID == bson.NilObjectID { return merrors.InvalidArgument("organization ID cannot be empty") } return nil } -func validateDeleteAll(org *model.Organization, accountRef primitive.ObjectID) error { +func validateDeleteAll(org *model.Organization, accountRef bson.ObjectID) error { if org == nil { return merrors.InvalidArgument("organization cannot be nil") } - if accountRef == primitive.NilObjectID { + if accountRef == bson.NilObjectID { return merrors.InvalidArgument("account ID cannot be empty") } return nil diff --git a/api/server/interface/accountservice/types.go b/api/server/interface/accountservice/types.go index 173c8cb4..243f7ce3 100644 --- a/api/server/interface/accountservice/types.go +++ b/api/server/interface/accountservice/types.go @@ -10,7 +10,7 @@ import ( "github.com/tech/sendico/pkg/model" accountserviceimp "github.com/tech/sendico/server/interface/accountservice/internal" "github.com/tech/sendico/server/interface/middleware" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // AccountService defines all account-related workflows. @@ -45,14 +45,14 @@ type AccountService interface { ctx context.Context, org *model.Organization, acct *model.Account, - roleDescID primitive.ObjectID, + roleDescID bson.ObjectID, ) error JoinOrganization( ctx context.Context, org *model.Organization, acct *model.Account, - roleDescID primitive.ObjectID, + roleDescID bson.ObjectID, ) error UpdateLogin( @@ -65,14 +65,14 @@ type AccountService interface { DeleteAccount( ctx context.Context, org *model.Organization, - accountRef primitive.ObjectID, + accountRef bson.ObjectID, ) error // RemoveAccountFromOrganization just drops it from the member slice. RemoveAccountFromOrganization( ctx context.Context, org *model.Organization, - accountRef primitive.ObjectID, + accountRef bson.ObjectID, ) error DeleteOrganization( @@ -84,7 +84,7 @@ type AccountService interface { DeleteAll( ctx context.Context, org *model.Organization, - accountRef primitive.ObjectID, + accountRef bson.ObjectID, ) error } diff --git a/api/server/interface/api/srequest/changepolicies.go b/api/server/interface/api/srequest/changepolicies.go index 41956432..2c6154e8 100644 --- a/api/server/interface/api/srequest/changepolicies.go +++ b/api/server/interface/api/srequest/changepolicies.go @@ -2,11 +2,11 @@ package srequest import ( "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type ChangePolicies struct { - RoleRef primitive.ObjectID `json:"roleRef"` + RoleRef bson.ObjectID `json:"roleRef"` Add *[]model.RolePolicy `json:"add,omitempty"` Remove *[]model.RolePolicy `json:"remove,omitempty"` } diff --git a/api/server/interface/api/srequest/changerole.go b/api/server/interface/api/srequest/changerole.go index 6b74e9ad..ec2b3517 100644 --- a/api/server/interface/api/srequest/changerole.go +++ b/api/server/interface/api/srequest/changerole.go @@ -1,8 +1,8 @@ package srequest -import "go.mongodb.org/mongo-driver/bson/primitive" +import "go.mongodb.org/mongo-driver/v2/bson" type ChangeRole struct { - AccountRef primitive.ObjectID `json:"accountRef"` - NewRoleDescriptionRef primitive.ObjectID `json:"newRoleDescriptionRef"` + AccountRef bson.ObjectID `json:"accountRef"` + NewRoleDescriptionRef bson.ObjectID `json:"newRoleDescriptionRef"` } diff --git a/api/server/interface/api/srequest/file.go b/api/server/interface/api/srequest/file.go index 0e5ede29..9104ef99 100644 --- a/api/server/interface/api/srequest/file.go +++ b/api/server/interface/api/srequest/file.go @@ -1,7 +1,7 @@ package srequest -import "go.mongodb.org/mongo-driver/bson/primitive" +import "go.mongodb.org/mongo-driver/v2/bson" type FileUpload struct { - ObjRef primitive.ObjectID `json:"objRef"` + ObjRef bson.ObjectID `json:"objRef"` } diff --git a/api/server/interface/api/srequest/ledger.go b/api/server/interface/api/srequest/ledger.go index 71d3c55e..e2f2a3bf 100644 --- a/api/server/interface/api/srequest/ledger.go +++ b/api/server/interface/api/srequest/ledger.go @@ -6,7 +6,7 @@ import ( "github.com/tech/sendico/pkg/ledgerconv" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type LedgerAccountType string @@ -28,13 +28,13 @@ const ( ) type CreateLedgerAccount struct { - AccountType LedgerAccountType `json:"accountType"` - Currency string `json:"currency"` - AllowNegative bool `json:"allowNegative,omitempty"` - Role model.AccountRole `json:"role"` - Describable model.Describable `json:"describable"` - OwnerRef *primitive.ObjectID `json:"ownerRef,omitempty"` - Metadata map[string]string `json:"metadata,omitempty"` + AccountType LedgerAccountType `json:"accountType"` + Currency string `json:"currency"` + AllowNegative bool `json:"allowNegative,omitempty"` + Role model.AccountRole `json:"role"` + Describable model.Describable `json:"describable"` + OwnerRef *bson.ObjectID `json:"ownerRef,omitempty"` + Metadata map[string]string `json:"metadata,omitempty"` } func (r *CreateLedgerAccount) Validate() error { diff --git a/api/server/interface/api/srequest/reorder.go b/api/server/interface/api/srequest/reorder.go index 5ba37632..46555f6e 100644 --- a/api/server/interface/api/srequest/reorder.go +++ b/api/server/interface/api/srequest/reorder.go @@ -1,19 +1,19 @@ package srequest -import "go.mongodb.org/mongo-driver/bson/primitive" +import "go.mongodb.org/mongo-driver/v2/bson" type Reorder struct { - ParentRef primitive.ObjectID `json:"parentRef"` - From int `json:"from"` - To int `json:"to"` + ParentRef bson.ObjectID `json:"parentRef"` + From int `json:"from"` + To int `json:"to"` } type ReorderX struct { - ObjectRef primitive.ObjectID `json:"objectRef"` - To int `json:"to"` + ObjectRef bson.ObjectID `json:"objectRef"` + To int `json:"to"` } type ReorderXDefault struct { ReorderX `json:",inline"` - ParentRef primitive.ObjectID `json:"parentRef"` + ParentRef bson.ObjectID `json:"parentRef"` } diff --git a/api/server/interface/api/srequest/sgchange.go b/api/server/interface/api/srequest/sgchange.go index 11048dca..f686cae5 100644 --- a/api/server/interface/api/srequest/sgchange.go +++ b/api/server/interface/api/srequest/sgchange.go @@ -1,13 +1,13 @@ package srequest -import "go.mongodb.org/mongo-driver/bson/primitive" +import "go.mongodb.org/mongo-driver/v2/bson" type GroupItemChange struct { - GroupRef primitive.ObjectID `json:"groupRef"` - ItemRef primitive.ObjectID `json:"itemRef"` + GroupRef bson.ObjectID `json:"groupRef"` + ItemRef bson.ObjectID `json:"itemRef"` } type RemoveItemFromGroup struct { GroupItemChange `json:",inline"` - TargetItemRef primitive.ObjectID `json:"targetItemRef"` + TargetItemRef bson.ObjectID `json:"targetItemRef"` } diff --git a/api/server/interface/api/srequest/taggable.go b/api/server/interface/api/srequest/taggable.go index c762aead..43fa1b8c 100644 --- a/api/server/interface/api/srequest/taggable.go +++ b/api/server/interface/api/srequest/taggable.go @@ -1,20 +1,20 @@ package srequest -import "go.mongodb.org/mongo-driver/bson/primitive" +import "go.mongodb.org/mongo-driver/v2/bson" // TaggableSingle is used for single tag operations (add/remove tag) type TaggableSingle struct { - ObjectRef primitive.ObjectID `json:"objectRef"` - TagRef primitive.ObjectID `json:"tagRef"` + ObjectRef bson.ObjectID `json:"objectRef"` + TagRef bson.ObjectID `json:"tagRef"` } // TaggableMultiple is used for multiple tag operations (add tags, set tags) type TaggableMultiple struct { - ObjectRef primitive.ObjectID `json:"objectRef"` - TagRefs []primitive.ObjectID `json:"tagRefs"` + ObjectRef bson.ObjectID `json:"objectRef"` + TagRefs []bson.ObjectID `json:"tagRefs"` } // TaggableObject is used for object-only operations (remove all tags, get tags) type TaggableObject struct { - ObjectRef primitive.ObjectID `json:"objectRef"` + ObjectRef bson.ObjectID `json:"objectRef"` } diff --git a/api/server/interface/api/srequest/wallet.go b/api/server/interface/api/srequest/wallet.go index 8dbaabd5..b82a188e 100644 --- a/api/server/interface/api/srequest/wallet.go +++ b/api/server/interface/api/srequest/wallet.go @@ -2,11 +2,11 @@ package srequest import ( "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type CreateWallet struct { Description model.Describable `json:"description"` Asset model.ChainAssetKey `json:"asset"` - OwnerRef *primitive.ObjectID `json:"ownerRef,omitempty"` + OwnerRef *bson.ObjectID `json:"ownerRef,omitempty"` } diff --git a/api/server/interface/api/sresponse/account.go b/api/server/interface/api/sresponse/account.go index 2dfc58e9..1c8c78c7 100644 --- a/api/server/interface/api/sresponse/account.go +++ b/api/server/interface/api/sresponse/account.go @@ -6,7 +6,7 @@ import ( "github.com/tech/sendico/pkg/api/http/response" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type accountData struct { @@ -26,7 +26,7 @@ func _createAccount(account *model.Account, isAnonymous bool) *accountData { } } -func _toAccount(account *model.Account, orgRef primitive.ObjectID) *accountData { +func _toAccount(account *model.Account, orgRef bson.ObjectID) *accountData { return _createAccount(account, model.AccountIsAnonymous(&account.UserDataBase, orgRef)) } @@ -45,7 +45,7 @@ type accountsResponse struct { Accounts []accountData `json:"accounts"` } -func Accounts(logger mlogger.Logger, accounts []model.Account, orgRef primitive.ObjectID, accessToken *TokenData) http.HandlerFunc { +func Accounts(logger mlogger.Logger, accounts []model.Account, orgRef bson.ObjectID, accessToken *TokenData) http.HandlerFunc { // Convert each account to its public representation. publicAccounts := make([]accountData, len(accounts)) for i, a := range accounts { diff --git a/api/server/interface/model/token.go b/api/server/interface/model/token.go index 9390ab60..57032ec6 100644 --- a/api/server/interface/model/token.go +++ b/api/server/interface/model/token.go @@ -8,11 +8,11 @@ import ( "github.com/tech/sendico/pkg/model" mduration "github.com/tech/sendico/pkg/mutil/duration" "github.com/tech/sendico/server/interface/middleware" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type AccountToken struct { - AccountRef primitive.ObjectID + AccountRef bson.ObjectID Login string Name string Locale string @@ -56,7 +56,7 @@ func Claims2Token(claims middleware.MapClaims) (*AccountToken, error) { if account, err = getTokenParam(claims, paramNameID); err != nil { return nil, err } - if at.AccountRef, err = primitive.ObjectIDFromHex(account); err != nil { + if at.AccountRef, err = bson.ObjectIDFromHex(account); err != nil { return nil, err } if at.Login, err = getTokenParam(claims, paramNameLogin); err != nil { diff --git a/api/server/internal/mutil/param/getter.go b/api/server/internal/mutil/param/getter.go index 7c65029a..d8eba536 100644 --- a/api/server/internal/mutil/param/getter.go +++ b/api/server/internal/mutil/param/getter.go @@ -7,7 +7,7 @@ import ( "github.com/go-chi/chi/v5" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -31,32 +31,32 @@ func GetOrganizationID(r *http.Request) string { return GetParam(r, OrganizationRefName()) } -func GetOrganizationRef(r *http.Request) (primitive.ObjectID, error) { - return primitive.ObjectIDFromHex(GetOrganizationID(r)) +func GetOrganizationRef(r *http.Request) (bson.ObjectID, error) { + return bson.ObjectIDFromHex(GetOrganizationID(r)) } func GetStatusID(r *http.Request) string { return GetParam(r, OrganizationRefName()) } -func GetStatusRef(r *http.Request) (primitive.ObjectID, error) { - return primitive.ObjectIDFromHex(GetStatusID(r)) +func GetStatusRef(r *http.Request) (bson.ObjectID, error) { + return bson.ObjectIDFromHex(GetStatusID(r)) } func GetProjectID(r *http.Request) string { return GetParam(r, ProjectRefName()) } -func GetProjectRef(r *http.Request) (primitive.ObjectID, error) { - return primitive.ObjectIDFromHex(GetProjectID(r)) +func GetProjectRef(r *http.Request) (bson.ObjectID, error) { + return bson.ObjectIDFromHex(GetProjectID(r)) } func GetInvitationID(r *http.Request) string { return GetParam(r, InvitationRefName()) } -func GetInvitationRef(r *http.Request) (primitive.ObjectID, error) { - return primitive.ObjectIDFromHex(GetOrganizationID(r)) +func GetInvitationRef(r *http.Request) (bson.ObjectID, error) { + return bson.ObjectIDFromHex(GetOrganizationID(r)) } func GetToken(r *http.Request) string { diff --git a/api/server/internal/mutil/param/helper.go b/api/server/internal/mutil/param/helper.go index 92d10c5c..60105b4f 100644 --- a/api/server/internal/mutil/param/helper.go +++ b/api/server/internal/mutil/param/helper.go @@ -4,14 +4,14 @@ import ( "net/http" mutilimp "github.com/tech/sendico/server/internal/mutil/param/internal" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type ParamHelper interface { Name() string RefName() string GetID(r *http.Request) string - GetRef(r *http.Request) (primitive.ObjectID, error) + GetRef(r *http.Request) (bson.ObjectID, error) AddRef(base string) string } diff --git a/api/server/internal/mutil/param/internal/helper.go b/api/server/internal/mutil/param/internal/helper.go index 2a9f9e06..4639db38 100644 --- a/api/server/internal/mutil/param/internal/helper.go +++ b/api/server/internal/mutil/param/internal/helper.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/go-chi/chi/v5" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) func addParam(base string, param string) string { @@ -38,8 +38,8 @@ func (ph *ParamHelper) GetID(r *http.Request) string { return getParam(r, ph.RefName()) } -func (ph *ParamHelper) GetRef(r *http.Request) (primitive.ObjectID, error) { - return primitive.ObjectIDFromHex(ph.GetID(r)) +func (ph *ParamHelper) GetRef(r *http.Request) (bson.ObjectID, error) { + return bson.ObjectIDFromHex(ph.GetID(r)) } func (ph *ParamHelper) AddRef(base string) string { diff --git a/api/server/internal/mutil/param/ref.go b/api/server/internal/mutil/param/ref.go index 040bd77d..24973ccc 100644 --- a/api/server/internal/mutil/param/ref.go +++ b/api/server/internal/mutil/param/ref.go @@ -3,9 +3,9 @@ package mutil import ( "net/http" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) -func GetAccountRef(r *http.Request) (primitive.ObjectID, error) { - return primitive.ObjectIDFromHex(GetAccountID(r)) +func GetAccountRef(r *http.Request) (bson.ObjectID, error) { + return bson.ObjectIDFromHex(GetAccountID(r)) } diff --git a/api/server/internal/server/aapitemplate/db.go b/api/server/internal/server/aapitemplate/db.go index e1dcc84d..5e17c7e5 100644 --- a/api/server/internal/server/aapitemplate/db.go +++ b/api/server/internal/server/aapitemplate/db.go @@ -4,18 +4,18 @@ import ( "context" "github.com/tech/sendico/pkg/db/repository/builder" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type DB[T any] interface { - Create(ctx context.Context, accountRef primitive.ObjectID, object *T) error - Get(ctx context.Context, accountRef, objectRef primitive.ObjectID, result *T) error - Update(ctx context.Context, accountRef primitive.ObjectID, object *T) error - Patch(ctx context.Context, accountRef, objectRef primitive.ObjectID, patch builder.Patch) error - Delete(ctx context.Context, accountRef, objectRef primitive.ObjectID) error - List(ctx context.Context, accountRef, organizationRef primitive.ObjectID) ([]T, error) + Create(ctx context.Context, accountRef bson.ObjectID, object *T) error + Get(ctx context.Context, accountRef, objectRef bson.ObjectID, result *T) error + Update(ctx context.Context, accountRef bson.ObjectID, object *T) error + Patch(ctx context.Context, accountRef, objectRef bson.ObjectID, patch builder.Patch) error + Delete(ctx context.Context, accountRef, objectRef bson.ObjectID) error + List(ctx context.Context, accountRef, organizationRef bson.ObjectID) ([]T, error) } type ReorderDB interface { - Reorder(ctx context.Context, accountRef, objectRef primitive.ObjectID, newIndex int, filter builder.Query) error + Reorder(ctx context.Context, accountRef, objectRef bson.ObjectID, newIndex int, filter builder.Query) error } diff --git a/api/server/internal/server/aapitemplate/delete.go b/api/server/internal/server/aapitemplate/delete.go index 2d4ee0e6..c7448598 100644 --- a/api/server/internal/server/aapitemplate/delete.go +++ b/api/server/internal/server/aapitemplate/delete.go @@ -9,11 +9,11 @@ import ( "github.com/tech/sendico/pkg/mutil/mzap" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) -func (a *AccountAPI[T]) deleteImp(ctx context.Context, account *model.Account, objectRef primitive.ObjectID) error { +func (a *AccountAPI[T]) deleteImp(ctx context.Context, account *model.Account, objectRef bson.ObjectID) error { if err := a.DB.Delete(ctx, *account.GetID(), objectRef); err != nil { a.Logger.Warn("Error deleting object", zap.Error(err), mzap.StorableRef(account), mzap.ObjRef("object_ref", objectRef)) return err diff --git a/api/server/internal/server/aapitemplate/nconfig.go b/api/server/internal/server/aapitemplate/nconfig.go index 5a5516e9..f986ad15 100644 --- a/api/server/internal/server/aapitemplate/nconfig.go +++ b/api/server/internal/server/aapitemplate/nconfig.go @@ -4,14 +4,14 @@ import ( "github.com/tech/sendico/pkg/messaging" notifications "github.com/tech/sendico/pkg/messaging/envelope" model "github.com/tech/sendico/pkg/model/notification" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // NotificationHandler is a function that processes an object of type T and returns an error. -type NotificationHandler[T any] func(template T, actorAccountRef primitive.ObjectID) error +type NotificationHandler[T any] func(template T, actorAccountRef bson.ObjectID) error // sinkNotification is the default no-op strategy. -func sinkNotification[T any](_ T, _ primitive.ObjectID) error { +func sinkNotification[T any](_ T, _ bson.ObjectID) error { return nil } @@ -19,7 +19,7 @@ func sinkNotification[T any](_ T, _ primitive.ObjectID) error { type NotificationConfig[T any] struct { producer messaging.Producer // The factory now receives a NotificationAction so it knows which event is being processed. - factory func(template T, actorAccountRef primitive.ObjectID, t model.NotificationAction) notifications.Envelope + factory func(template T, actorAccountRef bson.ObjectID, t model.NotificationAction) notifications.Envelope CreateNotification NotificationHandler[T] UpdateNotification NotificationHandler[T] NeedArchiveNotification bool @@ -43,20 +43,20 @@ func NewNotificationConfig[T any](producer messaging.Producer) *NotificationConf } // WithNotifications sets the notification factory and switches all endpoints to the sending strategy. -func (nc *NotificationConfig[T]) WithNotifications(factory func(template T, actorAccountRef primitive.ObjectID, typ model.NotificationAction) notifications.Envelope) *NotificationConfig[T] { +func (nc *NotificationConfig[T]) WithNotifications(factory func(template T, actorAccountRef bson.ObjectID, typ model.NotificationAction) notifications.Envelope) *NotificationConfig[T] { nc.factory = factory // Build sending functions for each notification type. - nc.CreateNotification = func(template T, actorAccountRef primitive.ObjectID) error { + nc.CreateNotification = func(template T, actorAccountRef bson.ObjectID) error { return nc.producer.SendMessage(factory(template, actorAccountRef, model.NACreated)) } - nc.UpdateNotification = func(template T, actorAccountRef primitive.ObjectID) error { + nc.UpdateNotification = func(template T, actorAccountRef bson.ObjectID) error { return nc.producer.SendMessage(factory(template, actorAccountRef, model.NAUpdated)) } - nc.ArchiveNotification = func(template T, actorAccountRef primitive.ObjectID) error { + nc.ArchiveNotification = func(template T, actorAccountRef bson.ObjectID) error { return nc.producer.SendMessage(factory(template, actorAccountRef, model.NAArchived)) } nc.NeedArchiveNotification = true - nc.DeleteNotification = func(template T, actorAccountRef primitive.ObjectID) error { + nc.DeleteNotification = func(template T, actorAccountRef bson.ObjectID) error { return nc.producer.SendMessage(factory(template, actorAccountRef, model.NADeleted)) } nc.NeedDeleteNotification = true diff --git a/api/server/internal/server/aapitemplate/service.go b/api/server/internal/server/aapitemplate/service.go index aa8b569c..a9e32ae6 100644 --- a/api/server/internal/server/aapitemplate/service.go +++ b/api/server/internal/server/aapitemplate/service.go @@ -11,7 +11,7 @@ import ( eapi "github.com/tech/sendico/server/interface/api" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -67,7 +67,7 @@ func (a *AccountAPI[T]) Build() *AccountAPI[T] { return a } -func (a *AccountAPI[T]) WithNotifications(factory func(template *T, actorAccountRef primitive.ObjectID, t model.NotificationAction) notifications.Envelope) *AccountAPI[T] { +func (a *AccountAPI[T]) WithNotifications(factory func(template *T, actorAccountRef bson.ObjectID, t model.NotificationAction) notifications.Envelope) *AccountAPI[T] { a.nconfig.WithNotifications(factory) a.Logger.Info("Notificatons handler installed") return a diff --git a/api/server/internal/server/accountapiimp/delete.go b/api/server/internal/server/accountapiimp/delete.go index 5ab2a615..29b0986a 100644 --- a/api/server/internal/server/accountapiimp/delete.go +++ b/api/server/internal/server/accountapiimp/delete.go @@ -10,7 +10,7 @@ import ( "github.com/tech/sendico/pkg/mservice" "github.com/tech/sendico/pkg/mutil/mzap" "github.com/tech/sendico/server/interface/api/sresponse" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -97,7 +97,7 @@ func (a *AccountAPI) deleteAll(r *http.Request, account *model.Account, token *s } // Check if user has permission to delete the organization - canDelete, err := a.enf.Enforce(ctx, orgPolicy.ID, account.ID, orgRef, primitive.NilObjectID, model.ActionDelete) + canDelete, err := a.enf.Enforce(ctx, orgPolicy.ID, account.ID, orgRef, bson.NilObjectID, model.ActionDelete) if err != nil { a.logger.Error("Failed to check delete permission", zap.Error(err), mzap.StorableRef(account)) return response.Auto(a.logger, a.Name(), err) @@ -118,6 +118,6 @@ func (a *AccountAPI) deleteAll(r *http.Request, account *model.Account, token *s } // Helper method to get current organization reference from request context -func (a *AccountAPI) getCurrentOrganizationRef(r *http.Request) (primitive.ObjectID, error) { +func (a *AccountAPI) getCurrentOrganizationRef(r *http.Request) (bson.ObjectID, error) { return a.oph.GetRef(r) } diff --git a/api/server/internal/server/accountapiimp/employees.go b/api/server/internal/server/accountapiimp/employees.go index 66b138b1..6006048f 100644 --- a/api/server/internal/server/accountapiimp/employees.go +++ b/api/server/internal/server/accountapiimp/employees.go @@ -7,7 +7,7 @@ import ( "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" "github.com/tech/sendico/server/interface/api/sresponse" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -18,7 +18,7 @@ func (a *AccountAPI) getEmployees(r *http.Request, account *model.Account, token return response.BadReference(a.logger, a.Name(), a.oph.Name(), a.oph.GetID(r), err) } ctx := r.Context() - res, err := a.enf.Enforce(ctx, a.accountsPermissionRef, account.ID, orgRef, primitive.NilObjectID, model.ActionRead) + res, err := a.enf.Enforce(ctx, a.accountsPermissionRef, account.ID, orgRef, bson.NilObjectID, model.ActionRead) if err != nil { a.logger.Warn("Failed to check accounts access permissions", zap.Error(err), mzap.ObjRef("organization_ref", orgRef), mzap.StorableRef(account)) return response.Auto(a.logger, a.Name(), err) diff --git a/api/server/internal/server/accountapiimp/password_test.go b/api/server/internal/server/accountapiimp/password_test.go index ae1f8064..130752c5 100644 --- a/api/server/internal/server/accountapiimp/password_test.go +++ b/api/server/internal/server/accountapiimp/password_test.go @@ -3,9 +3,9 @@ package accountapiimp import ( "testing" - "github.com/tech/sendico/pkg/model" "github.com/stretchr/testify/assert" - "go.mongodb.org/mongo-driver/bson/primitive" + "github.com/tech/sendico/pkg/model" + "go.mongodb.org/mongo-driver/v2/bson" ) // TestPasswordResetTokenGeneration tests the token generation logic @@ -105,8 +105,8 @@ func TestPasswordResetFlowLogic(t *testing.T) { assert.NotEqual(t, originalToken, resetToken, "Reset token should be different from empty") // Step 3: User clicks reset link with token - userID := primitive.NewObjectID() - assert.NotEqual(t, primitive.NilObjectID, userID, "User ID should be valid") + userID := bson.NewObjectID() + assert.NotEqual(t, bson.NilObjectID, userID, "User ID should be valid") // Step 4: System validates token and updates password storedToken := resetToken diff --git a/api/server/internal/server/accountapiimp/service.go b/api/server/internal/server/accountapiimp/service.go index eb88dea2..62970d48 100644 --- a/api/server/internal/server/accountapiimp/service.go +++ b/api/server/internal/server/accountapiimp/service.go @@ -25,7 +25,7 @@ import ( eapi "github.com/tech/sendico/server/interface/api" "github.com/tech/sendico/server/interface/services/fileservice" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -44,7 +44,7 @@ type AccountAPI struct { oph mutil.ParamHelper aph mutil.ParamHelper tph mutil.ParamHelper - accountsPermissionRef primitive.ObjectID + accountsPermissionRef bson.ObjectID accService accountservice.AccountService chainGateway chainWalletClient chainAsset *chainv1.Asset diff --git a/api/server/internal/server/accountapiimp/signup.go b/api/server/internal/server/accountapiimp/signup.go index c885ce7a..6b35508c 100644 --- a/api/server/internal/server/accountapiimp/signup.go +++ b/api/server/internal/server/accountapiimp/signup.go @@ -20,11 +20,11 @@ import ( chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1" "github.com/tech/sendico/server/interface/api/srequest" "github.com/tech/sendico/server/interface/api/sresponse" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) -func (a *AccountAPI) createOrg(ctx context.Context, sr *srequest.Signup, permissionRef primitive.ObjectID) (*model.Organization, error) { +func (a *AccountAPI) createOrg(ctx context.Context, sr *srequest.Signup, permissionRef bson.ObjectID) (*model.Organization, error) { name := strings.TrimSpace(sr.Organization.Name) if name == "" { return nil, merrors.InvalidArgument("organization name must not be empty") @@ -35,7 +35,7 @@ func (a *AccountAPI) createOrg(ctx context.Context, sr *srequest.Signup, permiss // explicitly set org ref for permission related checks as unprotected template implementation // is not aware of permisssions and won't set org - orgRef := primitive.NewObjectID() + orgRef := bson.NewObjectID() org := &model.Organization{ OrganizationBase: model.OrganizationBase{ PermissionBound: model.PermissionBound{ @@ -54,7 +54,7 @@ func (a *AccountAPI) createOrg(ctx context.Context, sr *srequest.Signup, permiss }, TimeZone: sr.OrganizationTimeZone, }, - Members: []primitive.ObjectID{}, + Members: []bson.ObjectID{}, } if err := a.odb.Unprotected().Create(ctx, org); err != nil { a.logger.Warn("Failed to create organization", zap.Error(err)) @@ -174,7 +174,7 @@ func (a *AccountAPI) signupTransactionBody(ctx context.Context, sr *srequest.Sig return nil, nil } -func (a *AccountAPI) grantAllPermissions(ctx context.Context, organizationRef primitive.ObjectID, roleID primitive.ObjectID, newAccount *model.Account) error { +func (a *AccountAPI) grantAllPermissions(ctx context.Context, organizationRef bson.ObjectID, roleID bson.ObjectID, newAccount *model.Account) error { om := a.pmanager.Permission() policies, err := a.plcdb.All(ctx, organizationRef) if err != nil { diff --git a/api/server/internal/server/accountapiimp/signup_integration_test.go b/api/server/internal/server/accountapiimp/signup_integration_test.go index 835f2a0b..fbe3acbc 100644 --- a/api/server/internal/server/accountapiimp/signup_integration_test.go +++ b/api/server/internal/server/accountapiimp/signup_integration_test.go @@ -17,15 +17,10 @@ import ( "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mongodb" "github.com/testcontainers/testcontainers-go/wait" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" ) -// Helper function to create string pointers -func stringPtr(s string) *string { - return &s -} - // TestSignupRequestSerialization tests JSON marshaling/unmarshaling with real MongoDB func TestSignupRequestSerialization(t *testing.T) { if os.Getenv("RUN_DOCKER_TESTS") == "" { @@ -51,7 +46,7 @@ func TestSignupRequestSerialization(t *testing.T) { require.NoError(t, err, "failed to get MongoDB connection string") clientOptions := options.Client().ApplyURI(mongoURI) - client, err := mongo.Connect(ctx, clientOptions) + client, err := mongo.Connect(clientOptions) require.NoError(t, err, "failed to connect to MongoDB") defer func() { err := client.Disconnect(ctx) diff --git a/api/server/internal/server/accountapiimp/signup_test.go b/api/server/internal/server/accountapiimp/signup_test.go index 9a366c67..d2861b59 100644 --- a/api/server/internal/server/accountapiimp/signup_test.go +++ b/api/server/internal/server/accountapiimp/signup_test.go @@ -11,7 +11,7 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/server/interface/api/srequest" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -264,7 +264,7 @@ func (s *stubAccountDB) GetByToken(ctx context.Context, email string) (*model.Ac return nil, merrors.NotImplemented("stub") } -func (s *stubAccountDB) GetAccountsByRefs(ctx context.Context, orgRef primitive.ObjectID, refs []primitive.ObjectID) ([]model.Account, error) { +func (s *stubAccountDB) GetAccountsByRefs(ctx context.Context, orgRef bson.ObjectID, refs []bson.ObjectID) ([]model.Account, error) { return nil, merrors.NotImplemented("stub") } @@ -276,7 +276,7 @@ func (s *stubAccountDB) InsertMany(ctx context.Context, objects []*model.Account return merrors.NotImplemented("stub") } -func (s *stubAccountDB) Get(ctx context.Context, objectRef primitive.ObjectID, result *model.Account) error { +func (s *stubAccountDB) Get(ctx context.Context, objectRef bson.ObjectID, result *model.Account) error { return merrors.NotImplemented("stub") } @@ -284,11 +284,11 @@ func (s *stubAccountDB) Update(ctx context.Context, object *model.Account) error return merrors.NotImplemented("stub") } -func (s *stubAccountDB) Patch(ctx context.Context, objectRef primitive.ObjectID, patch builder.Patch) error { +func (s *stubAccountDB) Patch(ctx context.Context, objectRef bson.ObjectID, patch builder.Patch) error { return merrors.NotImplemented("stub") } -func (s *stubAccountDB) Delete(ctx context.Context, objectRef primitive.ObjectID) error { +func (s *stubAccountDB) Delete(ctx context.Context, objectRef bson.ObjectID) error { return merrors.NotImplemented("stub") } @@ -296,7 +296,7 @@ func (s *stubAccountDB) DeleteMany(ctx context.Context, query builder.Query) err return merrors.NotImplemented("stub") } -func (s *stubAccountDB) DeleteCascade(ctx context.Context, objectRef primitive.ObjectID) error { +func (s *stubAccountDB) DeleteCascade(ctx context.Context, objectRef bson.ObjectID) error { return merrors.NotImplemented("stub") } diff --git a/api/server/internal/server/confirmationimp/store.go b/api/server/internal/server/confirmationimp/store.go index fb2d4e79..9e513445 100644 --- a/api/server/internal/server/confirmationimp/store.go +++ b/api/server/internal/server/confirmationimp/store.go @@ -11,7 +11,7 @@ import ( "github.com/tech/sendico/pkg/db/confirmation" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) var ( @@ -39,7 +39,7 @@ func NewStore(db confirmation.DB) *ConfirmationStore { func (s *ConfirmationStore) Create( ctx context.Context, - accountRef primitive.ObjectID, + accountRef bson.ObjectID, destination string, target model.ConfirmationTarget, cfg Config, @@ -63,7 +63,7 @@ func (s *ConfirmationStore) Create( func (s *ConfirmationStore) Resend( ctx context.Context, - accountRef primitive.ObjectID, + accountRef bson.ObjectID, destination string, target model.ConfirmationTarget, cfg Config, @@ -103,7 +103,7 @@ func (s *ConfirmationStore) Resend( func (s *ConfirmationStore) Verify( ctx context.Context, - accountRef primitive.ObjectID, + accountRef bson.ObjectID, destination string, target model.ConfirmationTarget, code string, @@ -137,7 +137,7 @@ func (s *ConfirmationStore) Verify( } func (s *ConfirmationStore) buildRecord( - accountRef primitive.ObjectID, + accountRef bson.ObjectID, destination string, target model.ConfirmationTarget, cfg Config, diff --git a/api/server/internal/server/invitationimp/accept.go b/api/server/internal/server/invitationimp/accept.go index c4292886..58cc8d20 100644 --- a/api/server/internal/server/invitationimp/accept.go +++ b/api/server/internal/server/invitationimp/accept.go @@ -11,11 +11,11 @@ import ( "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" "github.com/tech/sendico/server/interface/api/srequest" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) -func (a *InvitationAPI) doAccept(ctx context.Context, invitationRef primitive.ObjectID, accData *model.AccountData) error { +func (a *InvitationAPI) doAccept(ctx context.Context, invitationRef bson.ObjectID, accData *model.AccountData) error { inv, err := a.getPendingInvitation(ctx, invitationRef) if err != nil { return err @@ -38,7 +38,7 @@ func (a *InvitationAPI) doAccept(ctx context.Context, invitationRef primitive.Ob return nil } -func (a *InvitationAPI) getPendingInvitation(ctx context.Context, invitationRef primitive.ObjectID) (*model.Invitation, error) { +func (a *InvitationAPI) getPendingInvitation(ctx context.Context, invitationRef bson.ObjectID) (*model.Invitation, error) { a.Logger.Debug("Fetching invitation", mzap.ObjRef("invitation_ref", invitationRef)) var inv model.Invitation if err := a.db.Unprotected().Get(ctx, invitationRef, &inv); err != nil { @@ -52,7 +52,7 @@ func (a *InvitationAPI) getPendingInvitation(ctx context.Context, invitationRef return &inv, nil } -func (a *InvitationAPI) getOrganization(ctx context.Context, orgRef primitive.ObjectID, email string) (*model.Organization, error) { +func (a *InvitationAPI) getOrganization(ctx context.Context, orgRef bson.ObjectID, email string) (*model.Organization, error) { a.Logger.Debug("Fetching organization", mzap.ObjRef("organization_ref", orgRef), zap.String("email", email)) var org model.Organization if err := a.odb.Unprotected().Get(ctx, orgRef, &org); err != nil { diff --git a/api/server/internal/server/invitationimp/notifications.go b/api/server/internal/server/invitationimp/notifications.go index 42ddb719..29cf5b23 100644 --- a/api/server/internal/server/invitationimp/notifications.go +++ b/api/server/internal/server/invitationimp/notifications.go @@ -6,12 +6,12 @@ import ( "github.com/tech/sendico/pkg/model" nm "github.com/tech/sendico/pkg/model/notification" "github.com/tech/sendico/pkg/mutil/mzap" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) func (a *InvitationAPI) notification( invitation *model.Invitation, - actorAccountRef primitive.ObjectID, + actorAccountRef bson.ObjectID, t nm.NotificationAction, ) messaging.Envelope { a.Logger.Debug("Sending notification of new invitation created", mzap.StorableRef(invitation)) diff --git a/api/server/internal/server/ledgerapiimp/balance.go b/api/server/internal/server/ledgerapiimp/balance.go index 660fc113..880981e7 100644 --- a/api/server/internal/server/ledgerapiimp/balance.go +++ b/api/server/internal/server/ledgerapiimp/balance.go @@ -11,7 +11,7 @@ import ( ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -28,7 +28,7 @@ func (a *LedgerAPI) getBalance(r *http.Request, account *model.Account, token *s } ctx := r.Context() - res, err := a.enf.Enforce(ctx, a.balancePerm, account.ID, orgRef, primitive.NilObjectID, model.ActionRead) + res, err := a.enf.Enforce(ctx, a.balancePerm, account.ID, orgRef, bson.NilObjectID, model.ActionRead) if err != nil { a.logger.Warn("Failed to check ledger balance access permissions", zap.Error(err), mutil.PLog(a.oph, r), zap.String("ledger_account_ref", accountRef)) return response.Auto(a.logger, a.Name(), err) diff --git a/api/server/internal/server/ledgerapiimp/create.go b/api/server/internal/server/ledgerapiimp/create.go index 986140e2..30f60c35 100644 --- a/api/server/internal/server/ledgerapiimp/create.go +++ b/api/server/internal/server/ledgerapiimp/create.go @@ -15,7 +15,7 @@ import ( "github.com/tech/sendico/server/interface/api/srequest" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -27,7 +27,7 @@ func (a *LedgerAPI) createAccount(r *http.Request, account *model.Account, token } ctx := r.Context() - allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, primitive.NilObjectID, model.ActionCreate) + allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, bson.NilObjectID, model.ActionCreate) if err != nil { a.logger.Warn("Failed to check ledger accounts access permissions", zap.Error(err), mutil.PLog(a.oph, r)) return response.Auto(a.logger, a.Name(), err) diff --git a/api/server/internal/server/ledgerapiimp/list.go b/api/server/internal/server/ledgerapiimp/list.go index 27488139..708ccee4 100644 --- a/api/server/internal/server/ledgerapiimp/list.go +++ b/api/server/internal/server/ledgerapiimp/list.go @@ -11,7 +11,7 @@ import ( ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "google.golang.org/protobuf/types/known/wrapperspb" ) @@ -24,7 +24,7 @@ func (a *LedgerAPI) listAccounts(r *http.Request, account *model.Account, token } ctx := r.Context() - hasReadPermission, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, primitive.NilObjectID, model.ActionRead) + hasReadPermission, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, bson.NilObjectID, model.ActionRead) if err != nil { a.logger.Warn("Failed to check ledger accounts access permissions", zap.Error(err), mutil.PLog(a.oph, r)) return response.Auto(a.logger, a.Name(), err) diff --git a/api/server/internal/server/ledgerapiimp/service.go b/api/server/internal/server/ledgerapiimp/service.go index 4114c04e..74c3feea 100644 --- a/api/server/internal/server/ledgerapiimp/service.go +++ b/api/server/internal/server/ledgerapiimp/service.go @@ -16,7 +16,7 @@ import ( ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" eapi "github.com/tech/sendico/server/interface/api" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -33,8 +33,8 @@ type LedgerAPI struct { enf auth.Enforcer oph mutil.ParamHelper aph mutil.ParamHelper - permissionRef primitive.ObjectID - balancePerm primitive.ObjectID + permissionRef bson.ObjectID + balancePerm bson.ObjectID } func (a *LedgerAPI) Name() mservice.Type { return mservice.LedgerAccounts } diff --git a/api/server/internal/server/papitemplate/db.go b/api/server/internal/server/papitemplate/db.go index 118663ba..19cff0bc 100644 --- a/api/server/internal/server/papitemplate/db.go +++ b/api/server/internal/server/papitemplate/db.go @@ -5,19 +5,19 @@ import ( "github.com/tech/sendico/pkg/db/repository/builder" "github.com/tech/sendico/pkg/model" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type ProtectedDB[T any] interface { - Create(ctx context.Context, accountRef, organizationRef primitive.ObjectID, object *T) error - Get(ctx context.Context, accountRef, objectRef primitive.ObjectID, result *T) error - Update(ctx context.Context, accountRef primitive.ObjectID, object *T) error - Delete(ctx context.Context, accountRef, objectRef primitive.ObjectID) error - DeleteCascadeAuth(ctx context.Context, accountRef, objectRef primitive.ObjectID) error - SetArchived(ctx context.Context, accountRef, organizationRef, objectRef primitive.ObjectID, isArchived, cascade bool) error - List(ctx context.Context, accountRef, organizationRef, parentRef primitive.ObjectID, cursor *model.ViewCursor) ([]T, error) + Create(ctx context.Context, accountRef, organizationRef bson.ObjectID, object *T) error + Get(ctx context.Context, accountRef, objectRef bson.ObjectID, result *T) error + Update(ctx context.Context, accountRef bson.ObjectID, object *T) error + Delete(ctx context.Context, accountRef, objectRef bson.ObjectID) error + DeleteCascadeAuth(ctx context.Context, accountRef, objectRef bson.ObjectID) error + SetArchived(ctx context.Context, accountRef, organizationRef, objectRef bson.ObjectID, isArchived, cascade bool) error + List(ctx context.Context, accountRef, organizationRef, parentRef bson.ObjectID, cursor *model.ViewCursor) ([]T, error) } type ReorderDB interface { - Reorder(ctx context.Context, accountRef, objectRef primitive.ObjectID, newIndex int, filter builder.Query) error + Reorder(ctx context.Context, accountRef, objectRef bson.ObjectID, newIndex int, filter builder.Query) error } diff --git a/api/server/internal/server/papitemplate/delete.go b/api/server/internal/server/papitemplate/delete.go index 6616d9e0..91240d9a 100644 --- a/api/server/internal/server/papitemplate/delete.go +++ b/api/server/internal/server/papitemplate/delete.go @@ -9,11 +9,11 @@ import ( "github.com/tech/sendico/pkg/mutil/mzap" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) -func (a *ProtectedAPI[T]) deleteImp(ctx context.Context, account *model.Account, objectRef primitive.ObjectID, cascade *bool) error { +func (a *ProtectedAPI[T]) deleteImp(ctx context.Context, account *model.Account, objectRef bson.ObjectID, cascade *bool) error { var err error if (cascade != nil) && (*cascade) { _, err = a.a.DBFactory().TransactionFactory().CreateTransaction().Execute(ctx, func(ctx context.Context) (any, error) { diff --git a/api/server/internal/server/papitemplate/nconfig.go b/api/server/internal/server/papitemplate/nconfig.go index a6949f52..7a6ea1d0 100644 --- a/api/server/internal/server/papitemplate/nconfig.go +++ b/api/server/internal/server/papitemplate/nconfig.go @@ -4,14 +4,14 @@ import ( "github.com/tech/sendico/pkg/messaging" notifications "github.com/tech/sendico/pkg/messaging/envelope" model "github.com/tech/sendico/pkg/model/notification" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) // NotificationHandler is a function that processes an object of type T and returns an error. -type NotificationHandler[T any] func(template T, actorAccountRef primitive.ObjectID) error +type NotificationHandler[T any] func(template T, actorAccountRef bson.ObjectID) error // sinkNotification is the default no-op strategy. -func sinkNotification[T any](_ T, _ primitive.ObjectID) error { +func sinkNotification[T any](_ T, _ bson.ObjectID) error { return nil } @@ -19,7 +19,7 @@ func sinkNotification[T any](_ T, _ primitive.ObjectID) error { type NotificationConfig[T any] struct { producer messaging.Producer // The factory now receives a NotificationAction so it knows which event is being processed. - factory func(template T, actorAccountRef primitive.ObjectID, t model.NotificationAction) notifications.Envelope + factory func(template T, actorAccountRef bson.ObjectID, t model.NotificationAction) notifications.Envelope CreateNotification NotificationHandler[T] UpdateNotification NotificationHandler[T] NeedArchiveNotification bool @@ -43,20 +43,20 @@ func NewNotificationConfig[T any](producer messaging.Producer) *NotificationConf } // WithNotifications sets the notification factory and switches all endpoints to the sending strategy. -func (nc *NotificationConfig[T]) WithNotifications(factory func(template T, actorAccountRef primitive.ObjectID, typ model.NotificationAction) notifications.Envelope) *NotificationConfig[T] { +func (nc *NotificationConfig[T]) WithNotifications(factory func(template T, actorAccountRef bson.ObjectID, typ model.NotificationAction) notifications.Envelope) *NotificationConfig[T] { nc.factory = factory // Build sending functions for each notification type. - nc.CreateNotification = func(template T, actorAccountRef primitive.ObjectID) error { + nc.CreateNotification = func(template T, actorAccountRef bson.ObjectID) error { return nc.producer.SendMessage(factory(template, actorAccountRef, model.NACreated)) } - nc.UpdateNotification = func(template T, actorAccountRef primitive.ObjectID) error { + nc.UpdateNotification = func(template T, actorAccountRef bson.ObjectID) error { return nc.producer.SendMessage(factory(template, actorAccountRef, model.NAUpdated)) } - nc.ArchiveNotification = func(template T, actorAccountRef primitive.ObjectID) error { + nc.ArchiveNotification = func(template T, actorAccountRef bson.ObjectID) error { return nc.producer.SendMessage(factory(template, actorAccountRef, model.NAArchived)) } nc.NeedArchiveNotification = true - nc.DeleteNotification = func(template T, actorAccountRef primitive.ObjectID) error { + nc.DeleteNotification = func(template T, actorAccountRef bson.ObjectID) error { return nc.producer.SendMessage(factory(template, actorAccountRef, model.NADeleted)) } nc.NeedDeleteNotification = true diff --git a/api/server/internal/server/papitemplate/service.go b/api/server/internal/server/papitemplate/service.go index 1f85c132..11e9315e 100644 --- a/api/server/internal/server/papitemplate/service.go +++ b/api/server/internal/server/papitemplate/service.go @@ -11,7 +11,7 @@ import ( eapi "github.com/tech/sendico/server/interface/api" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -82,7 +82,7 @@ func (a *ProtectedAPI[T]) Build() *ProtectedAPI[T] { return a } -func (a *ProtectedAPI[T]) WithNotifications(factory func(template *T, actorAccountRef primitive.ObjectID, t model.NotificationAction) notifications.Envelope) *ProtectedAPI[T] { +func (a *ProtectedAPI[T]) WithNotifications(factory func(template *T, actorAccountRef bson.ObjectID, t model.NotificationAction) notifications.Envelope) *ProtectedAPI[T] { a.nconfig.WithNotifications(factory) a.Logger.Info("Notificatons handler installed") return a diff --git a/api/server/internal/server/papitemplate/tconfig.go b/api/server/internal/server/papitemplate/tconfig.go index ae711af9..577f713b 100644 --- a/api/server/internal/server/papitemplate/tconfig.go +++ b/api/server/internal/server/papitemplate/tconfig.go @@ -6,7 +6,7 @@ import ( "net/http" "github.com/tech/sendico/server/interface/api/srequest" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" ) type ( @@ -17,12 +17,12 @@ type ( // TaggableDB interface defines the required methods for tag operations type TaggableDB interface { - AddTag(ctx context.Context, accountRef, objectRef, tagRef primitive.ObjectID) error - AddTags(ctx context.Context, accountRef, objectRef primitive.ObjectID, tagRefs []primitive.ObjectID) error - RemoveTag(ctx context.Context, accountRef, objectRef, tagRef primitive.ObjectID) error - RemoveAllTags(ctx context.Context, accountRef, objectRef primitive.ObjectID) error - SetTags(ctx context.Context, accountRef, objectRef primitive.ObjectID, tagRefs []primitive.ObjectID) error - GetTags(ctx context.Context, accountRef, objectRef primitive.ObjectID) ([]primitive.ObjectID, error) + AddTag(ctx context.Context, accountRef, objectRef, tagRef bson.ObjectID) error + AddTags(ctx context.Context, accountRef, objectRef bson.ObjectID, tagRefs []bson.ObjectID) error + RemoveTag(ctx context.Context, accountRef, objectRef, tagRef bson.ObjectID) error + RemoveAllTags(ctx context.Context, accountRef, objectRef bson.ObjectID) error + SetTags(ctx context.Context, accountRef, objectRef bson.ObjectID, tagRefs []bson.ObjectID) error + GetTags(ctx context.Context, accountRef, objectRef bson.ObjectID) ([]bson.ObjectID, error) } type TaggableConfig struct { diff --git a/api/server/internal/server/paymentapiimp/discovery.go b/api/server/internal/server/paymentapiimp/discovery.go index d58c7175..998f5390 100644 --- a/api/server/internal/server/paymentapiimp/discovery.go +++ b/api/server/internal/server/paymentapiimp/discovery.go @@ -8,12 +8,12 @@ import ( "github.com/tech/sendico/pkg/api/http/response" "github.com/tech/sendico/pkg/discovery" - me "github.com/tech/sendico/pkg/messaging/envelope" "github.com/tech/sendico/pkg/merrors" + me "github.com/tech/sendico/pkg/messaging/envelope" "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -31,7 +31,7 @@ func (a *PaymentAPI) listDiscoveryRegistry(r *http.Request, account *model.Accou } ctx := r.Context() - allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, primitive.NilObjectID, model.ActionRead) + allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, bson.NilObjectID, model.ActionRead) if err != nil { a.logger.Warn("Failed to check payments access permissions", zap.Error(err), mutil.PLog(a.oph, r)) return response.Auto(a.logger, a.Name(), err) @@ -65,7 +65,7 @@ func (a *PaymentAPI) getDiscoveryRefresh(r *http.Request, account *model.Account } ctx := r.Context() - allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, primitive.NilObjectID, model.ActionRead) + allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, bson.NilObjectID, model.ActionRead) if err != nil { a.logger.Warn("Failed to check payments access permissions", zap.Error(err), mutil.PLog(a.oph, r)) return response.Auto(a.logger, a.Name(), err) diff --git a/api/server/internal/server/paymentapiimp/list.go b/api/server/internal/server/paymentapiimp/list.go index a6cb598d..15f2fba0 100644 --- a/api/server/internal/server/paymentapiimp/list.go +++ b/api/server/internal/server/paymentapiimp/list.go @@ -13,7 +13,7 @@ import ( orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -27,7 +27,7 @@ func (a *PaymentAPI) listPayments(r *http.Request, account *model.Account, token } ctx := r.Context() - allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, primitive.NilObjectID, model.ActionRead) + allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, bson.NilObjectID, model.ActionRead) if err != nil { a.logger.Warn("Failed to check payments access permissions", zap.Error(err), mutil.PLog(a.oph, r)) return response.Auto(a.logger, a.Name(), err) diff --git a/api/server/internal/server/paymentapiimp/pay.go b/api/server/internal/server/paymentapiimp/pay.go index cb032f01..71fa2b96 100644 --- a/api/server/internal/server/paymentapiimp/pay.go +++ b/api/server/internal/server/paymentapiimp/pay.go @@ -13,7 +13,7 @@ import ( "github.com/tech/sendico/server/interface/api/srequest" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -26,7 +26,7 @@ func (a *PaymentAPI) initiatePayment(r *http.Request, account *model.Account, to } ctx := r.Context() - allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, primitive.NilObjectID, model.ActionCreate) + allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, bson.NilObjectID, model.ActionCreate) if err != nil { a.logger.Warn("Failed to check payments access permissions", zap.Error(err), mutil.PLog(a.oph, r)) return response.Auto(a.logger, a.Name(), err) diff --git a/api/server/internal/server/paymentapiimp/paybatch.go b/api/server/internal/server/paymentapiimp/paybatch.go index 7afb16e2..ac1f5962 100644 --- a/api/server/internal/server/paymentapiimp/paybatch.go +++ b/api/server/internal/server/paymentapiimp/paybatch.go @@ -12,7 +12,7 @@ import ( "github.com/tech/sendico/server/interface/api/srequest" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -24,7 +24,7 @@ func (a *PaymentAPI) initiatePaymentsByQuote(r *http.Request, account *model.Acc } ctx := r.Context() - allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, primitive.NilObjectID, model.ActionCreate) + allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, bson.NilObjectID, model.ActionCreate) if err != nil { a.logger.Warn("Failed to check payments access permissions", zap.Error(err), mutil.PLog(a.oph, r)) return response.Auto(a.logger, a.Name(), err) diff --git a/api/server/internal/server/paymentapiimp/quote.go b/api/server/internal/server/paymentapiimp/quote.go index b9a7a0af..6090da4d 100644 --- a/api/server/internal/server/paymentapiimp/quote.go +++ b/api/server/internal/server/paymentapiimp/quote.go @@ -12,7 +12,7 @@ import ( "github.com/tech/sendico/server/interface/api/srequest" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -24,7 +24,7 @@ func (a *PaymentAPI) quotePayment(r *http.Request, account *model.Account, token } ctx := r.Context() - allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, primitive.NilObjectID, model.ActionCreate) + allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, bson.NilObjectID, model.ActionCreate) if err != nil { a.logger.Warn("Failed to check payments access permissions", zap.Error(err), mutil.PLog(a.oph, r)) return response.Auto(a.logger, a.Name(), err) @@ -76,7 +76,7 @@ func (a *PaymentAPI) quotePayments(r *http.Request, account *model.Account, toke } ctx := r.Context() - allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, primitive.NilObjectID, model.ActionCreate) + allowed, err := a.enf.Enforce(ctx, a.permissionRef, account.ID, orgRef, bson.NilObjectID, model.ActionCreate) if err != nil { a.logger.Warn("Failed to check payments access permissions", zap.Error(err), mutil.PLog(a.oph, r)) return response.Auto(a.logger, a.Name(), err) diff --git a/api/server/internal/server/paymentapiimp/service.go b/api/server/internal/server/paymentapiimp/service.go index fe87ef74..cafbbdd1 100644 --- a/api/server/internal/server/paymentapiimp/service.go +++ b/api/server/internal/server/paymentapiimp/service.go @@ -20,7 +20,7 @@ import ( orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1" eapi "github.com/tech/sendico/server/interface/api" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -43,7 +43,7 @@ type PaymentAPI struct { refreshMu sync.RWMutex refreshEvent *discovery.RefreshEvent - permissionRef primitive.ObjectID + permissionRef bson.ObjectID } func (a *PaymentAPI) Name() mservice.Type { return mservice.Payments } diff --git a/api/server/internal/server/permissionsimp/changepolicies.go b/api/server/internal/server/permissionsimp/changepolicies.go index 24c30a7d..b240a1da 100644 --- a/api/server/internal/server/permissionsimp/changepolicies.go +++ b/api/server/internal/server/permissionsimp/changepolicies.go @@ -12,7 +12,7 @@ import ( "github.com/tech/sendico/pkg/mservice" "github.com/tech/sendico/server/interface/api/srequest" "github.com/tech/sendico/server/interface/api/sresponse" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -53,14 +53,14 @@ func (a *PermissionsAPI) changePoliciesImp( handle := func(items *[]model.RolePolicy, action model.Action, opName string, apply func(context.Context, *model.RolePolicy) error) error { for _, it := range *items { // 1) permission check - ok, err := a.enforcer.Enforce(ctx, a.policiesPermissionRef, account.ID, it.OrganizationRef, primitive.NilObjectID, action) + ok, err := a.enforcer.Enforce(ctx, a.policiesPermissionRef, account.ID, it.OrganizationRef, bson.NilObjectID, action) if err != nil { a.logger.Warn(fmt.Sprintf("failed to enforce permission while %s policy", opName), zap.Error(err), zap.Any(opName, &it)) return err } if !ok { a.logger.Debug(fmt.Sprintf("policy %s denied", opName)) - return merrors.AccessDenied(mservice.Policies, string(action), primitive.NilObjectID) + return merrors.AccessDenied(mservice.Policies, string(action), bson.NilObjectID) } // 2) perform the add/remove diff --git a/api/server/internal/server/permissionsimp/changerole.go b/api/server/internal/server/permissionsimp/changerole.go index 5d33f3ea..9eac4d6c 100644 --- a/api/server/internal/server/permissionsimp/changerole.go +++ b/api/server/internal/server/permissionsimp/changerole.go @@ -12,7 +12,7 @@ import ( "github.com/tech/sendico/server/interface/api/srequest" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -52,7 +52,7 @@ func (a *PermissionsAPI) changeRole(r *http.Request, account *model.Account, _ * return a.changeRoleImp(ctx, &req, orgRef, account) } -func (a *PermissionsAPI) changeRoleImp(ctx context.Context, req *srequest.ChangeRole, organizationRef primitive.ObjectID, account *model.Account) http.HandlerFunc { +func (a *PermissionsAPI) changeRoleImp(ctx context.Context, req *srequest.ChangeRole, organizationRef bson.ObjectID, account *model.Account) http.HandlerFunc { roles, err := a.enforcer.GetRoles(ctx, req.AccountRef, organizationRef) // TODO: add check that role revocation won't leave venue without the owner if err != nil { diff --git a/api/server/internal/server/permissionsimp/get_all.go b/api/server/internal/server/permissionsimp/get_all.go index f7e388ed..2ee1cc23 100644 --- a/api/server/internal/server/permissionsimp/get_all.go +++ b/api/server/internal/server/permissionsimp/get_all.go @@ -9,14 +9,14 @@ import ( "github.com/tech/sendico/pkg/mutil/mzap" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) func (a *PermissionsAPI) getRolePolicies(ctx context.Context, roles []model.RoleDescription) ([]model.RolePolicy, error) { policies := make([]model.RolePolicy, 0) - uniqueRefs := make(map[primitive.ObjectID]struct{}) + uniqueRefs := make(map[bson.ObjectID]struct{}) for _, role := range roles { uniqueRefs[*role.GetID()] = struct{}{} } @@ -40,7 +40,7 @@ func (a *PermissionsAPI) getAll(r *http.Request, account *model.Account, accessT } ctx := r.Context() - res, err := a.enforcer.Enforce(ctx, a.rolesPermissionRef, account.ID, orgRef, primitive.NilObjectID, model.ActionRead) + res, err := a.enforcer.Enforce(ctx, a.rolesPermissionRef, account.ID, orgRef, bson.NilObjectID, model.ActionRead) if err != nil { a.logger.Debug("Error occurred", zap.Error(err)) response.Auto(a.logger, a.Name(), err) diff --git a/api/server/internal/server/permissionsimp/permissions.go b/api/server/internal/server/permissionsimp/permissions.go index 88ee50dc..ad92767d 100644 --- a/api/server/internal/server/permissionsimp/permissions.go +++ b/api/server/internal/server/permissionsimp/permissions.go @@ -8,11 +8,11 @@ import ( "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" "github.com/tech/sendico/server/interface/api/sresponse" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) -func (a *PermissionsAPI) permissions(ctx context.Context, organizationRef primitive.ObjectID, roles []model.Role, permissions []model.Permission, accessToken *sresponse.TokenData) http.HandlerFunc { +func (a *PermissionsAPI) permissions(ctx context.Context, organizationRef bson.ObjectID, roles []model.Role, permissions []model.Permission, accessToken *sresponse.TokenData) http.HandlerFunc { roleDescs, err := a.rdb.List(ctx, organizationRef, nil) if err != nil { a.logger.Warn("Failed to fetch organization roles", zap.Error(err), mzap.ObjRef("organization_ref", organizationRef)) diff --git a/api/server/internal/server/permissionsimp/service.go b/api/server/internal/server/permissionsimp/service.go index 6de6c739..9fdafb60 100644 --- a/api/server/internal/server/permissionsimp/service.go +++ b/api/server/internal/server/permissionsimp/service.go @@ -14,7 +14,7 @@ import ( "github.com/tech/sendico/pkg/mservice" eapi "github.com/tech/sendico/server/interface/api" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -25,8 +25,8 @@ type PermissionsAPI struct { rdb role.DB enforcer auth.Enforcer manager auth.Manager - rolesPermissionRef primitive.ObjectID - policiesPermissionRef primitive.ObjectID + rolesPermissionRef bson.ObjectID + policiesPermissionRef bson.ObjectID Rph mutil.ParamHelper tf transaction.Factory auth auth.Manager diff --git a/api/server/internal/server/walletapiimp/balance.go b/api/server/internal/server/walletapiimp/balance.go index 96f62e27..cb02265b 100644 --- a/api/server/internal/server/walletapiimp/balance.go +++ b/api/server/internal/server/walletapiimp/balance.go @@ -15,7 +15,7 @@ import ( connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -34,7 +34,7 @@ func (a *WalletAPI) getWalletBalance(r *http.Request, account *model.Account, to } ctx := r.Context() - res, err := a.enf.Enforce(ctx, a.balancesPermissionRef, account.ID, orgRef, primitive.NilObjectID, model.ActionRead) + res, err := a.enf.Enforce(ctx, a.balancesPermissionRef, account.ID, orgRef, bson.NilObjectID, model.ActionRead) if err != nil { a.logger.Warn("Failed to check wallet balance permissions", zap.Error(err), mutil.PLog(a.oph, r), zap.String("wallet_ref", walletRef)) return response.Auto(a.logger, a.Name(), err) diff --git a/api/server/internal/server/walletapiimp/create.go b/api/server/internal/server/walletapiimp/create.go index 0c5615cb..3e7e5ab9 100644 --- a/api/server/internal/server/walletapiimp/create.go +++ b/api/server/internal/server/walletapiimp/create.go @@ -18,7 +18,7 @@ import ( "github.com/tech/sendico/server/interface/api/srequest" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -40,7 +40,7 @@ func (a *WalletAPI) create(r *http.Request, account *model.Account, token *sresp } ctx := r.Context() - res, err := a.enf.Enforce(ctx, a.walletsPermissionRef, account.ID, orgRef, primitive.NilObjectID, model.ActionCreate) + res, err := a.enf.Enforce(ctx, a.walletsPermissionRef, account.ID, orgRef, bson.NilObjectID, model.ActionCreate) if err != nil { a.logger.Warn("Failed to check chain wallet access permissions", zap.Error(err), mutil.PLog(a.oph, r), mzap.StorableRef(account)) return response.Auto(a.logger, a.Name(), err) diff --git a/api/server/internal/server/walletapiimp/list.go b/api/server/internal/server/walletapiimp/list.go index 4c0373fe..0923d31d 100644 --- a/api/server/internal/server/walletapiimp/list.go +++ b/api/server/internal/server/walletapiimp/list.go @@ -16,7 +16,7 @@ import ( connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -32,7 +32,7 @@ func (a *WalletAPI) listWallets(r *http.Request, account *model.Account, token * } ctx := r.Context() - hasReadPermission, err := a.enf.Enforce(ctx, a.walletsPermissionRef, account.ID, orgRef, primitive.NilObjectID, model.ActionRead) + hasReadPermission, err := a.enf.Enforce(ctx, a.walletsPermissionRef, account.ID, orgRef, bson.NilObjectID, model.ActionRead) if err != nil { a.logger.Warn("Failed to check chain wallet access permissions", zap.Error(err), mutil.PLog(a.oph, r)) return response.Auto(a.logger, a.Name(), err) diff --git a/api/server/internal/server/walletapiimp/service.go b/api/server/internal/server/walletapiimp/service.go index 08f9d4c2..451a2af7 100644 --- a/api/server/internal/server/walletapiimp/service.go +++ b/api/server/internal/server/walletapiimp/service.go @@ -14,7 +14,7 @@ import ( "github.com/tech/sendico/pkg/mservice" eapi "github.com/tech/sendico/server/interface/api" mutil "github.com/tech/sendico/server/internal/mutil/param" - "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/v2/bson" "go.uber.org/zap" ) @@ -31,8 +31,8 @@ type WalletAPI struct { enf auth.Enforcer oph mutil.ParamHelper wph mutil.ParamHelper - walletsPermissionRef primitive.ObjectID - balancesPermissionRef primitive.ObjectID + walletsPermissionRef bson.ObjectID + balancesPermissionRef bson.ObjectID assets chainassets.DB // Gateway connection settings diff --git a/api/server/tmp/build-errors.log b/api/server/tmp/build-errors.log index f50898d0..a2a130a4 100644 --- a/api/server/tmp/build-errors.log +++ b/api/server/tmp/build-errors.log @@ -1 +1 @@ -exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1 \ No newline at end of file +exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1 \ No newline at end of file diff --git a/ci/prod/.env.runtime b/ci/prod/.env.runtime index d8f536e7..cd002757 100644 --- a/ci/prod/.env.runtime +++ b/ci/prod/.env.runtime @@ -91,6 +91,11 @@ FEES_GRPC_PORT=50060 FEES_METRICS_PORT=9402 # Billing documents stack +DOCUMENTS_MONGO_HOST=sendico_db1 +DOCUMENTS_MONGO_PORT=27017 +DOCUMENTS_MONGO_DATABASE=billing_fees +DOCUMENTS_MONGO_AUTH_SOURCE=admin +DOCUMENTS_MONGO_REPLICA_SET=sendico-rs DOCUMENTS_DIR=billing_documents DOCUMENTS_COMPOSE_PROJECT=sendico-billing-documents DOCUMENTS_SERVICE_NAME=sendico_billing_documents diff --git a/ci/prod/compose/billing_documents.yml b/ci/prod/compose/billing_documents.yml index 9709a80e..b1062c02 100644 --- a/ci/prod/compose/billing_documents.yml +++ b/ci/prod/compose/billing_documents.yml @@ -18,6 +18,13 @@ services: image: ${REGISTRY_URL}/billing/documents:${APP_V} pull_policy: always environment: + DOCUMENTS_MONGO_HOST: ${DOCUMENTS_MONGO_HOST} + DOCUMENTS_MONGO_PORT: ${DOCUMENTS_MONGO_PORT} + DOCUMENTS_MONGO_DATABASE: ${DOCUMENTS_MONGO_DATABASE} + DOCUMENTS_MONGO_USER: ${DOCUMENTS_MONGO_USER} + DOCUMENTS_MONGO_PASSWORD: ${DOCUMENTS_MONGO_PASSWORD} + DOCUMENTS_MONGO_AUTH_SOURCE: ${DOCUMENTS_MONGO_AUTH_SOURCE} + DOCUMENTS_MONGO_REPLICA_SET: ${DOCUMENTS_MONGO_REPLICA_SET} DOCUMENTS_GRPC_PORT: ${DOCUMENTS_GRPC_PORT} DOCUMENTS_METRICS_PORT: ${DOCUMENTS_METRICS_PORT} NATS_URL: ${NATS_URL} diff --git a/ci/prod/scripts/deploy/billing_documents.sh b/ci/prod/scripts/deploy/billing_documents.sh index 8666c5b8..f9174e69 100755 --- a/ci/prod/scripts/deploy/billing_documents.sh +++ b/ci/prod/scripts/deploy/billing_documents.sh @@ -16,6 +16,13 @@ COMPOSE_FILE="billing_documents.yml" SERVICE_NAMES="${DOCUMENTS_SERVICE_NAME}" REQUIRED_SECRETS=( + DOCUMENTS_MONGO_HOST + DOCUMENTS_MONGO_PORT + DOCUMENTS_MONGO_DATABASE + DOCUMENTS_MONGO_USER + DOCUMENTS_MONGO_PASSWORD + DOCUMENTS_MONGO_AUTH_SOURCE + DOCUMENTS_MONGO_REPLICA_SET NATS_USER NATS_PASSWORD NATS_URL @@ -37,6 +44,13 @@ b64enc() { printf '%s' "$1" | base64 | tr -d '\n' } +DOCUMENTS_MONGO_HOST_B64="$(b64enc "${DOCUMENTS_MONGO_HOST}")" +DOCUMENTS_MONGO_PORT_B64="$(b64enc "${DOCUMENTS_MONGO_PORT}")" +DOCUMENTS_MONGO_DATABASE_B64="$(b64enc "${DOCUMENTS_MONGO_DATABASE}")" +DOCUMENTS_MONGO_USER_B64="$(b64enc "${DOCUMENTS_MONGO_USER}")" +DOCUMENTS_MONGO_PASSWORD_B64="$(b64enc "${DOCUMENTS_MONGO_PASSWORD}")" +DOCUMENTS_MONGO_AUTH_SOURCE_B64="$(b64enc "${DOCUMENTS_MONGO_AUTH_SOURCE}")" +DOCUMENTS_MONGO_REPLICA_SET_B64="$(b64enc "${DOCUMENTS_MONGO_REPLICA_SET}")" NATS_USER_B64="$(b64enc "${NATS_USER}")" NATS_PASSWORD_B64="$(b64enc "${NATS_PASSWORD}")" NATS_URL_B64="$(b64enc "${NATS_URL}")" @@ -68,6 +82,13 @@ ssh "${SSH_OPTS[@]}" "$REMOTE_TARGET" \ COMPOSE_FILE="$COMPOSE_FILE" \ COMPOSE_PROJECT="$DOCUMENTS_COMPOSE_PROJECT" \ SERVICES_LINE="$SERVICES_LINE" \ + DOCUMENTS_MONGO_HOST_B64="$DOCUMENTS_MONGO_HOST_B64" \ + DOCUMENTS_MONGO_PORT_B64="$DOCUMENTS_MONGO_PORT_B64" \ + DOCUMENTS_MONGO_DATABASE_B64="$DOCUMENTS_MONGO_DATABASE_B64" \ + DOCUMENTS_MONGO_USER_B64="$DOCUMENTS_MONGO_USER_B64" \ + DOCUMENTS_MONGO_PASSWORD_B64="$DOCUMENTS_MONGO_PASSWORD_B64" \ + DOCUMENTS_MONGO_AUTH_SOURCE_B64="$DOCUMENTS_MONGO_AUTH_SOURCE_B64" \ + DOCUMENTS_MONGO_REPLICA_SET_B64="$DOCUMENTS_MONGO_REPLICA_SET_B64" \ NATS_USER_B64="$NATS_USER_B64" \ NATS_PASSWORD_B64="$NATS_PASSWORD_B64" \ NATS_URL_B64="$NATS_URL_B64" \ @@ -112,10 +133,20 @@ decode_b64() { printf '%s' "$val" | base64 "${BASE64_DECODE_FLAG}" } +DOCUMENTS_MONGO_HOST="$(decode_b64 "$DOCUMENTS_MONGO_HOST_B64")" +DOCUMENTS_MONGO_PORT="$(decode_b64 "$DOCUMENTS_MONGO_PORT_B64")" +DOCUMENTS_MONGO_DATABASE="$(decode_b64 "$DOCUMENTS_MONGO_DATABASE_B64")" +DOCUMENTS_MONGO_USER="$(decode_b64 "$DOCUMENTS_MONGO_USER_B64")" +DOCUMENTS_MONGO_PASSWORD="$(decode_b64 "$DOCUMENTS_MONGO_PASSWORD_B64")" +DOCUMENTS_MONGO_AUTH_SOURCE="$(decode_b64 "$DOCUMENTS_MONGO_AUTH_SOURCE_B64")" +DOCUMENTS_MONGO_REPLICA_SET="$(decode_b64 "$DOCUMENTS_MONGO_REPLICA_SET_B64")" NATS_USER="$(decode_b64 "$NATS_USER_B64")" NATS_PASSWORD="$(decode_b64 "$NATS_PASSWORD_B64")" NATS_URL="$(decode_b64 "$NATS_URL_B64")" +export DOCUMENTS_MONGO_HOST DOCUMENTS_MONGO_PORT DOCUMENTS_MONGO_DATABASE +export DOCUMENTS_MONGO_USER DOCUMENTS_MONGO_PASSWORD +export DOCUMENTS_MONGO_AUTH_SOURCE DOCUMENTS_MONGO_REPLICA_SET export NATS_USER NATS_PASSWORD NATS_URL COMPOSE_PROJECT_NAME="$COMPOSE_PROJECT" export COMPOSE_PROJECT_NAME diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index ae4d2e26..b1d2000d 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -341,6 +341,13 @@ services: NATS_USER: ${NATS_USER} NATS_PASSWORD: ${NATS_PASSWORD} NATS_URL: nats://${NATS_USER}:${NATS_PASSWORD}@dev-nats:4222 + DOCUMENTS_MONGO_HOST: dev-mongo-1 + DOCUMENTS_MONGO_PORT: 27017 + DOCUMENTS_MONGO_DATABASE: payments_orchestrator + DOCUMENTS_MONGO_USER: ${MONGO_USER} + DOCUMENTS_MONGO_PASSWORD: ${MONGO_PASSWORD} + DOCUMENTS_MONGO_AUTH_SOURCE: admin + DOCUMENTS_MONGO_REPLICA_SET: dev-rs DOCUMENTS_GRPC_PORT: 50061 DOCUMENTS_METRICS_PORT: 9409 diff --git a/frontend/pweb/lib/pages/status/success.dart b/frontend/pweb/lib/pages/status/success.dart index acf3781d..9e7f7a39 100644 --- a/frontend/pweb/lib/pages/status/success.dart +++ b/frontend/pweb/lib/pages/status/success.dart @@ -36,8 +36,7 @@ class StatusPageSuccess extends StatelessWidget { style: Theme.of(context).textTheme.bodyMedium, ), const SizedBox(height: 20.0), - if (action != null) - action!, + ?action, ], ), ), diff --git a/frontend/pweb/lib/services/posthog.dart b/frontend/pweb/lib/services/posthog.dart index 15ceaf28..8c95bb9b 100644 --- a/frontend/pweb/lib/services/posthog.dart +++ b/frontend/pweb/lib/services/posthog.dart @@ -79,8 +79,8 @@ class PosthogService { 'pageOpened', properties: { 'page': page.name, - if (path != null) 'path': path, - if (uiSource != null) 'uiSource': uiSource, + 'path': ?path, + 'uiSource': ?uiSource, }, ); } diff --git a/frontend/pweb/pubspec.yaml b/frontend/pweb/pubspec.yaml index 1c75cfe8..e73c7f88 100644 --- a/frontend/pweb/pubspec.yaml +++ b/frontend/pweb/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 2.4.0+488 +version: 2.5.0+495 environment: sdk: ^3.8.1 diff --git a/version b/version index 9183195a..fad066f8 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.4.0 \ No newline at end of file +2.5.0 \ No newline at end of file