scw

package
v1.0.0-beta.30 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: Apache-2.0 Imports: 32 Imported by: 121

README

Scaleway config

TL;DR

Recommended config file:

# Get your credentials on https://console.scaleway.com/project/credentials
access_key: SCWXXXXXXXXXXXXXXXXX
secret_key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
default_organization_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
default_project_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
default_region: fr-par
default_zone: fr-par-1

Config file path

The function GetConfigPath will try to locate the config file in the following ways:

  1. Custom directory: $SCW_CONFIG_PATH
  2. XDG base directory: $XDG_CONFIG_HOME/scw/config.yaml
  3. Unix home directory: $HOME/.config/scw/config.yaml
  4. Windows home directory: %USERPROFILE%/.config/scw/config.yaml

Reading config order

ClientOption ordering will decide the order in which the config should apply:

p, _ := scw.MustLoadConfig().GetActiveProfile()

scw.NewClient(
    scw.WithProfile(p),                     // active profile applies first
    scw.WithEnv(),                          // existing env variables may overwrite active profile
    scw.WithDefaultRegion(scw.RegionFrPar)  // any prior region set will be discarded to usr the new one
)

Environment variables

Variable Description Legacy variables
$SCW_ACCESS_KEY Access key of a token (get yours) $SCALEWAY_ACCESS_KEY (used by terraform)
$SCW_SECRET_KEY Secret key of a token (get yours) $SCW_TOKEN (used by cli), $SCALEWAY_TOKEN (used by terraform), $SCALEWAY_ACCESS_KEY (used by terraform)
$SCW_DEFAULT_ORGANIZATION_ID Your default organization ID (get yours) $SCW_ORGANIZATION (used by cli),$SCALEWAY_ORGANIZATION (used by terraform)
$SCW_DEFAULT_PROJECT_ID Your default project ID (get yours)
$SCW_DEFAULT_REGION Your default region $SCW_REGION (used by cli),$SCALEWAY_REGION (used by terraform)
$SCW_DEFAULT_ZONE Your default availability zone $SCW_ZONE (used by cli),$SCALEWAY_ZONE (used by terraform)
$SCW_API_URL Url of the API -
$SCW_INSECURE Set this to true to enable the insecure mode $SCW_TLSVERIFY (inverse flag used by the cli)
$SCW_PROFILE Set the config profile to use -

Documentation

Index

Constants

View Source
const (
	B  Size = 1
	KB      = 1000 * B
	MB      = 1000 * KB
	GB      = 1000 * MB
	TB      = 1000 * GB
	PB      = 1000 * TB
)
View Source
const (
	// Up-to-date
	ScwCacheDirEnv              = "SCW_CACHE_DIR"
	ScwConfigPathEnv            = "SCW_CONFIG_PATH"
	ScwAccessKeyEnv             = "SCW_ACCESS_KEY"
	ScwSecretKeyEnv             = "SCW_SECRET_KEY" // #nosec G101
	ScwActiveProfileEnv         = "SCW_PROFILE"
	ScwAPIURLEnv                = "SCW_API_URL"
	ScwInsecureEnv              = "SCW_INSECURE"
	ScwDefaultOrganizationIDEnv = "SCW_DEFAULT_ORGANIZATION_ID"
	ScwDefaultProjectIDEnv      = "SCW_DEFAULT_PROJECT_ID"
	ScwDefaultRegionEnv         = "SCW_DEFAULT_REGION"
	ScwDefaultZoneEnv           = "SCW_DEFAULT_ZONE"
	ScwEnableBeta               = "SCW_ENABLE_BETA"
	DebugEnv                    = logger.DebugEnv
)

Environment variables

