-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add commands to get and update root encryption key (#1541)
* feat: add commands to get and update root encryption key * chore: rename command to align with vault product
- Loading branch information
1 parent
064d7eb
commit aa52e0c
Showing
3 changed files
with
95 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,41 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/supabase/cli/internal/utils/flags" | ||
"github.com/supabase/cli/internal/vault/get" | ||
"github.com/supabase/cli/internal/vault/update" | ||
) | ||
|
||
var ( | ||
vaultCmd = &cobra.Command{ | ||
GroupID: groupManagementAPI, | ||
Use: "vault", | ||
Short: "Manage column encryption of Supabase projects", | ||
} | ||
|
||
rootKeyGetCmd = &cobra.Command{ | ||
Use: "get-root-key", | ||
Short: "Get the root encryption key of a Supabase project", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return get.Run(cmd.Context(), flags.ProjectRef) | ||
}, | ||
} | ||
|
||
rootKeyUpdateCmd = &cobra.Command{ | ||
Use: "update-root-key", | ||
Short: "Update root encryption key of a Supabase project", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return update.Run(cmd.Context(), flags.ProjectRef, os.Stdin) | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
vaultCmd.PersistentFlags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.") | ||
vaultCmd.AddCommand(rootKeyUpdateCmd) | ||
vaultCmd.AddCommand(rootKeyGetCmd) | ||
rootCmd.AddCommand(vaultCmd) | ||
} |
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,23 @@ | ||
package get | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/supabase/cli/internal/utils" | ||
) | ||
|
||
func Run(ctx context.Context, projectRef string) error { | ||
resp, err := utils.GetSupabase().GetPgsodiumConfigWithResponse(ctx, projectRef) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if resp.JSON200 == nil { | ||
return errors.New("Unexpected error retrieving project root key: " + string(resp.Body)) | ||
} | ||
|
||
fmt.Println(resp.JSON200.RootKey) | ||
return nil | ||
} |
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,31 @@ | ||
package update | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/supabase/cli/internal/utils" | ||
"github.com/supabase/cli/internal/utils/credentials" | ||
"github.com/supabase/cli/pkg/api" | ||
) | ||
|
||
func Run(ctx context.Context, projectRef string, stdin *os.File) error { | ||
fmt.Fprintf(os.Stderr, "Enter a new root key: ") | ||
input := credentials.PromptMasked(stdin) | ||
resp, err := utils.GetSupabase().UpdatePgsodiumConfigWithResponse(ctx, projectRef, api.UpdatePgsodiumConfigBody{ | ||
RootKey: strings.TrimSpace(input), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if resp.JSON200 == nil { | ||
return errors.New("Unexpected error updating project root key: " + string(resp.Body)) | ||
} | ||
|
||
fmt.Println("Finished " + utils.Aqua("supabase root-key update") + ".") | ||
return nil | ||
} |