symbiosis

package module
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: Apache-2.0 Imports: 7 Imported by: 12

README

Symbiosis Golang SDK


Coverage Status

Installation

symbiosis-go is compatible with modern Go releases in module mode, with Go installed:

go get github.com/symbiosis-cloud/symbiosis-go

will resolve and add the package to the current development module, along with its dependencies.

Alternatively the same can be achieved if you use import in a package:

import "github.com/symbiosis-cloud/symbiosis-go"

and run go get without parameters.

Usage

Creating the client

You can easily instantiate the API client by providing it with a valid API key:

client, err := symbiosis.NewClientFromAPIKey(os.Getenv("SYMBIOSIS_API_KEY"))
Customizing client

ClientOptions can be passed to symbiosis.NewClientFromAPIKey()

for example:

// Changing the symbiosis API endpoint
client, err := symbiosis.NewClientFromAPIKey(os.Getenv("SYMBIOSIS_API_KEY"), symbiosis.WithEndpoint("https://some-other-url"))

// Setting a default timeout
client, err := symbiosis.NewClientFromAPIKey(os.Getenv("SYMBIOSIS_API_KEY"), symbiosis.WithTimeout(time.Second * 30)))
Inviting team members:
members, err := client.InviteTeamMembers([]string{"test1@symbiosis.host", "test2@symbiosis.host"}, symbiosis.RoleAdmin)

Valid roles can be obtained by using the symbiosis.GetValidRoles() function which returns a map[string]bool of valid roles.

Running tests

go test

Generating mocks

Mocks can be generated by running (requires Docker):

docker run -v "$PWD":/src -w /src vektra/mockery --all

TODO:

  • Expand readme
  • Add single node creation call
  • Public docs
  • Add integration tests

Documentation

Index

Constants

View Source
const (
	APIEndpoint        = "https://api.symbiosis.host"
	StagingAPIEndpoint = "https://api.staging.symbiosis.host"
)
View Source
const RegionJson = `{
	"id": "random-uuid",
	"name": "germany-1"
}`

Variables

This section is empty.

Functions

func GetValidRoles

func GetValidRoles() map[UserRole]bool

func ValidateRole

func ValidateRole(role UserRole) error

Types

type ApiKey added in v1.1.6

type ApiKey struct {
	ID          string    `json:"id"`
	Token       string    `json:"token"`
	SubjectID   string    `json:"subjectId"`
	Role        UserRole  `json:"role"`
	Description string    `json:"description"`
	LastUsedAt  time.Time `json:"lastUsedAt"`
}

type ApiKeyCollection added in v1.1.6

type ApiKeyCollection []*ApiKey

type ApiKeyInput added in v1.1.6

type ApiKeyInput struct {
	Role        UserRole `json:"role"`
	Description string   `json:"description"`
}

type ApiKeyService added in v1.1.6

type ApiKeyService interface {
	Create(input ApiKeyInput) (*ApiKey, error)
	List() (ApiKeyCollection, error)
	Delete(id string) error
}

type ApiKeyServiceClient added in v1.1.6

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

func (*ApiKeyServiceClient) Create added in v1.1.6

func (n *ApiKeyServiceClient) Create(input ApiKeyInput) (*ApiKey, error)

func (*ApiKeyServiceClient) Delete added in v1.1.6

func (n *ApiKeyServiceClient) Delete(id string) error

func (*ApiKeyServiceClient) List added in v1.1.6

type AuthError

type AuthError struct {
	StatusCode int
	Err        error
}

func (*AuthError) Error

func (e *AuthError) Error() string

type AutoscalingSettings added in v1.0.9

type AutoscalingSettings struct {
	Enabled bool `json:"enabled"`
	MinSize int  `json:"minSize"`
	MaxSize int  `json:"maxSize"`
}

type CallOption

type CallOption func(req *resty.Request)

func WithBody

func WithBody(body interface{}) CallOption

type Client

type Client struct {
	Team     TeamService
	Cluster  ClusterService
	NodePool NodePoolService
	Node     NodeService
	Secret   SecretService
	Project  ProjectService
	Region   RegionService
	ApiKeys  ApiKeyService
	// contains filtered or unexported fields
}

func NewClientFromAPIKey

