disable command error handing improvements (#67)

This commit is contained in:
Michael Quigley 2022-09-26 16:00:50 -04:00
parent 9e14a8b0ba
commit e58fd0760f
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62

View File

@ -31,10 +31,16 @@ func newDisableCommand() *disableCommand {
func (cmd *disableCommand) run(_ *cobra.Command, args []string) { func (cmd *disableCommand) run(_ *cobra.Command, args []string) {
env, err := zrokdir.LoadEnvironment() env, err := zrokdir.LoadEnvironment()
if err != nil { if err != nil {
if !panicInstead {
showError("could not load environment; not active?", err)
}
panic(err) panic(err)
} }
zrok, err := newZrokClient(env.ApiEndpoint) zrok, err := newZrokClient(env.ApiEndpoint)
if err != nil { if err != nil {
if !panicInstead {
showError("could not create zrok service client", err)
}
panic(err) panic(err)
} }
auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.ZrokToken) auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.ZrokToken)
@ -44,9 +50,15 @@ func (cmd *disableCommand) run(_ *cobra.Command, args []string) {
} }
_, err = zrok.Identity.Disable(req, auth) _, err = zrok.Identity.Disable(req, auth)
if err != nil { if err != nil {
if !panicInstead {
showError("zrok service call failed", err)
}
panic(err) panic(err)
} }
if err := zrokdir.Delete(); err != nil { if err := zrokdir.Delete(); err != nil {
if !panicInstead {
showError("error removing local zrok directory", err)
}
panic(err) panic(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)