atlas

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPlanIDNotFound = errors.New("plan-id not in the catalog")

	ErrUnauthorized = errors.New("Invalid API key")

	ErrClusterNotFound      = errors.New("Cluster not found")
	ErrClusterAlreadyExists = errors.New("Cluster already exists")

	ErrUserNotFound      = errors.New("User not found")
	ErrUserAlreadyExists = errors.New("User already exists")
)

Different errors the api may return.

View Source
var (
	ClusterStateIdle      = "IDLE"
	ClusterStateCreating  = "CREATING"
	ClusterStateUpdating  = "UPDATING"
	ClusterStateDeleting  = "DELETING"
	ClusterStateDeleted   = "DELETED"
	ClusterStateRepairing = "REPAIRING"
)

All states a cluster can be in.

View Source
var (
	ClusterTypeReplicaSet = "REPLICASET"
	ClusterTypeSharded    = "SHARDED"
)

The different types of clusters available in Atlas.

Functions

This section is empty.

Types

type AutoScalingConfig

type AutoScalingConfig struct {
	DiskGBEnabled bool `json:"diskGBEnabled,omitempty"`
}

AutoScalingConfig represents the autoscaling settings for a cluster.

type BIConnectorConfig

type BIConnectorConfig struct {
	Enabled        bool   `json:"enabled,omitempty"`
	ReadPreference string `json:"readPreference,omitempty"`
}

BIConnectorConfig represents the BI connector settings for a cluster.

type Client

type Client interface {
	CreateCluster(cluster Cluster) (*Cluster, error)
	UpdateCluster(cluster Cluster) (*Cluster, error)
	DeleteCluster(name string) error
	GetCluster(name string) (*Cluster, error)
	GetDashboardURL(clusterName string) string

	CreateUser(user User) (*User, error)
	GetUser(name string) (*User, error)
	DeleteUser(name string) error

	GetProvider(name string) (*Provider, error)
}

Client is an interface for interacting with the Atlas API.

type Cluster

type Cluster struct {
	Name string `json:"name"`

	AutoScaling              AutoScalingConfig `json:"autoScaling,omitempty"`
	BackupEnabled            bool              `json:"backupEnabled,omitempty"`
	BIConnector              BIConnectorConfig `json:"biConnector,omitempty"`
	ClusterType              string            `json:"clusterType,omitempty"`
	DiskSizeGB               float64           `json:"diskSizeGB,omitempty"`
	EncryptionAtRestProvider string            `json:"encryptionAtRestProvider,omitempty"`
	MongoDBMajorVersion      string            `json:"mongoDBMajorVersion,omitempty"`
	NumShards                uint              `json:"numShards,omitempty"`
	ProviderBackupEnabled    bool              `json:"providerBackupEnabled,omitempty"`
	ReplicationSpecs         []ReplicationSpec `json:"replicationSpecs,omitempty"`
	ProviderSettings         *ProviderSettings `json:"providerSettings"`

	// Read-only attributes
	StateName  string `json:"stateName,omitempty"`
	SrvAddress string `json:"srvAddress,omitempty"`
}

Cluster represents a single cluster in Atlas.

type HTTPClient

type HTTPClient struct {
	BaseURL    string
	GroupID    string
	PublicKey  string
	PrivateKey string

	HTTP *http.Client
}

HTTPClient is the main implementation of the Client interface which communicates with the Atlas API.

func NewClient

func NewClient(baseURL string, groupID string, publicKey string, privateKey string) *HTTPClient

NewClient will create a new HTTPClient with the specified connection details.

func (*HTTPClient) CreateCluster

func (c *HTTPClient) CreateCluster(cluster Cluster) (*Cluster, error)

CreateCluster will create a new cluster asynchronously. POST /clusters

func (*HTTPClient) CreateUser

func (c *HTTPClient) CreateUser(user User) (*User, error)

