Help us shape the future of Go! Take the 2026 Go Developer Survey

aiven

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2018 License: MIT Imports: 9 Imported by: 1

README

Aiven

Aiven has a Python Client, but not a Go client. This is a Go SDK which enables you to use it with Terraform to automatically spin up services together with the rest of your architecture.

Development

This SDK is currently still under development. Only the bits that I currently need are sporadically added. If any new features are required, feel free to open an issue or a PR.

This has been developed purely for the goal of using this together with Terraform, but with general usage in mind. You can see the Terraform provider here

Testing

Currently, tests are only run in development and not through CI. This is due to the requirement of an actual credit card. In the future we'll look into enabling a mock for this so we can run unit tests on CI and do integration tests on our own.

Documentation

Index

Constants

View Source
const APIURL = "https://api.aiven.io/v1beta"

APIURL is the URL we'll use to speak to Aiven. This can be overwritten.

Variables

View Source
var (
	// ErrNoResponseData is uses when there is no data available in the response.
	ErrNoResponseData = errors.New("No response data available")

	// ErrInvalidHost is used when the provided host is formatted incorrectly.
	ErrInvalidHost = errors.New("Host doesn't isn't in the correct format: `hostname:port`")
)

Functions

This section is empty.

Types

type APIResponse

type APIResponse struct {
	Errors  []Error `json:"errors,omitempty"`
	Message string  `json:"message,omitempty"`
}

APIResponse represents a response returned by the Aiven API.

type Backup

type Backup struct {
}

Backup represents the backup model on Aiven.

type BillingHandler

type BillingHandler struct {
	Cards *CardsHandler
	// contains filtered or unexported fields
}

BillingHandler is the client that interacts with the Aiven Billing endpoints.

type Card

type Card struct {
	Brand        string   `json:"brand"`
	CardID       string   `json:"card_id"`
	Country      string   `json:"country"`
	CountryCode  string   `json:"country_code"`
	ExpMonth     int      `json:"exp_month"`
	ExpYear      int      `json:"exp_year"`
	Last4        string   `json:"last4"`
	Name         string   `json:"name"`
	ProjectNames []string `json:"projects"`
}

Card represents the card model on Aiven.

type CardListResponse

type CardListResponse struct {
	APIResponse
	Cards []*Card `json:"cards"`
}

CardListResponse is the response for listing cards.

type CardsHandler

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

CardsHandler is the client that interacts with the cards endpoints on Aiven.

func (*CardsHandler) List

func (h *CardsHandler) List() ([]*Card, error)

List lists all the cards linked to the authenticated account/

type Client

type Client struct {
	APIKey string
	Client *http.Client

	Projects     *ProjectsHandler
	Services     *ServicesHandler
	Databases    *DatabasesHandler
	ServiceUsers *ServiceUsersHandler
	KafkaTopics  *KafkaTopicsHandler
	Billing      *BillingHandler
}

Client represents the instance that does all the calls to the Aiven API.

func NewMFAUserClient added in v0.0.2

func NewMFAUserClient(email, otp, password string) (*Client, error)

NewMFAUserClient creates a new client based on email, one-time password and password.

func NewTokenClient

func NewTokenClient(key string) (*Client, error)

NewTokenClient creates a new client based on a given token.

func NewUserClient

func NewUserClient(email, password string) (*Client, error)

NewUserClient creates a new client based on email and password.

func (*Client) Init

func (c *Client) Init()

Init initializes the client and sets up all the handlers.

type ConsumerGroup added in v0.0.2

type ConsumerGroup struct {
	GroupName string `json:"group_name"`
	Offset    int    `json:"offset"`
}

ConsumerGroup is the group used in partitions.

type CreateDatabaseRequest

type CreateDatabaseRequest struct {
	Database  string `json:"database"`
	LcCollate string `json:"lc_collate,omitempty"`
	LcType    string `json:"lc_type,omitempty"`
}

CreateDatabaseRequest are the parameters used to create a database.

