http

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AUTHORIZATION_HEADER_NAME string = "Authorization"
	IAS_TOKEN_URL_PATTERN     string = "^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"
	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 (
	CONTENT_TYPE_HEADER              string  = "Content-Type"
	CONTENT_TYPE_URL_ENCODED         string  = "application/x-www-form-urlencoded"
	TOKEN_EXPIRATION_TIME_PERCENTAGE float32 = 0.95
)
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 CSRF_VERB = "fetch"
View Source
const (
	DEFAULT_HTTP_REQUEST_TIMEOUT_IN_S = 3 * time.Second
)
View Source
const (
	INVALID_OAUTH_TOKEN_ERROR_MESSAGE = "Invalid oAuth 2.0 token response.\nURL: %s\nMethod: %s\nResponse code: %s"
)
View Source
const PASSCODE string = "passcode"

Variables

This section is empty.

Functions

func ContentTypeUrlFormEncoded

func ContentTypeUrlFormEncoded() map[string]string

func CreateHttpClient

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

func IsSuccessfulBasedOnSuccessResponseCodes

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

func StatusCode

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

func UseCertificateAuthentication

func UseCertificateAuthentication(certAuthentication *tls.CertificateAuthentication) oAuthorizationHeaderOption

Types

type AuthorizationHeader

type AuthorizationHeader interface {
	GetName() string
	GetValue() string
	HasValue() bool
}

func CreateAuthorizationHeader

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

Currently Basic authentication and Bearer token authentication is supported, OAuth 2.0 will be added later

type AuthorizationHeaderGenerator

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

func NewBasicAuthorizationHeader

func NewBasicAuthorizationHeader(u string, p string) AuthorizationHeaderGenerator

func NewBearerAuthorizationHeader added in v0.0.1

func NewBearerAuthorizationHeader(t string) AuthorizationHeaderGenerator

func NewExternalAuthorizationHeader

func NewExternalAuthorizationHeader(v string) AuthorizationHeaderGenerator

func NewIasAuthorizationHeader

func NewIasAuthorizationHeader(tokenUrl, user, clientCert string) AuthorizationHeaderGenerator

func NewOAuthorizationHeader

func NewOAuthorizationHeader(tokenType TokenType, grantType GrantType, tokenUrl string, executor HttpExecutor, requestBody string, cachingKey string, opts ...oAuthorizationHeaderOption) AuthorizationHeaderGenerator

type AuthorizationHeaderView

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

func EmptyAuthorizationHeader

func EmptyAuthorizationHeader() AuthorizationHeaderView

func NewAuthorizationHeaderView

func NewAuthorizationHeaderView(value string) AuthorizationHeaderView

func (AuthorizationHeaderView) GetName

func (h AuthorizationHeaderView) GetName() string

func (AuthorizationHeaderView) GetValue

func (h AuthorizationHeaderView) GetValue() string

func (AuthorizationHeaderView) HasValue

func (h AuthorizationHeaderView) HasValue() bool

type CacheableAuthorizationHeader

type CacheableAuthorizationHeader interface {
	AuthorizationHeader
	GetCachingKey() string
	GetCacheableValue() (string, error)
	ApplyCachedToken(token string) (CacheableAuthorizationHeader, error)
}

type CacheableAuthorizationHeaderView

type CacheableAuthorizationHeaderView struct {
	AuthorizationHeaderView
	// contains filtered or unexported fields
}

func NewCacheableAuthorizationHeaderView

func NewCacheableAuthorizationHeaderView(value string, header *oAuthorizationHeader) CacheableAuthorizationHeaderView

func (CacheableAuthorizationHeaderView) ApplyCachedToken

func (CacheableAuthorizationHeaderView) GetCacheableValue

func (h CacheableAuthorizationHeaderView) GetCacheableValue() (string, error)

func (CacheableAuthorizationHeaderView) GetCachingKey

func (h CacheableAuthorizationHeaderView) GetCachingKey() string

type CachedToken

type CachedToken struct {
	Token     string `json:"token,omitempty"`
	Timestamp string `json:"timestamp,omitempty"`
}

type GrantType

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

func (GrantType) Ordinal

func (e GrantType) Ordinal() uint

func (GrantType) String

func (t GrantType) String() string

type HttpExecutor

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

type HttpHeaders

type HttpHeaders map[string]string

type HttpRequestExecutor

type HttpRequestExecutor struct {
	executors.Executor
	// contains filtered or unexported fields
}

func DefaultHttpRequestExecutor

func DefaultHttpRequestExecutor() *HttpRequestExecutor

func NewHttpRequestExecutor

func NewHttpRequestExecutor(h AuthorizationHeader) *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 NewHttpRequestParametersFromContext

func NewHttpRequestParametersFromContext(ctx executors.ExecutorContext) *HttpRequestParameters

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 uint        `json:"size"`
	Time        int64       `json:"time"`
	// contains filtered or unexported fields
}

func NewHttpResponse

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

func (HttpResponse) ToMap

func (r HttpResponse) ToMap() (map[string]interface{}, error)

TODO: Implementation can be improved with reflection and removing json marshalling-unmarshalling process

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"`
	// contains filtered or unexported fields
}

func NewOAuthToken

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

func (OAuthToken) HasValue

func (t OAuthToken) HasValue() bool

type OAuthTokenParseError

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

func NewOAuthTokenParseError

func NewOAuthTokenParseError(url string, method string, responseCode string) *OAuthTokenParseError

func (*OAuthTokenParseError) Error

func (e *OAuthTokenParseError) Error() string

type TokenFetcher

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

func NewCsrfTokenFetcher

func NewCsrfTokenFetcher(p *HttpRequestParameters, authHeader AuthorizationHeader) 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) Ordinal

func (e TokenType) Ordinal() uint

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