Skip to content

Commit

Permalink
Feat: Add group diff to print difference of 2 groups
Browse files Browse the repository at this point in the history
  • Loading branch information
popsu committed Oct 13, 2023
1 parent b7dca29 commit 28d1941
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
28 changes: 28 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/okta/okta-sdk-golang/v2/okta"
"github.com/okta/okta-sdk-golang/v2/okta/query"
"github.com/samber/lo"
)

type OIClient struct {
Expand Down Expand Up @@ -148,3 +149,30 @@ func (oi *OIClient) PrintUsersInGroup(wantGroupName string) error {

return nil
}

// PrintGroupDiff prints the difference of 2 groups
func (oi *OIClient) PrintGroupDiff(groupA, groupB string) error {
groupAUsers, err := oi.GetUsersInGroup(groupA)
if err != nil {
return err
}
groupBUsers, err := oi.GetUsersInGroup(groupB)
if err != nil {
return err
}

notInB, notInA := lo.Difference(groupAUsers, groupBUsers)

fmt.Printf("Users in %s, but not in %s:\n", groupA, groupB)
for _, user := range notInB {
fmt.Println(user)
}
fmt.Println()

fmt.Printf("Users in %s, but not in %s:\n", groupB, groupA)
for _, user := range notInA {
fmt.Println(user)
}

return nil
}
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module github.com/popsu/okta-info

go 1.21.1

require github.com/okta/okta-sdk-golang/v2 v2.20.0
require (
github.com/okta/okta-sdk-golang/v2 v2.20.0
github.com/samber/lo v1.38.1
)

require (
github.com/BurntSushi/toml v1.1.0 // indirect
Expand All @@ -12,6 +15,7 @@ require (
github.com/kr/pretty v0.1.0 // indirect
github.com/patrickmn/go-cache v0.0.0-20180815053127-5633e0862627 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ github.com/patrickmn/go-cache v0.0.0-20180815053127-5633e0862627 h1:pSCLCl6joCFR
github.com/patrickmn/go-cache v0.0.0-20180815053127-5633e0862627/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
Expand All @@ -31,6 +33,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM=
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM=
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ func run() error {
return oic.PrintUsersInGroup(os.Args[2])
case "user":
return oic.PrintGroupsForUser(os.Args[2])
case "diff":
return oic.PrintGroupDiff(os.Args[2], os.Args[3])
default:
fmt.Println("Invalid subcommand. Valid commands are: group and user")
fmt.Println("Invalid subcommand. Valid commands are: group, diff and user")
os.Exit(1)
}
// should not get here ever
Expand Down

0 comments on commit 28d1941

Please sign in to comment.