Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/functions/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func parseEnvFile(envFilePath string, fsys afero.Fs) ([]string, error) {
envFilePath = filepath.Join(utils.CurrentDirAbs, envFilePath)
}
env := []string{}
secrets, err := set.ListSecrets(envFilePath, fsys)
secrets, err := set.ListSecretsWithConfig(envFilePath, fsys)
for _, v := range secrets {
env = append(env, fmt.Sprintf("%s=%s", v.Name, v.Value))
}
Expand Down
8 changes: 8 additions & 0 deletions internal/secrets/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,20 @@ func Run(ctx context.Context, projectRef, envFilePath string, args []string, fsy
}

func ListSecrets(envFilePath string, fsys afero.Fs, envArgs ...string) (api.CreateSecretBody, error) {
return parseSecrets(map[string]string{}, envFilePath, fsys, envArgs...)
}

func ListSecretsWithConfig(envFilePath string, fsys afero.Fs, envArgs ...string) (api.CreateSecretBody, error) {
envMap := map[string]string{}
for name, secret := range utils.Config.EdgeRuntime.Secrets {
if len(secret.SHA256) > 0 {
envMap[name] = secret.Value
}
}
return parseSecrets(envMap, envFilePath, fsys, envArgs...)
}

func parseSecrets(envMap map[string]string, envFilePath string, fsys afero.Fs, envArgs ...string) (api.CreateSecretBody, error) {
if len(envFilePath) > 0 {
parsed, err := parseEnvFile(envFilePath, fsys)
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions internal/secrets/set/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/supabase/cli/internal/testing/apitest"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/pkg/api"
"github.com/supabase/cli/pkg/config"
)

func TestSecretSetCommand(t *testing.T) {
Expand Down Expand Up @@ -65,6 +66,21 @@ func TestSecretSetCommand(t *testing.T) {
assert.Empty(t, apitest.ListUnmatchedRequests())
})

t.Run("Ignores edge runtime config secrets", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
secrets := utils.Config.EdgeRuntime.Secrets
t.Cleanup(func() { utils.Config.EdgeRuntime.Secrets = secrets })
utils.Config.EdgeRuntime.Secrets = config.SecretsConfig{
"FOO": {Value: "foo", SHA256: "hash"},
}
// Run test
result, err := ListSecrets("", fsys, "BAR=bar")
// Check error
assert.NoError(t, err)
assert.ElementsMatch(t, api.CreateSecretBody{{Name: "BAR", Value: "bar"}}, result)
})

t.Run("throws error on empty secret", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
Expand Down
Loading