better disable cleanup; keep frontend identity around after disable

This commit is contained in:
Michael Quigley 2022-10-13 15:15:44 -04:00
parent 462025f5fa
commit 201982f25f
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
4 changed files with 37 additions and 20 deletions

View File

@ -55,11 +55,16 @@ func (cmd *disableCommand) run(_ *cobra.Command, args []string) {
} }
panic(err) panic(err)
} }
if err := zrokdir.Delete(); err != nil { if err := zrokdir.DeleteEnvironment(); err != nil {
if !panicInstead { if !panicInstead {
showError("error removing local zrok directory", err) showError("error removing zrok environment", err)
} }
panic(err) panic(err)
} }
if err := zrokdir.DeleteZitiIdentity("backend"); err != nil {
if !panicInstead {
showError("error removing zrok backend identity", err)
}
}
fmt.Printf("zrok environment '%v' disabled for '%v'\n", env.ZitiIdentityId, env.ZrokToken) fmt.Printf("zrok environment '%v' disabled for '%v'\n", env.ZitiIdentityId, env.ZrokToken)
} }

View File

@ -79,7 +79,7 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
} }
panic(err) panic(err)
} }
if err := zrokdir.WriteZitiIdentity("environment", resp.Payload.Cfg); err != nil { if err := zrokdir.SaveZitiIdentity("backend", resp.Payload.Cfg); err != nil {
if !panicInstead { if !panicInstead {
showError("there was an error writing the environment file", err) showError("there was an error writing the environment file", err)
} }

View File

@ -67,7 +67,7 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
} }
panic(err) panic(err)
} }
zif, err := zrokdir.ZitiIdentityFile("environment") zif, err := zrokdir.ZitiIdentityFile("backend")
if err != nil { if err != nil {
ui.Close() ui.Close()
if !panicInstead { if !panicInstead {

View File

@ -14,17 +14,6 @@ type Environment struct {
ApiEndpoint string `json:"api_endpoint"` ApiEndpoint string `json:"api_endpoint"`
} }
func Delete() error {
path, err := zrokDir()
if err != nil {
return err
}
if err := os.RemoveAll(path); err != nil {
return err
}
return nil
}
func LoadEnvironment() (*Environment, error) { func LoadEnvironment() (*Environment, error) {
ef, err := environmentFile() ef, err := environmentFile()
if err != nil { if err != nil {
@ -59,7 +48,27 @@ func SaveEnvironment(env *Environment) error {
return nil return nil
} }
func WriteZitiIdentity(name, data string) error { func DeleteEnvironment() error {
ef, err := environmentFile()
if err != nil {
return errors.Wrap(err, "error getting environment file")
}
if err := os.Remove(ef); err != nil {
return errors.Wrap(err, "error removing environment file")
}
return nil
}
func ZitiIdentityFile(name string) (string, error) {
zrd, err := zrokDir()
if err != nil {
return "", err
}
return filepath.Join(zrd, "identities", fmt.Sprintf("%v.json", name)), nil
}
func SaveZitiIdentity(name, data string) error {
zif, err := ZitiIdentityFile(name) zif, err := ZitiIdentityFile(name)
if err != nil { if err != nil {
return err return err
@ -73,12 +82,15 @@ func WriteZitiIdentity(name, data string) error {
return nil return nil
} }
func ZitiIdentityFile(name string) (string, error) { func DeleteZitiIdentity(name string) error {
zrd, err := zrokDir() zif, err := ZitiIdentityFile(name)
if err != nil { if err != nil {
return "", err return errors.Wrapf(err, "error getting ziti identity file path for '%v'", name)
} }
return filepath.Join(zrd, "identities", fmt.Sprintf("%v.json", name)), nil if err := os.Remove(zif); err != nil {
return errors.Wrapf(err, "error removing ziti identity file '%v'", zif)
}
return nil
} }
func environmentFile() (string, error) { func environmentFile() (string, error) {