Skip to content

Commit

Permalink
add user/group structs and update scim deps
Browse files Browse the repository at this point in the history
  • Loading branch information
florindragos committed Apr 23, 2024
1 parent 205823c commit b58ae2a
Show file tree
Hide file tree
Showing 16 changed files with 297 additions and 81 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ on:
env:
VAULT_ADDR: https://vault.eng.aserto.com/
PRE_RELEASE: ${{ github.ref == 'refs/heads/main' && 'main' || '' }}
GO_VERSION: "1.20"
GO_RELEASER_VERSION: "v1.20.0"
GO_LANGCI_LINT_VERSION: "v1.53.3"
GO_TESTSUM_VERSION: "1.10.1"
GO_VERSION: "1.22"
GO_RELEASER_VERSION: "v1.24.0"
GO_LANGCI_LINT_VERSION: "v1.56.2"
GO_TESTSUM_VERSION: "1.11.0"

jobs:
test:
Expand Down
6 changes: 3 additions & 3 deletions Depfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ go:
version: "v1.3.13"
goreleaser:
importPath: github.com/goreleaser/goreleaser
version: "v1.20.0"
version: "v1.24.0"
golangci-lint:
importPath: "github.com/golangci/golangci-lint/cmd/golangci-lint"
version: "v1.53.3"
version: "v1.56.2"
gotestsum:
importPath: "gotest.tools/gotestsum"
version: "v1.10.0"
version: "v1.11.0"

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module github.com/aserto-dev/scim

go 1.20
go 1.22

