newOpenshiftClient creates a new openshiftClient for the specified reference.
(ref openshiftReference)
| 30 | |
| 31 | // newOpenshiftClient creates a new openshiftClient for the specified reference. |
| 32 | func newOpenshiftClient(ref openshiftReference) (*openshiftClient, error) { |
| 33 | // We have already done this parsing in ParseReference, but thrown away |
| 34 | // httpClient. So, parse again. |
| 35 | // (We could also rework/split restClientFor to "get base URL" to be done |
| 36 | // in ParseReference, and "get httpClient" to be done here. But until/unless |
| 37 | // we support non-default clusters, this is good enough.) |
| 38 | |
| 39 | // Overall, this is modelled on openshift/origin/pkg/cmd/util/clientcmd.New().ClientConfig() and openshift/origin/pkg/client. |
| 40 | cmdConfig := defaultClientConfig() |
| 41 | logrus.Debugf("cmdConfig: %#v", cmdConfig) |
| 42 | restConfig, err := cmdConfig.ClientConfig() |
| 43 | if err != nil { |
| 44 | return nil, err |
| 45 | } |
| 46 | // REMOVED: SetOpenShiftDefaults (values are not overridable in config files, so hard-coded these defaults.) |
| 47 | logrus.Debugf("restConfig: %#v", restConfig) |
| 48 | baseURL, httpClient, err := restClientFor(restConfig) |
| 49 | if err != nil { |
| 50 | return nil, err |
| 51 | } |
| 52 | logrus.Debugf("URL: %#v", *baseURL) |
| 53 | |
| 54 | if httpClient == nil { |
| 55 | httpClient = http.DefaultClient |
| 56 | } |
| 57 | |
| 58 | return &openshiftClient{ |
| 59 | ref: ref, |
| 60 | baseURL: baseURL, |
| 61 | httpClient: httpClient, |
| 62 | bearerToken: restConfig.BearerToken, |
| 63 | username: restConfig.Username, |
| 64 | password: restConfig.Password, |
| 65 | }, nil |
| 66 | } |
| 67 | |
| 68 | func (c *openshiftClient) close() { |
| 69 | c.httpClient.CloseIdleConnections() |
no test coverage detected
searching dependent graphs…