View Source
const (
	// ZoneFrPar1 represents the fr-par-1 zone
	ZoneFrPar1 = Zone("fr-par-1")
	// ZoneFrPar2 represents the fr-par-2 zone
	ZoneFrPar2 = Zone("fr-par-2")
	// ZoneFrPar3 represents the fr-par-3 zone
	ZoneFrPar3 = Zone("fr-par-3")
	// ZoneNlAms1 represents the nl-ams-1 zone
	ZoneNlAms1 = Zone("nl-ams-1")
	// ZoneNlAms2 represents the nl-ams-2 zone
	ZoneNlAms2 = Zone("nl-ams-2")
	// ZoneNlAms3 represents the nl-ams-3 zone
	ZoneNlAms3 = Zone("nl-ams-3")
	// ZonePlWaw1 represents the pl-waw-1 zone
	ZonePlWaw1 = Zone("pl-waw-1")
	// ZonePlWaw2 represents the pl-waw-2 zone
	ZonePlWaw2 = Zone("pl-waw-2")
	// ZonePlWaw3 represents the pl-waw-3 zone
	ZonePlWaw3 = Zone("pl-waw-3")
)
View Source
const (
	// RegionFrPar represents the fr-par region
	RegionFrPar = Region("fr-par")
	// RegionNlAms represents the nl-ams region
	RegionNlAms = Region("nl-ams")
	// RegionPlWaw represents the pl-waw region
	RegionPlWaw = Region("pl-waw")
)
View Source
const (

	// Reserved name for the default profile.
	DefaultProfileName = "default"
)

Variables

AllRegions is an array that list all regions

AllZones is an array that list all zones

View Source
var ErrNoHomeDir = errors.New("user home directory not found")

ErrNoHomeDir errors when no user directory is found

Functions

func BoolPtr

func BoolPtr(v bool) *bool

BoolPtr returns a pointer to the bool value passed in.

func BoolSlicePtr

func BoolSlicePtr(src []bool) []*bool

BoolSlicePtr converts a slice of bool values into a slice of bool pointers

func BytesPtr

func BytesPtr(v []byte) *[]byte

BytesPtr returns a pointer to the []byte value passed in.

func BytesSlicePtr

func BytesSlicePtr(src [][]byte) []*[]byte

BytesSlicePtr converts a slice of []byte values into a slice of []byte pointers

func EncodeJSONObject

func EncodeJSONObject(v JSONObject, escape EscapeMode) (string, error)

EncodeJSONObject marshals the value into a JSON string, and optionally base64 encodes the string before returning it.

Will panic if the escape mode is unknown.

func Float32Ptr

func Float32Ptr(v float32) *float32

Float32Ptr returns a pointer to the float32 value passed in.

func Float32SlicePtr

func Float32SlicePtr(src []float32) []*float32

Float32SlicePtr converts a slice of float32 values into a slice of float32 pointers

func Float64Ptr

func Float64Ptr(v float64) *float64

Float64Ptr returns a pointer to the float64 value passed in.

func Float64SlicePtr

func Float64SlicePtr(src []float64) []*float64

Float64SlicePtr converts a slice of float64 values into a slice of float64 pointers

func GetCacheDirectory

func GetCacheDirectory() string

GetCacheDirectory returns the default cache directory. Cache directory is based on the following priority order: - $SCW_CACHE_DIR - $XDG_CACHE_HOME/scw - $HOME/.cache/scw - $USERPROFILE/.cache/scw

func GetConfigPath

func GetConfigPath() string

GetConfigPath returns the default path. Default path is based on the following priority order: - $SCW_CONFIG_PATH - $XDG_CONFIG_HOME/scw/config.yaml - $HOME/.config/scw/config.yaml - $USERPROFILE/.config/scw/config.yaml

func GetScwConfigDir

func GetScwConfigDir() (string, error)

GetScwConfigDir returns the path to scw config folder

func IPPtr

func IPPtr(v net.IP) *net.IP

IPPtr returns a pointer to the net.IP value passed in.

func Int32Ptr

func Int32Ptr(v int32) *int32

Int32Ptr returns a pointer to the int32 value passed in.

func Int32SlicePtr

func Int32SlicePtr(src []int32) []*int32

Int32SlicePtr converts a slice of int32 values into a slice of int32 pointers

func Int64Ptr

func Int64Ptr(v int64) *int64

Int64Ptr returns a pointer to the int64 value passed in.

func Int64SlicePtr

func Int64SlicePtr(src []int64) []*int64

Int64SlicePtr converts a slice of int64 values into a slice of int64 pointers

func StringPtr

func StringPtr(v string) *string

StringPtr returns a pointer to the string value passed in.

func StringSlicePtr

func StringSlicePtr(src []string) []*string

StringSlicePtr converts a slice of string values into a slice of string pointers

func StringsPtr

func StringsPtr(v []string) *[]string

