client

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMasterServerNotFound = errors.New("master server not found")

Functions

func HasStatusCode

func HasStatusCode(err error, statusCode int) bool

func IsNotFound

func IsNotFound(err error) bool

func IsUnautorized

func IsUnautorized(err error) bool

func NewError

func NewError(httpCode int, message string) error

func NewMapParams

func NewMapParams(params map[string]string) map[string]Param

Types

type APIError

type APIError struct {
	Errors []APIErrorItem `json:"errors"`
}

func (*APIError) Error

func (e *APIError) Error() string

type APIErrorItem

type APIErrorItem struct {
	Detail string `json:"detail"`
}

type Client

type Client struct {
	User     *UserClient
	Server   *ServerClient
	Monitor  *MonitorClient
	Service  *ServiceClient
	Listener *ListenerClient
	MaxScale *MaxScaleClient
}

func NewClient

func NewClient(baseUrl string, opts ...mdbhttp.Option) (*Client, error)

func NewClientWithDefaultCredentials

func NewClientWithDefaultCredentials(baseUrl string, opts ...mdbhttp.Option) (*Client, error)

type Data

type Data[T any] struct {
	ID            string         `json:"id,omitempty"`
	Type          ObjectType     `json:"type"`
	Attributes    T              `json:"attributes"`
	Relationships *Relationships `json:"relationships,omitempty"`
}

type Error

type Error struct {
	HTTPCode int
	Message  string
}

func (*Error) Error

func (e *Error) Error() string

type GenericClient

type GenericClient[T any] struct {
	// contains filtered or unexported fields
}

func NewGenericClient

func NewGenericClient[T any](client *mdbhttp.Client, path string, objectType ObjectType) GenericClient[T]

func (*GenericClient[T]) AllExists

func (c *GenericClient[T]) AllExists(ctx context.Context, ids []string, options ...Option) (bool, error)

func (*GenericClient[T]) Create

func (c *GenericClient[T]) Create(ctx context.Context, name string, attributes T, options ...Option) error

func (*GenericClient[T]) Delete

func (c *GenericClient[T]) Delete(ctx context.Context, name string, options ...Option) error

func (*GenericClient[T]) Get

func (c *GenericClient[T]) Get(ctx context.Context, name string, options ...Option) (*Data[T], error)

func (*GenericClient[T]) List

func (c *GenericClient[T]) List(ctx context.Context, options ...Option) ([]Data[T], error)

func (*GenericClient[T]) ListIndex

func (c *GenericClient[T]) ListIndex(ctx context.Context, options ...Option) (ds.Index[Data[T]], error)

func (*GenericClient[T]) Patch

func (c *GenericClient[T]) Patch(ctx context.Context, name string, attributes T, options ...Option) error

func (*GenericClient[T]) Put

func (c *GenericClient[T]) Put(ctx context.Context, name string, options ...Option) error

func (*GenericClient[T]) Start

func (c *GenericClient[T]) Start(ctx context.Context, name string, options ...Option) error

func (*GenericClient[T]) Stop

func (c *GenericClient[T]) Stop(ctx context.Context, name string, options ...Option) error

type List

type List[T any] struct {
	Data []Data[T] `json:"data"`
}

type ListenerAttributes

type ListenerAttributes struct {
	State      string             `json:"state,omitempty"`
	Parameters ListenerParameters `json:"parameters"`
}

type ListenerClient

type ListenerClient struct {
	GenericClient[ListenerAttributes]
}

func NewListenerClient

func NewListenerClient(client *mdbhttp.Client) *ListenerClient

type ListenerParameters

type ListenerParameters struct {
	Port     int32     `json:"port"`
	Protocol string    `json:"protocol"`
	Params   MapParams `json:"-"`
}

func (ListenerParameters) MarshalJSON

func (l ListenerParameters) MarshalJSON() ([]byte, error)

type MapParams

type MapParams map[string]Param

type MaxScaleAttributes

type MaxScaleAttributes struct {
	ConfigSync *MaxScaleConfigSync `json:"config_sync,omitempty"`
	Parameters MaxScaleParameters  `json:"parameters"`
}

type MaxScaleClient

type MaxScaleClient struct {
	GenericClient[MaxScaleAttributes]
	// contains filtered or unexported fields
}

func NewMaxScaleClient

func NewMaxScaleClient(client *mdbhttp.Client) *MaxScaleClient

func (*MaxScaleClient) Get

func (*MaxScaleClient) Patch

func (m *MaxScaleClient) Patch(ctx context.Context, attributes MaxScaleAttributes) error

type MaxScaleConfigSync

type MaxScaleConfigSync struct {
	Version int `json:"version"`
}

type MaxScaleParameters

type MaxScaleParameters struct {
	ConfigSyncCluster  string          `json:"config_sync_cluster"`
	ConfigSyncUser     string          `json:"config_sync_user"`
	ConfigSyncPassword string          `json:"config_sync_password"`
	ConfigSyncDB       string          `json:"config_sync_db"`
	ConfigSyncInterval metav1.Duration `json:"config_sync_interval"`
	ConfigSyncTimeout  metav1.Duration `json:"config_sync_timeout"`
	Params             MapParams       `json:"-"`
}

func (MaxScaleParameters) MarshalJSON

func (m MaxScaleParameters) MarshalJSON() ([]byte, error)

type MonitorAttributes

