Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
feat: improve auth features
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Dec 3, 2019
1 parent e34cb53 commit 9b2b0fd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 38 deletions.
20 changes: 3 additions & 17 deletions cmd/addUser.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
Copyright © 2019 NAME HERE <EMAIL ADDRESS>
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 (
Expand All @@ -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")
},
Expand Down
5 changes: 3 additions & 2 deletions cmd/addUsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
},
Expand Down
35 changes: 16 additions & 19 deletions cmd/deleteUser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit 9b2b0fd

Please sign in to comment.