From 9b2b0fd45abf6d3249feb09d755b5f4cef8cbf28 Mon Sep 17 00:00:00 2001 From: Maina Wycliffe Date: Tue, 3 Dec 2019 23:19:37 +0300 Subject: [PATCH] feat: improve auth features --- cmd/addUser.go | 20 +++----------------- cmd/addUsers.go | 5 +++-- cmd/deleteUser.go | 35 ++++++++++++++++------------------- 3 files changed, 22 insertions(+), 38 deletions(-) diff --git a/cmd/addUser.go b/cmd/addUser.go index effec6e..ebc2d00 100644 --- a/cmd/addUser.go +++ b/cmd/addUser.go @@ -1,18 +1,3 @@ -/* -Copyright © 2019 NAME HERE - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ package cmd import ( @@ -23,8 +8,9 @@ import ( // addUserCmd represents the addUser command var addUserCmd = &cobra.Command{ - Use: "addUser", - Short: "Add a new Firebase user", + Use: "addUser", + Aliases: []string{"add-user", "add"}, + Short: "Add a new Firebase user", Run: func(cmd *cobra.Command, args []string) { fmt.Println("addUser called") }, diff --git a/cmd/addUsers.go b/cmd/addUsers.go index 695b66c..3d489d9 100644 --- a/cmd/addUsers.go +++ b/cmd/addUsers.go @@ -8,8 +8,9 @@ import ( // addUsersCmd represents the addUsers command var addUsersCmd = &cobra.Command{ - Use: "addUsers", - Short: "Add new multiple Firebase Users", + Use: "addUsers", + Aliases: []string{"add-users"}, + Short: "Add multiple Firebase Auth Users from file - JSON or YAML Supported!", Run: func(cmd *cobra.Command, args []string) { fmt.Println("addUsers called") }, diff --git a/cmd/deleteUser.go b/cmd/deleteUser.go index aa2d0ba..ac6e4f4 100644 --- a/cmd/deleteUser.go +++ b/cmd/deleteUser.go @@ -2,41 +2,38 @@ package cmd import ( "context" + "errors" "fmt" - "log" - "github.com/mainawycliffe/kamanda/firebase/auth" + "github.com/mainawycliffe/kamanda/firebase" "github.com/spf13/cobra" ) // deleteUserCmd represents the deleteUser command var deleteUserCmd = &cobra.Command{ - Use: "deleteUser", - Short: "Delete a Firebase User", - Run: func(cmd *cobra.Command, args []string) { - - uid, err := cmd.Flags().GetString("uid") - - if err != nil { - log.Fatalf("Error while reading uid flag: %s", err.Error()) + Use: "deleteUsers", + Aliases: []string{"delete-users", "delete"}, + Short: "Delete multiple Firebase Auth User by their UID", + RunE: func(cmd *cobra.Command, args []string) error { + // args = list of uids + if len(args) == 0 { + return errors.New("atleast one Firebase user uid is required!") } - fmt.Println(fmt.Sprintf("deleteUser called %v", uid)) + fmt.Println(fmt.Sprintf("deleteUser called %v", args)) - // call firebase auth to delete firebase - err = auth.DeleteFirebaseUser(context.Background(), nil, uid) + firebase := &firebase.Firebase{} + + err := firebase.InitializeFirbeaseApp(context.Background(), "") if err != nil { - log.Fatalf("%s", err.Error()) + return err } + + return nil }, } func init() { authCmd.AddCommand(deleteUserCmd) - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - deleteUserCmd.Flags().String("uid", "", "The UID of the Firebase User you want to delete (required)") - _ = deleteUserCmd.MarkFlagRequired("uid") }