ClientConfig implements ClientConfig
()
| 125 | |
| 126 | // ClientConfig implements ClientConfig |
| 127 | func (config *DirectClientConfig) ClientConfig() (*restclient.Config, error) { |
| 128 | // check that getAuthInfo, getContext, and getCluster do not return an error. |
| 129 | // Do this before checking if the current config is usable in the event that an |
| 130 | // AuthInfo, Context, or Cluster config with user-defined names are not found. |
| 131 | // This provides a user with the immediate cause for error if one is found |
| 132 | configAuthInfo, err := config.getAuthInfo() |
| 133 | if err != nil { |
| 134 | return nil, err |
| 135 | } |
| 136 | |
| 137 | _, err = config.getContext() |
| 138 | if err != nil { |
| 139 | return nil, err |
| 140 | } |
| 141 | |
| 142 | configClusterInfo, err := config.getCluster() |
| 143 | if err != nil { |
| 144 | return nil, err |
| 145 | } |
| 146 | |
| 147 | if err := config.ConfirmUsable(); err != nil { |
| 148 | return nil, err |
| 149 | } |
| 150 | |
| 151 | clientConfig := &restclient.Config{} |
| 152 | clientConfig.Host = configClusterInfo.Server |
| 153 | |
| 154 | if len(config.overrides.Timeout) > 0 { |
| 155 | timeout, err := ParseTimeout(config.overrides.Timeout) |
| 156 | if err != nil { |
| 157 | return nil, err |
| 158 | } |
| 159 | clientConfig.Timeout = timeout |
| 160 | } |
| 161 | |
| 162 | if u, err := url.ParseRequestURI(clientConfig.Host); err == nil && u.Opaque == "" && len(u.Path) > 1 { |
| 163 | u.RawQuery = "" |
| 164 | u.Fragment = "" |
| 165 | clientConfig.Host = u.String() |
| 166 | } |
| 167 | if len(configAuthInfo.Impersonate) > 0 { |
| 168 | clientConfig.Impersonate = restclient.ImpersonationConfig{ |
| 169 | UserName: configAuthInfo.Impersonate, |
| 170 | Groups: configAuthInfo.ImpersonateGroups, |
| 171 | Extra: configAuthInfo.ImpersonateUserExtra, |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | // only try to read the auth information if we are secure |
| 176 | if restclient.IsConfigTransportTLS(*clientConfig) { |
| 177 | var err error |
| 178 | var persister restclient.AuthProviderConfigPersister |
| 179 | if config.configAccess != nil { |
| 180 | authInfoName, _ := config.getAuthInfoName() |
| 181 | persister = PersisterForUser(config.configAccess, authInfoName) |
| 182 | } |
| 183 | userAuthPartialConfig, err := config.getUserIdentificationPartialConfig(configAuthInfo, config.fallbackReader, persister) |
| 184 | if err != nil { |