StringsPtr returns a pointer to the []string value passed in.

func StringsSlicePtr

func StringsSlicePtr(src [][]string) []*[]string

StringsSlicePtr converts a slice of []string values into a slice of []string pointers

func TimeDurationPtr

func TimeDurationPtr(v time.Duration) *time.Duration

TimeDurationPtr returns a pointer to the Duration value passed in.

func TimePtr

func TimePtr(v time.Time) *time.Time

TimePtr returns a pointer to the Time value passed in.

func Uint32Ptr

func Uint32Ptr(v uint32) *uint32

Uint32Ptr returns a pointer to the uint32 value passed in.

func Uint32SlicePtr

func Uint32SlicePtr(src []uint32) []*uint32

Uint32SlicePtr converts a slice of uint32 values into a slice of uint32 pointers

func Uint64Ptr

func Uint64Ptr(v uint64) *uint64

Uint64Ptr returns a pointer to the uint64 value passed in.

func Uint64SlicePtr

func Uint64SlicePtr(src []uint64) []*uint64

Uint64SlicePtr converts a slice of uint64 values into a slice of uint64 pointers

Types

type Client

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

Client is the Scaleway client which performs API requests.

This client should be passed in the `NewApi` functions whenever an API instance is created. Creating a Client is done with the `NewClient` function.

func NewClient

func NewClient(opts ...ClientOption) (*Client, error)

NewClient instantiate a new Client object.

Zero or more ClientOption object can be passed as a parameter. These options will then be applied to the client.

func (*Client) Do

func (c *Client) Do(req *ScalewayRequest, res interface{}, opts ...RequestOption) (err error)

Do performs HTTP request(s) based on the ScalewayRequest object. RequestOptions are applied prior to doing the request.

func (*Client) GetAccessKey

func (c *Client) GetAccessKey() (accessKey string, exists bool)

func (*Client) GetDefaultOrganizationID

func (c *Client) GetDefaultOrganizationID() (organizationID string, exists bool)

GetDefaultOrganizationID returns the default organization ID of the client. This value can be set in the client option WithDefaultOrganizationID(). Be aware this value can be empty.

func (*Client) GetDefaultPageSize

func (c *Client) GetDefaultPageSize() (pageSize uint32, exists bool)

GetDefaultPageSize returns the default page size of the client. This value can be set in the client option WithDefaultPageSize(). Be aware this value can be empty.

func (*Client) GetDefaultProjectID

func (c *Client) GetDefaultProjectID() (projectID string, exists bool)

GetDefaultProjectID returns the default project ID of the client. This value can be set in the client option WithDefaultProjectID(). Be aware this value can be empty.

func (*Client) GetDefaultRegion

func (c *Client) GetDefaultRegion() (region Region, exists bool)

GetDefaultRegion returns the default region of the client. This value can be set in the client option WithDefaultRegion(). Be aware this value can be empty.

func (*Client) GetDefaultZone

func (c *Client) GetDefaultZone() (zone Zone, exists bool)

GetDefaultZone returns the default zone of the client. This value can be set in the client option WithDefaultZone(). Be aware this value can be empty.

func (*Client) GetSecretKey

func (c *Client) GetSecretKey() (secretKey string, exists bool)

type ClientOption

type ClientOption func(*settings)

ClientOption is a function which applies options to a settings object.

func WithAPIURL

func WithAPIURL(apiURL string) ClientOption

WithAPIURL client option overrides the API URL of the Scaleway API to the given URL.

func WithAuth

func WithAuth(accessKey, secretKey string) ClientOption

WithAuth client option sets the client access key and secret key.

func WithDefaultOrganizationID

func WithDefaultOrganizationID(organizationID string) ClientOption

WithDefaultOrganizationID client option sets the client default organization ID.

It will be used as the default value of the organization_id field in all requests made with this client.

func WithDefaultPageSize

func WithDefaultPageSize(pageSize uint32) ClientOption

WithDefaultPageSize client option overrides the default page size of the SDK.

It will be used as the default value of the page_size field in all requests made with this client.

func WithDefaultProjectID

func WithDefaultProjectID(projectID string) ClientOption

WithDefaultProjectID client option sets the client default project ID.

It will be used as the default value of the projectID field in all requests made with this client.

