http

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthorizationHeaderName = "Authorization"
	IasTokenUrlPattern      = "^https:\\/\\/(accounts\\.sap\\.com|[A-Za-z0-9+]+\\.accounts400\\.ondemand\\.com|[A-Za-z0-9+]+\\.accounts\\.ondemand\\.com)"
)
View Source
const (
	METHOD                    string = "method"
	URL                       string = "url"
	TOKEN_URL                 string = "tokenUrl"
	CSRF_URL                  string = "csrfUrl"
	CLIENT_ID                 string = "clientId"
	CLIENT_SECRET             string = "clientSecret"
	REFRESH_TOKEN             string = "refreshToken"
	RESPONSE_BODY_TRANSFORMER string = "responseBodyTransformer"
	HEADERS                   string = "headers"
	BODY                      string = "body"
	USER                      string = "user"
	PASSWORD                  string = "password"
	TIMEOUT                   string = "timeout"
	SUCCESS_RESPONSE_CODES    string = "successResponseCodes"
	SUCCEED_ON_TIMEOUT        string = "succeedOnTimeout"
	TRUSTED_CERTS             string = "trustedCerts"
	CLIENT_CERT               string = "clientCert"
	TRUST_ANY_CERT            string = "trustAnyCert"
	AUTHORIZATION_HEADER      string = "authorizationHeader"
)
View Source
const (
	CACHING_KEY_FORMAT                         string = "tokenUrl=%s&oAuthUser=%s&oAuthPwd=%s&getTokenBody=%s"
	PASSWORD_GRANT_FORMAT                      string = "grant_type=password&username=%s&password=%s"
	PASSWORD_CREDENTIALS_FORMAT_WITH_CLIENT_ID string = "grant_type=password&client_id=%s&username=%s&password=%s"
	CLIENT_CREDENTIALS_FORMAT                  string = "grant_type=client_credentials&client_id=%s&client_secret=%s"
	REFRESH_TOKEN_FORMAT                       string = "grant_type=refresh_token&refresh_token=%s"
	REFRESH_TOKEN_FORMAT_WITH_CERT             string = "grant_type=refresh_token&client_id=%s&refresh_token=%s"
)
View Source
const CsrfVerb = "fetch"
View Source
const (
	DefaultHttpRequestTimeout = 3 * time.Second
)
View Source
const PASSCODE string = "passcode"

Variables

This section is empty.

Functions

func ContentTypeUrlFormEncoded

func ContentTypeUrlFormEncoded() map[string]string

func CreateAuthorizationHeader

func CreateAuthorizationHeader(params *HttpRequestParameters) (string, error)

func CreateHttpClient

func CreateHttpClient(timeoutInS uint64, certAuth *tls.CertificateAuthentication) (*http.Client, error)

func IsSuccessfulBasedOnSuccessResponseCodes

func IsSuccessfulBasedOnSuccessResponseCodes(statusCode int, successResponseCodes []string) functional.OptionWithError[HttpResponse]

func ResponseBodyTransformer added in v0.0.3

func ResponseBodyTransformer(transformer string) functional.OptionWithError[HttpResponse]

func StatusCode

func StatusCode(code int) functional.OptionWithError[HttpResponse]

Types

type AuthorizationHeaderGenerator

type AuthorizationHeaderGenerator interface {
	Generate() (string, error)
}

func NewBasicAuthorizationHeader

func NewBasicAuthorizationHeader(u string, p string) AuthorizationHeaderGenerator

func NewIasAuthorizationHeader

func NewIasAuthorizationHeader(tokenUrl, user, clientCert string) AuthorizationHeaderGenerator

type CacheableAuthorizationHeaderGenerator added in v0.0.4

type CacheableAuthorizationHeaderGenerator interface {
	AuthorizationHeaderGenerator
	GenerateWithCacheAside() (string, error)
}

func NewOAuthorizationHeaderGenerator added in v0.0.4

func NewOAuthorizationHeaderGenerator(tokenType TokenType, tokenUrl string, executor HttpExecutor, requestBody string,
	opts ...OAuthorizationHeaderOption) CacheableAuthorizationHeaderGenerator

type GrantType

type GrantType uint
const (
	GrantType_CLIENT_CREDENTIALS GrantType = iota
	GrantType_PASSWORD
	GrantType_REFRESH_TOKEN
)

func (GrantType) String

func (t GrantType) String() string

type HttpExecutor

type HttpExecutor interface {
	ExecuteWithParameters(*HttpRequestParameters) (*HttpResponse, error)
}

type HttpHeaders

type HttpHeaders map[string]string

func (HttpHeaders) String added in v0.0.4

func (h HttpHeaders) String() string