func NewClientFromAPIKey(apiKey string, opts ...ClientOption) (*Client, error)

func NewClientFromToken added in v1.0.13

func NewClientFromToken(token string, teamId string, opts ...ClientOption) (*Client, error)

func (*Client) Call

func (c *Client) Call(route string, method string, targetInterface interface{}, opts ...CallOption) error

func (*Client) ValidateResponse

func (c *Client) ValidateResponse(resp *resty.Response) error

type ClientOption

type ClientOption func(c *resty.Client)

func WithEndpoint

func WithEndpoint(endpoint string) ClientOption

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

type Cluster

type Cluster struct {
	ID                string      `json:"id"`
	Name              string      `json:"name"`
	KubeVersion       string      `json:"kubeVersion"`
	APIServerEndpoint string      `json:"apiServerEndpoint"`
	State             string      `json:"state"`
	Region            *Region     `json:"region"`
	Nodes             []*Node     `json:"nodes"`
	NodePools         []*NodePool `json:"nodePools"`
	CreatedAt         time.Time   `json:"createdAt"`
	IsHighlyAvailable bool        `json:"isHighlyAvailable"`
}

type ClusterIdentity added in v1.0.4

type ClusterIdentity struct {
	CertificatePem                 string `json:"certificatePem"`
	PrivateKeyPem                  string `json:"privateKeyPem"`
	ExpiresAtEpochSecond           int    `json:"expiresAtEpochSecond"`
	ClusterCertificateAuthorityPem string `json:"clusterCertificateAuthorityPem"`
	KubeConfig                     string `json:"kubeConfig"`
}

type ClusterInput

type ClusterInput struct {
	Name              string                 `json:"name"`
	KubeVersion       string                 `json:"kubeVersion"`
	Region            string                 `json:"regionName"`
	Nodes             []ClusterNodePoolInput `json:"nodes"`
	IsHighlyAvailable bool                   `json:"isHighlyAvailable"`
}

type ClusterList

type ClusterList struct {
	Clusters []*Cluster `json:"content"`
	*SortAndPageable
}

type ClusterNodePoolInput added in v1.1.1

type ClusterNodePoolInput struct {
	Name         string              `json:"name"`
	NodeTypeName string              `json:"nodeTypeName"`
	Quantity     int                 `json:"quantity"`
	Labels       []NodeLabel         `json:"labels"`
	Taints       []NodeTaint         `json:"taints"`
	Autoscaling  AutoscalingSettings `json:"autoscaling"`
}

type ClusterService

type ClusterService interface {
	List(maxSize int, page int) (*ClusterList, error)
	Describe(clusterName string) (*Cluster, error)
	DescribeById(id string) (*Cluster, error)
	Create(input *ClusterInput) (*Cluster, error)
	Delete(clusterName string) error
	ListNodes(clusterName string) (*NodeList, error)
	CreateServiceAccountForSelf(clusterName string) (*ServiceAccount, error)
	GetServiceAccount(clusterName string, serviceAccountId string) (*ServiceAccount, error)
	CreateServiceAccount(clusterName string, subjectId string) (*ServiceAccount, error)
	DeleteServiceAccount(clusterName string, serviceAccountId string) error
	ListUserServiceAccounts(clusterName string) ([]*UserServiceAccount, error)
	GetIdentity(clusterName string) (*ClusterIdentity, error)
}

type ClusterServiceClient added in v1.0.10

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

func (*ClusterServiceClient) Create added in v1.0.10

func (c *ClusterServiceClient) Create(input *ClusterInput) (*Cluster, error)

func (*ClusterServiceClient) CreateServiceAccount added in v1.0.10

func (c *ClusterServiceClient) CreateServiceAccount(clusterName string, subjectId string) (*ServiceAccount, error)

func (*ClusterServiceClient) CreateServiceAccountForSelf added in v1.0.10

func (c *ClusterServiceClient) CreateServiceAccountForSelf(clusterName string) (*ServiceAccount, error)

func (*ClusterServiceClient) Delete added in v1.0.10

func (c *ClusterServiceClient) Delete(clusterName string) error

func (*ClusterServiceClient) DeleteServiceAccount added in v1.0.10

