utils

package
v0.0.0-...-c5b6784 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func Capitalize

func Capitalize(word string) string

Capitalize capitalizes the first letter of a word.

func CheckClaim

func CheckClaim(
	logger *zap.Logger,
	user *models.UserContext,
	claimName string,
	match *regexp.Regexp,
	resourceURL string,
) bool

CheckClaim checks whether claim in userContext matches claimName, match. It can be String or Strings claim.

func ContainsSubString

func ContainsSubString(value string, list []string) bool

func DecodeKeyPairs

func DecodeKeyPairs(list []string) (map[string]string, error)

func DefaultTo

func DefaultTo(v, d string) string

func DialAddress

func DialAddress(location *url.URL) string

DialAddress extracts the dial address from the url.

func FileExists

func FileExists(filename string) bool

func GenerateHmac

func GenerateHmac(req *http.Request, encKey string) (string, error)

func GetHashKey

func GetHashKey(token string) string

GetHashKey returns a hash of the encoded jwt token.

func GetRefreshedToken

func GetRefreshedToken(
	ctx context.Context,
	conf *oauth2.Config,
	httpClient *http.Client,
	oldRefreshToken string,
) (jwt.JSONWebToken, string, string, time.Time, time.Duration, error)

GetRefreshedToken attempts to refresh the access token, returning the parsed token, optionally with a renewed refresh token and the time the access and refresh tokens expire

NOTE: we may be able to extract the specific (non-standard) claim refresh_expires_in and refresh_expires from response.RawBody. When not available, keycloak provides us with the same (for now) expiry value for ID token.

func GetRequestHostURL

func GetRequestHostURL(req *http.Request) string

func GetWithin

func GetWithin(expires time.Time, within float64) time.Duration

GetWithin calculates a duration of x percent of the time period, i.e. something expires in 1 hours, get me a duration within 80%.

func HasAccess

func HasAccess(need map[string]bool, have []string, all bool) bool

func IsUpgradedConnection

func IsUpgradedConnection(req *http.Request) bool

func IsValidHTTPMethod

func IsValidHTTPMethod(method string) bool

func MergeMaps

func MergeMaps(dest, source map[string]string) map[string]string

MergeMaps simples copies the keys from source to destination.

func NewOAuth2Config

func NewOAuth2Config(
	clientID string,
	clientSecret string,
	authURL string,
	tokenURL string,
	scopes []string,
) func(redirectionURL string) *oauth2.Config

func ParseRefreshToken

func ParseRefreshToken(rawRefreshToken string) (*jwt.Claims, error)

func PrintError

func PrintError(message string, args ...interface{}) cli.ExitCoder

PrintError display the command line usage and error.

func RealIP

func RealIP(req *http.Request) string

RealIP retrieves the client ip address from a http request.

func ToHeader

func ToHeader(v string) string

func TransferBytes

func TransferBytes(src io.Reader, dest io.Writer, wg *sync.WaitGroup) (int64, error)

TransferBytes transfers bytes between the sink and source.

func TryDialEndpoint

func TryDialEndpoint(location *url.URL) (net.Conn, error)

TryDialEndpoint dials the upstream endpoint via plain HTTP.

func TryUpdateConnection

func TryUpdateConnection(req *http.Request, writer http.ResponseWriter, endpoint *url.URL) error

TryUpdateConnection attempt to upgrade the connection to a http pdy stream.

func VerifyOIDCTokens

func VerifyOIDCTokens(
	ctx context.Context,
	provider *oidc3.Provider,
	clientID string,
	rawAccessToken string,
	rawIDToken string,
	skipClientIDCheck bool,
	skipIssuerCheck bool,
) (*oidc3.IDToken, *oidc3.IDToken, error)

func VerifyToken

func VerifyToken(
	ctx context.Context,
	provider *oidc3.Provider,
	rawToken string,
	clientID string,
	skipClientIDCheck bool,
	skipIssuerCheck bool,
) (*oidc3.IDToken, error)

func WithOAuthURI

func WithOAuthURI(baseURI string, oauthURI string) func(uri string) string

WithOAuthURI returns the oauth uri.

Types

This section is empty.

Jump to

Keyboard shortcuts

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