CreateUser will create a new database user with read/write access to all databases. Endpoint: POST /databaseUsers

func (*HTTPClient) DeleteCluster

func (c *HTTPClient) DeleteCluster(name string) error

DeleteCluster will terminate a cluster asynchronously. DELETE /clusters/{CLUSTER-NAME}

func (*HTTPClient) DeleteUser

func (c *HTTPClient) DeleteUser(name string) error

DeleteUser will delete an existing database user. Endpoint: DELETE /databaseUsers/{USERNAME}

func (*HTTPClient) GetCluster

func (c *HTTPClient) GetCluster(name string) (*Cluster, error)

GetCluster will find a cluster by name. GET /clusters/{CLUSTER-NAME}

func (*HTTPClient) GetDashboardURL

func (c *HTTPClient) GetDashboardURL(clusterName string) string

GetDashboardURL prepares the url where the specific cluster can be found in the Dashboard UI

func (*HTTPClient) GetProvider

func (c *HTTPClient) GetProvider(name string) (*Provider, error)

GetProvider will find a provider by name using the private API. GET /cloudProviders/{NAME}/options

func (*HTTPClient) GetUser

func (c *HTTPClient) GetUser(name string) (*User, error)

GetUser will find a database user by its username. GET /databaseUsers/admin/{USERNAME}

func (*HTTPClient) UpdateCluster

func (c *HTTPClient) UpdateCluster(cluster Cluster) (*Cluster, error)

UpdateCluster will update a cluster asynchronously. PATCH /clusters/{CLUSTER-NAME}

type InstanceSize

type InstanceSize struct {
	Name string `json:"name"`
}

InstanceSize represents an available cluster size.

type Provider

type Provider struct {
	Name          string `json:"@provider"`
	InstanceSizes map[string]InstanceSize
}

Provider represents a single cloud provider to which a cluster can be deployed.

type ProviderSettings

type ProviderSettings struct {
	ProviderName        string `json:"providerName"`
	InstanceSizeName    string `json:"instanceSizeName"`
	RegionName          string `json:"regionName,omitempty"`
	BackingProviderName string `json:"backingProviderName,omitempty"`

	DiskIOPS         uint   `json:"diskIOPS,omitempty"`
	DiskTypeName     string `json:"diskTypeName,omitempty"`
	EncryptEBSVolume bool   `json:"encryptEBSVolume,omitempty"`
	VolumeType       string `json:"volumeType,omitempty"`
}

ProviderSettings represents the provider setting for a cluster.

type RegionsConfig

type RegionsConfig struct {
	ElectableNodes int `json:"electableNodes"`
	ReadOnlyNodes  int `json:"readOnlyNodes"`
	AnalyticsNodes int `json:"analyticsNodes,omitempty"`
	Priority       int `json:"priority,omitempty"`
}

RegionsConfig represents a region's config in a replication spec.

type ReplicationSpec

type ReplicationSpec struct {
	// Unique identifier for a zone's replication document. Required for existing
	// zones and optional if adding new zones to a Global Cluster.
	ID            string                   `json:"id,omitempty"`
	NumShards     uint                     `json:"numShards,omitempty"`
	RegionsConfig map[string]RegionsConfig `json:"regionsConfig,omitempty"`
	ZoneName      string                   `json:"zoneName,omitempty"`
}

ReplicationSpec represents the replication settings for a single region.

type Role

type Role struct {
	Name           string `json:"roleName"`
	DatabaseName   string `json:"databaseName,omitempty"`
	CollectionName string `json:"collectionName,omitempty"`
}

Role represents the role of a database user.

type User

type User struct {
	Username     string `json:"username"`
	Password     string `json:"password"`
	DatabaseName string `json:"databaseName"`
	LDAPAuthType string `json:"ldapAuthType,omitempty"`
	Roles        []Role `json:"roles,omitempty"`
}

User represents a single Atlas database user.

Jump to

Keyboard shortcuts

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