cartel

package
v0.85.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 16 Imported by: 3

README

Using the Cartel API client

Container Host is a HSDP service which provides a hardened Docker runtime environment. This API client allows one to spin up Container Host instances using a convenient API. Some examples below:

Spinning up a Container Host instance

package main

import (
	"github.com/philips-software/go-hsdp-api/cartel"
)

func main() {
	client, err := cartel.NewClient(nil, cartel.Config{
		Token:  "YourCartelToken",
		Secret: "YourCartelSecr3t",
		Host:   "cartel-host.here.com",
	})
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	myinstance, _, err := client.Create("myinstance.dev",
		cartel.EncryptVolumes(),
		cartel.VolumesAndSize(1, 50),
		cartel.SecurityGroups("https-from-cf", "tcp-1080"),
		cartel.UserGroups("my-ldap-group"))
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	fmt.Printf("InstanceID: %s\n", myinstance.InstanceID())
	fmt.Printf("InstanceIP: %s\n", myinstance.IPAddress())
}

Get instance details

package main

import (
	"github.com/philips-software/go-hsdp-api/cartel"
)

func pretty(data []byte) string {
	var prettyJSON bytes.Buffer
	_ = json.Indent(&prettyJSON, data, "", "    ")
	return string(prettyJSON.Bytes())
}

func main() {
	client, err := cartel.NewClient(nil, cartel.Config{
		Token:  "YourCartelToken",
		Secret: "YourCartelSecr3t",
		Host:   "cartel-host.here.com",
	})
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	details, _, err := client.Details("myinstancer.dev")
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	fmt.Printf("%v\n", pretty(details))
}

Destroying an instance

package main

import (
	"github.com/philips-software/go-hsdp-api/cartel"
)

func main() {
	client, err := cartel.NewClient(nil, cartel.Config{
		Token:  "YourCartelToken",
		Secret: "YourCartelSecr3t",
		Host:   "cartel-host.here.com",
	})
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	result, _, err := client.Destroy("myinstancer.dev")

	fmt.Printf("Result: %v\n", result.Success())
}

Documentation

Overview

Package cartel provides support for HSDP Cartel services

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingSecret         = errors.New("missing cartel secret")
	ErrMissingToken          = errors.New("missing cartel token")
	ErrMissingHost           = errors.New("missing cartel host")
	ErrNotFound              = errors.New("not found")
	ErrHostnameAlreadyExists = errors.New("hostname already exists")
	ErrInvalidSubnetType     = errors.New("invalid subnet type, must be public or private")
)

Functions

This section is empty.

Types

type AddTagResponse

type AddTagResponse struct {
	Message     string `json:"message,omitempty"`
	Code        int    `json:"code,omitempty"`
	Description string `json:"description,omitempty"`
}

func (AddTagResponse) Success

func (atr AddTagResponse) Success() bool

type Client

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

Client holds the client state

func NewClient

func NewClient(httpClient *http.Client, config *Config) (*Client, error)

NewClient returns an instance of the logger client with the given Config

func (*Client) AddSecurityGroups

func (c *Client) AddSecurityGroups(instances []string, groups []string) (*SecurityGroupsResponse, *Response, error)

func (*Client) AddTags

func (c *Client) AddTags(instances []string, tags map[string]string) (*AddTagResponse, *Response, error)

func (*Client) AddUserGroups

func (c *Client) AddUserGroups(instances []string, groups []string) (*UserGroupsResponse, *Response, error)

func (*Client) BastionHost added in v0.32.1

func (c *Client) BastionHost() string

BastionHost returns the bastion host if it can be guessed correctly An empty string is returned otherwise

func (*Client) Create

func (c *Client) Create(tagName string, opts ...RequestOptionFunc) (*CreateResponse, *Response, error)

func (*Client) Destroy

func (c *Client) Destroy(tagName string) (*DestroyResponse, *Response, error)

func (*Client) GetAllInstances

func (c *Client) GetAllInstances() (*[]InstanceDetails, *Response, error)

func (*Client) GetAllSubnets

func (c *Client) GetAllSubnets() (*SubnetDetails, *Response, error)

func (*Client) GetDeploymentState

func (c *Client) GetDeploymentState(nameTag string) (string, *Response, error)

func (*Client) GetDetails

func (c *Client) GetDetails(tag string) (*InstanceDetails, *Response, error)

func (*Client) GetDetailsMulti

func (c *Client) GetDetailsMulti(tags ...string) (*DetailsResponse, *Response, error)

func (*Client) GetRoles

func (c *Client) GetRoles() (*[]Role, *Response, error)

