()
| 42 | } |
| 43 | |
| 44 | func (f *apiClientFactory) getClient() (APIClient, error) { |
| 45 | // Now if the API key and address is not provided (we are not connecting to a remote instance), |
| 46 | // try to rip it out of the config. |
| 47 | if f.cfg.RawAddress == "" && f.cfg.APIKey == "" { |
| 48 | var err error |
| 49 | f.cfg, err = loadGUIConfig() |
| 50 | if err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | } else if f.cfg.Address() == "" || f.cfg.APIKey == "" { |
| 54 | return nil, errors.New("Both --gui-address and --gui-apikey should be specified") |
| 55 | } |
| 56 | |
| 57 | httpClient := http.Client{ |
| 58 | Transport: &http.Transport{ |
| 59 | TLSClientConfig: &tls.Config{ |
| 60 | InsecureSkipVerify: true, |
| 61 | }, |
| 62 | DialContext: func(_ context.Context, _, _ string) (net.Conn, error) { |
| 63 | return net.Dial(f.cfg.Network(), f.cfg.Address()) |
| 64 | }, |
| 65 | }, |
| 66 | } |
| 67 | return &apiClient{ |
| 68 | Client: httpClient, |
| 69 | cfg: f.cfg, |
| 70 | apikey: f.cfg.APIKey, |
| 71 | }, nil |
| 72 | } |
| 73 | |
| 74 | func loadGUIConfig() (config.GUIConfiguration, error) { |
| 75 | // Load the certs and get the ID |
no test coverage detected