From 335e24a993df2625c22002eccf881f3f31e0b1fc Mon Sep 17 00:00:00 2001 From: Uzair Ali <72073401+uzaxirr@users.noreply.github.com> Date: Sat, 27 Apr 2024 11:42:31 +0530 Subject: [PATCH] Provide dashboard Link in case of no API set --- config/config.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index f26c493a..2afd78b5 100644 --- a/config/config.go +++ b/config/config.go @@ -264,7 +264,12 @@ func DefaultAPIKey() string { // CivoAPIClient returns a civogo client using the current default API key func CivoAPIClient() (*civogo.Client, error) { - cliClient, err := civogo.NewClientWithURL(DefaultAPIKey(), Current.Meta.URL, Current.Meta.DefaultRegion) + apiKey := DefaultAPIKey() + if apiKey == "" { + fmt.Printf("Error: Creating the connection to Civo's API failed because no API key is supplied. This is required to authenticate requests. Please go to https://dashboard.civo.com/security to obtain your API key, then save it using the command 'civo apikey save YOUR_API_KEY'.\n") + return nil, fmt.Errorf("no API Key supplied, this is required") + } + cliClient, err := civogo.NewClientWithURL(apiKey, Current.Meta.URL, Current.Meta.DefaultRegion) if err != nil { return nil, err }