kimsufi

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddonGenericName

func AddonGenericName(name string) string

AddonGenericName returns the generic name of an addon. It strips out the last part of the name after the last dash. e.g. ram-64g-ecc-2400-24sk50 -> ram-64g-ecc-2400

func GetOVHEndpoints

func GetOVHEndpoints() []string

GetOVHEndpoints returns a list of OVH endpoints. It keeps only the ones starting with "ovh-".

func IntervalToDuration

func IntervalToDuration(interval int, unit string) string

IntervalToDuration converts an interval and a unit to a duration string. examples: - 1 year -> P1Y - 2 years -> P2Y - 1 month -> P1M - 2 months -> P2M - 12 months -> P1Y - 0 days -> P0D - 1 day -> P1D - 2 days -> P2D - 31 days -> P31D

func IsForbiddenError

func IsForbiddenError(err error) bool

IsForbiddenError checks if the error is an ovh.APIError with http.StatusForbidden code.

func IsNotAvailableError

func IsNotAvailableError(err error) bool

IsNotAvailableError checks if the error is an ovh.APIError which contains an availability error message.

Types

type Logger

type Logger struct {
	*logrus.Logger
}

Logger is a wrapper around logrus.Logger. It is used to log requests and responses.

func NewRequestLogger

func NewRequestLogger(l *logrus.Logger) *Logger

NewRequestLogger creates a new Logger for requests. If l is nil, a no-op logger is used.

func (*Logger) LogRequest

func (l *Logger) LogRequest(r *http.Request)

LogRequest logs the HTTP request. Format: request: method url proto header

func (*Logger) LogResponse

func (l *Logger) LogResponse(r *http.Response)

LogResponse logs the HTTP response. Format: response: status proto header

type MultiService

type MultiService map[string]Service

MultiService is a map of OVH endpoints to Services.

func NewMultiService

func NewMultiService(l *logrus.Logger, c *cache.Cache) (MultiService, error)

NewMultiService creates a new MultiService with a Service for each OVH endpoint.

func (MultiService) Endpoint

func (m MultiService) Endpoint(endpoint string) *Service

Endpoint returns the Service for the given endpoint.

type Service

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

Service is a wrapper around ovh.Client with optional caching and logging.

func NewService

func NewService(endpoint string, logger *logrus.Logger, c *cache.Cache) (*Service, error)

NewService creates a new Service for the given endpoint. logger is optional, if nil a no-op logger will be used. c is optional, if nil no caching will be used.

func (*Service) AddEcoItem

func (s *Service) AddEcoItem(cartID, planCode string, quantity int, priceConfig kimsufiorder.EcoItemPriceConfig) (*kimsufiorder.EcoItemResponse, error)

AddEcoItem adds an OVH eco item to the cart with the given planCode, quantity and duration, mode from priceConfig.

func (*Service) AssignCart

func (s *Service) AssignCart(cartID string) error

AssignCart assigns the cart to the user's account.

func (*Service) CheckoutCart

func (s *Service) CheckoutCart(cartID string, autoPay bool) (*kimsufiorder.CheckoutResponse, error)

CheckoutCart checks out the cart to place the order. If autoPay is true, the order will be paid automatically using the preferred payment method.

func (*Service) ConfigureEcoItemOptions

func (s *Service) ConfigureEcoItemOptions(cartID string, itemID int, options kimsufiorder.EcoItemOptions, userOptions kimsufiorder.Options, priceConfig kimsufiorder.EcoItemPriceConfig) (kimsufiorder.Options, error)

ConfigureEcoItemOptions configures the item options in the cart. It finds the cheapest mandatory options and merges them into the user options.

func (*Service) ConfigureItem

func (s *Service) ConfigureItem(cartID string, itemID int, configurations []kimsufiorder.ItemConfigurationRequest) ([]kimsufiorder.ItemConfigurationResponse, error)

ConfigureItem configures an item in the cart with the given configurations.

func (*Service) CreateCart

func (s *Service) CreateCart(ovhSubsidiary string, expire time.Time) (*kimsufiorder.CartResponse, error)

CreateCart creates a new cart which will expire at the given time.

func (*Service) GenerateItemAutoConfigurations

func (s *Service) GenerateItemAutoConfigurations(itemConfigurationOptions []kimsufiorder.ItemConfiguration) kimsufiorder.ItemConfigurationRequests

GenerateItemAutoConfigurations generates configurations for an item.. It returns every required configuration with only one allowed value.

func (*Service) GetAvailabilities

func (s *Service) GetAvailabilities(datacenters []string, planCode string, options map[string]string) (*kimsufiavailability.Availabilities, error)

GetAvailabilities returns servers availabilities. datacenters is a list of datacenters to filter on. planCode is the plan code to filter on. options is a map of additional query parameters. see https://eu.api.ovh.com/console/?section=%2Fdedicated%2Fserver&branch=v1#get-/dedicated/server/datacenter/availabilities

func (*Service) GetEcoInfo

func (s *Service) GetEcoInfo(cartID, planCode string) (kimsufiorder.EcoItemInfos, error)

GetEcoInfo returns information about an eco item in the cart.

func (*Service) GetEcoOptions

func (s *Service) GetEcoOptions(cartID string, planCode string) ([]kimsufiorder.EcoItemOption, error)

GetEcoOptions returns the options for an eco item in the cart.

func (*Service) GetItemRequiredConfiguration

func (s *Service) GetItemRequiredConfiguration(cartID string, itemID int) ([]kimsufiorder.ItemConfiguration, error)

GetItemRequiredConfiguration returns the required configuration options for an item in the cart.

func (*Service) ListServers

func (s *Service) ListServers(ovhSubsidiary string) (*kimsuficatalog.Catalog, error)

ListServers returns the catalog for the given OVH subsidiary. ovhSubsidiary is the country code to filter on, given in a two-letter format. see https://eu.api.ovh.com/console/?section=%2Forder&branch=v1#get-/order/catalog/public/eco

func (*Service) TestAuth

func (s *Service) TestAuth() error

TestAuth performs a test API request to check if the client is authenticated.

func (*Service) WithAuth

func (s *Service) WithAuth(appKey, appSecret, consumerKey string) (*Service, error)

WithAuth returns a new authenticated Service with the given credentials.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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