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

redshift

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package redshift emulates Amazon Redshift over the Query protocol. Clusters run as PostgreSQL containers on localhost (Redshift speaks PostgreSQL's wire protocol and most of its SQL); GetClusterCredentials creates real database logins. Parameter, subnet and security groups, snapshots and logging are metadata. Without Docker the API still answers and Inspect says that nothing runs.

Index

Constants

View Source
const Port = 5439

Port is where Redshift listens, inside the container too.

Variables

This section is empty.

Functions

func Alter

func Alter(user, password string) []string

Alter is the command that changes a password inside a container, where local connections are trusted. Check the name and password first.

func IAMUser

func IAMUser(principal string) string

IAMUser is the database user of an IAM identity, as GetClusterCredentialsWithIAM and Redshift Serverless name it: IAM:<user> or IAMR:<role>.

func Spec

func Spec(user, password, db string, host int) rds.Spec

Spec is the container of a cluster or workgroup: PostgreSQL on Redshift's port, where PUBLIC may create tables in schema public as on Redshift.

func ValidDB

func ValidDB(db string) bool

ValidDB checks a database name.

func ValidPassword

func ValidPassword(pw string) bool

ValidPassword checks a master or admin password: 8 to 64 printable ASCII characters with an uppercase letter, a lowercase letter and a digit, and none of ' " \ / @ or space.

func ValidRole

func ValidRole(r string) bool

ValidRole checks a DbUser or DbGroups name.

func ValidUser

func ValidUser(u string) bool

ValidUser checks a master or admin user name.

Types

type Cluster

type Cluster struct {
	ClusterIdentifier                string
	NodeType                         string
	ClusterStatus                    string `json:",omitempty"` // in views only, from Pogi.State
	ClusterAvailabilityStatus        string `json:",omitempty"` // in views only, from Pogi.State
	MasterUsername                   string
	DBName                           string
	Endpoint                         *rds.Endpoint `json:",omitempty"`
	ClusterCreateTime                time.Time
	AutomatedSnapshotRetentionPeriod int
	ManualSnapshotRetentionPeriod    int
	ClusterSecurityGroups            []Membership `json:",omitempty"`
	VpcSecurityGroups                []rds.VpcSecurityGroup
	ClusterParameterGroups           []ParameterGroupStatus
	ClusterSubnetGroupName           string
	VpcId                            string
	AvailabilityZone                 string
	PreferredMaintenanceWindow       string
	ClusterVersion                   string
	AllowVersionUpgrade              bool
	NumberOfNodes                    int
	PubliclyAccessible               bool
	Encrypted                        bool
	KmsKeyId                         string `json:",omitempty"`
	EnhancedVpcRouting               bool
	IamRoles                         []IamRole `json:",omitempty"`
	DefaultIamRoleArn                string    `json:",omitempty"`
	MaintenanceTrackName             string
	ClusterNodes                     []ClusterNode `json:",omitempty"` // in views only
	ClusterNamespaceArn              string
	AvailabilityZoneRelocationStatus string
	MultiAZ                          string
	Tags                             []rds.Tag
	ClusterSnapshotCopyStatus        *CopyStatus `json:",omitempty"`
	Logging                          *Logging    `json:",omitempty" query:"-"`
	ScheduleIdentifier               string      `json:"scheduleIdentifier,omitempty" query:"-"` // snapshot schedule
	Pogi                             rds.Server  `json:"pogi" query:"-"`
}

Cluster is a provisioned cluster; it owns its container.

type ClusterAssociation

type ClusterAssociation struct{ ClusterIdentifier, ScheduleAssociationState string }

ClusterAssociation is a cluster a schedule is set on.

type ClusterNode

type ClusterNode struct{ NodeRole, PrivateIPAddress, PublicIPAddress string }

ClusterNode is a node of a cluster; one container serves them all.

type CopyGrant

type CopyGrant struct {
	SnapshotCopyGrantName string
	KmsKeyId              string
	Tags                  []rds.Tag
}

CopyGrant lets Redshift use a KMS key to encrypt copied snapshots.

type CopyStatus

type CopyStatus struct {
	DestinationRegion             string
	RetentionPeriod               int
	ManualSnapshotRetentionPeriod int
	SnapshotCopyGrantName         string `json:",omitempty"`
}

CopyStatus is a cluster's snapshot copy setup.

type DB

type DB struct {
	Addr     string // 127.0.0.1:port; empty while nothing answers, and Note says why
	User     string // the master or admin user
	Password string
	Name     string // the default database
	Note     string
}

DB is where the database of a cluster or workgroup answers.

func NewDB

func NewDB(d *docker.Client, srv *rds.Server, user, password, db, what string) *DB

NewDB describes the database srv runs; what names its resource in notes.

func (*DB) Connect

func (d *DB) Connect(ctx context.Context, user, password, db string) (*pgx.Conn, error)

Connect logs in to database db (default: the default database) as user with password (default: the master user).

func (*DB) Login

func (d *DB) Login(ctx context.Context, login, user string, groups []string, create bool, password string, expiry time.Time) error

Login lets login sign in with password until expiry, the way temporary credentials do: a role that joins the database user it stands for (and acts as that user once signed in) and the groups that exist. create first makes the user when it is missing. Check the names first.

type IamRole

type IamRole struct{ IamRoleArn, ApplyStatus string }

IamRole is an IAM role of a cluster.

type Logging

type Logging struct {
	LoggingEnabled                              bool
	BucketName, S3KeyPrefix, LogDestinationType string
	LogExports                                  []string
}

Logging is a cluster's audit logging setup; pogi writes no logs.

type Membership

type Membership struct{ ClusterSecurityGroupName, Status string }

Membership is a cluster security group of a cluster.

type ParamGroup

type ParamGroup struct {
	ParameterGroupName   string
	ParameterGroupFamily string
	Description          string
	Tags                 []rds.Tag
	Params               map[string]string `json:",omitempty" query:"-"` // set by users
}

ParamGroup is a cluster parameter group.

type Parameter

type Parameter struct {
	ParameterName, ParameterValue, Description, Source, DataType, ApplyType string
	IsModifiable                                                            bool
}

Parameter is a parameter of a parameter group.

type ParameterGroupStatus

type ParameterGroupStatus struct{ ParameterGroupName, ParameterApplyStatus string }

ParameterGroupStatus is the parameter group of a cluster.

type Schedule

type Schedule struct {
	ScheduleDefinitions    []string
	ScheduleIdentifier     string
	ScheduleDescription    string
	Tags                   []rds.Tag
	AssociatedClusterCount int
	AssociatedClusters     []ClusterAssociation
}

Schedule is a snapshot schedule; ScheduleDefinitions are rate() or cron() expressions.

type SecurityGroup

type SecurityGroup struct {
	ClusterSecurityGroupName string
	Description              string
	Tags                     []rds.Tag
}

SecurityGroup is a cluster security group, without ingress rules.

type Service

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

Service is the Redshift emulator.

func New

func New(hub *core.Hub) *Service

New creates the Redshift service.

func (*Service) Close

func (s *Service) Close() error

Close removes the containers, except those persisted state resumes next run.

func (*Service) DB

func (s *Service) DB(account, region, id string) *DB

DB is where the database of a cluster answers, for the Data API; nil when there is no such cluster.

func (*Service) Info

func (s *Service) Info() core.Info

func (*Service) Inspect

func (s *Service) Inspect(table, id string) any

Inspect returns a cluster with pogi's side: container, master password, state and pogiNote.

func (*Service) Load

func (s *Service) Load(b []byte) error

Load restores state and reconnects to the containers by name (--persist leaves them behind on shutdown); containers of dropped clusters go.

func (*Service) Reset

func (s *Service) Reset()

func (*Service) Resources

func (s *Service) Resources() []core.Table

Resources lists clusters for the console.

func (*Service) Save

func (s *Service) Save() ([]byte, error)

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Snapshot

type Snapshot struct {
	SnapshotIdentifier            string
	ClusterIdentifier             string
	SnapshotCreateTime            time.Time
	Status                        string
	Port                          int
	AvailabilityZone              string
	ClusterCreateTime             time.Time
	MasterUsername                string
	ClusterVersion                string
	SnapshotType                  string
	NodeType                      string
	NumberOfNodes                 int
	DBName                        string
	VpcId                         string
	Encrypted                     bool
	KmsKeyId                      string `json:",omitempty"`
	EnhancedVpcRouting            bool
	OwnerAccount                  string
	ManualSnapshotRetentionPeriod int
	SnapshotArn                   string
	Tags                          []rds.Tag
}

Snapshot is a manual snapshot. ponytail: metadata only, like RDS's: restoring needs a dump of the container.

type SubnetGroup

type SubnetGroup struct {
	ClusterSubnetGroupName string
	Description            string
	VpcId                  string
	SubnetGroupStatus      string
	Subnets                []rds.Subnet
	Tags                   []rds.Tag
}

SubnetGroup is a cluster subnet group.

type TaggedResource

type TaggedResource struct {
	Tag                        rds.Tag
	ResourceName, ResourceType string
}

TaggedResource is a tag of a resource, as DescribeTags lists them.

Jump to

Keyboard shortcuts

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