func WithDefaultRegion

func WithDefaultRegion(region Region) ClientOption

WithDefaultRegion client option sets the client default region.

It will be used as the default value of the region field in all requests made with this client.

func WithDefaultZone

func WithDefaultZone(zone Zone) ClientOption

WithDefaultZone client option sets the client default zone.

It will be used as the default value of the zone field in all requests made with this client.

func WithEnv

func WithEnv() ClientOption

WithEnv client option configures a client from the environment variables.

func WithHTTPClient

func WithHTTPClient(httpClient httpClient) ClientOption

WithHTTPClient client option allows passing a custom http.Client which will be used for all requests.

func WithInsecure

func WithInsecure() ClientOption

WithInsecure client option enables insecure transport on the client.

func WithJWT

func WithJWT(token string) ClientOption

WithJWT client option sets the client session token.

func WithProfile

func WithProfile(p *Profile) ClientOption

WithProfile client option configures a client from the given profile.

func WithUserAgent

func WithUserAgent(ua string) ClientOption

WithUserAgent client option append a user agent to the default user agent of the SDK.

func WithoutAuth

func WithoutAuth() ClientOption

WithoutAuth client option sets the client token to an empty token.

type Config

type Config struct {
	Profile       `yaml:",inline"`
	ActiveProfile *string             `yaml:"active_profile,omitempty" json:"active_profile,omitempty"`
	Profiles      map[string]*Profile `yaml:"profiles,omitempty" json:"profiles,omitempty"`
}

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig read the config from the default path.

func LoadConfigFromPath

func LoadConfigFromPath(path string) (*Config, error)

LoadConfigFromPath read the config from the given path.

func MustLoadConfig

func MustLoadConfig() *Config

MustLoadConfig is like LoadConfig but panic instead of returning an error.

func (*Config) GetActiveProfile

func (c *Config) GetActiveProfile() (*Profile, error)

GetActiveProfile returns the active profile of the config based on the following order: env SCW_PROFILE > config active_profile > config root profile

func (*Config) GetProfile

func (c *Config) GetProfile(profileName string) (*Profile, error)

GetProfile returns the profile corresponding to the given profile name.

func (*Config) HumanConfig

func (c *Config) HumanConfig() (string, error)

HumanConfig will generate a config file with documented arguments.

func (*Config) IsEmpty

func (c *Config) IsEmpty() bool

func (*Config) Save

func (c *Config) Save() error

SaveTo will save the config to the default config path. This action will overwrite the previous file when it exists.

func (*Config) SaveTo

func (c *Config) SaveTo(path string) error

SaveTo will save the config to the given path. This action will overwrite the previous file when it exists.

func (*Config) String

func (c *Config) String() string

type ConfigFileNotFoundError

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

ConfigFileNotFound indicates that the config file could not be found

func (ConfigFileNotFoundError) Error

func (e ConfigFileNotFoundError) Error() string

func (ConfigFileNotFoundError) IsScwSdkError

func (e ConfigFileNotFoundError) IsScwSdkError()

ConfigFileNotFoundError implements the SdkError interface

type Decimal

type Decimal string

Decimal is a representation of a decimal value, such as 2.5. Comparable to language-native decimal formats, such as Java's BigDecimal or Python's decimal.Decimal. Lookup protobuf google.type.Decimal for details.

func (Decimal) String

func (d Decimal) String() string

type DeniedAuthenticationError

type DeniedAuthenticationError struct {
	Method string `json:"method"`
	Reason string `json:"reason"`

	RawBody json.RawMessage `json:"-"`
}

DeniedAuthenticationError implements the SdkError interface

func (DeniedAuthenticationError) Error

func (DeniedAuthenticationError) IsScwSdkError

func (r DeniedAuthenticationError) IsScwSdkError()

type Duration

type Duration struct {
	Seconds int64
	Nanos   int32
}

Duration represents a signed, fixed-length span of time represented as a count of seconds and fractions of seconds at nanosecond resolution. It is independent of any calendar and concepts like "day" or "month". It is related to Timestamp in that the difference between two Timestamp values is a Duration and it can be added or subtracted from a Timestamp. Range is approximately +-10,000 years.

func NewDurationFromTimeDuration

func NewDurationFromTimeDuration(t time.Duration) *Duration

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) ToTimeDuration