type CreateKafkaTopicRequest added in v0.0.2

type CreateKafkaTopicRequest struct {
	CleanupPolicy         *string `json:"cleanup_policy,omitempty"`
	MinimumInSyncReplicas *int    `json:"min_insync_replicas,omitempty"`
	Partitions            *int    `json:"partitions,omitempty"`
	Replication           *int    `json:"replication,omitempty"`
	RetentionBytes        *int    `json:"retention_bytes,omitempty"`
	RetentionHours        *int    `json:"retention_hours,omitempty"`
	TopicName             string  `json:"topic_name"`
}

CreateKafkaTopicRequest are the parameters used to create a kafka topic.

type CreateProjectRequest

type CreateProjectRequest struct {
	CardID  string `json:"card_id,omitempty"`
	Cloud   string `json:"cloud,omitempty"`
	Project string `json:"project"`
}

CreateProjectRequest are the parameters for creating a project.

type CreateServiceRequest

type CreateServiceRequest struct {
	Cloud       string `json:"cloud,omitempty"`
	GroupName   string `json:"group_name,omitempty"`
	Plan        string `json:"plan,omitempty"`
	ServiceName string `json:"service_name"`
	ServiceType string `json:"service_type"`
}

CreateServiceRequest are the parameters to create a Service.

type CreateServiceUserRequest

type CreateServiceUserRequest struct {
	Username string `json:"username"`
}

CreateServiceUserRequest are the parameters required to create a ServiceUser.

type Database

type Database struct {
	Database  string `json:"database"`
	LcCollate string `json:"lc_collate,omitempty"`
	LcType    string `json:"lc_type,omitempty"`
}

Database represents a database type on Aiven.

type DatabasesHandler

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

DatabasesHandler is the client which interacts with the Aiven database endpoints.

func (*DatabasesHandler) Create

func (h *DatabasesHandler) Create(project, service string, req CreateDatabaseRequest) (*Database, error)

Create creates a database with the given parameters.

func (*DatabasesHandler) Delete

func (h *DatabasesHandler) Delete(project, service, database string) error

Delete deletes the specified database.

type Error

type Error struct {
	Message  string `json:"message"`
	MoreInfo string `json:"more_info"`
	Status   int    `json:"status"`
}

Error represents an Aiven API Error.

func (Error) Error

func (e Error) Error() string

Error concatenates the Status, Message and MoreInfo values.

type KafkaListTopic added in v0.0.2

type KafkaListTopic struct {
	CleanupPolicy         string `json:"cleanup_policy"`
	MinimumInSyncReplicas int    `json:"min_insync_replicas"`
	Partitions            int    `json:"partitions"`
	Replication           int    `json:"replication"`
	RetentionBytes        int    `json:"retention_bytes"`
	RetentionHours        int    `json:"retention_hours"`
	State                 string `json:"state"`
	TopicName             string `json:"topic_name"`
}

KafkaListTopic represents kafka list topic model on Aiven.

type KafkaTopic added in v0.0.2

type KafkaTopic struct {
	CleanupPolicy         string       `json:"cleanup_policy"`
	MinimumInSyncReplicas int          `json:"min_insync_replicas"`
	Partitions            []*Partition `json:"partitions"`
	Replication           int          `json:"replication"`
	RetentionBytes        int          `json:"retention_bytes"`
	RetentionHours        int          `json:"retention_hours"`
	State                 string       `json:"state"`
	TopicName             string       `json:"topic_name"`
}

KafkaTopic represents a Kafka Topic on Aiven.

type KafkaTopicResponse added in v0.0.2

type KafkaTopicResponse struct {
	APIResponse
	Topic *KafkaTopic `json:"topic"`
}

KafkaTopicResponse is the response for Kafka Topic requests.

type KafkaTopicsHandler added in v0.0.2

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

KafkaTopicsHandler is the client which interacts with the kafka endpoints on Aiven.

func (*KafkaTopicsHandler) Create added in v0.0.2

