This repository has been archived by the owner on May 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Command For Unsetting Custom Claims
Adds the ability to remove custom claims from the user. It is not perfect yet, as it replaces key with null. #20
- Loading branch information
1 parent
721de83
commit a294766
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/mainawycliffe/kamanda/firebase/auth" | ||
"github.com/mainawycliffe/kamanda/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// unsetCustomClaimsCmd represents the unsetCustomClaims command | ||
var unsetCustomClaimsCmd = &cobra.Command{ | ||
Use: "custom-claims", | ||
Aliases: []string{"customClaims"}, | ||
Short: "Unset custom claims from a firebase user account", | ||
Example: "kamanda users unset custom-claims --keys \"role\"", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
keys, _ := cmd.Flags().GetStringArray("keys") | ||
hasError := false | ||
for _, v := range args { | ||
user, err := auth.RemoveCustomClaimFromUser(context.Background(), v, keys) | ||
if err != nil { | ||
hasError = true | ||
utils.StdOutError(os.Stderr, "Error removing custom claims for %s (%s)\n", v, user.Email) | ||
continue | ||
} | ||
utils.StdOutSuccess(os.Stdout, "Successfully remove custom claims for %s (%s)\n", v, user.Email) | ||
} | ||
if hasError { | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
}, | ||
} | ||
|
||
func init() { | ||
unsetCmd.AddCommand(unsetCustomClaimsCmd) | ||
unsetCustomClaimsCmd.Flags().StringArray("keys", nil, "Custom claims keys to remove") | ||
if err := unsetCustomClaimsCmd.MarkFlagRequired("keys"); err != nil { | ||
utils.StdOutError(os.Stderr, "%s\n", err.Error()) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters