Skip to content

Commit

Permalink
Add FindAcceptedUsers method to OCM Invite API (#1527)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored Mar 11, 2021
1 parent e3c9073 commit 73f1c7b
Show file tree
Hide file tree
Showing 53 changed files with 417 additions and 229 deletions.
6 changes: 1 addition & 5 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ issues:
text: "SA1019:"
linters:
- staticcheck
- path: pkg/publicshare/manager/json/json.go
text: "SA1019:"
linters:
- staticcheck
- path: internal/grpc/services/gateway/publicshareprovider.go
- path: pkg/utils/utils.go
text: "SA1019:"
linters:
- staticcheck
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contrib:

# for manual building only
deps:
cd /tmp && rm -rf golangci-lint && git clone --quiet -b 'v1.26.0' --single-branch --depth 1 https://github.com/golangci/golangci-lint &> /dev/null && cd golangci-lint/cmd/golangci-lint && go install
cd /tmp && rm -rf golangci-lint && git clone --quiet -b 'v1.38.0' --single-branch --depth 1 https://github.com/golangci/golangci-lint &> /dev/null && cd golangci-lint/cmd/golangci-lint && go install
cd /tmp && go get golang.org/x/tools/cmd/goimports

build-ci: off
Expand Down
3 changes: 3 additions & 0 deletions changelog/unreleased/ocm-find-accepted-users.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Add FindAcceptedUsers method to OCM Invite API

https://github.com/cs3org/reva/pull/1527
1 change: 1 addition & 0 deletions cmd/reva/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var (
rmCommand(),
moveCommand(),
mkdirCommand(),
ocmFindAcceptedUsersCommand(),
ocmShareCreateCommand(),
ocmShareListCommand(),
ocmShareRemoveCommand(),
Expand Down
79 changes: 79 additions & 0 deletions cmd/reva/ocm-find-accepted-users.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2018-2021 CERN
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package main

import (
"encoding/gob"
"io"
"os"

invitepb "github.com/cs3org/go-cs3apis/cs3/ocm/invite/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
"github.com/jedib0t/go-pretty/table"
)

func ocmFindAcceptedUsersCommand() *command {
cmd := newCommand("ocm-find-accepted-users")
cmd.Description = func() string { return "find remote users who have accepted invite tokens by their attributes" }
cmd.Usage = func() string { return "Usage: ocm-find-accepted-users <filter>" }

cmd.Action = func(w ...io.Writer) error {
var filter string
if cmd.NArg() == 1 {
filter = cmd.Args()[0]
}

ctx := getAuthContext()
client, err := getClient()
if err != nil {
return err
}

acceptedUsersRes, err := client.FindAcceptedUsers(ctx, &invitepb.FindAcceptedUsersRequest{
Filter: filter,
})
if err != nil {
return err
}
if acceptedUsersRes.Status.Code != rpc.Code_CODE_OK {
return formatError(acceptedUsersRes.Status)
}

if len(w) == 0 {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"OpaqueId", "Idp", "Mail", "DisplayName"})

for _, u := range acceptedUsersRes.AcceptedUsers {
t.AppendRows([]table.Row{
{u.Id.OpaqueId, u.Id.Idp, u.Mail, u.DisplayName},
})
}
t.Render()
} else {
enc := gob.NewEncoder(w[0])
if err := enc.Encode(acceptedUsersRes.AcceptedUsers); err != nil {
return err
}
}

return nil
}
return cmd
}
6 changes: 2 additions & 4 deletions cmd/reva/ocm-share-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package main

