-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: doctor command for troubleshooting
- Loading branch information
1 parent
dbd3e68
commit 32e8a72
Showing
5 changed files
with
106 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os/exec" | ||
|
||
"github.com/fatih/color" | ||
) | ||
|
||
func doctor() { | ||
|
||
// Check if gcloud sdk is available | ||
gcloudversioncommand := fmt.Sprintf("gcloud version | head -n 1") | ||
gcloudversion := exec.Command("bash", "-c", gcloudversioncommand) | ||
gcloudversionout, err := gcloudversion.Output() | ||
if err != nil { | ||
fmt.Println("Please reinstall gcloud sdk") | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("gcloud version: %s", gcloudversionout) | ||
|
||
// Check if user is authenticated in gcloud | ||
gcloudusercommand := fmt.Sprintf("gcloud auth list --filter=status:ACTIVE --format='value(account)'") | ||
gclouduser := exec.Command("bash", "-c", gcloudusercommand) | ||
gclouduserout, err := gclouduser.Output() | ||
if err != nil { | ||
fmt.Println("User not authenticated\nRun: gcloud auth application-default login") | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("Authenticated user account: %s", gclouduserout) | ||
|
||
// Check if cloud_sql_proxy is installed | ||
cloudsqlproxyversion := exec.Command("cloud_sql_proxy", "--version") | ||
cloudsqlproxyversionout, err := cloudsqlproxyversion.Output() | ||
if err != nil { | ||
fmt.Println("Please reinstall cloud_sql_proxy") | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("cloud_sql_proxy version: %s", cloudsqlproxyversionout) | ||
|
||
//Print eveything is ok | ||
green := color.New(color.FgGreen) | ||
boldGreen := green.Add(color.Bold) | ||
boldGreen.Printf("Your system is ready to connect CloudSQL instances") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters