restclient

package
v0.0.0-...-5670dcb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2025 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasStatusErr

func HasStatusErr(err error, codes ...int) bool

HasStatusErr returns true if err is a ResponseError caused by any of the codes given.

func HasValidStatusCode

func HasValidStatusCode(code int, acceptStatuses ...int) bool

func IsNotFoundError

func IsNotFoundError(err error) bool

Types

type APICallType

type APICallType string

type RequestConfiguration

type RequestConfiguration struct {
	Parameters map[string]string // Path parameters
	Query      map[string]string
	Headers    map[string]string
	Cookies    map[string]string
	Body       any
	Method     string
}

type Response

type Response struct {
	ResponseBody any
	// contains filtered or unexported fields
}

TODO: maybe consider to wrap http.Response in our Response struct to have access to headers, status code, etc. In order to have isPending method attached to a complete response object.

func (*Response) IsPending

func (r *Response) IsPending() bool

type StatusError

type StatusError struct {
	StatusCode int
	Inner      error
}

func (*StatusError) Error

func (e *StatusError) Error() string

func (*StatusError) Unwrap

func (e *StatusError) Unwrap() error

type UnstructuredClient

type UnstructuredClient struct {
	IdentifierFields       []string
	IdentifiersMatchPolicy string
	Resource               *unstructured.Unstructured
	//Doc                   libopenapi.Document         // Parsed OpenAPI document by libopenapi, needed for http request validation. TODO: to be re-enabled when libopenapi-validator is stable
	DocScheme *libopenapi.DocumentModel[v3.Document] // OpenAPI document model (high-level)
	Server    string
	Debug     bool
	SetAuth   func(req *http.Request)
}

func BuildClient

func BuildClient(ctx context.Context, kubeclient dynamic.Interface, swaggerPath string) (*UnstructuredClient, error)

BuildClient is a function that builds partial client from a swagger file.

func (*UnstructuredClient) Call

func (*UnstructuredClient) CallFindBySingle

func (u *UnstructuredClient) CallFindBySingle(ctx context.Context, cli *http.Client, path string, opts *RequestConfiguration) (Response, error)

CallFindBySingle executes a non-paginated FindBy operation.

func (*UnstructuredClient) CallForPagination

func (u *UnstructuredClient) CallForPagination(ctx context.Context, cli *http.Client, path string, opts *RequestConfiguration, paginator pagination.Paginator) (Response, *http.Response, error)

CallForPagination builds an `http.Request`, lets the paginator update it, executes it, and returns the response. TODO: to be refactored to avoid code duplication with Call method. Prerequisite for refactor is to change the Response struct to wrap http.Response directly. Differences with Call are mainly the paginator usage and the removal of debug transport setup (otherwise it would be set incrementally on each paginated call).

func (*UnstructuredClient) FindBy

func (u *UnstructuredClient) FindBy(ctx context.Context, cli *http.Client, path string, opts *RequestConfiguration, findByAction *getter.VerbsDescription) (Response, error)

FindBy locates a specific resource within an API response it retrieves. It serves as the primary orchestrator for the `FindBy` action of the Rest Dynamic Controller, delegating response parsing and item matching to helper functions: extractItemsFromResponse, findItemInList, and isItemMatch.

func (*UnstructuredClient) RequestedBody

func (u *UnstructuredClient) RequestedBody(httpMethod string, path string) (bodyParams stringset.StringSet, err error)

RequestedBody is a method that returns the body parameters for a given HTTP method and path.

func (*UnstructuredClient) RequestedParams

func (u *UnstructuredClient) RequestedParams(httpMethod string, path string) (parameters, query, headers, cookies stringset.StringSet, err error)

RequestedParams is a method that returns the parameters and query parameters for a given HTTP method and path.

func (*UnstructuredClient) ValidateRequest

func (u *UnstructuredClient) ValidateRequest(httpMethod string, path string, parameters map[string]string, query map[string]string, headers map[string]string, cookies map[string]string) error

ValidateRequest is a method that validates the request parameters, query, headers, and cookies against the OpenAPI document. It checks if the required parameters are present and returns an error if any required parameter is missing.

type UnstructuredClientInterface

type UnstructuredClientInterface interface {
	ValidateRequest(httpMethod string, path string, parameters map[string]string, query map[string]string, headers map[string]string, cookies map[string]string) error
	RequestedBody(httpMethod string, path string) (bodys stringset.StringSet, err error)
	RequestedParams(httpMethod string, path string) (parameters, query, headers, cookies stringset.StringSet, err error)
	FindBy(ctx context.Context, cli *http.Client, path string, conf *RequestConfiguration, findByAction *getter.VerbsDescription) (Response, error)
	Call(ctx context.Context, cli *http.Client, path string, conf *RequestConfiguration) (Response, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL