queryLAPIStatus checks if the Local API is reachable, and if the credentials are correct.
(ctx context.Context, hub *cwhub.Hub, credURL string, login string, password string)
| 24 | |
| 25 | // queryLAPIStatus checks if the Local API is reachable, and if the credentials are correct. |
| 26 | func queryLAPIStatus(ctx context.Context, hub *cwhub.Hub, credURL string, login string, password string) (bool, error) { |
| 27 | apiURL, err := url.Parse(credURL) |
| 28 | if err != nil { |
| 29 | return false, err |
| 30 | } |
| 31 | |
| 32 | client, err := apiclient.NewDefaultClient(apiURL, |
| 33 | LAPIURLPrefix, |
| 34 | "", |
| 35 | nil) |
| 36 | if err != nil { |
| 37 | return false, err |
| 38 | } |
| 39 | |
| 40 | pw := strfmt.Password(password) |
| 41 | |
| 42 | itemsForAPI := hub.GetInstalledListForAPI() |
| 43 | |
| 44 | t := models.WatcherAuthRequest{ |
| 45 | MachineID: &login, |
| 46 | Password: &pw, |
| 47 | Scenarios: itemsForAPI, |
| 48 | } |
| 49 | |
| 50 | _, _, err = client.Auth.AuthenticateWatcher(ctx, t) |
| 51 | if err != nil { |
| 52 | return false, err |
| 53 | } |
| 54 | |
| 55 | return true, nil |
| 56 | } |
| 57 | |
| 58 | func (cli *cliLapi) Status(ctx context.Context, out io.Writer, hub *cwhub.Hub) error { |
| 59 | cfg := cli.cfg() |
no test coverage detected
searching dependent graphs…