func (*Client) GetSecurityGroupDetails

func (c *Client) GetSecurityGroupDetails(group string) (*SecurityGroupDetails, *Response, error)

func (*Client) GetSecurityGroups

func (c *Client) GetSecurityGroups() (*[]string, *Response, error)

func (*Client) RemoveSecurityGroups

func (c *Client) RemoveSecurityGroups(instances []string, groups []string) (*SecurityGroupsResponse, *Response, error)

func (*Client) RemoveUserGroups

func (c *Client) RemoveUserGroups(instances []string, groups []string) (*UserGroupsResponse, *Response, error)

func (*Client) SetProtection

func (c *Client) SetProtection(nameTag string, protection bool) (*ProtectionResponse, *Response, error)

func (*Client) Start

func (c *Client) Start(nameTag string) (*StartResponse, *Response, error)

func (*Client) Stop

func (c *Client) Stop(nameTag string) (*StopResponse, *Response, error)

type Config

type Config struct {
	Region     string    `cloud:"-" json:"-"`
	Token      string    `cloud:"token" json:"token"`
	Secret     string    `cloud:"secret" json:"secret"`
	SkipVerify bool      `cloud:"skip_verify" json:"skip_verify"`
	NoTLS      bool      `cloud:"no_tls" json:"no_tls"`
	Host       string    `cloud:"host" json:"host"`
	DebugLog   io.Writer `cloud:"-" json:"-"`
}

Config the client

func (*Config) Valid

func (c *Config) Valid() (bool, error)

Valid returns if all required config fields are present, false otherwise

type CreateResponse

type CreateResponse struct {
	Message []struct {
		EipAddress interface{} `json:"eip_address"`
		InstanceID string      `json:"instance_id"`
		IPAddress  string      `json:"ip_address"`
		Name       string      `json:"name"`
		Role       string      `json:"role"`
	} `json:"message,omitempty"`
	Result      string `json:"result,omitempty"`
	Code        int    `json:"code,omitempty"`
	Description string `json:"description,omitempty"`
}

func (CreateResponse) IPAddress

func (cr CreateResponse) IPAddress() string

func (CreateResponse) InstanceID

func (cr CreateResponse) InstanceID() string

func (CreateResponse) Success

func (cr CreateResponse) Success() bool

type DestroyResponse

type DestroyResponse struct {
	AWS    string            `json:"AWS"`
	Cartel map[string]string `json:"Cartel"`
}

func (DestroyResponse) Success

func (dr DestroyResponse) Success() bool

type DetailsResponse

type DetailsResponse map[string]InstanceDetails

type InstanceDetails

type InstanceDetails struct {
	BlockDevices   []string          `json:"block_devices,omitempty"`
	InstanceID     string            `json:"instance_id"`
	InstanceType   string            `json:"instance_type,omitempty"`
	LaunchTime     string            `json:"launch_time,omitempty"`
	LdapGroups     LdapGroups        `json:"ldap_groups,omitempty"`
	PrivateAddress string            `json:"private_address,omitempty"`
	Protection     bool              `json:"protection,omitempty"`
	PublicAddress  string            `json:"public_address,omitempty"`
	Role           string            `json:"role"`
	SecurityGroups []string          `json:"security_groups,omitempty"`
	State          string            `json:"state,omitempty"`
	Subnet         string            `json:"subnet,omitempty"`
	Tags           map[string]string `json:"tags,omitempty"`
	Vpc            string            `json:"vpc,omitempty"`
	Zone           string            `json:"zone,omitempty"`
	Owner          string            `json:"owner,omitempty"`
	NameTag        string            `json:"name_tag,omitempty"`
}

type LdapGroups

type LdapGroups []string

func (*LdapGroups) UnmarshalJSON

func (lg *LdapGroups) UnmarshalJSON(b []byte) error

type OptionFunc

type OptionFunc func(*http.Request) error

OptionFunc is the function signature function for options

type ProtectionResponse

type ProtectionResponse struct {
	Message     string `json:"message,omitempty"`
	Code        int    `json:"code,omitempty"`
	Description string `json:"description,omitempty"`
}

func (ProtectionResponse) Success

func (pr ProtectionResponse) Success() bool

type RequestBody

