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

add additional login ids to mgmt cli #336

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Changes from all commits
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
31 changes: 21 additions & 10 deletions examples/managementcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import (
// Command line flags

var flags struct {
LoginID string
Email string
Phone string
Name string
Tenants []string
Domains []string
Description string
Permissions []string
LoginID string
Email string
Phone string
Name string
Tenants []string
Domains []string
Description string
Permissions []string
AdditionalLoginIDs []string
}

// Descope SDK
Expand Down Expand Up @@ -57,10 +58,14 @@ func userCreate(args []string) error {
tenants = append(tenants, &descope.AssociatedTenant{TenantID: tenantID})
}
user := &descope.UserRequest{}
user.Email = "[email protected]"
user.Email = flags.Email
user.Phone = flags.Phone
if flags.Email == "" && flags.Phone == "" {
user.Email = "[email protected]" // email or phone are required
Copy link
Member

@shilgapira shilgapira Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user.Email = "[email protected]" // email or phone are required

Why are we not just throwing an error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought about this as well, but it makes the API of the cli a bit more complex, I believe that this is the reason we add the default email in the first place

}
user.Name = flags.Name
user.Tenants = tenants
user.AdditionalLoginIDs = flags.AdditionalLoginIDs
_, err := descopeClient.Management.User().Create(context.Background(), args[0], user)
return err
}
Expand All @@ -71,10 +76,14 @@ func userUpdate(args []string) error {
tenants = append(tenants, &descope.AssociatedTenant{TenantID: tenantID})
}
user := &descope.UserRequest{}
user.Email = "[email protected]"
user.Email = flags.Email
user.Phone = flags.Phone
if flags.Email == "" && flags.Phone == "" {
user.Email = "[email protected]" // email or phone are required
}
user.Name = flags.Name
user.Tenants = tenants
user.AdditionalLoginIDs = flags.AdditionalLoginIDs

_, err := descopeClient.Management.User().Update(context.Background(), args[0], user)
return err
Expand Down Expand Up @@ -547,6 +556,7 @@ func main() {
cmd.Flags().StringVarP(&flags.Phone, "phone", "P", "", "the user's phone number")
cmd.Flags().StringVarP(&flags.Name, "name", "N", "", "the user's display name")
cmd.Flags().StringSliceVarP(&flags.Tenants, "tenants", "T", nil, "the ids of the user's tenants")
cmd.Flags().StringSliceVar(&flags.AdditionalLoginIDs, "additional-login-ids", nil, "the user's additional login id")
})

addCommand(userUpdate, "user-update <loginID>", "Update an existing user", func(cmd *cobra.Command) {
Expand All @@ -555,6 +565,7 @@ func main() {
cmd.Flags().StringVarP(&flags.Phone, "phone", "P", "", "the user's phone number")
cmd.Flags().StringVarP(&flags.Name, "name", "N", "", "the user's display name")
cmd.Flags().StringSliceVarP(&flags.Tenants, "tenants", "T", nil, "the ids of the user's tenants")
cmd.Flags().StringSliceVar(&flags.AdditionalLoginIDs, "additional-login-ids", nil, "the user's additional login id")
})

addCommand(userDelete, "user-delete <loginID>", "Delete an existing user", func(cmd *cobra.Command) {
Expand Down