diff --git a/cmd/pull.go b/cmd/pull.go index a7bd745..42c2cd8 100644 --- a/cmd/pull.go +++ b/cmd/pull.go @@ -1,11 +1,7 @@ package cmd import ( - "cloud.google.com/go/firestore" - "context" - firebase "firebase.google.com/go" "fmt" - "log" "ssm-v2/internal/store" "github.com/spf13/cobra" @@ -29,17 +25,3 @@ var pullCmd = &cobra.Command{ func init() { syncCmd.AddCommand(pullCmd) } - -func test(app *firebase.App) { - client, err := app.Firestore(context.Background()) - if err != nil { - log.Fatalf("error getting Firestore client: %v", err) - } - defer func(client *firestore.Client) { - err := client.Close() - if err != nil { - return - } - }(client) - -} diff --git a/cmd/push.go b/cmd/push.go index 2fe2ce3..22afe54 100644 --- a/cmd/push.go +++ b/cmd/push.go @@ -1,9 +1,13 @@ package cmd import ( + "cloud.google.com/go/firestore" + "context" "fmt" - + "github.com/sirupsen/logrus" "github.com/spf13/cobra" + "log" + "ssm-v2/internal/store" ) // pushCmd represents the push command @@ -12,20 +16,41 @@ var pushCmd = &cobra.Command{ Short: "A brief description of your command", Long: ``, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("push called") + user, err := store.LoginUser(userEmail, userPassword) + if err != nil { + fmt.Println(err) + return + } + + userId := user["user_id"].(string) + + upload(userId) }, } func init() { syncCmd.AddCommand(pushCmd) +} - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // pushCmd.PersistentFlags().String("foo", "", "A help for foo") +func upload(documentID string) { + client, err := store.App.Firestore(context.Background()) + if err != nil { + log.Fatalf("error getting Firestore client: %v", err) + } + defer func(client *firestore.Client) { + err := client.Close() + if err != nil { + return + } + }(client) - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // pushCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + configurations := client.Collection("configurations") + //configurations. + _, err = configurations.Doc(documentID).Create(context.Background(), map[string]interface{}{ + "something": "with nothing", + }) + if err != nil { + logrus.Fatalf("error adding configuration: %v", err) + } + logrus.Info("Configuration uploaded with reference %s", documentID) } diff --git a/cmd/sync.go b/cmd/sync.go index 49ab011..976b1df 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -4,6 +4,11 @@ import ( "github.com/spf13/cobra" ) +var ( + userEmail string + userPassword string +) + // syncCmd represents the sync command var syncCmd = &cobra.Command{ Use: "sync", @@ -15,4 +20,9 @@ var syncCmd = &cobra.Command{ func init() { rootCmd.AddCommand(syncCmd) + syncCmd.PersistentFlags().StringVarP(&userEmail, "email", "e", "", "email address") + syncCmd.PersistentFlags().StringVarP(&userPassword, "password", "p", "", "password") + _ = syncCmd.MarkPersistentFlagRequired("email") + _ = syncCmd.MarkPersistentFlagRequired("password") + } diff --git a/internal/store/firebase.go b/internal/store/firebase.go index 9fd1415..3038547 100644 --- a/internal/store/firebase.go +++ b/internal/store/firebase.go @@ -113,7 +113,6 @@ func parseToken(tokenString string) map[string]interface{} { if err != nil { log.Fatalf("Error parsing token: %v", err) } - fmt.Println(token) if claims, ok := token.Claims.(jwt.MapClaims); ok { result := make(map[string]interface{}) if email, ok := claims["email"]; ok {