func (c *ClusterServiceClient) DeleteServiceAccount(clusterName string, serviceAccountId string) error

func (*ClusterServiceClient) Describe added in v1.0.10

func (c *ClusterServiceClient) Describe(clusterName string) (*Cluster, error)

func (*ClusterServiceClient) DescribeById added in v1.0.10

func (c *ClusterServiceClient) DescribeById(id string) (*Cluster, error)

func (*ClusterServiceClient) GetIdentity added in v1.0.10

func (c *ClusterServiceClient) GetIdentity(clusterName string) (*ClusterIdentity, error)

func (*ClusterServiceClient) GetServiceAccount added in v1.0.10

func (c *ClusterServiceClient) GetServiceAccount(clusterName string, serviceAccountId string) (*ServiceAccount, error)

func (*ClusterServiceClient) List added in v1.0.10

func (c *ClusterServiceClient) List(maxSize int, page int) (*ClusterList, error)

func (*ClusterServiceClient) ListNodes added in v1.0.10

func (c *ClusterServiceClient) ListNodes(clusterName string) (*NodeList, error)

func (*ClusterServiceClient) ListUserServiceAccounts added in v1.0.10

func (c *ClusterServiceClient) ListUserServiceAccounts(clusterName string) ([]*UserServiceAccount, error)

type Configuration added in v1.1.3

type Configuration struct {
	ProductionBranch string `json:"productionBranch"`
}

type GenericError

type GenericError struct {
	Status    int32  `json:"status"`
	ErrorType string `json:"error"`
	Message   string `json:"message"`
	Path      string `json:"path"`
}

func (*GenericError) Error

func (e *GenericError) Error() string

type Invite

type Invite struct {
	Emails []string `json:"emails"`
	Role   UserRole `json:"role"`
}

type Node

type Node struct {
	ID                 string    `json:"id"`
	Name               string    `json:"name"`
	NodeType           *NodeType `json:"nodeType"`
	Region             *Region   `json:"region"`
	PrivateIPv4Address string    `json:"privateIPv4Address"`
	State              string    `json:"state"`
	// contains filtered or unexported fields
}

type NodeLabel added in v1.0.5

type NodeLabel struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type NodeList

type NodeList struct {
	Nodes []*Node `json:"content"`
	*SortAndPageable
}

type NodePool

type NodePool struct {
	ID              string              `json:"id"`
	Name            string              `json:"name"`
	NodeTypeName    string              `json:"nodeTypeName"`
	ClusterName     string              `json:"clusterName"`
	DesiredQuantity int                 `json:"desiredQuantity"`
	Labels          []*NodeLabel        `json:"labels"`
	Taints          []*NodeTaint        `json:"taints"`
	Nodes           []*Node             `json:"nodes"`
	Autoscaling     AutoscalingSettings `json:"autoscaling"`
}

type NodePoolInput

type NodePoolInput struct {
	Name         string              `json:"name"`
	ClusterName  string              `json:"clusterName"`
	NodeTypeName string              `json:"nodeTypeName"`
	Quantity     int                 `json:"quantity"`
	Labels       []NodeLabel         `json:"labels"`
	Taints       []NodeTaint         `json:"taints"`
	Autoscaling  AutoscalingSettings `json:"autoscaling"`
}

type NodePoolService

type NodePoolService interface {
	Describe(id string) (*NodePool, error)
	Create(input *NodePoolInput) (*NodePool, error)
	Update(nodePoolId string, input *NodePoolUpdateInput) error
	Delete(nodePoolId string) error
}

type NodePoolServiceClient added in v1.0.10

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

func (*NodePoolServiceClient) Create added in v1.0.10

func (n *NodePoolServiceClient) Create(input *NodePoolInput) (*NodePool, error)

func (*NodePoolServiceClient) Delete added in v1.0.10

func (n *NodePoolServiceClient) Delete(nodePoolId string) error

func (*NodePoolServiceClient) Describe added in v1.0.10

func (n *NodePoolServiceClient) Describe(id string) (*NodePool, error)

func (*NodePoolServiceClient) Update added in v1.0.10

func (n *NodePoolServiceClient) Update(nodePoolId string, input *NodePoolUpdateInput) error

type NodePoolUpdateInput

