// setRequestObjectInfo adds necessary type information to requests. func setRequestObjectInfo(req *rest.Request, namespace string, mapping *meta.RESTMapping) { // if namespace scoped resource, set namespace req.NamespaceIfScoped(namespace, isNamespaceScoped(mapping)) // set resource name req.Resource(mapping.Resource) }
// overrideAuth specifies the token to authenticate the request with. token == "" is not allowed func overrideAuth(token *string, req *restclient.Request) (*restclient.Request, error) { if token != nil { if len(*token) == 0 { return nil, errors.New("impersonating token may not be empty") } req.SetHeader("Authorization", fmt.Sprintf("Bearer %s", *token)) } return req, nil }
// namespace applies a namespace to the request if the configured // resource is a namespaced resource. Otherwise, it just returns the // passed in request. func (rc *ResourceClient) namespace(req *restclient.Request) *restclient.Request { if rc.resource.Namespaced { return req.Namespace(rc.ns) } return req }