Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
77e6c5e
Update dependencies
carabasdaniel Apr 10, 2025
7b179a1
Fix sdk linting issues
carabasdaniel Apr 11, 2025
bd76d0e
Fix linting for openapi, okta and ldap plugins
carabasdaniel Apr 11, 2025
fbfa2de
Fix linting in jumpcloud, google and fusionauth plugins
carabasdaniel Apr 14, 2025
2336137
Fix linting for azuread, azuredb2c and cognito plugins
carabasdaniel Apr 14, 2025
27587c4
Fix auth0 and cli linting errors
carabasdaniel Apr 14, 2025
8ba9f1c
Update ci go linter and go releaser versions
carabasdaniel Apr 14, 2025
11440b6
Use linting rules from topaz and update formatting with gofumpt
carabasdaniel Apr 15, 2025
fdba13a
Update error messages and address review comments
carabasdaniel Apr 15, 2025
7c4eece
Merge commit 'f46d21fedde94c6732608fab3845d95f60d09e77' into updates
carabasdaniel Apr 15, 2025
1363ce7
Update cognito fetch groups func
carabasdaniel Apr 15, 2025
f20611d
Update azuread plugin fetcher
carabasdaniel Apr 16, 2025
b3320c7
Update azureadb2c fetcher
carabasdaniel Apr 16, 2025
ba5768e
Update google and azure plugin fetchers
carabasdaniel Apr 17, 2025
cd92aed
Update auth0 plugin fetcher and httpclient
carabasdaniel Apr 22, 2025
9e30c50
Add fetcher helpers to sdk
carabasdaniel Apr 23, 2025
4ac7be3
Remove BASE_DIR from makefile
carabasdaniel Apr 23, 2025
69c5807
Address review comments
carabasdaniel Apr 24, 2025
0170d18
Fix generic fetcher map yield helper
carabasdaniel Apr 24, 2025
ebcb245
Create a custom error writer in sdk
carabasdaniel Apr 25, 2025
ea1a067
Update error writer
carabasdaniel Apr 29, 2025
670337f
ErrorWriter embeds an io.Writer
ronenh Apr 30, 2025
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
50 changes: 24 additions & 26 deletions plugins/auth0/pkg/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (f *Fetcher) fetchUsers(ctx context.Context, outputWriter *js.JSONArrayWrit
}

