// VersionedParams will take the provided object, serialize it to a map[string][]string using the // implicit RESTClient API version and the default parameter codec, and then add those as parameters // to the request. Use this to provide versioned query parameters from client libraries. func (r *Request) VersionedParams(obj runtime.Object, codec runtime.ParameterCodec) *Request { if r.err != nil { return r } params, err := codec.EncodeParameters(obj, *r.content.GroupVersion) if err != nil { r.err = err return r } for k, v := range params { for _, value := range v { // TODO: Move it to setParam method, once we get rid of // FieldSelectorParam & LabelSelectorParam methods. if k == unversioned.LabelSelectorQueryParam(r.content.GroupVersion.String()) && value == "" { // Don't set an empty selector for backward compatibility. // Since there is no way to get the difference between empty // and unspecified string, we don't set it to avoid having // labelSelector= param in every request. continue } if k == unversioned.FieldSelectorQueryParam(r.content.GroupVersion.String()) { if len(value) == 0 { // Don't set an empty selector for backward compatibility. // Since there is no way to get the difference between empty // and unspecified string, we don't set it to avoid having // fieldSelector= param in every request. continue } // TODO: Filtering should be handled somewhere else. selector, err := fields.ParseSelector(value) if err != nil { r.err = fmt.Errorf("unparsable field selector: %v", err) return r } filteredSelector, err := selector.Transform( func(field, value string) (newField, newValue string, err error) { return fieldMappings.filterField(r.content.GroupVersion, r.resource, field, value) }) if err != nil { r.err = fmt.Errorf("untransformable field selector: %v", err) return r } value = filteredSelector.String() } r.setParam(k, value) } } return r }
// FieldsSelectorParam adds the given selector as a query parameter with the name paramName. func (r *Request) FieldsSelectorParam(s fields.Selector) *Request { if r.err != nil { return r } if s == nil { return r } if s.Empty() { return r } s2, err := s.Transform(func(field, value string) (newField, newValue string, err error) { return fieldMappings.filterField(r.content.GroupVersion, r.resource, field, value) }) if err != nil { r.err = err return r } return r.setParam(unversioned.FieldSelectorQueryParam(r.content.GroupVersion.String()), s2.String()) }