require (
github.com/aserto-dev/certs v0.0.5
github.com/aserto-dev/errors v0.0.6
github.com/aserto-dev/go-aserto v0.30.0
github.com/aserto-dev/go-directory v0.30.5
github.com/aserto-dev/logger v0.0.4
github.com/elimity-com/scim v0.0.0-20230426070224-941a5eac92f3
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
Expand Down
12 changes: 10 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/di-wu/parser v0.2.2/go.mod h1:SLp58pW6WamdmznrVRrw2NTyn4wAvT9rrEFynKX7nYo=
github.com/di-wu/parser v0.3.0 h1:NMOvy5ifswgt4gsdhySVcKOQtvjC43cHZIfViWctqQY=
github.com/di-wu/parser v0.3.0/go.mod h1:SLp58pW6WamdmznrVRrw2NTyn4wAvT9rrEFynKX7nYo=
github.com/di-wu/xsd-datetime v1.0.0 h1:vZoGNkbzpBNoc+JyfVLEbutNDNydYV8XwHeV7eUJoxI=
github.com/di-wu/xsd-datetime v1.0.0/go.mod h1:i3iEhrP3WchwseOBeIdW/zxeoleXTOzx1WyDXgdmOww=
github.com/elimity-com/scim v0.0.0-20230426070224-941a5eac92f3 h1:+zrUtdBUJpY9qptMaaY3CA3T/lBI2+QqfUbzM2uxJss=
github.com/elimity-com/scim v0.0.0-20230426070224-941a5eac92f3/go.mod h1:JkjcmqbLW+khwt2fmBPJFBhx2zGZ8XobRZ+O0VhlwWo=
github.com/elimity-com/scim v0.0.0-20240320110924-172bf2aee9c8 h1:0+BTyxIYgiVAry/P5s8R4dYuLkhB9Nhso8ogFWNr4IQ=
github.com/elimity-com/scim v0.0.0-20240320110924-172bf2aee9c8/go.mod h1:JkjcmqbLW+khwt2fmBPJFBhx2zGZ8XobRZ+O0VhlwWo=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand All @@ -52,6 +54,7 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand All @@ -64,7 +67,9 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
Expand All @@ -82,9 +87,11 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
Expand Down Expand Up @@ -190,6 +197,7 @@ google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
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=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.20
go 1.22

use (
.
Expand Down
2 changes: 1 addition & 1 deletion magefiles/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/aserto-dev/scim/magefiles

go 1.20
go 1.22

require (
github.com/aserto-dev/mage-loot v0.8.15
Expand Down
6 changes: 6 additions & 0 deletions magefiles/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand All @@ -65,6 +66,7 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/gitleaks/go-gitdiff v0.7.4 h1:8vICc4moyRR2poklblThdQ0ckMet22mEvFJSxPsiDlk=
Expand Down Expand Up @@ -143,9 +145,11 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kyokomi/emoji v2.2.4+incompatible h1:np0woGKwx9LiHAQmwZx79Oc0rHpNw3o+3evou4BEPv4=
github.com/kyokomi/emoji v2.2.4+incompatible/go.mod h1:mZ6aGCD7yk8j6QY6KICwnZ2pxoszVseX1DNoGtU2tBA=
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
Expand All @@ -172,6 +176,7 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
Expand Down Expand Up @@ -517,6 +522,7 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/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=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
Expand Down
2 changes: 1 addition & 1 deletion magefiles/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
const containerImage string = "scim"

func init() {
os.Setenv("GO_VERSION", "1.20")
os.Setenv("GO_VERSION", "1.22")
}

// Build builds all binaries in ./cmd.
Expand Down
19 changes: 12 additions & 7 deletions pkg/app/handlers/users/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ import (

func (u UsersResourceHandler) Create(r *http.Request, attributes scim.ResourceAttributes) (scim.Resource, error) {
u.logger.Trace().Any("attributes", attributes).Msg("creating user")
object, err := common.ResourceAttributesToObject(attributes, "user", attributes["userName"].(string))
user, err := common.ResourceAttributesToUser(attributes)
if err != nil {
u.logger.Error().Err(err).Msg("failed to convert attributes to user")
return scim.Resource{}, serrors.ScimErrorInvalidSyntax
}

object, err := common.UserToObject(user)
if err != nil {
u.logger.Error().Err(err).Msg("failed to convert user to object")
return scim.Resource{}, serrors.ScimErrorInvalidSyntax
}

Expand All @@ -37,16 +44,14 @@ func (u UsersResourceHandler) Create(r *http.Request, attributes scim.ResourceAt
Version: resp.Result.Etag,
})

err = u.setAllIdentities(r.Context(), resp.Result.Id, attributes)
err = u.setAllIdentities(r.Context(), resp.Result.Id, user)
if err != nil {
return scim.Resource{}, err
}

if attributes["groups"] != nil {
err = u.setUserGroups(r.Context(), resp.Result.Id, attributes["groups"].([]string))
if err != nil {
return scim.Resource{}, err
}
err = u.setUserGroups(r.Context(), resp.Result.Id, user.Groups)
if err != nil {
return scim.Resource{}, err
}

return resource, nil
Expand Down
31 changes: 1 addition & 30 deletions pkg/app/handlers/users/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/elimity-com/scim"
serrors "github.com/elimity-com/scim/errors"
"github.com/pkg/errors"
"github.com/scim2/filter-parser/v2"
)

func (u UsersResourceHandler) Get(r *http.Request, id string) (scim.Resource, error) {
Expand Down Expand Up @@ -46,19 +45,10 @@ func (u UsersResourceHandler) GetAll(r *http.Request, params scim.ListRequestPar
var (
resources = make([]scim.Resource, 0)
pageToken = ""
err error
f filter.AttributeExpression
pageSize = 100
skipIndex = 1 // start index is 1-based
)

if params.Filter != nil {
f, err = filter.ParseAttrExp([]byte(params.Filter.(*filter.AttributeExpression).String()))
if err != nil {
return scim.Page{}, err
}
}

if params.Count != 0 && params.Count < pageSize {
pageSize = params.Count
}
Expand All @@ -72,7 +62,6 @@ func (u UsersResourceHandler) GetAll(r *http.Request, params scim.ListRequestPar
pageToken = resp.Page.NextToken

for _, v := range resp.Results {
insert := false
createdAt := v.CreatedAt.AsTime()
updatedAt := v.UpdatedAt.AsTime()
resource := common.ObjectToResource(v, scim.Meta{
Expand All @@ -81,25 +70,7 @@ func (u UsersResourceHandler) GetAll(r *http.Request, params scim.ListRequestPar
Version: v.Etag,
})

if params.Filter != nil {
switch f.Operator {
case filter.EQ:
if resource.Attributes[f.AttributePath.AttributeName] == f.CompareValue {
insert = true
}
case filter.NE:
if resource.Attributes[f.AttributePath.AttributeName] != f.CompareValue {
insert = true
}
case filter.CO, filter.SW, filter.EW, filter.GT, filter.GE, filter.LT, filter.LE, filter.PR:
// TODO: implement
return scim.Page{}, serrors.ScimErrorInvalidFilter
}

} else {
insert = true
}
if insert {
if params.FilterValidator == nil || params.FilterValidator.PassesFilter(resource.Attributes) == nil {
if skipIndex <= params.StartIndex {
skipIndex++
continue
Expand Down
33 changes: 12 additions & 21 deletions pkg/app/handlers/users/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
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/common"
"github.com/aserto-dev/scim/pkg/config"
"github.com/aserto-dev/scim/pkg/directory"
"github.com/elimity-com/scim"
serrors "github.com/elimity-com/scim/errors"
"github.com/pkg/errors"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -42,7 +42,7 @@ func NewUsersResourceHandler(cfg *config.Config, logger *zerolog.Logger) (*Users
}, nil
}

func (u UsersResourceHandler) setUserGroups(ctx context.Context, userID string, groups []string) error {
func (u UsersResourceHandler) setUserGroups(ctx context.Context, userID string, groups []common.UserGroup) error {
relations, err := u.dirClient.Reader.GetRelations(ctx, &dsr.GetRelationsRequest{
SubjectType: "user",
SubjectId: userID,
Expand Down Expand Up @@ -73,7 +73,7 @@ func (u UsersResourceHandler) setUserGroups(ctx context.Context, userID string,
SubjectType: "user",
Relation: "member",
ObjectType: "group",
ObjectId: v,
ObjectId: v.Value,
}})
if err != nil {
return err
Expand Down Expand Up @@ -175,38 +175,29 @@ func (u UsersResourceHandler) removeIdentity(ctx context.Context, identity strin
return err
}

func (u UsersResourceHandler) setAllIdentities(ctx context.Context, userID string, attributes scim.ResourceAttributes) error {
if attributes["userName"] != nil {
err := u.setIdentity(ctx, userID, attributes["userName"].(string), map[string]interface{}{IdentityKindKey: "IDENTITY_KIND_USERNAME"})
func (u UsersResourceHandler) setAllIdentities(ctx context.Context, userID string, user *common.User) error {
if user.UserName != "" {
err := u.setIdentity(ctx, userID, user.UserName, map[string]interface{}{IdentityKindKey: "IDENTITY_KIND_USERNAME"})
if err != nil {
return err
}
}

if attributes["emails"] != nil && u.cfg.SCIM.CreateEmailIdentities {
for _, m := range attributes["emails"].([]interface{}) {
email, ok := m.(map[string]interface{})
if !ok {
return errors.New("emails attribute is not a list of maps")
}
if email["value"].(string) == attributes["userName"].(string) {
if u.cfg.SCIM.CreateEmailIdentities {
for _, email := range user.Emails {
if email.Value == user.UserName {
continue
}

err := u.setIdentity(ctx, userID, email["value"].(string), map[string]interface{}{IdentityKindKey: "IDENTITY_KIND_EMAIL"})
err := u.setIdentity(ctx, userID, email.Value, map[string]interface{}{IdentityKindKey: "IDENTITY_KIND_EMAIL"})
if err != nil {
return err
}
}
}

if attributes["externalId"] != nil {
externalID := attributes["externalId"]
externalIDStr, ok := externalID.(string)
if !ok {
return errors.New("externalId attribute is not a string")
}
err := u.setIdentity(ctx, userID, externalIDStr, map[string]interface{}{IdentityKindKey: "IDENTITY_KIND_PID"})
if user.ExternalID != "" {
err := u.setIdentity(ctx, userID, user.ExternalID, map[string]interface{}{IdentityKindKey: "IDENTITY_KIND_PID"})
if err != nil {
return err
}
Expand Down
17 changes: 10 additions & 7 deletions pkg/app/handlers/users/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ func (u UsersResourceHandler) Replace(r *http.Request, id string, attributes sci
return scim.Resource{}, err
}

object, err := common.ResourceAttributesToObject(attributes, "user", id)
user, err := common.ResourceAttributesToUser(attributes)
if err != nil {
return scim.Resource{}, serrors.ScimErrorInvalidSyntax
}

object, err := common.UserToObject(user)
if err != nil {
return scim.Resource{}, serrors.ScimErrorInvalidSyntax
}
Expand All @@ -41,16 +46,14 @@ func (u UsersResourceHandler) Replace(r *http.Request, id string, attributes sci
return scim.Resource{}, err
}

err = u.setAllIdentities(r.Context(), id, attributes)
err = u.setAllIdentities(r.Context(), id, user)
if err != nil {
return scim.Resource{}, err
}

if attributes["groups"] != nil {
err = u.setUserGroups(r.Context(), id, attributes["groups"].([]string))
if err != nil {
return scim.Resource{}, err
}
err = u.setUserGroups(r.Context(), id, user.Groups)
if err != nil {
return scim.Resource{}, err
}

createdAt := setResp.Result.CreatedAt.AsTime()
Expand Down
Loading

0 comments on commit b58ae2a

Please sign in to comment.