func (d *Duration) ToTimeDuration() *time.Duration

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

type EscapeMode

type EscapeMode uint

EscapeMode is the mode that should be use for escaping a value

const (
	NoEscape EscapeMode = iota
	Base64Escape
	QuotedEscape
)

The modes for escaping a value before it is marshaled, and unmarshalled.

type File

type File struct {
	// Name of the file
	Name string `json:"name"`

	// ContentType used in the HTTP header `Content-Type`
	ContentType string `json:"content_type"`

	// Content of the file
	Content io.Reader `json:"content"`
}

File is the structure used to receive / send a file from / to the API

func (*File) MarshalJSON

func (f *File) MarshalJSON() ([]byte, error)

func (*File) UnmarshalJSON

func (f *File) UnmarshalJSON(b []byte) error

type IPNet

type IPNet struct {
	net.IPNet
}

IPNet inherits net.IPNet and represents an IP network.

func (IPNet) MarshalJSON

func (n IPNet) MarshalJSON() ([]byte, error)

func (*IPNet) UnmarshalJSON

func (n *IPNet) UnmarshalJSON(b []byte) error

type InvalidArgumentsError

type InvalidArgumentsError struct {
	Details []InvalidArgumentsErrorDetail `json:"details"`

	RawBody json.RawMessage `json:"-"`
}

func (*InvalidArgumentsError) Error

func (e *InvalidArgumentsError) Error() string

func (*InvalidArgumentsError) GetRawBody

func (e *InvalidArgumentsError) GetRawBody() json.RawMessage

func (*InvalidArgumentsError) IsScwSdkError

func (e *InvalidArgumentsError) IsScwSdkError()

IsScwSdkError implements the SdkError interface

type InvalidArgumentsErrorDetail

type InvalidArgumentsErrorDetail struct {
	ArgumentName string `json:"argument_name"`
	Reason       string `json:"reason"`
	HelpMessage  string `json:"help_message"`
}

type InvalidClientOptionError

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

InvalidClientOptionError indicates that at least one of client data has been badly provided for the client creation.

func NewInvalidClientOptionError

func NewInvalidClientOptionError(format string, a ...interface{}) *InvalidClientOptionError

func (InvalidClientOptionError) Error

func (e InvalidClientOptionError) Error() string

func (InvalidClientOptionError) IsScwSdkError

func (e InvalidClientOptionError) IsScwSdkError()

IsScwSdkError implements the SdkError interface

type InvalidRequestError

type InvalidRequestError struct {
	Message string `json:"message"`

	Fields map[string][]string `json:"fields"`

	Resource string `json:"resource"`

	RawBody json.RawMessage `json:"-"`
}

InvalidRequestError is only returned by the instance API. Warning: this is not a standard error.

func (*InvalidRequestError) ToInvalidArgumentsError

func (e *InvalidRequestError) ToInvalidArgumentsError() *InvalidArgumentsError

ToSdkError returns a standard error InvalidArgumentsError or nil Fields is nil.

func (*InvalidRequestError) ToQuotasExceededError

func (e *InvalidRequestError) ToQuotasExceededError() *QuotasExceededError

type JSONObject

type JSONObject map[string]interface{}

JSONObject represent any JSON object. See struct.proto. It will be marshaled into a json string. This type can be used just like any other map.

Example:

values := scw.JSONValue{
	"Foo": "Bar",
}
values["Baz"] = "Qux"

func DecodeJSONObject

func DecodeJSONObject(v string, escape EscapeMode) (JSONObject, error)

DecodeJSONObject will attempt to decode the string input as a JSONValue. Optionally decoding base64 the value first before JSON unmarshalling.

Will panic if the escape mode is unknown.

type Money

type Money struct {
	// CurrencyCode is the 3-letter currency code defined in ISO 4217.
	CurrencyCode string `json:"currency_code"`

	// Units is the whole units of the amount.
	// For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar.
	Units int64 `json:"units"`

	// Nanos is the number of nano (10^-9) units of the amount.
	// The value must be between -999,999,999 and +999,999,999 inclusive.
	// If `units` is positive, `nanos` must be positive or zero.
	// If `units` is zero, `nanos` can be positive, zero, or negative.
	// If `units` is negative, `nanos` must be negative or zero.
	// For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000.
	Nanos int32 `json:"nanos"`
}

