mirror of
https://github.com/openziti/zrok.git
synced 2025-02-13 00:40:02 +01:00
improved self-service error messages for zrok invite and zrok enable (#145)
This commit is contained in:
parent
71c0503bf4
commit
6035207f2e
@ -57,7 +57,8 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
zrok, err := zrd.Client()
|
zrok, err := zrd.Client()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
cmd.endpointError(zrd.ApiEndpoint())
|
||||||
|
tui.Error("error creating service client", err)
|
||||||
}
|
}
|
||||||
auth := httptransport.APIKeyAuth("X-TOKEN", "header", token)
|
auth := httptransport.APIKeyAuth("X-TOKEN", "header", token)
|
||||||
req := environment.NewEnableParams()
|
req := environment.NewEnableParams()
|
||||||
@ -87,6 +88,7 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
|
|||||||
prg.Send(fmt.Sprintf("the zrok service returned an error: %v", err))
|
prg.Send(fmt.Sprintf("the zrok service returned an error: %v", err))
|
||||||
prg.Quit()
|
prg.Quit()
|
||||||
<-done
|
<-done
|
||||||
|
cmd.endpointError(zrd.ApiEndpoint())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
prg.Send("writing the environment details...")
|
prg.Send("writing the environment details...")
|
||||||
@ -110,6 +112,14 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
|
|||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cmd *enableCommand) endpointError(apiEndpoint, _ string) {
|
||||||
|
fmt.Printf("%v\n\n", tui.ErrorStyle.Render("there was a problem enabling your environment!"))
|
||||||
|
fmt.Printf("you are trying to use the zrok service at: %v\n\n", tui.CodeStyle.Render(apiEndpoint))
|
||||||
|
fmt.Printf("you can change your zrok service endpoint using this command:\n\n")
|
||||||
|
fmt.Printf("%v\n\n", tui.CodeStyle.Render("$ zrok config set apiEndpoint <newEndpoint>"))
|
||||||
|
fmt.Printf("(where newEndpoint is something like: %v)\n\n", tui.CodeStyle.Render("https://some.zrok.io"))
|
||||||
|
}
|
||||||
|
|
||||||
func getHost() (string, string, error) {
|
func getHost() (string, string, error) {
|
||||||
info, err := host.Info()
|
info, err := host.Info()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -44,13 +44,6 @@ func newInviteCommand() *inviteCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cmd *inviteCommand) run(_ *cobra.Command, _ []string) {
|
func (cmd *inviteCommand) run(_ *cobra.Command, _ []string) {
|
||||||
if _, err := tea.NewProgram(&cmd.tui).Run(); err != nil {
|
|
||||||
tui.Error("unable to run interface", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
if cmd.tui.done {
|
|
||||||
email := cmd.tui.inputs[0].Value()
|
|
||||||
|
|
||||||
zrd, err := zrokdir.Load()
|
zrd, err := zrokdir.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tui.Error("error loading zrokdir", err)
|
tui.Error("error loading zrokdir", err)
|
||||||
@ -59,10 +52,19 @@ func (cmd *inviteCommand) run(_ *cobra.Command, _ []string) {
|
|||||||
zrok, err := zrd.Client()
|
zrok, err := zrd.Client()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
|
cmd.endpointError(zrd.ApiEndpoint())
|
||||||
tui.Error("error creating zrok api client", err)
|
tui.Error("error creating zrok api client", err)
|
||||||
}
|
}
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := tea.NewProgram(&cmd.tui).Run(); err != nil {
|
||||||
|
tui.Error("unable to run interface", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if cmd.tui.done {
|
||||||
|
email := cmd.tui.inputs[0].Value()
|
||||||
|
|
||||||
req := account.NewInviteParams()
|
req := account.NewInviteParams()
|
||||||
req.Body = &rest_model_zrok.InviteRequest{
|
req.Body = &rest_model_zrok.InviteRequest{
|
||||||
Email: email,
|
Email: email,
|
||||||
@ -70,16 +72,22 @@ func (cmd *inviteCommand) run(_ *cobra.Command, _ []string) {
|
|||||||
}
|
}
|
||||||
_, err = zrok.Account.Invite(req)
|
_, err = zrok.Account.Invite(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !panicInstead {
|
cmd.endpointError(zrd.ApiEndpoint())
|
||||||
tui.Error("error creating invitation", err)
|
tui.Error("error creating invitation", err)
|
||||||
}
|
}
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("invitation sent to '%v'!\n", email)
|
fmt.Printf("invitation sent to '%v'!\n", email)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cmd *inviteCommand) endpointError(apiEndpoint, _ string) {
|
||||||
|
fmt.Printf("%v\n\n", tui.ErrorStyle.Render("there was a problem creating an invitation!"))
|
||||||
|
fmt.Printf("you are trying to use the zrok service at: %v\n\n", tui.CodeStyle.Render(apiEndpoint))
|
||||||
|
fmt.Printf("you can change your zrok service endpoint using this command:\n\n")
|
||||||
|
fmt.Printf("%v\n\n", tui.CodeStyle.Render("$ zrok config set apiEndpoint <newEndpoint>"))
|
||||||
|
fmt.Printf("(where newEndpoint is something like: %v)\n\n", tui.CodeStyle.Render("https://some.zrok.io"))
|
||||||
|
}
|
||||||
|
|
||||||
type inviteTui struct {
|
type inviteTui struct {
|
||||||
focusIndex int
|
focusIndex int
|
||||||
msg string
|
msg string
|
||||||
|
Loading…
Reference in New Issue
Block a user