func (h *KafkaTopicsHandler) Create(project, service string, req CreateKafkaTopicRequest) error

Create creats a specific kafka topic.

func (*KafkaTopicsHandler) Delete added in v0.0.2

func (h *KafkaTopicsHandler) Delete(project, service, topic string) error

Delete deletes a specific kafka topic.

func (*KafkaTopicsHandler) Get added in v0.0.2

func (h *KafkaTopicsHandler) Get(project, service, topic string) (*KafkaTopic, error)

Get gets a specific kafka topic.

func (*KafkaTopicsHandler) List added in v0.0.2

func (h *KafkaTopicsHandler) List(project, service string) ([]*KafkaListTopic, error)

List lists all the kafka topics.

func (*KafkaTopicsHandler) Update added in v0.0.2

func (h *KafkaTopicsHandler) Update(project, service, topic string, req UpdateKafkaTopicRequest) error

Update updates a specific topic with the given parameters.

type KafkaTopicsResponse added in v0.0.2

type KafkaTopicsResponse struct {
	APIResponse
	Topics []*KafkaListTopic `json:"topics"`
}

KafkaTopicsResponse is the response for listing kafka topics.

type Partition added in v0.0.2

type Partition struct {
	ConsumerGroups []*ConsumerGroup `json:"consumer_groups"`
	EarliestOffset int              `json:"earliest_offset"`
	ISR            int              `json:"isr"`
	LatestOffset   int              `json:"latest_offset"`
	Partition      int              `json:"partition"`
	Size           int              `json:"size"`
}

Partition represents a Kafka partition.

type Project

type Project struct {
	AvailableCredits string `json:"available_credits"`
	BillingAddress   string `json:"billing_address"`
	Card             Card   `json:"card_info"`
	Country          string `json:"country"`
	CountryCode      string `json:"country_code"`
	DefaultCloud     string `json:"default_cloud"`
	EstimatedBalance string `json:"estimated_balance"`
	PaymentMethod    string `json:"payment_method"`
	Name             string `json:"project_name"`
	VatID            string `json:"vat_id"`
}

Project represents the Project model on Aiven.

type ProjectListResponse

type ProjectListResponse struct {
	APIResponse
	Projects []*Project `json:"projects"`
}

ProjectListResponse is the response from Aiven for listing projects.

type ProjectResponse

type ProjectResponse struct {
	APIResponse
	Project *Project `json:"project"`
}

ProjectResponse is the response from Aiven for the project endpoints.

type ProjectsHandler

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

ProjectsHandler is the client which interacts with the Projects endpoints on Aiven.

func (*ProjectsHandler) Create

Create creates a new project.

func (*ProjectsHandler) Delete

func (h *ProjectsHandler) Delete(project string) error

Delete deletes the given project.

func (*ProjectsHandler) Get

func (h *ProjectsHandler) Get(project string) (*Project, error)

Get gets the specified project.

func (*ProjectsHandler) List

func (h *ProjectsHandler) List() ([]*Project, error)

List lists all the available projects linked to the account.

func (*ProjectsHandler) Update

func (h *ProjectsHandler) Update(project string, req UpdateProjectRequest) (*Project, error)

Update updates the specified project with the given parameters.

type Service

type Service struct {
	CloudName  string         `json:"cloud_name"`
	CreateTime string         `json:"create_time"`
	UpdateTime string         `json:"update_time"`
	GroupList  []string       `json:"group_list"`
	NodeCount  int            `json:"node_count"`
	Plan       string         `json:"plan"`
	Name       string         `json:"service_name"`
	Type       string         `json:"service_type"`
	URI        string         `json:"service_uri"`
	State      string         `json:"state"`
	Metadata   interface{}    `json:"metadata"`
	Users      []*ServiceUser `json:"users"`
}

Service represents the Service model on Aiven.

func (*Service) Hostname

func (s *Service) Hostname() (string, error)

Hostname parses the hostname out of the Service URI.

func (*Service) Port