type NodePoolUpdateInput struct {
	Name        string              `json:"name,omitempty"`
	Quantity    int                 `json:"quantity"`
	Autoscaling AutoscalingSettings `json:"autoscaling"`
}

type NodeService

type NodeService interface {
	Describe(name string) (*Node, error)
	Recycle(name string) error
	Delete(name string) error
	Types() ([]NodeType, error)
}

type NodeServiceClient added in v1.0.10

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

func (*NodeServiceClient) Delete added in v1.0.10

func (n *NodeServiceClient) Delete(name string) error

func (*NodeServiceClient) Describe added in v1.0.10

func (n *NodeServiceClient) Describe(name string) (*Node, error)

func (*NodeServiceClient) Recycle added in v1.0.10

func (n *NodeServiceClient) Recycle(name string) error

func (*NodeServiceClient) Types added in v1.1.4

func (n *NodeServiceClient) Types() ([]NodeType, error)

type NodeTaint added in v1.0.5

type NodeTaint struct {
	Key    string          `json:"key"`
	Value  string          `json:"value"`
	Effect SchedulerEffect `json:"effect"`
}

type NodeType

type NodeType struct {
	ID        string   `json:"id"`
	Name      string   `json:"name"`
	MemoryMi  int      `json:"memoryMi"`
	StorageGi int      `json:"storageGi"`
	Vcpu      int      `json:"vcpu"`
	Product   *Product `json:"product"`
}

type NotFoundError

type NotFoundError struct {
	StatusCode int
	URL        string
	Method     string
}

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type Product

type Product struct {
	ProductCosts []*ProductCost `json:"productCosts"`
}

type ProductCost

type ProductCost struct {
	Currency string  `json:"currency"`
	UnitCost float32 `json:"unitCost"`
}

type Project added in v1.1.3

type Project struct {
	ID                  string        `json:"id"`
	Name                string        `json:"name"`
	Owner               string        `json:"owner"`
	Repository          string        `json:"repository"`
	Configuration       Configuration `json:"configuration"`
	ProductionClusterID interface{}   `json:"productionClusterId"`
}

type ProjectEnvironment added in v1.1.2

type ProjectEnvironment string
const (
	ENVIRONMENT_DEVELOPMENT ProjectEnvironment = "development"
	ENVIRONMENT_PREVIEW     ProjectEnvironment = "preview"
	ENVIRONMENT_PRODUCTION  ProjectEnvironment = "production"
)

type ProjectService added in v1.1.3

type ProjectService interface {
	List() ([]*Project, error)
	Describe(projectName string) (*Project, error)
}

type ProjectServiceClient added in v1.1.3

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

func (*ProjectServiceClient) Describe added in v1.1.3

func (n *ProjectServiceClient) Describe(projectName string) (*Project, error)

func (*ProjectServiceClient) List added in v1.1.3

func (n *ProjectServiceClient) List() ([]*Project, error)

type Region

type Region struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type RegionService added in v1.1.4

type RegionService interface {
	List() ([]Region, error)
}

type RegionServiceClient added in v1.1.4

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

func (*RegionServiceClient) List added in v1.1.4

func (n *RegionServiceClient) List() ([]Region, error)

type SchedulerEffect added in v1.0.5

type SchedulerEffect string
const (
	EFFECT_NO_SCHEDULE        SchedulerEffect = "NoSchedule"
	EFFECT_PREFER_NO_SCHEDULE SchedulerEffect = "PreferNoSchedule"
	EFFECT_NO_EXECUTE         SchedulerEffect = "NoExecute"
)

type Secret added in v1.1.2

type Secret struct {
	DevelopmentValue string `json:"developmentValue"`
	PreviewValue     string `json:"previewValue"`
	ProductionValue  string `json:"productionValue"`
}

type SecretCollection added in v1.1.2

type SecretCollection map[string]*Secret

type SecretService added in v1.1.2

type SecretService interface {
	Create(project string, secretKey string, input Secret) error
	GetSecretsByProject(project string) (SecretCollection, error)
	GetSecretsByProjectAndEnvironment(project string, environment ProjectEnvironment) (map[string]string, error)
}

type SecretServiceClient added in v1.1.2

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

func (*SecretServiceClient) Create added in v1.1.2