Money represents an amount of money with its currency type.

func NewMoneyFromFloat

func NewMoneyFromFloat(value float64, currencyCode string, precision int) *Money

NewMoneyFromFloat converts a float with currency to a Money.

value: The float value. currencyCode: The 3-letter currency code defined in ISO 4217. precision: The number of digits after the decimal point used to parse the nanos part of the value.

Examples: - (value = 1.3333, precision = 2) => Money{Units = 1, Nanos = 330000000} - (value = 1.123456789, precision = 9) => Money{Units = 1, Nanos = 123456789}

func (Money) String

func (m Money) String() string

String returns the string representation of Money.

func (Money) ToFloat

func (m Money) ToFloat() float64

ToFloat converts a Money object to a float.

type OutOfStockError

type OutOfStockError struct {
	Resource string `json:"resource"`

	RawBody json.RawMessage `json:"-"`
}

func (*OutOfStockError) Error

func (e *OutOfStockError) Error() string

func (*OutOfStockError) GetRawBody

func (e *OutOfStockError) GetRawBody() json.RawMessage

func (*OutOfStockError) IsScwSdkError

func (e *OutOfStockError) IsScwSdkError()

IsScwSdkError implements the SdkError interface

type PermissionsDeniedError

type PermissionsDeniedError struct {
	Details []struct {
		Resource string `json:"resource"`
		Action   string `json:"action"`
	} `json:"details"`

	RawBody json.RawMessage `json:"-"`
}

func (*PermissionsDeniedError) Error

func (e *PermissionsDeniedError) Error() string

func (*PermissionsDeniedError) GetRawBody

func (e *PermissionsDeniedError) GetRawBody() json.RawMessage

func (*PermissionsDeniedError) IsScwSdkError

func (e *PermissionsDeniedError) IsScwSdkError()

IsScwSdkError implements the SdkError interface

type PreconditionFailedError

type PreconditionFailedError struct {
	Precondition string `json:"precondition"`
	HelpMessage  string `json:"help_message"`

	RawBody json.RawMessage `json:"-"`
}

PreconditionFailedError implements the SdkError interface

func (PreconditionFailedError) Error

func (r PreconditionFailedError) Error() string

func (PreconditionFailedError) IsScwSdkError

func (r PreconditionFailedError) IsScwSdkError()

type Profile

type Profile struct {
	AccessKey             *string `yaml:"access_key,omitempty" json:"access_key,omitempty"`
	SecretKey             *string `yaml:"secret_key,omitempty" json:"secret_key,omitempty"`
	APIURL                *string `yaml:"api_url,omitempty" json:"api_url,omitempty"`
	Insecure              *bool   `yaml:"insecure,omitempty" json:"insecure,omitempty"`
	DefaultOrganizationID *string `yaml:"default_organization_id,omitempty" json:"default_organization_id,omitempty"`
	DefaultProjectID      *string `yaml:"default_project_id,omitempty" json:"default_project_id,omitempty"`
	DefaultRegion         *string `yaml:"default_region,omitempty" json:"default_region,omitempty"`
	DefaultZone           *string `yaml:"default_zone,omitempty" json:"default_zone,omitempty"`
	SendTelemetry         *bool   `yaml:"send_telemetry,omitempty" json:"send_telemetry,omitempty"`
}

func LoadEnvProfile

func LoadEnvProfile() *Profile

func MergeProfiles

func MergeProfiles(original *Profile, others ...*Profile) *Profile

MergeProfiles merges profiles in a new one. The last profile has priority.

func (*Profile) String

func (p *Profile) String() string

type QuotasExceededError

type QuotasExceededError struct {
	Details []QuotasExceededErrorDetail `json:"details"`
	RawBody json.RawMessage             `json:"-"`
}

func (*QuotasExceededError) Error

func (e *QuotasExceededError) Error() string

func (*QuotasExceededError) GetRawBody

func (e *QuotasExceededError) GetRawBody() json.RawMessage

func (*QuotasExceededError) IsScwSdkError

func (e *QuotasExceededError) IsScwSdkError()

IsScwSdkError implements the SdkError interface

type QuotasExceededErrorDetail

