utils

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HELMNAMESPACEENV = "POD_NAMESPACE"
)
View Source
const (
	HttpSchemePath = "https://"
)

Variables

This section is empty.

Functions

func CalculateBackoff

func CalculateBackoff(retryCount uint8) time.Duration

Calculates the backoff duration for exponential backoff based on the retry count

func CloseHttpClient

func CloseHttpClient(resp *http.Response)

closing an HTTP client's response body

func ComputePageRange

func ComputePageRange(pageSize int32, offset int32, totalCount int) (int, int)

ComputePageRange computes the startIndex and endIndex based on the provided pageSize, offset and totalCount. It returns -1 for the endIndex if there are no items to paginate. This function is used during the handling of pageSize/Offset in a HTTP Query

func ConvertUrlToSecretpath

func ConvertUrlToSecretpath(urls string) (string, error)

ConvertUrlToFilepath converts URL to File path example: before: https://registry.intel.com/hello after: registryintelcom

func CopyFile

func CopyFile(dstName, srcName string) (written int64, err error)

func CreateHttpHeaderReq

func CreateHttpHeaderReq(method, url string, body *bytes.Reader, headers map[string]string) (*http.Request, error)

Creates an HTTP request with the specified method, URL, request body, and headers

headers := map[string]string{
	"Authorization": rc.AdminBearerToken,
	"Accept": "application/json",
	"Content-Type": "application/json",
	// you can add more headers here
}

func CreateHttpHeaderReqCtx

func CreateHttpHeaderReqCtx(ctx context.Context, method, url string, body *bytes.Reader, headers map[string]string) (*http.Request, error)

Creates an HTTP request with the specified context, method, URL, request body, and headers

headers := map[string]string{
	"Authorization": rc.AdminBearerToken,
	"Accept": "application/json",
	"Content-Type": "application/json",
	// you can add more headers here
}

func CreateRequestBody

func CreateRequestBody(bodyReq interface{}) (*bytes.Reader, error)

createRequestBody creates a request body from the given input using JSON marshaling

func DoHttpRequestWithRetry

func DoHttpRequestWithRetry(req *http.Request, httpClient *http.Client, maxRetries uint8) (*http.Response, error)

The function attempts to send the request using the client, with the ability to retry multiple times in case of failure.

func DownloadFile

func DownloadFile(filepath string, fileurl string) error

DownloadFile Downloads file through url and copies it to the specified path

func FileExists

func FileExists(filename string) bool

func FilterPredicates

func FilterPredicates(filters []*Filter, columns map[string]string) ([]func(s *sql.Selector), error)

FilterPredicates creates SQL predicates based on provided Filter configuration.

func GrpcToHttpStatusCode

func GrpcToHttpStatusCode(grpcStatus codes.Code) int

GrpcToHttpStatusCode coverts grpc status code to http status code

func HttpToGrpcStatusCode

func HttpToGrpcStatusCode(httpStatusCode int) codes.Code

HttpToGrpcStatusCode coverts http status code to grpc status code

func IsAbsFilePath

func IsAbsFilePath(path string) error

func IsUrl

func IsUrl(u string) bool

IsUrl checks if the present

func IsValidDNSName

func IsValidDNSName(dnsName string) error

func IsValidFile

func IsValidFile(filename string) bool

func IsValidHost

func IsValidHost(host string) error

IsValidHost TODO: This is a stupid validation. Fix this ASAP

func IsValidHostnamePort

func IsValidHostnamePort(val string) bool

IsValidHostnamePort validates a <dns>:<port> combination for fields typically used for socket address.

func IsValidIPV4Port

func IsValidIPV4Port(uRL string) error

IsValidIPV4Port assumes the uRL is of the format <ip>:<port> for a valid url. The other assumption is that the host is a valid IP4 TODO: Enhance this function later if other formats are valid

func IsValidNamespace

func IsValidNamespace(ns string) error

IsValidNamespace TODO: fix this rudimentary validation

func IsValidPort

func IsValidPort(port string) error

func IsValidPortInt

func IsValidPortInt(port int) error

func IsValidUrl

func IsValidUrl(url string) error

func NewInClusterClient

func NewInClusterClient() (kubernetes.Interface, error)

func NewInClusterDynamicClient

func NewInClusterDynamicClient() (dynamic.Interface, error)

func OrderByOptions

func OrderByOptions(orderBys []*OrderBy, columns map[string]string) ([]func(selector *sql.Selector), error)

OrderByOptions generates SQL selector based on the Ordering configuration and Valid Columns on which ordering is allowed

func RemoveFile

func RemoveFile(name string) error

func RetrieveFQDN

func RetrieveFQDN(urls string) (string, error)

RetrieveFQDN inspect and remove the sheme of http protocol example: before: https://registry.intel.com/hello after: registry.intel.com

func SetHttpHeaders

func SetHttpHeaders(req *http.Request, headers map[string]string)

Sets the headers of an HTTP request using the provided key-value pairs input paramter example:

headers := map[string]string{
	"Authorization": rc.AdminBearerToken,
	"Accept": "application/json",
	"Content-Type": "application/json",
	// you can add more headers here
}

func StartHttpReadinessProbe

func StartHttpReadinessProbe(readinessProbe string, baseURL string, pattern string, uri string)

func TerminateSideCar

func TerminateSideCar(istioQuitEndpoint string) error

Types

type Filelink string
const (
	Symbollink Filelink = "symbol"
	Hardlink   Filelink = "hard"
	Normalfile Filelink = "normal"
	Wrongfile  Filelink = ""
)
func CheckFileLink(filename string) Filelink

type Filter

type Filter struct {
	Name  string
	Value string
}

func ParseFilter

func ParseFilter(filterParameter string) ([]*Filter, error)

ParseFilter parses the given filter string and returns a list of Filter If any error is encountered, an nil Filter slice and non-nil error is returned

type KubernetesAPI

type KubernetesAPI struct {
	Client kubernetes.Interface
}

func (*KubernetesAPI) NewInClusterClient

func (kapi *KubernetesAPI) NewInClusterClient() error

type OrderBy

type OrderBy struct {
	Name   string
	IsDesc bool
}

func ParseOrderBy

func ParseOrderBy(orderByParameter string) ([]*OrderBy, error)

ParseOrderBy parses the incoming orderBy query string Below is a sample orderBy query specifying that the results should be sorted that name is ascending and create_time should be descending

/books?orderBy="name asc, create_time desc"

type SchemeType

type SchemeType string
const (
	HttpScheme SchemeType = "https://"
)

Jump to

Keyboard shortcuts

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