func (n *SecretServiceClient) Create(project string, secretKey string, input Secret) error

func (*SecretServiceClient) GetSecretsByProject added in v1.1.2

func (n *SecretServiceClient) GetSecretsByProject(project string) (SecretCollection, error)

func (*SecretServiceClient) GetSecretsByProjectAndEnvironment added in v1.1.2

func (n *SecretServiceClient) GetSecretsByProjectAndEnvironment(project string, environment ProjectEnvironment) (map[string]string, error)

type ServiceAccount

type ServiceAccount struct {
	ID                          string `json:"id"`
	KubeConfig                  string `json:"kubeConfig"`
	ServiceAccountToken         string `json:"serviceAccountToken"`
	ClusterCertificateAuthority string `json:"clusterCertificateAuthority"`
}

type ServiceAccountInput

type ServiceAccountInput struct {
	SubjectId string `json:"subjectId"`
}

type SortAndPageable

type SortAndPageable struct {
	Pageable struct {
		Sort struct {
			Sorted   bool `json:"sorted"`
			Unsorted bool `json:"unsorted"`
			Empty    bool `json:"empty"`
		} `json:"sort"`
		PageNumber int  `json:"pageNumber"`
		PageSize   int  `json:"pageSize"`
		Offset     int  `json:"offset"`
		Paged      bool `json:"paged"`
		Unpaged    bool `json:"unpaged"`
	} `json:"pageable"`
	TotalPages    int  `json:"totalPages"`
	TotalElements int  `json:"totalElements"`
	Last          bool `json:"last"`
	Sort          struct {
		Sorted   bool `json:"sorted"`
		Unsorted bool `json:"unsorted"`
		Empty    bool `json:"empty"`
	} `json:"sort"`
	NumberOfElements int  `json:"numberOfElements"`
	First            bool `json:"first"`
	Size             int  `json:"size"`
	Number           int  `json:"number"`
	Empty            bool `json:"empty"`
}

type SymbiosisClient added in v1.0.10

type SymbiosisClient interface {
	NewClientFromAPIKey(apiKey string, opts ...ClientOption) (*Client, error)
}

type TeamMember

type TeamMember struct {
	Email  string   `json:"email"`
	TeamId string   `json:"teamId"`
	Role   UserRole `json:"role"`
}

type TeamService

type TeamService interface {
	GetMemberByEmail(email string) (*TeamMember, error)
	GetInvitationByEmail(email string) (*TeamMember, error)
	InviteMembers(emails []string, role UserRole) ([]*TeamMember, error)
	DeleteMember(email string) error
	ChangeRole(email string, role UserRole) error
}

type TeamServiceClient added in v1.0.10

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

func (*TeamServiceClient) ChangeRole added in v1.0.10

func (t *TeamServiceClient) ChangeRole(email string, role UserRole) error

func (*TeamServiceClient) DeleteMember added in v1.0.10

func (t *TeamServiceClient) DeleteMember(email string) error

func (*TeamServiceClient) GetInvitationByEmail added in v1.0.10

func (t *TeamServiceClient) GetInvitationByEmail(email string) (*TeamMember, error)

func (*TeamServiceClient) GetMemberByEmail added in v1.0.10

func (t *TeamServiceClient) GetMemberByEmail(email string) (*TeamMember, error)

func (*TeamServiceClient) InviteMembers added in v1.0.10

func (t *TeamServiceClient) InviteMembers(emails []string, role UserRole) ([]*TeamMember, error)

type UserRole added in v1.1.6

type UserRole string
const (

	// Has full access, can create teams
	ROLE_OWNER UserRole = "OWNER"

	// Has full access within a team, can invite other team members
	ROLE_ADMIN UserRole = "ADMIN"

	// Can manage resources in clusters but not create them
	ROLE_MEMBER UserRole = "MEMBER"
)

type UserServiceAccount

type UserServiceAccount struct {
	ID        string    `json:"id"`
	CreatedAt time.Time `json:"createdAt"`
	SubjectID string    `json:"subjectId"`
	APIKeyID  string    `json:"apiKeyId"`
	Type      string    `json:"type"`
}

Directories

Path Synopsis
example module

Jump to

Keyboard shortcuts

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