diff --git a/changelog/unreleased/update-libregraph-api.md b/changelog/unreleased/update-libregraph-api.md new file mode 100644 index 0000000000..f8da54c775 --- /dev/null +++ b/changelog/unreleased/update-libregraph-api.md @@ -0,0 +1,5 @@ +Change: Update libre-graph-api to v0.3.0 + +This updates the libre-graph-api to use the latest spec and types. + +https://github.com/owncloud/ocis/pull/2858 diff --git a/go.mod b/go.mod index a2cd56ad20..fb8ecb8e33 100644 --- a/go.mod +++ b/go.mod @@ -46,7 +46,7 @@ require ( github.com/olekukonko/tablewriter v0.0.5 github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.17.0 - github.com/owncloud/open-graph-api-go v0.0.0-20211018134924-bea0e2a6ec3e + github.com/owncloud/libre-graph-api-go v0.3.0 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.11.0 github.com/rs/zerolog v1.26.0 @@ -199,8 +199,8 @@ require ( github.com/prometheus/common v0.32.1 // indirect github.com/prometheus/procfs v0.7.3 // indirect github.com/prometheus/statsd_exporter v0.22.2 // indirect - github.com/rickb777/date v1.16.1 // indirect - github.com/rickb777/plural v1.4.1 // indirect + github.com/rickb777/date v1.12.4 // indirect + github.com/rickb777/plural v1.2.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/rs/cors v1.8.0 // indirect github.com/rs/xid v1.3.0 // indirect diff --git a/go.sum b/go.sum index e8cb72438e..022d2745fa 100644 --- a/go.sum +++ b/go.sum @@ -993,7 +993,6 @@ github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042 github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48= github.com/onsi/gomega v1.17.0 h1:9Luw4uT5HTjHTN8+aNcSThgH1vdXnmdJ8xIfZ4wyTRE= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= @@ -1010,8 +1009,8 @@ github.com/oracle/oci-go-sdk v24.3.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35uk github.com/orcaman/concurrent-map v0.0.0-20210501183033-44dafcb38ecc h1:Ak86L+yDSOzKFa7WM5bf5itSOo1e3Xh8bm5YCMUXIjQ= github.com/orcaman/concurrent-map v0.0.0-20210501183033-44dafcb38ecc/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI= github.com/ovh/go-ovh v1.1.0/go.mod h1:AxitLZ5HBRPyUd+Zl60Ajaag+rNTdVXWIkzfrVuTXWA= -github.com/owncloud/open-graph-api-go v0.0.0-20211018134924-bea0e2a6ec3e h1:Aww53qP8t9WmFq88NZk5BIcVz6zH4z4QqE98JEpsLRs= -github.com/owncloud/open-graph-api-go v0.0.0-20211018134924-bea0e2a6ec3e/go.mod h1:1Z3JQaJg9KjZ9dW5fxA0hfqdgL9Ma/9wmU3Uk+7rIx4= +github.com/owncloud/libre-graph-api-go v0.3.0 h1:CjSWuL6Gd+HgIlZfBLjYTloH1F/8naxaL5xZZz4N+ms= +github.com/owncloud/libre-graph-api-go v0.3.0/go.mod h1:dOt7+kXldpyUGBFdfFBs6PbWElqqa2/Q5+pMF9izL3w= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= @@ -1092,13 +1091,10 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2/go.mod h1:7tZKcyumwBO6qip7RNQ5r77yrssm9bfCowcLEBcU5IA= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/rickb777/date v1.12.4 h1:+6IzcCCS/1t17DrmnEvrznyq7nM8vPwir6/UhlyohKw= github.com/rickb777/date v1.12.4/go.mod h1:xP0eo/I5qmUt97yRGClHZfyLZ3ikMw6v6SU5MOGZTE0= -github.com/rickb777/date v1.16.1 h1:nUx7FrnRLxwj4QpbuHOz7RRcnEyFOiXnZxdC2lx0f8c= -github.com/rickb777/date v1.16.1/go.mod h1:QwU+l0bIHSFsMQH12voxZbC531J+lM3A/ZFq5gku8F8= +github.com/rickb777/plural v1.2.0 h1:5tvEc7UBCZ7l8h/2UeybSkt/uu1DQsZFOFdNevmUhlE= github.com/rickb777/plural v1.2.0/go.mod h1:UdpyWFCGbo3mvK3f/PfZOAOrkjzJlYN/sD46XNWJ+Es= -github.com/rickb777/plural v1.3.0/go.mod h1:xyHbelv4YvJE51gjMnHvk+U2e9zIysg6lTnSQK8XUYA= -github.com/rickb777/plural v1.4.1 h1:5MMLcbIaapLFmvDGRT5iPk8877hpTPt8Y9cdSKRw9sU= -github.com/rickb777/plural v1.4.1/go.mod h1:kdmXUpmKBJTS0FtG/TFumd//VBWsNTD7zOw7x4umxNw= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= diff --git a/graph/pkg/service/v0/drives.go b/graph/pkg/service/v0/drives.go index aa370cbdfd..065998ac33 100644 --- a/graph/pkg/service/v0/drives.go +++ b/graph/pkg/service/v0/drives.go @@ -22,11 +22,11 @@ import ( types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" ctxpkg "github.com/cs3org/reva/pkg/ctx" "github.com/go-chi/render" + libregraph "github.com/owncloud/libre-graph-api-go" "github.com/owncloud/ocis/graph/pkg/service/v0/errorcode" "github.com/owncloud/ocis/ocis-pkg/service/grpc" sproto "github.com/owncloud/ocis/settings/pkg/proto/v0" settingsSvc "github.com/owncloud/ocis/settings/pkg/service/v0" - msgraph "github.com/owncloud/open-graph-api-go" merrors "go-micro.dev/v4/errors" ) @@ -190,7 +190,7 @@ func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) { errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error()) return } - drive := msgraph.Drive{} + drive := libregraph.Drive{} if err := json.NewDecoder(r.Body).Decode(&drive); err != nil { errorcode.GeneralException.Render(w, r, http.StatusBadRequest, "invalid schema definition") return @@ -268,7 +268,7 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) { return } - drive := msgraph.Drive{} + drive := libregraph.Drive{} if err = json.NewDecoder(r.Body).Decode(&drive); err != nil { errorcode.GeneralException.Render(w, r, http.StatusBadRequest, fmt.Sprintf("invalid request body: %v", r.Body)) return @@ -341,38 +341,34 @@ func cs3TimestampToTime(t *types.Timestamp) time.Time { return time.Unix(int64(t.Seconds), int64(t.Nanos)) } -func cs3ResourceToDriveItem(res *storageprovider.ResourceInfo) (*msgraph.DriveItem, error) { +func cs3ResourceToDriveItem(res *storageprovider.ResourceInfo) (*libregraph.DriveItem, error) { size := new(int64) *size = int64(res.Size) // uint64 -> int :boom: name := path.Base(res.Path) - driveItem := &msgraph.DriveItem{ - BaseItem: msgraph.BaseItem{ - Entity: msgraph.Entity{ - Id: &res.Id.OpaqueId, - }, - Name: &name, - ETag: &res.Etag, - }, + driveItem := &libregraph.DriveItem{ + Id: &res.Id.OpaqueId, + Name: &name, + ETag: &res.Etag, Size: size, } if res.Mtime != nil { lastModified := cs3TimestampToTime(res.Mtime) - driveItem.BaseItem.LastModifiedDateTime = &lastModified + driveItem.LastModifiedDateTime = &lastModified } if res.Type == storageprovider.ResourceType_RESOURCE_TYPE_FILE { - driveItem.File = &msgraph.OpenGraphFile{ // FIXME We cannot use msgraph.File here because the openapi codegenerator autodetects 'File' as a go type ... + driveItem.File = &libregraph.OpenGraphFile{ // FIXME We cannot use libregraph.File here because the openapi codegenerator autodetects 'File' as a go type ... MimeType: &res.MimeType, } } if res.Type == storageprovider.ResourceType_RESOURCE_TYPE_CONTAINER { - driveItem.Folder = &msgraph.Folder{} + driveItem.Folder = &libregraph.Folder{} } return driveItem, nil } -func formatDriveItems(mds []*storageprovider.ResourceInfo) ([]*msgraph.DriveItem, error) { - responses := make([]*msgraph.DriveItem, 0, len(mds)) +func formatDriveItems(mds []*storageprovider.ResourceInfo) ([]*libregraph.DriveItem, error) { + responses := make([]*libregraph.DriveItem, 0, len(mds)) for i := range mds { res, err := cs3ResourceToDriveItem(mds[i]) if err != nil { @@ -384,31 +380,22 @@ func formatDriveItems(mds []*storageprovider.ResourceInfo) ([]*msgraph.DriveItem return responses, nil } -func cs3StorageSpaceToDrive(baseURL *url.URL, space *storageprovider.StorageSpace) (*msgraph.Drive, error) { +func cs3StorageSpaceToDrive(baseURL *url.URL, space *storageprovider.StorageSpace) (*libregraph.Drive, error) { rootID := space.Root.StorageId + "!" + space.Root.OpaqueId - drive := &msgraph.Drive{ - BaseItem: msgraph.BaseItem{ - Entity: msgraph.Entity{ - Id: &space.Id.OpaqueId, - }, - Name: &space.Name, - //"createdDateTime": "string (timestamp)", // TODO read from StorageSpace ... needs Opaque for now - //"description": "string", // TODO read from StorageSpace ... needs Opaque for now - }, - Owner: &msgraph.IdentitySet{ - User: &msgraph.Identity{ + drive := &libregraph.Drive{ + Id: &space.Id.OpaqueId, + Name: &space.Name, + //"createdDateTime": "string (timestamp)", // TODO read from StorageSpace ... needs Opaque for now + //"description": "string", // TODO read from StorageSpace ... needs Opaque for now + Owner: &libregraph.IdentitySet{ + User: &libregraph.Identity{ Id: &space.Owner.Id.OpaqueId, // DisplayName: , TODO read and cache from users provider }, }, - DriveType: &space.SpaceType, - Root: &msgraph.DriveItem{ - BaseItem: msgraph.BaseItem{ - Entity: msgraph.Entity{ - Id: &rootID, - }, - }, + Root: &libregraph.DriveItem{ + Id: &rootID, }, } @@ -422,7 +409,7 @@ func cs3StorageSpaceToDrive(baseURL *url.URL, space *storageprovider.StorageSpac if space.Mtime != nil { lastModified := cs3TimestampToTime(space.Mtime) - drive.BaseItem.LastModifiedDateTime = &lastModified + drive.LastModifiedDateTime = &lastModified } if space.Quota != nil { var t int64 @@ -431,7 +418,7 @@ func cs3StorageSpaceToDrive(baseURL *url.URL, space *storageprovider.StorageSpac } else { t = int64(space.Quota.QuotaMaxBytes) } - drive.Quota = &msgraph.Quota{ + drive.Quota = &libregraph.Quota{ Total: &t, } } @@ -440,8 +427,8 @@ func cs3StorageSpaceToDrive(baseURL *url.URL, space *storageprovider.StorageSpac return drive, nil } -func (g Graph) formatDrives(ctx context.Context, baseURL *url.URL, mds []*storageprovider.StorageSpace) ([]*msgraph.Drive, error) { - responses := make([]*msgraph.Drive, 0, len(mds)) +func (g Graph) formatDrives(ctx context.Context, baseURL *url.URL, mds []*storageprovider.StorageSpace) ([]*libregraph.Drive, error) { + responses := make([]*libregraph.Drive, 0, len(mds)) for i := range mds { res, err := cs3StorageSpaceToDrive(baseURL, mds[i]) if err != nil { @@ -458,11 +445,11 @@ func (g Graph) formatDrives(ctx context.Context, baseURL *url.URL, mds []*storag return responses, nil } -func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.StorageSpace) (msgraph.Quota, error) { +func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.StorageSpace) (libregraph.Quota, error) { client, err := g.GetClient() if err != nil { g.logger.Error().Err(err).Msg("error creating grpc client") - return msgraph.Quota{}, err + return libregraph.Quota{}, err } req := &gateway.GetQuotaRequest{ @@ -478,17 +465,17 @@ func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.Storage switch { case err != nil: g.logger.Error().Err(err).Msg("error sending get quota grpc request") - return msgraph.Quota{}, err + return libregraph.Quota{}, err case res.Status.Code != cs3rpc.Code_CODE_OK: g.logger.Error().Err(err).Msg("error sending sending get quota grpc request") - return msgraph.Quota{}, err + return libregraph.Quota{}, err } total := int64(res.TotalBytes) used := int64(res.UsedBytes) remaining := total - used - qta := msgraph.Quota{ + qta := libregraph.Quota{ Remaining: &remaining, Total: &total, Used: &used, @@ -514,7 +501,7 @@ func calculateQuotaState(total int64, used int64) (state string) { } } -func getQuota(quota *msgraph.Quota, defaultQuota string) *provider.Quota { +func getQuota(quota *libregraph.Quota, defaultQuota string) *provider.Quota { switch { case quota != nil && quota.Total != nil: if q := *quota.Total; q >= 0 { diff --git a/graph/pkg/service/v0/errorcode/errorcode.go b/graph/pkg/service/v0/errorcode/errorcode.go index 23dc333e58..0f540fa7ce 100644 --- a/graph/pkg/service/v0/errorcode/errorcode.go +++ b/graph/pkg/service/v0/errorcode/errorcode.go @@ -6,7 +6,7 @@ import ( "github.com/go-chi/chi/v5/middleware" "github.com/go-chi/render" - msgraph "github.com/owncloud/open-graph-api-go" + libregraph "github.com/owncloud/libre-graph-api-go" ) // ErrorCode defines code as used in MS Graph - see https://docs.microsoft.com/en-us/graph/errors?context=graph%2Fapi%2F1.0&view=graph-rest-1.0 @@ -86,8 +86,8 @@ func (e ErrorCode) Render(w http.ResponseWriter, r *http.Request, status int, ms } innererror["request-id"] = middleware.GetReqID(r.Context()) - resp := &msgraph.OdataError{ - Error: msgraph.OdataErrorMain{ + resp := &libregraph.OdataError{ + Error: libregraph.OdataErrorMain{ Code: e.String(), Message: msg, Innererror: &innererror,