func (s *Service) Port() (string, error)

Port parses the port out of the service URI.

type ServiceListResponse

type ServiceListResponse struct {
	APIResponse
	Services []*Service `json:"services"`
}

ServiceListResponse represents the response from Aiven for listing services.

type ServiceResponse

type ServiceResponse struct {
	APIResponse
	Service *Service `json:"service"`
}

ServiceResponse represents the response from Aiven after interacting with the Service API.

type ServiceUser

type ServiceUser struct {
	Username   string `json:"username"`
	Password   string `json:"password"`
	Type       string `json:"type"`
	AccessCert string `json:"access_cert"`
	AccessKey  string `json:"access_key"`
}

ServiceUser is the representation of a Service User in the Aiven API.

type ServiceUserResponse

type ServiceUserResponse struct {
	APIResponse
	User *ServiceUser `json:"user"`
}

ServiceUserResponse represents the response after creating a ServiceUser.

type ServiceUsersHandler

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

ServiceUsersHandler is the client that interacts with the ServiceUsers endpoints.

func (*ServiceUsersHandler) Create

func (h *ServiceUsersHandler) Create(project, service string, req CreateServiceUserRequest) (*ServiceUser, error)

Create creates the given User on Aiven.

func (*ServiceUsersHandler) Delete

func (h *ServiceUsersHandler) Delete(project, service, user string) error

Delete deletes the given Service User in Aiven.

type ServicesHandler

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

ServicesHandler is the client that interacts with the Service API endpoints on Aiven.

func (*ServicesHandler) Create

func (h *ServicesHandler) Create(project string, req CreateServiceRequest) (*Service, error)

Create creates the given Service on Aiven.

func (*ServicesHandler) Delete

func (h *ServicesHandler) Delete(project, service string) error

Delete will delete the given service from Aiven.

func (*ServicesHandler) Get

func (h *ServicesHandler) Get(project, service string) (*Service, error)

Get gets a specific service from Aiven.

func (*ServicesHandler) List

func (h *ServicesHandler) List(project string) ([]*Service, error)

List will fetch all services for a given project.

func (*ServicesHandler) Update

func (h *ServicesHandler) Update(project, service string, req UpdateServiceRequest) (*Service, error)

Update will update the given service with the given parameters.

type Token

type Token struct {
	Token string `json:"token"`
	State string `json:"state"`
}

Token represents a user token.

func MFAUserToken added in v0.0.2

func MFAUserToken(email, otp, password string, client *http.Client) (*Token, error)

MFAUserToken retrieves a User Auth Token for a given email/password pair.

func UserToken

func UserToken(email, password string, client *http.Client) (*Token, error)

UserToken creates an authentication token without Multi Factor auth.

type UpdateKafkaTopicRequest added in v0.0.2

type UpdateKafkaTopicRequest struct {
	MinimumInSyncReplicas *int `json:"min_insync_replicas,omitempty"`
	Partitions            *int `json:"partitions,omitempty"`
	RetentionBytes        *int `json:"retention_bytes,omitempty"`
	RetentionHours        *int `json:"retention_hours,omitempty"`
}

UpdateKafkaTopicRequest are the parameters used to update a kafka topic.

type UpdateProjectRequest

type UpdateProjectRequest struct {
	CardID         string `json:"card_id,omitempty"`
	Cloud          string `json:"cloud,omitempty"`
	BillingAddress string `json:"billing_address"`
}

UpdateProjectRequest are the parameters for updating a project.

type UpdateServiceRequest

type UpdateServiceRequest struct {
	Cloud     string `json:"cloud,omitempty"`
	GroupName string `json:"group_name,omitempty"`
	Plan      string `json:"plan,omitempty"`
	Powered   bool   `json:"powered"` // TODO: figure out if we can overwrite the default?
}

UpdateServiceRequest are the parameters to update a Service.

type User

type User struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Type     string `json:"type"`
}

User is the representation of a User model in the Aiven API.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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