type HttpRequestExecutor

type HttpRequestExecutor struct {
	executors.Executor
}

func NewDefaultHttpRequestExecutor added in v0.0.4

func NewDefaultHttpRequestExecutor() *HttpRequestExecutor

func (*HttpRequestExecutor) Execute

func (*HttpRequestExecutor) ExecuteWithParameters

func (e *HttpRequestExecutor) ExecuteWithParameters(p *HttpRequestParameters) (*HttpResponse, error)

type HttpRequestParameters

type HttpRequestParameters struct {
	// contains filtered or unexported fields
}

func NewHttpRequestParameters

func NewHttpRequestParameters(method, url string, opts ...functional.OptionWithError[HttpRequestParameters]) (*HttpRequestParameters, error)

func NewHttpRequestParametersFromContext

func NewHttpRequestParametersFromContext(ctx executors.Context) (*HttpRequestParameters, error)

func (HttpRequestParameters) GetAuthorizationHeader

func (p HttpRequestParameters) GetAuthorizationHeader() string

func (HttpRequestParameters) GetCertificateAuthentication

func (p HttpRequestParameters) GetCertificateAuthentication() *tls.CertificateAuthentication

func (HttpRequestParameters) GetClientId

func (p HttpRequestParameters) GetClientId() string

func (HttpRequestParameters) GetClientSecret

func (p HttpRequestParameters) GetClientSecret() string

func (HttpRequestParameters) GetCsrfUrl

func (p HttpRequestParameters) GetCsrfUrl() string

func (HttpRequestParameters) GetPassword

func (p HttpRequestParameters) GetPassword() string

func (HttpRequestParameters) GetRefreshToken

func (p HttpRequestParameters) GetRefreshToken() string

func (HttpRequestParameters) GetTokenUrl

func (p HttpRequestParameters) GetTokenUrl() string

func (HttpRequestParameters) GetUser

func (p HttpRequestParameters) GetUser() string

type HttpResponse

type HttpResponse struct {
	Url                     string      `json:"url"`
	Method                  string      `json:"method"`
	Content                 string      `json:"body"`
	Headers                 HttpHeaders `json:"headers"`
	StatusCode              string      `json:"status"`
	SizeInBytes             uint64      `json:"size"`
	Time                    int64       `json:"time"`
	ResponseBodyTransformer string      `json:"responseBodyTransformer"`
	// contains filtered or unexported fields
}

func NewHttpResponse

func NewHttpResponse(opts ...functional.OptionWithError[HttpResponse]) (*HttpResponse, error)

func (HttpResponse) ToMap

func (r HttpResponse) ToMap() map[string]string

type IllegalTokenTypeError

type IllegalTokenTypeError struct {
	// contains filtered or unexported fields
}

func NewIllegalTokenTypeError

func NewIllegalTokenTypeError(tokenType TokenType) *IllegalTokenTypeError

func (*IllegalTokenTypeError) Error

func (e *IllegalTokenTypeError) Error() string

type OAuthToken

type OAuthToken struct {
	TokenType   string `json:"token_type"`
	AccessToken string `json:"access_token"`
	IdToken     string `json:"id_token,omitempty"`
	ExpiresIn   int64  `json:"expires_in,omitempty"`
}

func NewOAuthToken

func NewOAuthToken(token string) (*OAuthToken, error)

type OAuthorizationHeaderOption added in v0.0.4

type OAuthorizationHeaderOption func(*oAuthorizationHeaderGenerator)

func UseCertificateAuthentication

func UseCertificateAuthentication(certAuthentication *tls.CertificateAuthentication) OAuthorizationHeaderOption

func WithAuthenticationHeader added in v0.0.4

func WithAuthenticationHeader(header string) OAuthorizationHeaderOption

func WithCacheStore added in v0.0.6

func WithCacheStore(store map[string]string) OAuthorizationHeaderOption

func WithCachingKey added in v0.0.4

func WithCachingKey(cacheKey string) OAuthorizationHeaderOption

type TokenFetcher

type TokenFetcher interface {
	Fetch() (string, error)
	// contains filtered or unexported methods
}

func NewCsrfTokenFetcher

func NewCsrfTokenFetcher(p *HttpRequestParameters, authHeader string) TokenFetcher

func NewIasTokenFetcher

func NewIasTokenFetcher(tokenUrl, user, clientCert string) TokenFetcher

func NewOAuthTokenFetcher

func NewOAuthTokenFetcher(opts ...functional.Option[oAuthTokenFetcher]) TokenFetcher

type TokenType

type TokenType uint
const (
	TokenType_ACCESS TokenType = iota
	TokenType_ID
)

func (TokenType) String

func (t TokenType) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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