type QuotasExceededErrorDetail struct {
	Resource string `json:"resource"`
	Quota    uint32 `json:"quota"`
	Current  uint32 `json:"current"`
}

type Region

type Region string

Region is a geographical location

func ParseRegion

func ParseRegion(region string) (Region, error)

ParseRegion parses a string value into a Region and returns an error if it has a bad format.

func (Region) Exists

func (region Region) Exists() bool

Exists checks whether a region exists

func (Region) GetZones

func (region Region) GetZones() []Zone

GetZones is a function that returns the zones for the specified region

func (Region) String

func (region Region) String() string

String returns a Region as a string

func (*Region) UnmarshalJSON

func (region *Region) UnmarshalJSON(input []byte) error

UnmarshalJSON implements the Unmarshaler interface for a Region. this to call ParseRegion on the string input and return the correct Region object.

type RequestOption

type RequestOption func(*ScalewayRequest)

RequestOption is a function that applies options to a ScalewayRequest.

func WithAllPages

func WithAllPages() RequestOption

WithAllPages aggregate all pages in the response of a List request. Will error when pagination is not supported on the request.

func WithAuthRequest

func WithAuthRequest(accessKey, secretKey string) RequestOption

WithAuthRequest overwrites the client access key and secret key used in the request.

func WithContext

func WithContext(ctx context.Context) RequestOption

WithContext request option sets the context of a ScalewayRequest

func WithRegions

func WithRegions(regions ...Region) RequestOption

WithRegions aggregate results from requested regions in the response of a List request. response rows are sorted by region using order of given regions Will error when pagination is not supported on the request.

func WithZones

func WithZones(zones ...Zone) RequestOption

WithZones aggregate results from requested zones in the response of a List request. response rows are sorted by zone using order of given zones Will error when pagination is not supported on the request.

type ResourceExpiredError

type ResourceExpiredError struct {
	Resource     string    `json:"resource"`
	ResourceID   string    `json:"resource_id"`
	ExpiredSince time.Time `json:"expired_since"`

	RawBody json.RawMessage `json:"-"`
}

ResourceExpiredError implements the SdkError interface

func (ResourceExpiredError) Error

func (r ResourceExpiredError) Error() string

func (ResourceExpiredError) IsScwSdkError

func (r ResourceExpiredError) IsScwSdkError()

type ResourceLockedError

type ResourceLockedError struct {
	Resource   string `json:"resource"`
	ResourceID string `json:"resource_id"`

	RawBody json.RawMessage `json:"-"`
}

func (*ResourceLockedError) Error

func (e *ResourceLockedError) Error() string

func (*ResourceLockedError) GetRawBody

func (e *ResourceLockedError) GetRawBody() json.RawMessage

func (*ResourceLockedError) IsScwSdkError

func (e *ResourceLockedError) IsScwSdkError()

IsScwSdkError implements the SdkError interface

type ResourceNotFoundError

type ResourceNotFoundError struct {
	Resource   string `json:"resource"`
	ResourceID string `json:"resource_id"`

	RawBody json.RawMessage `json:"-"`
}

func (*ResourceNotFoundError) Error

func (e *ResourceNotFoundError) Error() string

func (*ResourceNotFoundError) GetRawBody

func (e *ResourceNotFoundError) GetRawBody() json.RawMessage

func (*ResourceNotFoundError) IsScwSdkError

func (e *ResourceNotFoundError) IsScwSdkError()

IsScwSdkError implements the SdkError interface

type ResponseError

type ResponseError struct {
	// Message is a human-friendly error message
	Message string `json:"message"`

	// Type is a string code that defines the kind of error. This field is only used by instance API
	Type string `json:"type,omitempty"`

	// Resource is a string code that defines the resource concerned by the error. This field is only used by instance API
	Resource string `json:"resource,omitempty"`

	// Fields contains detail about validation error. This field is only used by instance API
	Fields map[string][]string `json:"fields,omitempty"`

	// StatusCode is the HTTP status code received
	StatusCode int `json:"-"`

	// Status is the HTTP status received
	Status string `json:"-"`

	RawBody json.RawMessage `json:"-"`
}

ResponseError is an error type for the Scaleway API

func (*ResponseError) Error

func (e *ResponseError) Error() string

func (*ResponseError) GetRawBody