type RequestBody struct {
	Token         string            `json:"token,omitempty"`
	NameTag       []string          `json:"name-tag,omitempty"`
	Role          string            `json:"role,omitempty"`
	SecurityGroup []string          `json:"security_group,omitempty"`
	Image         string            `json:"image,omitempty"`
	LDAPGroups    []string          `json:"ldap_groups,omitempty"`
	InstanceType  string            `json:"instance_type,omitempty"`
	NumVolumes    int               `json:"num_vols,omitempty" validate:"max=6"`
	VolSize       int               `json:"vol_size,omitempty" validate:"min=1,max=1000"`
	VolumeType    string            `json:"vol_type,omitempty"`
	IOPs          int               `json:"iops,omitempty" validate:"min=1,max=4000"`
	EncryptVols   bool              `json:"encrypt_vols"`
	SubnetType    string            `json:"subnet_type,omitempty"`
	Subnet        string            `json:"subnet,omitempty"`
	Tags          map[string]string `json:"tags,omitempty"`
	Protect       bool              `json:"protect"`
	VpcId         string            `json:"vpc_id,omitempty"`
}

RequestBody contains parameters for Cartel calls

func (*RequestBody) ToJson

func (crb *RequestBody) ToJson() []byte

type RequestOptionFunc

type RequestOptionFunc func(*RequestBody) error

func IOPs

func IOPs(iops int) RequestOptionFunc

IOPs sets the number of IOPs to provision for attached storage

func Image added in v0.37.0

func Image(image string) RequestOptionFunc

Image sets the image type

func InSubnet

func InSubnet(subnetID string) RequestOptionFunc

InSubnet sets the subnet

func InstanceRole added in v0.21.0

func InstanceRole(role string) RequestOptionFunc

InstanceRole sets the instance role

func InstanceType

func InstanceType(instanceType string) RequestOptionFunc

InstanceType sets the instance type

func Protect

func Protect(value bool) RequestOptionFunc

Protect enables volume encryption

func SecurityGroups

func SecurityGroups(groups ...string) RequestOptionFunc

SecurityGroups sets the security groups

func SubnetType

func SubnetType(subnetType string) RequestOptionFunc

SubnetType sets the subnet type

func Tags added in v0.23.0

func Tags(tags map[string]string) RequestOptionFunc

Tags sets the Tags for the instance

func UserGroups

func UserGroups(groups ...string) RequestOptionFunc

UserGroups sets the user groups (LDAP groups)

func VPCID

func VPCID(vpcID string) RequestOptionFunc

VPCID Sets the VPC ID to use

func VolumeEncryption

func VolumeEncryption(value bool) RequestOptionFunc

VolumeEncryption enables volume encryption

func VolumeType

func VolumeType(volumeType string) RequestOptionFunc

VolumeType sets the EBS volume type

func VolumesAndSize

func VolumesAndSize(nrVols, size int) RequestOptionFunc

VolumesAndSize sets the number of volumes to attach and their size (in GB)

type Response

type Response struct {
	*http.Response
	Message string
}

Response holds a Cartel response

func (*Response) StatusCode added in v0.73.0

func (r *Response) StatusCode() int

type Role

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

type SecurityGroupDetails

type SecurityGroupDetails []SecurityRule

type SecurityGroupsResponse

type SecurityGroupsResponse struct {
	Message     json.RawMessage `json:"message,omitempty"`
	Result      string          `json:"result,omitempty"`
	Code        int             `json:"code,omitempty"`
	Description string          `json:"description,omitempty"`
}

func (SecurityGroupsResponse) Success

func (sgr SecurityGroupsResponse) Success() bool

type SecurityRule

type SecurityRule struct {
	PortRange string   `json:"port_range"`
	Protocol  string   `json:"protocol"`
	Source    []string `json:"source"`
}

type StartResponse

type StartResponse struct {
	Message     json.RawMessage `json:"message,omitempty"`
	Code        int             `json:"code,omitempty"`
	Description string          `json:"description,omitempty"`
}

func (StartResponse) Success

func (sr StartResponse) Success() bool

type StopResponse

type StopResponse struct {
	Message     json.RawMessage `json:"message,omitempty"`
	Code        int             `json:"code,omitempty"`
	Description string          `json:"description,omitempty"`
}

func (StopResponse) Success

func (sr StopResponse) Success() bool

type Subnet

type Subnet struct {
	ID      string `json:"id"`
	Network string `json:"network"`
}

type SubnetDetails

type SubnetDetails map[string]Subnet

type UserGroupsResponse

type UserGroupsResponse struct {
	Message     json.RawMessage `json:"message,omitempty"`
	Result      string          `json:"result,omitempty"`
	Code        int             `json:"code,omitempty"`
	Description string          `json:"description,omitempty"`
}

func (UserGroupsResponse) Success

func (ugr UserGroupsResponse) Success() bool

Jump to

Keyboard shortcuts

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