for _, user := range users {
obj, err := f.buildOutputObjects(ctx, user)
obj, err := f.userToMap(ctx, user)
if err != nil {
common.WriteErrorWithExitCode(errorWriter, err, 1)
}
Expand All @@ -120,7 +120,7 @@ func (f *Fetcher) fetchUsers(ctx context.Context, outputWriter *js.JSONArrayWrit
}

// return a object map to output or a boolean to skip current user.
func (f *Fetcher) buildOutputObjects(ctx context.Context, user *management.User) (map[string]any, error) {
func (f *Fetcher) userToMap(ctx context.Context, user *management.User) (map[string]any, error) {
var obj map[string]any

res, err := user.MarshalJSON()
Expand Down Expand Up @@ -175,7 +175,7 @@ func (f *Fetcher) fetchGroups(ctx context.Context, outputWriter *js.JSONArrayWri
for _, role := range roles {
res := role.String()

var obj map[string]interface{}
var obj map[string]any

if err := json.Unmarshal([]byte(res), &obj); err != nil {
common.WriteErrorWithExitCode(errorWriter, err, 1)
Expand Down Expand Up @@ -261,11 +261,11 @@ func (f *Fetcher) fetchRoles(ctx context.Context, opts []management.RequestOptio

func (f *Fetcher) fetchUserRoles(ctx context.Context, uID string) ([]map[string]any, error) {
page := 0
finished := false
hasNext := true

var results []map[string]any

for !finished {
for hasNext {
reqOpts := management.Page(page)

roles, err := f.client.Mgmt.User.Roles(ctx, uID, reqOpts)
Expand All @@ -287,9 +287,7 @@ func (f *Fetcher) fetchUserRoles(ctx context.Context, uID string) ([]map[string]
results = append(results, obj)
}

if !roles.HasNext() {
finished = true
}
hasNext = roles.HasNext()

page++
}
Expand All @@ -299,11 +297,11 @@ func (f *Fetcher) fetchUserRoles(ctx context.Context, uID string) ([]map[string]

func (f *Fetcher) fetchOrgs(ctx context.Context, uID string) ([]map[string]any, error) {
page := 0
finished := false
hasNext := true

var results []map[string]any

for !finished {
for hasNext {
reqOpts := management.Page(page)

orgs, err := f.client.Mgmt.User.Organizations(ctx, uID, reqOpts)
Expand All @@ -312,25 +310,23 @@ func (f *Fetcher) fetchOrgs(ctx context.Context, uID string) ([]map[string]any,
}

for _, org := range orgs.Organizations {
obj, err := formatObject(org)
obj, err := toJSONMap(org)
if err != nil {
return nil, err
}

results = append(results, obj)
}

if !orgs.HasNext() {
finished = true
}
hasNext = orgs.HasNext()

page++
}

return results, nil
}

func formatObject(org any) (map[string]any, error) {
func toJSONMap(org any) (map[string]any, error) {
res, err := json.Marshal(org)
if err != nil {
return nil, err
Expand All @@ -352,7 +348,16 @@ func (f *Fetcher) getConnectionQuery() string {
return `identities.connection:"` + f.ConnectionName + `"`
}

// Specialized SAML user list function
type User struct {
management.User
}

type UserList struct {
management.List
Users []*User `json:"users"`
}

// UserList is a specialized SAML user list function
//
// The Auth0 golang SDK does not properly handle the unmarshal of the returned payload into a management.UserList.
//
Expand All @@ -362,19 +367,12 @@ func (f *Fetcher) getConnectionQuery() string {
// "email_verified":"user@domain.com"
//
// Which results in an unmarshal error when calling
// `func (m *UserManager) List(ctx context.Context, opts ...RequestOption) (ul *UserList, err error)`
//
// func (m *UserManager) List(ctx context.Context, opts ...RequestOption) (ul *UserList, err error)
//
// resulting in an error `strconv.ParseBool: parsing "user@domain.com": invalid syntax`
//
// The implementation below works around the issues by using custom JSON marshaling to map the values into the management.User instances.
type User struct {
management.User
}

type UserList struct {
management.List
Users []*User `json:"users"`
}

func (ul UserList) UserList() []*management.User {
return lo.Map(ul.Users, func(v *User, i int) *management.User { return &v.User })
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/azuread/pkg/azureclient/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c *RefreshTokenCredential) GetToken(ctx context.Context, options policy.To
// process the response
defer res.Body.Close()

var responseData map[string]interface{}
var responseData map[string]any

body, _ := io.ReadAll(res.Body)

Expand Down
8 changes: 4 additions & 4 deletions plugins/azuread/pkg/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (f *Fetcher) fetchUsers(ctx context.Context) iter.Seq2[map[string]any, erro
return fetcher.YieldError(err)
}

return fetcher.YieldMap(func(object any) ([]byte, error) {
return fetcher.YieldMap(aadUsers, func(object any) ([]byte, error) {
user, ok := object.(models.Userable)
if !ok {
return nil, errors.ErrUnsupported
Expand All @@ -90,7 +90,7 @@ func (f *Fetcher) fetchUsers(ctx context.Context) iter.Seq2[map[string]any, erro
objString := "{" + string(objBytes) + "}"

return []byte(objString), nil
}, aadUsers)
})
}

func (f *Fetcher) fetchGroups(ctx context.Context) iter.Seq2[map[string]any, error] {
Expand All @@ -99,7 +99,7 @@ func (f *Fetcher) fetchGroups(ctx context.Context) iter.Seq2[map[string]any, err
return fetcher.YieldError(err)
}

return fetcher.YieldMap(func(object any) ([]byte, error) {
return fetcher.YieldMap(aadGroups, func(object any) ([]byte, error) {
group, ok := object.(models.Groupable)
if !ok {
return nil, errors.ErrUnsupported
Expand All @@ -119,5 +119,5 @@ func (f *Fetcher) fetchGroups(ctx context.Context) iter.Seq2[map[string]any, err
objString := "{" + string(objBytes) + "}"

return []byte(objString), nil
}, aadGroups)
})
}
2 changes: 1 addition & 1 deletion plugins/azureadb2c/pkg/azureclient/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c *RefreshTokenCredential) GetToken(ctx context.Context, options policy.To
// process the response
defer res.Body.Close()

var responseData map[string]interface{}
var responseData map[string]any

body, _ := io.ReadAll(res.Body)

Expand Down
8 changes: 4 additions & 4 deletions plugins/azureadb2c/pkg/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (f *Fetcher) fetchUsers(ctx context.Context) iter.Seq2[map[string]any, erro
return fetcher.YieldError(err)
}

return fetcher.YieldMap(func(object any) ([]byte, error) {
return fetcher.YieldMap(aadUsers, func(object any) ([]byte, error) {
user, ok := object.(models.Userable)
if !ok {
return nil, errors.ErrUnsupported
Expand All @@ -90,7 +90,7 @@ func (f *Fetcher) fetchUsers(ctx context.Context) iter.Seq2[map[string]any, erro
objString := "{" + string(objBytes) + "}"

return []byte(objString), nil
}, aadUsers)
})
}

func (f *Fetcher) fetchGroups(ctx context.Context) iter.Seq2[map[string]any, error] {
Expand All @@ -99,7 +99,7 @@ func (f *Fetcher) fetchGroups(ctx context.Context) iter.Seq2[map[string]any, err
return fetcher.YieldError(err)
}

return fetcher.YieldMap(func(object any) ([]byte, error) {
return fetcher.YieldMap(aadGroups, func(object any) ([]byte, error) {
group, ok := object.(models.Groupable)
if !ok {
return nil, errors.ErrUnsupported
Expand All @@ -119,5 +119,5 @@ func (f *Fetcher) fetchGroups(ctx context.Context) iter.Seq2[map[string]any, err
objString := "{" + string(objBytes) + "}"

return []byte(objString), nil
}, aadGroups)
})
}
4 changes: 2 additions & 2 deletions plugins/cognito/pkg/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (f *Fetcher) Fetch(ctx context.Context, outputWriter, errorWriter io.Writer
return err
}

var obj map[string]interface{}
var obj map[string]any
if err := json.Unmarshal(userBytes, &obj); err != nil {
_, _ = errorWriter.Write([]byte(err.Error()))
}
Expand Down Expand Up @@ -103,5 +103,5 @@ func (f *Fetcher) fetchGroups() iter.Seq2[map[string]any, error] {
return fetcher.YieldError(err)
}

return fetcher.YieldMap(json.Marshal, groups)
return fetcher.YieldMap(groups, json.Marshal)
}
2 changes: 1 addition & 1 deletion plugins/fusionauth/pkg/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (f *Fetcher) Fetch(ctx context.Context, outputWriter, errorWriter io.Writer
return err
}

var obj map[string]interface{}
var obj map[string]any
if err := json.Unmarshal(userBytes, &obj); err != nil {
_, _ = errorWriter.Write([]byte(err.Error()))
return err
Expand Down
2 changes: 1 addition & 1 deletion plugins/google/pkg/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (f *Fetcher) fetchUsers() iter.Seq2[map[string]any, error] {
return fetcher.YieldError(err)
}

return fetcher.YieldMap(json.Marshal, users)
return fetcher.YieldMap(users, json.Marshal)
}

func (f *Fetcher) fetchGroups() iter.Seq2[map[string]any, error] {
Expand Down
6 changes: 3 additions & 3 deletions plugins/jumpcloud/pkg/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (f *Fetcher) Fetch(ctx context.Context, outputWriter, errorWriter io.Writer
continue
}

var obj map[string]interface{}
var obj map[string]any

if err := json.Unmarshal(userBytes, &obj); err != nil {
common.WriteErrorWithExitCode(errorWriter, err, 1)
Expand Down Expand Up @@ -86,7 +86,7 @@ func (f *Fetcher) fetchGroups(ctx context.Context,
continue
}

var obj map[string]interface{}
var obj map[string]any
if err := json.Unmarshal(groupBytes, &obj); err != nil {
common.WriteErrorWithExitCode(errorWriter, err, 1)
continue
Expand All @@ -101,7 +101,7 @@ func (f *Fetcher) fetchGroups(ctx context.Context,
if err != nil {
common.WriteErrorWithExitCode(errorWriter, err, 1)
} else {
var users []map[string]interface{}
var users []map[string]any
if err := json.Unmarshal(usersInGroupBytes, &users); err != nil {
common.WriteErrorWithExitCode(errorWriter, err, 1)
}
Expand Down
26 changes: 13 additions & 13 deletions plugins/okta/pkg/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ func (fetcher *Fetcher) fetchGroups(ctx context.Context, writer *js.JSONArrayWri
return nil
}

func (fetcher *Fetcher) processUser(ctx context.Context, user *okta.User, errorWriter io.Writer) (map[string]interface{}, error) {
func (fetcher *Fetcher) processUser(ctx context.Context, user *okta.User, errorWriter io.Writer) (map[string]any, error) {
userBytes, err := json.Marshal(user)
if err != nil {
common.SetExitCode(1)
return nil, err
}

var userResult map[string]interface{}
var userResult map[string]any

if err := json.Unmarshal(userBytes, &userResult); err != nil {
common.SetExitCode(1)
Expand Down Expand Up @@ -160,14 +160,14 @@ func (fetcher *Fetcher) processUser(ctx context.Context, user *okta.User, errorW
return userResult, nil
}

func (fetcher *Fetcher) processGroup(ctx context.Context, group *okta.Group, errorWriter io.Writer) (map[string]interface{}, error) {
func (fetcher *Fetcher) processGroup(ctx context.Context, group *okta.Group, errorWriter io.Writer) (map[string]any, error) {
userBytes, err := json.Marshal(group)
if err != nil {
common.SetExitCode(1)
return nil, err
}

var groupResult map[string]interface{}
var groupResult map[string]any

if err := json.Unmarshal(userBytes, &groupResult); err != nil {
common.SetExitCode(1)
Expand All @@ -188,10 +188,10 @@ func (fetcher *Fetcher) processGroup(ctx context.Context, group *okta.Group, err
return groupResult, nil
}

func (fetcher *Fetcher) getGroups(ctx context.Context, userID string, errorWriter io.Writer) ([]map[string]interface{}, error) {
func (fetcher *Fetcher) getGroups(ctx context.Context, userID string, errorWriter io.Writer) ([]map[string]any, error) {
var (
response *okta.APIResponse
result []map[string]interface{}
result []map[string]any
groups []okta.Group
err error
)
Expand All @@ -210,7 +210,7 @@ func (fetcher *Fetcher) getGroups(ctx context.Context, userID string, errorWrite
return nil, err
}

var obj map[string]interface{}
var obj map[string]any
if err := json.Unmarshal(groupBytes, &obj); err != nil {
return nil, err
}
Expand All @@ -231,10 +231,10 @@ func (fetcher *Fetcher) getGroups(ctx context.Context, userID string, errorWrite
return result, nil
}

func (fetcher *Fetcher) getUserRoles(ctx context.Context, userID string, errorWriter io.Writer) ([]map[string]interface{}, error) {
func (fetcher *Fetcher) getUserRoles(ctx context.Context, userID string, errorWriter io.Writer) ([]map[string]any, error) {
var (
response *okta.APIResponse
result []map[string]interface{}
result []map[string]any
roles []okta.Role
err error
)
Expand All @@ -253,7 +253,7 @@ func (fetcher *Fetcher) getUserRoles(ctx context.Context, userID string, errorWr
return nil, err
}

var obj map[string]interface{}
var obj map[string]any

if err := json.Unmarshal(roleBytes, &obj); err != nil {
return nil, err
Expand All @@ -275,10 +275,10 @@ func (fetcher *Fetcher) getUserRoles(ctx context.Context, userID string, errorWr
return result, nil
}

func (fetcher *Fetcher) getGroupRoles(ctx context.Context, groupID string, errorWriter io.Writer) ([]map[string]interface{}, error) {
func (fetcher *Fetcher) getGroupRoles(ctx context.Context, groupID string, errorWriter io.Writer) ([]map[string]any, error) {
var (
response *okta.APIResponse
result []map[string]interface{}
result []map[string]any
roles []okta.Role
err error
)
Expand All @@ -297,7 +297,7 @@ func (fetcher *Fetcher) getGroupRoles(ctx context.Context, groupID string, error
return nil, err
}

var obj map[string]interface{}
var obj map[string]any
if err := json.Unmarshal(roleBytes, &obj); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/openapi/pkg/openapi/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func New(directory, specURL, idFormat, serviceName string) (*Client, error) {

if serviceName != "" {
if doc.Info.Extensions == nil {
doc.Info.Extensions = make(map[string]interface{}, 0)
doc.Info.Extensions = make(map[string]any, 0)
}

doc.Info.Extensions["ServiceName"] = canonicalizeServiceName(serviceName, Canonical)
Expand Down
Loading
Loading