import (
"fmt"
"io"
"os"
"strconv"
Expand All @@ -39,7 +38,7 @@ import (
func ocmShareCreateCommand() *command {
cmd := newCommand("ocm-share-create")
cmd.Description = func() string { return "create OCM share to a user or group" }
cmd.Usage = func() string { return "Usage: ocm-share create [-flags] <path>" }
cmd.Usage = func() string { return "Usage: ocm-share-create [-flags] <path>" }
grantType := cmd.String("type", "user", "grantee type (user or group)")
grantee := cmd.String("grantee", "", "the grantee")
idp := cmd.String("idp", "", "the idp of the grantee, default to same idp as the user triggering the action")
Expand Down Expand Up @@ -78,7 +77,7 @@ func ocmShareCreateCommand() *command {
return err
}

remoteUserRes, err := client.GetRemoteUser(ctx, &invitepb.GetRemoteUserRequest{
remoteUserRes, err := client.GetAcceptedUser(ctx, &invitepb.GetAcceptedUserRequest{
RemoteUserId: &userpb.UserId{OpaqueId: *grantee, Idp: *idp},
})
if err != nil {
Expand Down Expand Up @@ -148,7 +147,6 @@ func ocmShareCreateCommand() *command {
return formatError(shareRes.Status)
}

fmt.Println("create share done")
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "Owner.Idp", "Owner.OpaqueId", "ResourceId", "Permissions", "Type", "Grantee.Idp", "Grantee.OpaqueId", "Created", "Updated"})
Expand Down
2 changes: 1 addition & 1 deletion cmd/revad/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func initCPUCount(conf *coreConf, log *zerolog.Logger) {
log.Error().Err(err).Msg("error adjusting number of cpus")
os.Exit(1)
}
//log.Info().Msgf("%s", getVersionString())
// log.Info().Msgf("%s", getVersionString())
log.Info().Msgf("running on %d cpus", ncpus)
}

Expand Down
15 changes: 8 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/cheggaaa/pb v1.0.29
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e
github.com/cs3org/go-cs3apis v0.0.0-20210209091240-d16c30974508
github.com/cs3org/go-cs3apis v0.0.0-20210310133342-f4a10134033c
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/eventials/go-tus v0.0.0-20200718001131-45c7ec8f5d59
github.com/go-ldap/ldap/v3 v3.2.4
Expand All @@ -34,7 +34,7 @@ require (
github.com/mitchellh/mapstructure v1.4.1
github.com/onsi/ginkgo v1.15.1
github.com/onsi/gomega v1.11.0
github.com/ory/fosite v0.38.0
github.com/ory/fosite v0.39.0
github.com/pkg/errors v0.9.1
github.com/pkg/xattr v0.4.3
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
Expand All @@ -50,12 +50,13 @@ require (
golang.org/x/sys v0.0.0-20210218155724-8ebf48af031b
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221
google.golang.org/grpc v1.36.0
google.golang.org/protobuf v1.23.0
)

go 1.13

replace github.com/eventials/go-tus => github.com/andrewmostello/go-tus v0.0.0-20200314041820-904a9904af9a

replace github.com/oleiade/reflections => github.com/oleiade/reflections v1.0.1

replace google.golang.org/grpc => google.golang.org/grpc v1.26.0 // temporary downgrade
replace (
github.com/eventials/go-tus => github.com/andrewmostello/go-tus v0.0.0-20200314041820-904a9904af9a
github.com/oleiade/reflections => github.com/oleiade/reflections v1.0.1
google.golang.org/grpc => google.golang.org/grpc v1.26.0 // temporary downgrade
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJff
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
github.com/cs3org/go-cs3apis v0.0.0-20210209091240-d16c30974508 h1:AyeoeZZGPC1lTN7mhgh8HGwwRlvG8hXJ/06q9P+ad9I=
github.com/cs3org/go-cs3apis v0.0.0-20210209091240-d16c30974508/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/go-cs3apis v0.0.0-20210310133342-f4a10134033c h1:+HOawEG8T4uBZI/zJNAFcm4ygbiP+Zci0XRaVGZ0rYM=
github.com/cs3org/go-cs3apis v0.0.0-20210310133342-f4a10134033c/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cucumber/godog v0.8.1/go.mod h1:vSh3r/lM+psC1BPXvdkSEuNjmXfpVqrMGYAElF6hxnA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down Expand Up @@ -834,6 +836,8 @@ github.com/ory/dockertest/v3 v3.5.4/go.mod h1:J8ZUbNB2FOhm1cFZW9xBpDsODqsSWcyYgt
github.com/ory/fosite v0.29.0/go.mod h1:0atSZmXO7CAcs6NPMI/Qtot8tmZYj04Nddoold4S2h0=
github.com/ory/fosite v0.38.0 h1:4y+IurqBAu/Gf0NlW47gabRJZyYIqda+OFHMx5fsy6Q=
github.com/ory/fosite v0.38.0/go.mod h1:37r59qkOSPueYKmaA7EHiXrDMF1B+XPN+MgkZgTRg3Y=
github.com/ory/fosite v0.39.0 h1:u1Ct/ME7XYzREvufr7ehBIdq/KatjVLIYg/ABqWzprw=
github.com/ory/fosite v0.39.0/go.mod h1:37r59qkOSPueYKmaA7EHiXrDMF1B+XPN+MgkZgTRg3Y=
github.com/ory/go-acc v0.0.0-20181118080137-ddc355013f90/go.mod h1:sxnvPCxChFuSmTJGj8FdMupeq1BezCiEpDjTUXQ4hf4=
github.com/ory/go-acc v0.2.5 h1:31irXHzG2vnKQSE4weJm7AdfrnpaVjVCq3nD7viXCJE=
github.com/ory/go-acc v0.2.5/go.mod h1:4Kb/UnPcT8qRAk3IAxta+hvVapdxTLWtrr7bFLlEgpw=
Expand Down
10 changes: 5 additions & 5 deletions grpc-tests/userprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ func Test_service_GetUser(t *testing.T) {

for _, tt := range providers {
t.Run(tt.name, func(t *testing.T) {
//start revad with the specific provider
// start revad with the specific provider
cmd := exec.Command("../cmd/revad/revad", "-c", "userproviders/"+tt.name+".toml")
err := cmd.Start()

if err != nil {
t.Fatalf("Could not start revad! ERROR: %v", err)
}

//wait till port is open
// wait till port is open
_ = waitForPort("open")

//even the port is open the service might not be available yet
// even the port is open the service might not be available yet
time.Sleep(1 * time.Second)

GetUser(t, tt.existingIdp)

//kill revad
// kill revad
err = cmd.Process.Signal(os.Kill)
if err != nil {
t.Fatalf("Could not kill revad! ERROR: %v", err)
Expand Down Expand Up @@ -184,7 +184,7 @@ func GetUser(t *testing.T, existingIdp string) {
if tt.want.User == nil {
assert.Nil(t, userResp.User)
} else {
//make sure not to run into a nil pointer error
// make sure not to run into a nil pointer error
if userResp.User == nil {
t.Fatalf("no user in response %v", userResp)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/grpc/services/appregistry/appregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func Test_ListAppProviders(t *testing.T) {
"currently/ignored": "an other address",
},

//only Status and Providers will be asserted in the tests
// only Status and Providers will be asserted in the tests
want: &registrypb.ListAppProvidersResponse{
Status: &rpcv1beta1.Status{
Code: 1,
Expand Down Expand Up @@ -79,7 +79,7 @@ func Test_ListAppProviders(t *testing.T) {
name: "empty rules",
rules: map[string]interface{}{},

//only Status and Providers will be asserted in the tests
// only Status and Providers will be asserted in the tests
want: &registrypb.ListAppProvidersResponse{
Status: &rpcv1beta1.Status{
Code: 1,
Expand All @@ -97,7 +97,7 @@ func Test_ListAppProviders(t *testing.T) {
"text/json": nil,
},

//only Status and Providers will be asserted in the tests
// only Status and Providers will be asserted in the tests
want: &registrypb.ListAppProvidersResponse{
Status: &rpcv1beta1.Status{
Code: 1,
Expand Down Expand Up @@ -154,7 +154,7 @@ func Test_GetAppProviders(t *testing.T) {
{
name: "simple",
search: &providerv1beta1.ResourceInfo{MimeType: "text/json"},
//only Status and Providers will be asserted in the tests
// only Status and Providers will be asserted in the tests
want: &registrypb.GetAppProvidersResponse{
Status: &rpcv1beta1.Status{
Code: 1,
Expand Down
24 changes: 20 additions & 4 deletions internal/grpc/services/gateway/ocminvitemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,33 @@ func (s *svc) AcceptInvite(ctx context.Context, req *invitepb.AcceptInviteReques
return res, nil
}

func (s *svc) GetRemoteUser(ctx context.Context, req *invitepb.GetRemoteUserRequest) (*invitepb.GetRemoteUserResponse, error) {
func (s *svc) GetAcceptedUser(ctx context.Context, req *invitepb.GetAcceptedUserRequest) (*invitepb.GetAcceptedUserResponse, error) {
c, err := pool.GetOCMInviteManagerClient(s.c.OCMInviteManagerEndpoint)
if err != nil {
return &invitepb.GetRemoteUserResponse{
return &invitepb.GetAcceptedUserResponse{
Status: status.NewInternal(ctx, err, "error getting user invite provider client"),
}, nil
}

res, err := c.GetRemoteUser(ctx, req)
res, err := c.GetAcceptedUser(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling AcceptInvite")
return nil, errors.Wrap(err, "gateway: error calling GetAcceptedUser")
}

return res, nil
}

func (s *svc) FindAcceptedUsers(ctx context.Context, req *invitepb.FindAcceptedUsersRequest) (*invitepb.FindAcceptedUsersResponse, error) {
c, err := pool.GetOCMInviteManagerClient(s.c.OCMInviteManagerEndpoint)
if err != nil {
return &invitepb.FindAcceptedUsersResponse{
Status: status.NewInternal(ctx, err, "error getting user invite provider client"),
}, nil
}

res, err := c.FindAcceptedUsers(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling FindAcceptedUsers")
}

return res, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ func (s *svc) GetQuota(ctx context.Context, req *gateway.GetQuotaRequest) (*prov

res, err := c.GetQuota(ctx, &provider.GetQuotaRequest{
Opaque: req.GetOpaque(),
//Ref: req.GetRef(), // TODO send which storage space ... or root
// Ref: req.GetRef(), // TODO send which storage space ... or root
})
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling GetQuota")
Expand Down
22 changes: 18 additions & 4 deletions internal/grpc/services/ocminvitemanager/ocminvitemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,30 @@ func (s *service) AcceptInvite(ctx context.Context, req *invitepb.AcceptInviteRe
}, nil
}

func (s *service) GetRemoteUser(ctx context.Context, req *invitepb.GetRemoteUserRequest) (*invitepb.GetRemoteUserResponse, error) {
remoteUser, err := s.im.GetRemoteUser(ctx, req.RemoteUserId)
func (s *service) GetAcceptedUser(ctx context.Context, req *invitepb.GetAcceptedUserRequest) (*invitepb.GetAcceptedUserResponse, error) {
remoteUser, err := s.im.GetAcceptedUser(ctx, req.RemoteUserId)
if err != nil {
return &invitepb.GetRemoteUserResponse{
return &invitepb.GetAcceptedUserResponse{
Status: status.NewInternal(ctx, err, "error fetching remote user details"),
}, nil
}

return &invitepb.GetRemoteUserResponse{
return &invitepb.GetAcceptedUserResponse{
Status: status.NewOK(ctx),
RemoteUser: remoteUser,
}, nil
}

func (s *service) FindAcceptedUsers(ctx context.Context, req *invitepb.FindAcceptedUsersRequest) (*invitepb.FindAcceptedUsersResponse, error) {
acceptedUsers, err := s.im.FindAcceptedUsers(ctx, req.Filter)
if err != nil {
return &invitepb.FindAcceptedUsersResponse{
Status: status.NewInternal(ctx, err, "error finding remote users"),
}, nil
}

return &invitepb.FindAcceptedUsersResponse{
Status: status.NewOK(ctx),
AcceptedUsers: acceptedUsers,
}, nil
}
2 changes: 1 addition & 1 deletion internal/grpc/services/storageprovider/transcoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (x XS) String() string { return string(x) }
const (
// XSInvalid means the checksum type is invalid.
XSInvalid XS = "invalid"
//XSUnset means the checksum is optional.
// XSUnset means the checksum is optional.
XSUnset = "unset"
// XSAdler32 means the checksum is adler32
XSAdler32 = "adler32"
Expand Down
2 changes: 1 addition & 1 deletion internal/http/services/oidcprovider/oidcprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func getStore(clients map[string]fosite.Client) *storage.MemoryStore {
Clients: clients,
AuthorizeCodes: map[string]storage.StoreAuthorizeCode{},
AccessTokens: map[string]fosite.Requester{},
RefreshTokens: map[string]fosite.Requester{},
RefreshTokens: map[string]storage.StoreRefreshToken{},
PKCES: map[string]fosite.Requester{},
AccessTokenRequestIDs: map[string]string{},
RefreshTokenRequestIDs: map[string]string{},
Expand Down
Loading

0 comments on commit 73f1c7b

Please sign in to comment.