Skip to content

Commit 033ba80

Browse files
--purge arg on remove
1 parent 6d4cd9b commit 033ba80

File tree

8 files changed

+51
-0
lines changed

8 files changed

+51
-0
lines changed

cmd/sst/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,14 @@ var root = &cli.Command{
837837
Long: "Only run it for the given component.",
838838
},
839839
},
840+
{
841+
Name: "purge",
842+
Type: "bool",
843+
Description: cli.Description{
844+
Short: "Fully remove the stage state",
845+
Long: "Remove all state associated with the stage, including the passphrase. Warning: This is irreversible and the stage's encryption key and state will be permanently lost.",
846+
},
847+
},
840848
},
841849
Run: CmdRemove,
842850
},

cmd/sst/remove.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func CmdRemove(c *cli.Cli) error {
4747
err = p.Run(c.Context, &project.StackInput{
4848
Command: "remove",
4949
Target: target,
50+
Purge: c.Bool("purge"),
5051
ServerPort: s.Port,
5152
Verbose: c.Bool("verbose"),
5253
})

pkg/project/provider/aws.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,22 @@ func (a *AwsHome) getPassphrase(app string, stage string) (string, error) {
691691
return *result.Parameter.Value, nil
692692
}
693693

694+
func (a *AwsHome) removePassphrase(app, stage string) error {
695+
ssmClient := ssm.NewFromConfig(a.provider.config)
696+
697+
_, err := ssmClient.DeleteParameter(context.TODO(), &ssm.DeleteParameterInput{
698+
Name: aws.String(a.pathForPassphrase(app, stage)),
699+
})
700+
if err != nil {
701+
var pnf *ssmTypes.ParameterNotFound
702+
if errors.As(err, &pnf) {
703+
return nil
704+
}
705+
return err
706+
}
707+
return nil
708+
}
709+
694710
func (a *AwsHome) setPassphrase(app, stage, passphrase string) error {
695711
ssmClient := ssm.NewFromConfig(a.provider.config)
696712

pkg/project/provider/cloudflare.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ func (c *CloudflareHome) removeData(kind, app, stage string) error {
169169
return nil
170170
}
171171

172+
func (c *CloudflareHome) removePassphrase(app, stage string) error {
173+
return c.removeData("passphrase", app, stage)
174+
}
175+
172176
// these should go into secrets manager once it's out of beta
173177
func (c *CloudflareHome) setPassphrase(app, stage string, passphrase string) error {
174178
return c.putData("passphrase", app, stage, bytes.NewReader([]byte(passphrase)))

pkg/project/provider/local.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ func (l *LocalHome) removeData(key, app, stage string) error {
6565
return os.Remove(p)
6666
}
6767

68+
func (c *LocalHome) removePassphrase(app, stage string) error {
69+
return c.removeData("passphrase", app, stage)
70+
}
71+
6872
// these should go into secrets manager once it's out of beta
6973
func (c *LocalHome) setPassphrase(app, stage string, passphrase string) error {
7074
return c.putData("passphrase", app, stage, bytes.NewReader([]byte(passphrase)))

pkg/project/provider/provider.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Home interface {
2929
getPassphrase(app, stage string) (string, error)
3030
listStages(app string) ([]string, error)
3131
cleanup(key, app, stage string) error
32+
removePassphrase(app, stage string) error
3233
info() (util.KeyValuePairs[string], error)
3334
}
3435

@@ -168,6 +169,19 @@ func Cleanup(backend Home, app, stage string) error {
168169
return nil
169170
}
170171

172+
func Purge(backend Home, app, stage string) error {
173+
if err := backend.removeData("secret", app, stage); err != nil {
174+
return err
175+
}
176+
if err := backend.removeData("app", app, stage); err != nil {
177+
return err
178+
}
179+
if err := backend.removePassphrase(app, stage); err != nil {
180+
return err
181+
}
182+
return nil
183+
}
184+
171185
func GetSecrets(backend Home, app, stage string) (map[string]string, error) {
172186
if stage == "" {
173187
stage = "_fallback"

pkg/project/run.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,9 @@ loop:
653653

654654
if input.Command == "remove" && len(complete.Resources) == 0 {
655655
provider.Cleanup(p.home, p.app.Name, p.app.Stage)
656+
if input.Purge {
657+
provider.Purge(p.home, p.app.Name, p.app.Stage)
658+
}
656659
}
657660

658661
log.Info("done running stack command", "resources", len(complete.Resources))

pkg/project/stack.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type StackInput struct {
2323
Dev bool
2424
Verbose bool
2525
Continue bool
26+
Purge bool
2627
SkipHash string
2728
PolicyPath string
2829
}

0 commit comments

Comments
 (0)