func (e *ResponseError) GetRawBody() json.RawMessage

func (*ResponseError) IsScwSdkError

func (e *ResponseError) IsScwSdkError()

IsScwSdkError implement SdkError interface

func (*ResponseError) UnmarshalJSON

func (e *ResponseError) UnmarshalJSON(b []byte) error

type ScalewayRequest

type ScalewayRequest struct {
	Method  string
	Path    string
	Headers http.Header
	Query   url.Values
	Body    io.Reader
	// contains filtered or unexported fields
}

ScalewayRequest contains all the contents related to performing a request on the Scaleway API.

func (*ScalewayRequest) SetBody

func (req *ScalewayRequest) SetBody(body interface{}) error

SetBody json marshal the given body and write the json content type to the request. It also catches when body is a file.

type SdkError

type SdkError interface {
	Error() string
	IsScwSdkError()
}

SdkError is a base interface for all Scaleway SDK errors.

type ServiceInfo

type ServiceInfo struct {
	// Name is the name of the API
	Name string `json:"name"`

	// Description is a human readable description for the API
	Description string `json:"description"`

	// Version is the version of the API
	Version string `json:"version"`

	// DocumentationURL is the a web url where the documentation of the API can be found
	DocumentationURL *string `json:"documentation_url"`
}

ServiceInfo contains API metadata These metadata are only here for debugging. Do not rely on these values

type Size

type Size uint64

Size represents a size in bytes.

func SizePtr

func SizePtr(v Size) *Size

SizePtr returns a pointer to the Size value passed in.

func (Size) String

func (s Size) String() string

String returns the string representation of a Size.

type TimeSeries

type TimeSeries struct {
	// Name of the metric.
	Name string `json:"name"`

	// Points contains all the points that composed the series.
	Points []*TimeSeriesPoint `json:"points"`

	// Metadata contains some string metadata related to a metric.
	Metadata map[string]string `json:"metadata"`
}

TimeSeries represents a time series that could be used for graph purposes.

type TimeSeriesPoint

type TimeSeriesPoint struct {
	Timestamp time.Time
	Value     float32
}

TimeSeriesPoint represents a point of a time series.

func (TimeSeriesPoint) MarshalJSON

func (tsp TimeSeriesPoint) MarshalJSON() ([]byte, error)

func (*TimeSeriesPoint) UnmarshalJSON

func (tsp *TimeSeriesPoint) UnmarshalJSON(b []byte) error

type TransientStateError

type TransientStateError struct {
	Resource     string `json:"resource"`
	ResourceID   string `json:"resource_id"`
	CurrentState string `json:"current_state"`

	RawBody json.RawMessage `json:"-"`
}

func (*TransientStateError) Error

func (e *TransientStateError) Error() string

func (*TransientStateError) GetRawBody

func (e *TransientStateError) GetRawBody() json.RawMessage

func (*TransientStateError) IsScwSdkError

func (e *TransientStateError) IsScwSdkError()

IsScwSdkError implements the SdkError interface

type UnknownResource

type UnknownResource struct {
	Message string          `json:"message"`
	RawBody json.RawMessage `json:"-"`
}

UnknownResource is only returned by the instance API. Warning: this is not a standard error.

func (*UnknownResource) ToResourceNotFoundError

func (e *UnknownResource) ToResourceNotFoundError() *ResourceNotFoundError

ToSdkError returns a standard error InvalidArgumentsError or nil Fields is nil.

type Zone

type Zone string

Zone is an availability zone

func ParseZone

func ParseZone(zone string) (Zone, error)

ParseZone parses a string value into a Zone and returns an error if it has a bad format.

func (Zone) Exists

func (zone Zone) Exists() bool

Exists checks whether a zone exists

func (Zone) Region

func (zone Zone) Region() (Region, error)

Region returns the parent Region for the Zone. Manipulates the string directly to allow unlisted zones formatted as xx-yyy-z.

func (Zone) String

func (zone Zone) String() string

String returns a Zone as a string

func (*Zone) UnmarshalJSON

func (zone *Zone) UnmarshalJSON(input []byte) error

UnmarshalJSON implements the Unmarshaler interface for a Zone. this to call ParseZone on the string input and return the correct Zone object.

Jump to

Keyboard shortcuts

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