/
check.go
38 lines (35 loc) · 1.05 KB
/
check.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package command
import (
"coscale/api"
"os"
)
// CheckObjectName is the name of the check-config subcommand
var CheckObjectName = "check-config"
// CheckObject is the check-config subcommand and is used to check to api configuration
var CheckObject = &Command{
Name: CheckObjectName,
UsageLine: `check-config is used to check to api configuration file`,
Run: func(cmd *Command, args []string) {
// check for getting the config file path
file, err := GetConfigPath()
if err != nil {
cmd.PrintResult("", err)
}
// check if the file actually exists
if _, err := os.Stat(file); err != nil {
cmd.PrintResult("", err)
}
// check if the configuration file can be parsed
config, err := api.ReadApiConfiguration(file)
if err != nil {
cmd.PrintResult("", err)
}
// check if we can loggin with this configuration
api := api.NewApi(config.BaseUrl, config.AccessToken, config.AppId, false)
err = api.Login()
if err != nil {
cmd.PrintResult("", err)
}
cmd.PrintResult(`{"msg":"Configuration successfuly checked!"}`, nil)
},
}