client

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ContentTypeXML  = "application/xml"
	ContentTypeJSON = "application/json"
)

Allowed content types.

View Source
const AuthRetriesMax = 3

AuthRetriesMax is the maximum number of times the client will attempt to login before returning an error.

Variables

View Source
var (
	// ErrAuthorization is returned when the client is unable to authenticate with the server.
	ErrAuthorization = errors.New("authorization")

	// ErrContentType is returned when the client or server responds with an unknown content type header.
	ErrContentType = errors.New("content type")
)

Functions

func HandleResponse

func HandleResponse(resp *http.Response) error

HandleResponse handles custom behavior based on server response.

Types

type AuthService

type AuthService struct {
	// Gateway is the auth endpoint
	Gateway string `json:"gateway"`

	// SharedSecret is the fedsvc shared secret
	SharedSecret string `json:"sharedSecret"`

	// PodName is the GraphQL Pod name
	PodName string `json:"podName"`

	// Namespace is the GraphQL Namespace name
	Namespace string `json:"namespace"`

	// ObjectScaleID is just that
	ObjectScaleID string `json:"objectScaleID"`
	// contains filtered or unexported fields
}

AuthService is an in-cluster Authenticator.

func (*AuthService) IsAuthenticated

func (auth *AuthService) IsAuthenticated() bool

IsAuthenticated returns true if the authenticated has been established. This does not mean the next request is guaranteed to succeed as authentication can become expired.

func (*AuthService) Login

func (auth *AuthService) Login(ctx context.Context, ht *http.Client) error

Login obtains fresh authentication token(s) from the server.

func (*AuthService) Token

func (auth *AuthService) Token() string

Token returns the current authentication token.

type AuthUser

type AuthUser struct {
	// Gateway is the auth endpoint
	Gateway string `json:"gateway"`

	// Username used to authenticate management user
	Username string `json:"username"`

	// Password used to authenticate management user
	Password string `json:"password"`
	// contains filtered or unexported fields
}

AuthUser is an out-of-cluster or username+password based Authenticator.

func (*AuthUser) IsAuthenticated

func (auth *AuthUser) IsAuthenticated() bool

IsAuthenticated returns true if the authenticated has been established. This does not mean the next request is guaranteed to succeed as authentication can become expired.

func (*AuthUser) Login

func (auth *AuthUser) Login(ctx context.Context, ht *http.Client) error

Login obtains fresh authentication token(s) from the server.

func (*AuthUser) SetLogger

func (auth *AuthUser) SetLogger(log logr.Logger)

SetLogger configures the logger used internally to AuthUser.

func (*AuthUser) Token

func (auth *AuthUser) Token() string

Token returns the current authentication token.

type Authenticator

type Authenticator interface {
	// IsAuthenticated returns true if the authenticated has been established.  This
	// does not mean the next request is guaranteed to succeed as authentication can
	// become expired.
	IsAuthenticated() bool

	// Login obtains fresh authentication token(s) from the server.
	Login(context.Context, *http.Client) error

	// Token returns the current authentication token.
	Token() string
}

Authenticator can perform a Login to the gateway.

type CountWriter

type CountWriter struct {
	N int
}

CountWriter is an io.Writer that counts bytes written without actually writing anything.

func (*CountWriter) Write

func (w *CountWriter) Write(p []byte) (int, error)

Write adds len(p) to the current value of N and returns len(p) without writing anything.

type LogWriter added in v0.2.0

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

func (*LogWriter) Write added in v0.2.0

func (w *LogWriter) Write(p []byte) (int, error)

type RemoteCaller

type RemoteCaller interface {
	MakeRemoteCall(ctx context.Context, r Request, into interface{}) error
}

RemoteCaller interface is used to create backend calls. into represents type, _into_ which data will be unmarshalled. Naming follows Effective Go naming convention https://go.dev/doc/effective_go#interface-names

type Request

type Request struct {
	// Method is the method of REST API request
	Method string

	// Path is the path of REST API request
	Path string

	// Body is the body of REST API request
	Body interface{}

	// ContentType is the body of REST API request
	ContentType string

	// Params are the parameters of the REST API request
	Params map[string]string
}

Request is an ObjectScale API request wrapper.

func (Request) HTTPWithContext

func (r Request) HTTPWithContext(ctx context.Context, uri string) (*http.Request, error)

HTTPWithContext converts the Request data into an http.Request object.

func (Request) Validate

func (r Request) Validate(uri string) error

Validate performs lightweight validation and can be used to detect misconfigured requests.

type Simple

type Simple struct {
	// Endpoint is the URL of the management API
	Endpoint string `json:"endpoint"`

	// Authenticator!=nil means Authenticator.Login will be called to
	// obtain login credentials.
	Authenticator Authenticator

	// Should X-EMC-Override header be added into the request
	OverrideHeader bool

	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Simple is the simple client definition.

func (*Simple) MakeRemoteCall

func (s *Simple) MakeRemoteCall(ctx context.Context, r Request, into interface{}) error

MakeRemoteCall executes an API request against the client endpoint, returning the object body of the response into a response object.

func (*Simple) SetLogger added in v0.2.0

func (s *Simple) SetLogger(log logr.Logger)

SetLogger sets the logger in the Simple client.

Jump to

Keyboard shortcuts

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