-
-
Notifications
You must be signed in to change notification settings - Fork 178
/
unset.go
49 lines (46 loc) · 1.36 KB
/
unset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package unset
import (
"context"
"fmt"
"net/http"
"os"
"strings"
"github.com/go-errors/errors"
"github.com/spf13/afero"
"github.com/supabase/cli/internal/secrets/list"
"github.com/supabase/cli/internal/utils"
)
func Run(ctx context.Context, projectRef string, args []string, fsys afero.Fs) error {
if len(args) == 0 {
secrets, err := list.GetSecretDigests(ctx, projectRef)
if err != nil {
return err
}
for _, secret := range secrets {
if !strings.HasPrefix(secret.Name, "SUPABASE_") {
args = append(args, secret.Name)
}
}
}
// 1. Sanity checks.
if len(args) == 0 {
fmt.Fprintln(os.Stderr, "You have not set any function secrets, nothing to do.")
return nil
}
msg := fmt.Sprintf("Do you want to unset these function secrets?\n • %s\n\n", strings.Join(args, "\n • "))
if shouldUnset, err := utils.NewConsole().PromptYesNo(ctx, msg, true); err != nil {
return err
} else if !shouldUnset {
return errors.New(context.Canceled)
}
// 2. Unset secret(s).
resp, err := utils.GetSupabase().V1BulkDeleteSecretsWithResponse(ctx, projectRef, args)
if err != nil {
return errors.Errorf("failed to delete secrets: %w", err)
}
if resp.StatusCode() != http.StatusOK {
return errors.New("Unexpected error unsetting project secrets: " + string(resp.Body))
}
fmt.Println("Finished " + utils.Aqua("supabase secrets unset") + ".")
return nil
}