mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-06 12:19:37 -06:00
Merge branch 'master' into go-embed
This commit is contained in:
@@ -26,7 +26,7 @@ linters:
|
||||
- unused
|
||||
- varcheck
|
||||
- depguard
|
||||
- golint
|
||||
- revive
|
||||
- goimports
|
||||
- unconvert
|
||||
- scopelint
|
||||
|
||||
@@ -3,8 +3,8 @@ package proto
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/asim/go-micro/v3/client"
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
"go-micro.dev/v4/client"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
|
||||
// MockBundleService can be used to write tests against the bundle service.
|
||||
@@ -40,7 +40,7 @@ type MockBundleService struct {
|
||||
GetBundleFunc func(ctx context.Context, req *GetBundleRequest, opts ...client.CallOption) (*GetBundleResponse, error)
|
||||
SaveBundleFunc func(ctx context.Context, req *SaveBundleRequest, opts ...client.CallOption) (*SaveBundleResponse, error)
|
||||
AddSettingToBundleFunc func(ctx context.Context, req *AddSettingToBundleRequest, opts ...client.CallOption) (*AddSettingToBundleResponse, error)
|
||||
RemoveSettingFromBundleFunc func(ctx context.Context, req *RemoveSettingFromBundleRequest, opts ...client.CallOption) (*empty.Empty, error)
|
||||
RemoveSettingFromBundleFunc func(ctx context.Context, req *RemoveSettingFromBundleRequest, opts ...client.CallOption) (*emptypb.Empty, error)
|
||||
}
|
||||
|
||||
// ListBundles will panic if the function has been called, but not mocked
|
||||
@@ -76,7 +76,7 @@ func (m MockBundleService) AddSettingToBundle(ctx context.Context, req *AddSetti
|
||||
}
|
||||
|
||||
// RemoveSettingFromBundle will panic if the function has been called, but not mocked
|
||||
func (m MockBundleService) RemoveSettingFromBundle(ctx context.Context, req *RemoveSettingFromBundleRequest, opts ...client.CallOption) (*empty.Empty, error) {
|
||||
func (m MockBundleService) RemoveSettingFromBundle(ctx context.Context, req *RemoveSettingFromBundleRequest, opts ...client.CallOption) (*emptypb.Empty, error) {
|
||||
if m.RemoveSettingFromBundleFunc != nil {
|
||||
return m.RemoveSettingFromBundleFunc(ctx, req, opts...)
|
||||
}
|
||||
@@ -128,7 +128,7 @@ type MockRoleService struct {
|
||||
ListRolesFunc func(ctx context.Context, req *ListBundlesRequest, opts ...client.CallOption) (*ListBundlesResponse, error)
|
||||
ListRoleAssignmentsFunc func(ctx context.Context, req *ListRoleAssignmentsRequest, opts ...client.CallOption) (*ListRoleAssignmentsResponse, error)
|
||||
AssignRoleToUserFunc func(ctx context.Context, req *AssignRoleToUserRequest, opts ...client.CallOption) (*AssignRoleToUserResponse, error)
|
||||
RemoveRoleFromUserFunc func(ctx context.Context, req *RemoveRoleFromUserRequest, opts ...client.CallOption) (*empty.Empty, error)
|
||||
RemoveRoleFromUserFunc func(ctx context.Context, req *RemoveRoleFromUserRequest, opts ...client.CallOption) (*emptypb.Empty, error)
|
||||
}
|
||||
|
||||
// ListRoles will panic if the function has been called, but not mocked
|
||||
@@ -156,7 +156,7 @@ func (m MockRoleService) AssignRoleToUser(ctx context.Context, req *AssignRoleTo
|
||||
}
|
||||
|
||||
// RemoveRoleFromUser will panic if the function has been called, but not mocked
|
||||
func (m MockRoleService) RemoveRoleFromUser(ctx context.Context, req *RemoveRoleFromUserRequest, opts ...client.CallOption) (*empty.Empty, error) {
|
||||
func (m MockRoleService) RemoveRoleFromUser(ctx context.Context, req *RemoveRoleFromUserRequest, opts ...client.CallOption) (*emptypb.Empty, error) {
|
||||
if m.RemoveRoleFromUserFunc != nil {
|
||||
return m.RemoveRoleFromUserFunc(ctx, req, opts...)
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
package proto
|
||||
|
||||
import (
|
||||
empty "github.com/golang/protobuf/ptypes/empty"
|
||||
_ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options"
|
||||
_ "google.golang.org/genproto/googleapis/api/annotations"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
emptypb "google.golang.org/protobuf/types/known/emptypb"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
@@ -3285,7 +3285,7 @@ var file_settings_proto_goTypes = []interface{}{
|
||||
(*Value)(nil), // 42: com.owncloud.ocis.settings.v0.Value
|
||||
(*ListValue)(nil), // 43: com.owncloud.ocis.settings.v0.ListValue
|
||||
(*ListOptionValue)(nil), // 44: com.owncloud.ocis.settings.v0.ListOptionValue
|
||||
(*empty.Empty)(nil), // 45: google.protobuf.Empty
|
||||
(*emptypb.Empty)(nil), // 45: google.protobuf.Empty
|
||||
}
|
||||
var file_settings_proto_depIdxs = []int32{
|
||||
33, // 0: com.owncloud.ocis.settings.v0.SaveBundleRequest.bundle:type_name -> com.owncloud.ocis.settings.v0.Bundle
|
||||
|
||||
@@ -5,18 +5,18 @@ package proto
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
empty "github.com/golang/protobuf/ptypes/empty"
|
||||
_ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options"
|
||||
_ "google.golang.org/genproto/googleapis/api/annotations"
|
||||
proto "google.golang.org/protobuf/proto"
|
||||
emptypb "google.golang.org/protobuf/types/known/emptypb"
|
||||
math "math"
|
||||
)
|
||||
|
||||
import (
|
||||
context "context"
|
||||
api "github.com/asim/go-micro/v3/api"
|
||||
client "github.com/asim/go-micro/v3/client"
|
||||
server "github.com/asim/go-micro/v3/server"
|
||||
api "go-micro.dev/v4/api"
|
||||
client "go-micro.dev/v4/client"
|
||||
server "go-micro.dev/v4/server"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
@@ -79,7 +79,7 @@ type BundleService interface {
|
||||
GetBundle(ctx context.Context, in *GetBundleRequest, opts ...client.CallOption) (*GetBundleResponse, error)
|
||||
ListBundles(ctx context.Context, in *ListBundlesRequest, opts ...client.CallOption) (*ListBundlesResponse, error)
|
||||
AddSettingToBundle(ctx context.Context, in *AddSettingToBundleRequest, opts ...client.CallOption) (*AddSettingToBundleResponse, error)
|
||||
RemoveSettingFromBundle(ctx context.Context, in *RemoveSettingFromBundleRequest, opts ...client.CallOption) (*empty.Empty, error)
|
||||
RemoveSettingFromBundle(ctx context.Context, in *RemoveSettingFromBundleRequest, opts ...client.CallOption) (*emptypb.Empty, error)
|
||||
}
|
||||
|
||||
type bundleService struct {
|
||||
@@ -134,9 +134,9 @@ func (c *bundleService) AddSettingToBundle(ctx context.Context, in *AddSettingTo
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *bundleService) RemoveSettingFromBundle(ctx context.Context, in *RemoveSettingFromBundleRequest, opts ...client.CallOption) (*empty.Empty, error) {
|
||||
func (c *bundleService) RemoveSettingFromBundle(ctx context.Context, in *RemoveSettingFromBundleRequest, opts ...client.CallOption) (*emptypb.Empty, error) {
|
||||
req := c.c.NewRequest(c.name, "BundleService.RemoveSettingFromBundle", in)
|
||||
out := new(empty.Empty)
|
||||
out := new(emptypb.Empty)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -151,7 +151,7 @@ type BundleServiceHandler interface {
|
||||
GetBundle(context.Context, *GetBundleRequest, *GetBundleResponse) error
|
||||
ListBundles(context.Context, *ListBundlesRequest, *ListBundlesResponse) error
|
||||
AddSettingToBundle(context.Context, *AddSettingToBundleRequest, *AddSettingToBundleResponse) error
|
||||
RemoveSettingFromBundle(context.Context, *RemoveSettingFromBundleRequest, *empty.Empty) error
|
||||
RemoveSettingFromBundle(context.Context, *RemoveSettingFromBundleRequest, *emptypb.Empty) error
|
||||
}
|
||||
|
||||
func RegisterBundleServiceHandler(s server.Server, hdlr BundleServiceHandler, opts ...server.HandlerOption) error {
|
||||
@@ -160,7 +160,7 @@ func RegisterBundleServiceHandler(s server.Server, hdlr BundleServiceHandler, op
|
||||
GetBundle(ctx context.Context, in *GetBundleRequest, out *GetBundleResponse) error
|
||||
ListBundles(ctx context.Context, in *ListBundlesRequest, out *ListBundlesResponse) error
|
||||
AddSettingToBundle(ctx context.Context, in *AddSettingToBundleRequest, out *AddSettingToBundleResponse) error
|
||||
RemoveSettingFromBundle(ctx context.Context, in *RemoveSettingFromBundleRequest, out *empty.Empty) error
|
||||
RemoveSettingFromBundle(ctx context.Context, in *RemoveSettingFromBundleRequest, out *emptypb.Empty) error
|
||||
}
|
||||
type BundleService struct {
|
||||
bundleService
|
||||
@@ -224,7 +224,7 @@ func (h *bundleServiceHandler) AddSettingToBundle(ctx context.Context, in *AddSe
|
||||
return h.BundleServiceHandler.AddSettingToBundle(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *bundleServiceHandler) RemoveSettingFromBundle(ctx context.Context, in *RemoveSettingFromBundleRequest, out *empty.Empty) error {
|
||||
func (h *bundleServiceHandler) RemoveSettingFromBundle(ctx context.Context, in *RemoveSettingFromBundleRequest, out *emptypb.Empty) error {
|
||||
return h.BundleServiceHandler.RemoveSettingFromBundle(ctx, in, out)
|
||||
}
|
||||
|
||||
@@ -436,7 +436,7 @@ type RoleService interface {
|
||||
ListRoles(ctx context.Context, in *ListBundlesRequest, opts ...client.CallOption) (*ListBundlesResponse, error)
|
||||
ListRoleAssignments(ctx context.Context, in *ListRoleAssignmentsRequest, opts ...client.CallOption) (*ListRoleAssignmentsResponse, error)
|
||||
AssignRoleToUser(ctx context.Context, in *AssignRoleToUserRequest, opts ...client.CallOption) (*AssignRoleToUserResponse, error)
|
||||
RemoveRoleFromUser(ctx context.Context, in *RemoveRoleFromUserRequest, opts ...client.CallOption) (*empty.Empty, error)
|
||||
RemoveRoleFromUser(ctx context.Context, in *RemoveRoleFromUserRequest, opts ...client.CallOption) (*emptypb.Empty, error)
|
||||
}
|
||||
|
||||
type roleService struct {
|
||||
@@ -481,9 +481,9 @@ func (c *roleService) AssignRoleToUser(ctx context.Context, in *AssignRoleToUser
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *roleService) RemoveRoleFromUser(ctx context.Context, in *RemoveRoleFromUserRequest, opts ...client.CallOption) (*empty.Empty, error) {
|
||||
func (c *roleService) RemoveRoleFromUser(ctx context.Context, in *RemoveRoleFromUserRequest, opts ...client.CallOption) (*emptypb.Empty, error) {
|
||||
req := c.c.NewRequest(c.name, "RoleService.RemoveRoleFromUser", in)
|
||||
out := new(empty.Empty)
|
||||
out := new(emptypb.Empty)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -497,7 +497,7 @@ type RoleServiceHandler interface {
|
||||
ListRoles(context.Context, *ListBundlesRequest, *ListBundlesResponse) error
|
||||
ListRoleAssignments(context.Context, *ListRoleAssignmentsRequest, *ListRoleAssignmentsResponse) error
|
||||
AssignRoleToUser(context.Context, *AssignRoleToUserRequest, *AssignRoleToUserResponse) error
|
||||
RemoveRoleFromUser(context.Context, *RemoveRoleFromUserRequest, *empty.Empty) error
|
||||
RemoveRoleFromUser(context.Context, *RemoveRoleFromUserRequest, *emptypb.Empty) error
|
||||
}
|
||||
|
||||
func RegisterRoleServiceHandler(s server.Server, hdlr RoleServiceHandler, opts ...server.HandlerOption) error {
|
||||
@@ -505,7 +505,7 @@ func RegisterRoleServiceHandler(s server.Server, hdlr RoleServiceHandler, opts .
|
||||
ListRoles(ctx context.Context, in *ListBundlesRequest, out *ListBundlesResponse) error
|
||||
ListRoleAssignments(ctx context.Context, in *ListRoleAssignmentsRequest, out *ListRoleAssignmentsResponse) error
|
||||
AssignRoleToUser(ctx context.Context, in *AssignRoleToUserRequest, out *AssignRoleToUserResponse) error
|
||||
RemoveRoleFromUser(ctx context.Context, in *RemoveRoleFromUserRequest, out *empty.Empty) error
|
||||
RemoveRoleFromUser(ctx context.Context, in *RemoveRoleFromUserRequest, out *emptypb.Empty) error
|
||||
}
|
||||
type RoleService struct {
|
||||
roleService
|
||||
@@ -558,7 +558,7 @@ func (h *roleServiceHandler) AssignRoleToUser(ctx context.Context, in *AssignRol
|
||||
return h.RoleServiceHandler.AssignRoleToUser(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *roleServiceHandler) RemoveRoleFromUser(ctx context.Context, in *RemoveRoleFromUserRequest, out *empty.Empty) error {
|
||||
func (h *roleServiceHandler) RemoveRoleFromUser(ctx context.Context, in *RemoveRoleFromUserRequest, out *emptypb.Empty) error {
|
||||
return h.RoleServiceHandler.RemoveRoleFromUser(ctx, in, out)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
merrors "github.com/asim/go-micro/v3/errors"
|
||||
"github.com/asim/go-micro/v3/metadata"
|
||||
ocislog "github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/ocis-pkg/middleware"
|
||||
"github.com/owncloud/ocis/ocis-pkg/service/grpc"
|
||||
@@ -19,6 +17,8 @@ import (
|
||||
svc "github.com/owncloud/ocis/settings/pkg/service/v0"
|
||||
store "github.com/owncloud/ocis/settings/pkg/store/filesystem"
|
||||
"github.com/stretchr/testify/assert"
|
||||
merrors "go-micro.dev/v4/errors"
|
||||
"go-micro.dev/v4/metadata"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"github.com/asim/go-micro/v3"
|
||||
"github.com/go-chi/chi/v5"
|
||||
chimiddleware "github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/owncloud/ocis/ocis-pkg/account"
|
||||
@@ -11,6 +10,7 @@ import (
|
||||
"github.com/owncloud/ocis/settings/pkg/assets"
|
||||
"github.com/owncloud/ocis/settings/pkg/proto/v0"
|
||||
svc "github.com/owncloud/ocis/settings/pkg/service/v0"
|
||||
"go-micro.dev/v4"
|
||||
)
|
||||
|
||||
// Server initializes the http service and server.
|
||||
|
||||
@@ -4,9 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
merrors "github.com/asim/go-micro/v3/errors"
|
||||
"github.com/asim/go-micro/v3/metadata"
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/ocis-pkg/middleware"
|
||||
"github.com/owncloud/ocis/ocis-pkg/roles"
|
||||
@@ -14,6 +11,9 @@ import (
|
||||
"github.com/owncloud/ocis/settings/pkg/proto/v0"
|
||||
"github.com/owncloud/ocis/settings/pkg/settings"
|
||||
store "github.com/owncloud/ocis/settings/pkg/store/filesystem"
|
||||
merrors "go-micro.dev/v4/errors"
|
||||
"go-micro.dev/v4/metadata"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
|
||||
// Service represents a service.
|
||||
@@ -190,7 +190,7 @@ func (g Service) AddSettingToBundle(ctx context.Context, req *proto.AddSettingTo
|
||||
}
|
||||
|
||||
// RemoveSettingFromBundle implements the BundleServiceHandler interface
|
||||
func (g Service) RemoveSettingFromBundle(ctx context.Context, req *proto.RemoveSettingFromBundleRequest, _ *empty.Empty) error {
|
||||
func (g Service) RemoveSettingFromBundle(ctx context.Context, req *proto.RemoveSettingFromBundleRequest, _ *emptypb.Empty) error {
|
||||
if err := g.checkStaticPermissionsByBundleID(ctx, req.BundleId); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -332,7 +332,7 @@ func (g Service) AssignRoleToUser(ctx context.Context, req *proto.AssignRoleToUs
|
||||
}
|
||||
|
||||
// RemoveRoleFromUser implements the RoleServiceHandler interface
|
||||
func (g Service) RemoveRoleFromUser(ctx context.Context, req *proto.RemoveRoleFromUserRequest, _ *empty.Empty) error {
|
||||
func (g Service) RemoveRoleFromUser(ctx context.Context, req *proto.RemoveRoleFromUserRequest, _ *emptypb.Empty) error {
|
||||
if err := g.checkStaticPermissionsByBundleType(ctx, proto.Bundle_TYPE_ROLE); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/asim/go-micro/v3/metadata"
|
||||
"github.com/owncloud/ocis/ocis-pkg/middleware"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go-micro.dev/v4/metadata"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
9
settings/pkg/store/errortypes/errortypes.go
Normal file
9
settings/pkg/store/errortypes/errortypes.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package errortypes
|
||||
|
||||
// BundleNotFound is the error to use when a bundle is not found.
|
||||
type BundleNotFound string
|
||||
|
||||
func (e BundleNotFound) Error() string { return "error: bundle not found: " + string(e) }
|
||||
|
||||
// IsBundleNotFound implements the IsBundleNotFound interface.
|
||||
func (e BundleNotFound) IsBundleNotFound() {}
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/owncloud/ocis/settings/pkg/proto/v0"
|
||||
"github.com/owncloud/ocis/settings/pkg/store/errortypes"
|
||||
)
|
||||
|
||||
var m = &sync.RWMutex{}
|
||||
@@ -110,7 +111,12 @@ func (s Store) WriteBundle(record *proto.Bundle) (*proto.Bundle, error) {
|
||||
func (s Store) AddSettingToBundle(bundleID string, setting *proto.Setting) (*proto.Setting, error) {
|
||||
bundle, err := s.ReadBundle(bundleID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if _, notFound := err.(errortypes.BundleNotFound); !notFound {
|
||||
return nil, err
|
||||
}
|
||||
bundle = new(proto.Bundle)
|
||||
bundle.Id = bundleID
|
||||
bundle.Type = proto.Bundle_TYPE_DEFAULT
|
||||
}
|
||||
if setting.Id == "" {
|
||||
setting.Id = uuid.Must(uuid.NewV4()).String()
|
||||
|
||||
@@ -1,22 +1,37 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/owncloud/ocis/settings/pkg/store/errortypes"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// Unmarshal file into record
|
||||
func (s Store) parseRecordFromFile(record proto.Message, filePath string) error {
|
||||
_, err := os.Stat(filePath)
|
||||
if err != nil {
|
||||
return errortypes.BundleNotFound(err.Error())
|
||||
}
|
||||
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
decoder := jsonpb.Unmarshaler{}
|
||||
if err = decoder.Unmarshal(file, record); err != nil {
|
||||
b, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(b) == 0 {
|
||||
return errortypes.BundleNotFound(filePath)
|
||||
}
|
||||
|
||||
if err := protojson.Unmarshal(b, record); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -30,8 +45,13 @@ func (s Store) writeRecordToFile(record proto.Message, filePath string) error {
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
encoder := jsonpb.Marshaler{}
|
||||
if err = encoder.Marshal(file, record); err != nil {
|
||||
v, err := protojson.Marshal(record)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = file.Write(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user