type MonitorAttributes struct {
	Module     mariadbv1alpha1.MonitorModule `json:"module"`
	State      string                        `json:"state,omitempty"`
	Parameters MonitorParameters             `json:"parameters"`
}

type MonitorClient

type MonitorClient struct {
	GenericClient[MonitorAttributes]
}

func NewMonitorClient

func NewMonitorClient(client *mdbhttp.Client) *MonitorClient

type MonitorParameters

type MonitorParameters struct {
	User                       string                                 `json:"user"`
	Password                   string                                 `json:"password"`
	MonitorInterval            metav1.Duration                        `json:"monitor_interval,omitempty"`
	CooperativeMonitoringLocks *mariadbv1alpha1.CooperativeMonitoring `json:"cooperative_monitoring_locks,omitempty"`
	Params                     MapParams                              `json:"-"`
}

func (MonitorParameters) MarshalJSON

func (m MonitorParameters) MarshalJSON() ([]byte, error)

type Object

type Object[T any] struct {
	Data Data[T] `json:"data"`
}

type ObjectType

type ObjectType string
const (
	ObjectTypeUsers     ObjectType = "inet"
	ObjectTypeServers   ObjectType = "servers"
	ObjectTypeMonitors  ObjectType = "monitors"
	ObjectTypeServices  ObjectType = "services"
	ObjectTypeListeners ObjectType = "listeners"
	ObjectTypeMaxScale  ObjectType = "maxscale"
)

type Option

type Option func(o *Options)

func WithForceQuery

func WithForceQuery() Option

func WithQuery

func WithQuery(q map[string]string) Option

func WithRelationships

func WithRelationships(rels *Relationships) Option

type Options

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

type RelationshipData

type RelationshipData struct {
	Data []RelationshipItem `json:"data,omitempty"`
}

type RelationshipItem

type RelationshipItem struct {
	ID   string     `json:"id"`
	Type ObjectType `json:"type"`
}

type Relationships

type Relationships struct {
	Servers   *RelationshipData `json:"servers,omitempty"`
	Monitors  *RelationshipData `json:"monitors,omitempty"`
	Services  *RelationshipData `json:"services,omitempty"`
	Listeners *RelationshipData `json:"listeners,omitempty"`
}

type RelationshipsBuilder

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

func NewRelationshipsBuilder

func NewRelationshipsBuilder() *RelationshipsBuilder

func (*RelationshipsBuilder) Build

func (b *RelationshipsBuilder) Build() *Relationships

func (*RelationshipsBuilder) WithListeners

func (b *RelationshipsBuilder) WithListeners(listeners ...string) *RelationshipsBuilder

func (*RelationshipsBuilder) WithMonitors

func (b *RelationshipsBuilder) WithMonitors(monitors ...string) *RelationshipsBuilder

func (*RelationshipsBuilder) WithServers

func (b *RelationshipsBuilder) WithServers(servers ...string) *RelationshipsBuilder

func (*RelationshipsBuilder) WithServices

func (b *RelationshipsBuilder) WithServices(services ...string) *RelationshipsBuilder

type ServerAttributes

type ServerAttributes struct {
	State      string           `json:"state,omitempty"`
	Parameters ServerParameters `json:"parameters"`
}

func (*ServerAttributes) IsMaster

func (s *ServerAttributes) IsMaster() bool

type ServerClient

type ServerClient struct {
	GenericClient[ServerAttributes]
}

func NewServerClient

func NewServerClient(client *mdbhttp.Client) *ServerClient

func (*ServerClient) ClearMaintenance

func (s *ServerClient) ClearMaintenance(ctx context.Context, name string) error

func (*ServerClient) SetMaintenance

func (s *ServerClient) SetMaintenance(ctx context.Context, name string) error

type ServerParameters

type ServerParameters struct {
	Address  string    `json:"address"`
	Port     int32     `json:"port"`
	Protocol string    `json:"protocol"`
	Params   MapParams `json:"-"`
}

func (ServerParameters) MarshalJSON

func (s ServerParameters) MarshalJSON() ([]byte, error)

type ServiceAttributes

type ServiceAttributes struct {
	Router     mariadbv1alpha1.ServiceRouter `json:"router"`
	State      string                        `json:"state,omitempty"`
	Parameters ServiceParameters             `json:"parameters"`
}

type ServiceClient

type ServiceClient struct {
	GenericClient[ServiceAttributes]
}

func NewServiceClient

func NewServiceClient(client *mdbhttp.Client) *ServiceClient

type ServiceParameters

type ServiceParameters struct {
	User     string    `json:"user"`
	Password string    `json:"password"`
	Params   MapParams `json:"-"`
}

func (ServiceParameters) MarshalJSON

func (s ServiceParameters) MarshalJSON() ([]byte, error)

type UserAccount

type UserAccount string
const (
	UserAccountBasic UserAccount = "basic"
	UserAccountAdmin UserAccount = "admin"
)

type UserAttributes

type UserAttributes struct {
	Account  UserAccount `json:"account"`
	Password *string     `json:"password,omitempty"`
}

type UserClient

type UserClient struct {
	GenericClient[UserAttributes]
}

func NewUserClient

func NewUserClient(client *mdbhttp.Client) *UserClient

func (*UserClient) DeleteDefaultAdmin

func (u *UserClient) DeleteDefaultAdmin(ctx context.Context) error

Jump to

Keyboard shortcuts

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