Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi tenant #8

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
groups
  • Loading branch information
florindragos committed Jun 14, 2024
commit e392e2b119c6dbfc1f5729bab7a894cc735e1edd
28 changes: 14 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ go 1.22

require (
github.com/aserto-dev/certs v0.0.5
github.com/aserto-dev/ds-load/sdk v0.0.0-20240513161945-bc0e942cc34c
github.com/aserto-dev/errors v0.0.7
github.com/aserto-dev/ds-load/sdk v0.0.0-20240613123912-0e9e0079986b
github.com/aserto-dev/errors v0.0.8
github.com/aserto-dev/go-aserto v0.30.0
github.com/aserto-dev/go-directory v0.31.3
github.com/aserto-dev/go-directory v0.31.4
github.com/aserto-dev/logger v0.0.4
github.com/elimity-com/scim v0.0.0-20240320110924-172bf2aee9c8
github.com/magefile/mage v1.15.0
github.com/mitchellh/mapstructure v1.5.0
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.32.0
github.com/rs/zerolog v1.33.0
github.com/scim2/filter-parser/v2 v2.2.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.0
google.golang.org/protobuf v1.33.1-0.20240408130810-98873a205002
google.golang.org/protobuf v1.34.1
)

require (
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.33.0-20240401165935-b983156c5e99.1 // indirect
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.1-20240508200655-46a4cf4ba109.1 // indirect
github.com/aserto-dev/header v0.0.4 // indirect
github.com/di-wu/parser v0.3.0 // indirect
github.com/di-wu/xsd-datetime v1.0.0 // indirect
Expand All @@ -32,7 +32,7 @@ require (
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
Expand All @@ -50,14 +50,14 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240415151819-79826c84ba32 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415151819-79826c84ba32 // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
google.golang.org/grpc v1.64.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
15 changes: 15 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.33.0-20240401165935-b983156c5e99.1 h1:2IGhRovxlsOIQgx2ekZWo4wTPAYpck41+18ICxs37is=
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.33.0-20240401165935-b983156c5e99.1/go.mod h1:Tgn5bgL220vkFOI0KPStlcClPeOJzAv4uT+V8JXGUnw=
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.1-20240508200655-46a4cf4ba109.1/go.mod h1:XF+P8+RmfdufmIYpGUC+6bF7S+IlmHDEnCrO3OXaUAQ=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
Expand All @@ -8,12 +9,16 @@ github.com/aserto-dev/certs v0.0.5 h1:URZEN3DMUIqob3pf78NtTpe7sYPrR2oJYV5MbJ91YK
github.com/aserto-dev/certs v0.0.5/go.mod h1:BGRgkJ4GB7XoETzDtnMxQySk5IVpJIa18aWuylvAsac=
github.com/aserto-dev/ds-load/sdk v0.0.0-20240513161945-bc0e942cc34c h1:18rNcpg6kdEVifo8GtH44L9TV+vA3gBuvOCo08qRAEA=
github.com/aserto-dev/ds-load/sdk v0.0.0-20240513161945-bc0e942cc34c/go.mod h1:8ew3zhN76EbKCmEDkbIG/HtI7AxcjVUNr85mPlHxF+U=
github.com/aserto-dev/ds-load/sdk v0.0.0-20240613123912-0e9e0079986b h1:bC9sCddCdOYEAszrPSkxp3NF2F4KJ2ic5yIhaW2uSJs=
github.com/aserto-dev/ds-load/sdk v0.0.0-20240613123912-0e9e0079986b/go.mod h1:AqJsEf8D2Qk2lzi0veBPGO1iCbfqYrb0O6J76dlhvPM=
github.com/aserto-dev/errors v0.0.7 h1:pBn9RhP2iiDl30oAWsf8aLxvt4yCpLKZOCJRIaeRMUs=
github.com/aserto-dev/errors v0.0.7/go.mod h1:wiQ68oKTyAQVAv+SvB5GyuAD6PewalA/D6Fq30gNUbQ=
github.com/aserto-dev/errors v0.0.8/go.mod h1:wiQ68oKTyAQVAv+SvB5GyuAD6PewalA/D6Fq30gNUbQ=
github.com/aserto-dev/go-aserto v0.30.0 h1:RZMM8ojXp4O15+qPKsFjQ+6/+KV3pXAwqCJrQjJRD5I=
github.com/aserto-dev/go-aserto v0.30.0/go.mod h1:y+Mrqm9yl3XgBA0lkZ4Pj2cZN1ytL1pjAwpG9rKQCJA=
github.com/aserto-dev/go-directory v0.31.3 h1:Twiulwykm+ivko+H73TMVSvSlE2urIN3XiGK1F2bz1U=
github.com/aserto-dev/go-directory v0.31.3/go.mod h1:Pjb9QcswMnuIPl8iDexG4d2AcFtLWDpVisGodrKuvC0=
github.com/aserto-dev/go-directory v0.31.4/go.mod h1:fgIT515NcK+4m1UyriBCPMwFHl3DHPaa8yBLbEb9r/I=
github.com/aserto-dev/header v0.0.4 h1:Bb58n1m2X/qRV3N2PS0avuFOyRcG8Iri7/qq0Wsunq8=
github.com/aserto-dev/header v0.0.4/go.mod h1:LNgRo3gStS71lO1d9Oue9e9kfVvirvUHvdZClzDmNwo=
github.com/aserto-dev/logger v0.0.4 h1:GF+17mhn03ZnE5KHCszrzGRcZULgczsql+y+PCHjgpI=
Expand Down Expand Up @@ -66,6 +71,7 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
Expand Down Expand Up @@ -100,6 +106,7 @@ github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
Expand Down Expand Up @@ -144,6 +151,7 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY=
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
Expand All @@ -156,6 +164,7 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -172,9 +181,11 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
Expand All @@ -190,19 +201,23 @@ google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUE
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo=
google.golang.org/genproto/googleapis/api v0.0.0-20240415151819-79826c84ba32 h1:wSV4wyEpYVUdxkO7uzZ9Fr1g7a+wllr4fuQqTaR53pw=
google.golang.org/genproto/googleapis/api v0.0.0-20240415151819-79826c84ba32/go.mod h1:wTHjrkbcS8AoQbb/0v9bFIPItZQPAsyVfgG9YPUhjAM=
google.golang.org/genproto/googleapis/api v0.0.0-20240515191416-fc5f0ca64291/go.mod h1:RGnPtTG7r4i8sPlNyDeikXF99hMM+hN6QMm4ooG9g2g=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415151819-79826c84ba32 h1:GRBZAfftU6zhUwoY2cfnbtig9cTfQKXH0rAdBFVxra4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415151819-79826c84ba32/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8/go.mod h1:I7Y+G38R2bu5j1aLzfFmQfTcU/WnFuqDwLZAbvKTKpM=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.33.1-0.20240408130810-98873a205002 h1:V7Da7qt0MkY3noVANIMVBk28nOnijADeOR3i5Hcvpj4=
google.golang.org/protobuf v1.33.1-0.20240408130810-98873a205002/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
120 changes: 59 additions & 61 deletions pkg/app/handlers/groups/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package groups
import (
"net/http"

cerr "github.com/aserto-dev/errors"
dsw "github.com/aserto-dev/go-directory/aserto/directory/writer/v3"
"github.com/aserto-dev/go-directory/pkg/derr"
"github.com/aserto-dev/scim/pkg/common"
"github.com/aserto-dev/scim/pkg/directory"
"github.com/elimity-com/scim"
serrors "github.com/elimity-com/scim/errors"
"github.com/pkg/errors"
)

func (u GroupResourceHandler) Create(r *http.Request, attributes scim.ResourceAttributes) (scim.Resource, error) {
u.logger.Trace().Any("attributes", attributes).Msg("creating group")
group, err := common.ResourceAttributesToGroup(attributes)
if err != nil {
return scim.Resource{}, serrors.ScimErrorInvalidSyntax
Expand All @@ -29,9 +28,8 @@ func (u GroupResourceHandler) Create(r *http.Request, attributes scim.ResourceAt
return scim.Resource{}, err
}

// converter := common.NewConverter(scimConfig)

object, err := u.converter.SCIMGroupToObject(group)
converter := common.NewConverter(scimConfig)
object, err := converter.SCIMGroupToObject(group)
if err != nil {
u.logger.Error().Err(err).Msg("failed to convert group to object")
return scim.Resource{}, serrors.ScimErrorInvalidSyntax
Expand All @@ -44,69 +42,69 @@ func (u GroupResourceHandler) Create(r *http.Request, attributes scim.ResourceAt
return scim.Resource{}, err
}

groupMap, err := common.ProtobufStructToMap(sourceGroupResp.Result.Properties)
if err != nil {
if errors.Is(cerr.UnwrapAsertoError(err), derr.ErrAlreadyExists) {
return scim.Resource{}, serrors.ScimErrorUniqueness
}
return scim.Resource{}, err
}
// groupMap, err := common.ProtobufStructToMap(sourceGroupResp.Result.Properties)
// if err != nil {
// if errors.Is(cerr.UnwrapAsertoError(err), derr.ErrAlreadyExists) {
// return scim.Resource{}, serrors.ScimErrorUniqueness
// }
// return scim.Resource{}, err
// }

transformResult, err := common.TransformResource(groupMap, scimConfig)
transformResult, err := common.TransformResource(attributes, scimConfig, "group")
if err != nil {
u.logger.Error().Err(err).Msg("failed to transform group")
return scim.Resource{}, serrors.ScimErrorInvalidSyntax
}

for _, object := range transformResult.Objects {
_, err := dirClient.Writer.SetObject(r.Context(), &dsw.SetObjectRequest{
Object: object,
})
if err != nil {
if errors.Is(cerr.UnwrapAsertoError(err), derr.ErrAlreadyExists) {
return scim.Resource{}, serrors.ScimErrorUniqueness
}
return scim.Resource{}, err
}

// _, err = dirClient.Writer.SetRelation(r.Context(), &dsw.SetRelationRequest{
// Relation: &dsc.Relation{
// ObjectType: resp.Result.Type,
// ObjectId: resp.Result.Id,
// Relation: u.cfg.SCIM.Transform.SourceRelation,
// SubjectType: u.cfg.SCIM.Transform.SourceGroupType,
// SubjectId: sourceGroupResp.Result.Id,
// },
// })

// if err != nil {
// return scim.Resource{}, err
// }

// if object.Type == u.cfg.SCIM.Transform.GroupObjectType {
// err = u.setGroupMappings(r.Context(), dirClient, resp.Result.Id)
// if err != nil {
// return scim.Resource{}, err
// }
// }
}

for _, relation := range transformResult.Relations {
_, err := dirClient.Writer.SetRelation(r.Context(), &dsw.SetRelationRequest{
Relation: relation,
})
if err != nil {
return scim.Resource{}, err
}
sync := directory.NewSync(scimConfig, dirClient)
meta, err := sync.UpdateGroup(r.Context(), sourceGroupResp.Result.Id, transformResult)
if err != nil {
return scim.Resource{}, err
}

createdAt := sourceGroupResp.Result.CreatedAt.AsTime()
updatedAt := sourceGroupResp.Result.UpdatedAt.AsTime()
result = u.converter.ObjectToResource(sourceGroupResp.Result, scim.Meta{
Created: &createdAt,
LastModified: &updatedAt,
Version: sourceGroupResp.Result.Etag,
})
// for _, object := range transformResult.Objects {
// _, err := dirClient.Writer.SetObject(r.Context(), &dsw.SetObjectRequest{
// Object: object,
// })
// if err != nil {
// if errors.Is(cerr.UnwrapAsertoError(err), derr.ErrAlreadyExists) {
// return scim.Resource{}, serrors.ScimErrorUniqueness
// }
// return scim.Resource{}, err
// }

// // _, err = dirClient.Writer.SetRelation(r.Context(), &dsw.SetRelationRequest{
// // Relation: &dsc.Relation{
// // ObjectType: resp.Result.Type,
// // ObjectId: resp.Result.Id,
// // Relation: u.cfg.SCIM.Transform.SourceRelation,
// // SubjectType: u.cfg.SCIM.Transform.SourceGroupType,
// // SubjectId: sourceGroupResp.Result.Id,
// // },
// // })

// // if err != nil {
// // return scim.Resource{}, err
// // }

// // if object.Type == u.cfg.SCIM.Transform.GroupObjectType {
// // err = u.setGroupMappings(r.Context(), dirClient, resp.Result.Id)
// // if err != nil {
// // return scim.Resource{}, err
// // }
// // }
// }

// for _, relation := range transformResult.Relations {
// _, err := dirClient.Writer.SetRelation(r.Context(), &dsw.SetRelationRequest{
// Relation: relation,
// })
// if err != nil {
// return scim.Resource{}, err
// }
// }

result = u.converter.ObjectToResource(sourceGroupResp.Result, meta)

return result, nil
}
75 changes: 37 additions & 38 deletions pkg/app/handlers/groups/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ package groups
import (
"net/http"

cerr "github.com/aserto-dev/errors"
dsr "github.com/aserto-dev/go-directory/aserto/directory/reader/v3"
dsw "github.com/aserto-dev/go-directory/aserto/directory/writer/v3"
"github.com/aserto-dev/go-directory/pkg/derr"
"github.com/aserto-dev/scim/pkg/directory"
serrors "github.com/elimity-com/scim/errors"
"github.com/pkg/errors"
)

func (u GroupResourceHandler) Delete(r *http.Request, id string) error {
Expand All @@ -23,39 +19,42 @@ func (u GroupResourceHandler) Delete(r *http.Request, id string) error {
return err
}

relations, err := dirClient.Reader.GetRelations(r.Context(), &dsr.GetRelationsRequest{
SubjectType: scimConfig.GroupObjectType,
SubjectId: id,
Relation: scimConfig.SourceRelation,
})
if err != nil {
if errors.Is(cerr.UnwrapAsertoError(err), derr.ErrObjectNotFound) {
return serrors.ScimErrorResourceNotFound(id)
}
return err
}

for _, v := range relations.Results {
_, err = dirClient.Writer.DeleteObject(r.Context(), &dsw.DeleteObjectRequest{
ObjectId: v.ObjectId,
ObjectType: v.ObjectType,
WithRelations: true,
})
if err != nil {
return err
}
}

_, err = dirClient.Writer.DeleteObject(r.Context(), &dsw.DeleteObjectRequest{
ObjectType: scimConfig.GroupObjectType,
ObjectId: id,
WithRelations: true,
})
if err != nil {
if errors.Is(cerr.UnwrapAsertoError(err), derr.ErrObjectNotFound) {
return serrors.ScimErrorResourceNotFound(id)
}
}
sync := directory.NewSync(scimConfig, dirClient)
err = sync.DeleteGroup(r.Context(), id)

// relations, err := dirClient.Reader.GetRelations(r.Context(), &dsr.GetRelationsRequest{
// SubjectType: scimConfig.GroupObjectType,
// SubjectId: id,
// Relation: scimConfig.SourceRelation,
// })
// if err != nil {
// if errors.Is(cerr.UnwrapAsertoError(err), derr.ErrObjectNotFound) {
// return serrors.ScimErrorResourceNotFound(id)
// }
// return err
// }

// for _, v := range relations.Results {
// _, err = dirClient.Writer.DeleteObject(r.Context(), &dsw.DeleteObjectRequest{
// ObjectId: v.ObjectId,
// ObjectType: v.ObjectType,
// WithRelations: true,
// })
// if err != nil {
// return err
// }
// }

// _, err = dirClient.Writer.DeleteObject(r.Context(), &dsw.DeleteObjectRequest{
// ObjectType: scimConfig.GroupObjectType,
// ObjectId: id,
// WithRelations: true,
// })
// if err != nil {
// if errors.Is(cerr.UnwrapAsertoError(err), derr.ErrObjectNotFound) {
// return serrors.ScimErrorResourceNotFound(id)
// }
// }

return err
}
Loading