gcp

package
v0.0.0-...-5c79d48 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetIDToken

func GetIDToken(ctx context.Context) (string, error)

GetIDToken gets an ID token from GCP instance metadata.

func RunCommand

func RunCommand(ctx context.Context, req *RunCommandRequest) error

RunCommand runs a command on an instance.

Types

type ClusterDetails

type ClusterDetails struct {
	// ProjectID is the GCP project ID to which the cluster belongs.
	ProjectID string
	// Locations are the cluster locations.
	Location string
	// Name is the cluster name.
	Name string
}

ClusterDetails is the cluster identification properties.

func (*ClusterDetails) CheckAndSetDefaults

func (c *ClusterDetails) CheckAndSetDefaults() error

CheckAndSetDefaults check and set defaults for ClusterDetails.

type GKEClient

type GKEClient interface {
	// ListClusters lists the GCP GKE clusters that belong to the projectID and are
	// located in location.
	// location supports wildcard "*".
	ListClusters(ctx context.Context, projectID string, location string) ([]GKECluster, error)
	// GetClusterRestConfig returns the Kubernetes client config to connect to the
	// specified cluster. The access token is based on the default credentials configured
	// for the current GCP Service Account and must include the following permissions:
	// - container.clusters.get
	// - container.clusters.impersonate
	// - container.clusters.list
	// - container.pods.get
	// - container.selfSubjectAccessReviews.create
	// - container.selfSubjectRulesReviews.create
	// It also returns the token expiration time from which the token is no longer valid.
	GetClusterRestConfig(ctx context.Context, cfg ClusterDetails) (*rest.Config, time.Time, error)
}

GKEClient is an interface to interact with GCP Clusters.

func NewGKEClient

func NewGKEClient(ctx context.Context) (GKEClient, error)

NewGKEClient returns a GKEClient interface wrapping container.ClusterManagerClient and oauth2.TokenSource for interacting with GCP Kubernetes Service.

func NewGKEClientWithConfig

func NewGKEClientWithConfig(ctx context.Context, cfg GKEClientConfig) (GKEClient, error)

NewGKEClientWithConfig returns a GKEClient interface wrapping container.ClusterManagerClient and oauth2.TokenSource for interacting with GCP Kubernetes Service.

type GKEClientConfig

type GKEClientConfig struct {
	// ClusterClient is the GCP client for container service.
	ClusterClient gcpGKEClient
	// TokenSource is the OAuth2 token generator for Google auth.
	// The scope must include the kubernetesEngineScope.
	TokenSource oauth2.TokenSource
}

GKEClientConfig is the client configuration for GKEClient.

func (*GKEClientConfig) CheckAndSetDefaults

func (c *GKEClientConfig) CheckAndSetDefaults(ctx context.Context) (err error)

CheckAndSetDefaults check and set defaults for GKEClientConfig.

type GKECluster

type GKECluster struct {
	// Name is the cluster name.
	Name string
	// Description is the cluster description field in GCP.
	Description string
	// Location is the cluster location.
	Location string
	// ProjectID is the GCP project ID to which the cluster belongs.
	ProjectID string
	// Status is the cluster current status.
	Status containerpb.Cluster_Status
	// Labels are the cluster labels in GCP.
	Labels map[string]string
}

GKECluster represents a GKE cluster and contains the information necessary for Teleport Discovery to decide whether or not to import the cluster.

type Instance

type Instance struct {
	// Name is the instance's name.
	Name string
	// Zone is the instance's zone.
	Zone string
	// ProjectID is the ID of the project the VM is in.
	ProjectID string
	// ServiceAccount is the email address of the VM's service account, if any.
	ServiceAccount string
	// Labels is the instance's labels.
	Labels map[string]string
	// contains filtered or unexported fields
}

Instance represents a GCP VM.

func (*Instance) InstanceRequest

func (i *Instance) InstanceRequest() InstanceRequest

InstanceRequest formats an instance request based on an instance.

type InstanceRequest

type InstanceRequest struct {
	// ProjectID is the ID of the VM's project.
	ProjectID string
	// Zone is the instance's zone.
	Zone string
	// Name is the instance's name.
	Name string
}

InstanceRequest contains parameters for making a request to a specific instance.

func (*InstanceRequest) CheckAndSetDefaults

func (req *InstanceRequest) CheckAndSetDefaults() error

type InstancesClient

type InstancesClient interface {
	// ListInstances lists the GCP VMs that belong to the given project and
	// zone.
	// zone supports wildcard "*".
	ListInstances(ctx context.Context, projectID, zone string) ([]*Instance, error)
	// StreamInstances streams the GCP VMs that belong to the given project and
	// zone.
	// zone supports wildcard "*".
	StreamInstances(ctx context.Context, projectID, zone string) stream.Stream[*Instance]
	// GetInstance gets a GCP VM.
	GetInstance(ctx context.Context, req *InstanceRequest) (*Instance, error)
	// AddSSHKey adds an SSH key to a GCP VM's metadata.
	AddSSHKey(ctx context.Context, req *SSHKeyRequest) error
	// RemoveSSHKey removes an SSH key from a GCP VM's metadata.
	RemoveSSHKey(ctx context.Context, req *SSHKeyRequest) error
}

InstanceClient is a client to interact with GCP VMs.

func NewInstancesClient

func NewInstancesClient(ctx context.Context) (InstancesClient, error)

NewInstancesClient creates a new InstancesClient.

func NewInstancesClientWithConfig

func NewInstancesClientWithConfig(ctx context.Context, cfg InstancesClientConfig) (InstancesClient, error)

NewInstancesClientWithConfig creates a new InstancesClient with custom config.

type InstancesClientConfig

type InstancesClientConfig struct {
	// InstanceClient is the underlying GCP client for the instances service.
	InstanceClient *compute.InstancesClient
}

InstancesClientConfig is the client configuration for InstancesClient.

func (*InstancesClientConfig) CheckAndSetDefaults

func (c *InstancesClientConfig) CheckAndSetDefaults(ctx context.Context) (err error)

CheckAndSetDefaults checks and sets defaults for InstancesClientConfig.

type RunCommandRequest

type RunCommandRequest struct {
	// Client is the instance client to use.
	Client InstancesClient
	// InstanceRequest is the set of parameters identifying the instance.
	InstanceRequest
	// Script is the script to execute.
	Script string
	// SSHPort is the ssh server port to connect to. Defaults to 22.
	SSHPort string
	// contains filtered or unexported fields
}

RunCommandRequest contains parameters for running a command on an instance.

func (*RunCommandRequest) CheckAndSetDefaults

func (req *RunCommandRequest) CheckAndSetDefaults() error

type SQLAdminClient

type SQLAdminClient interface {
	// UpdateUser updates an existing user for the project/instance configured in a session.
	UpdateUser(ctx context.Context, db types.Database, dbUser string, user *sqladmin.User) error
	// GetDatabaseInstance returns database instance details for the project/instance
	// configured in a session.
	GetDatabaseInstance(ctx context.Context, db types.Database) (*sqladmin.DatabaseInstance, error)
	// GenerateEphemeralCert returns a new client certificate with RSA key for the
	// project/instance configured in a session.
	GenerateEphemeralCert(ctx context.Context, db types.Database, identity tlsca.Identity) (*tls.Certificate, error)
}

SQLAdminClient defines an interface providing access to the GCP Cloud SQL API.

func NewSQLAdminClient

func NewSQLAdminClient(ctx context.Context) (SQLAdminClient, error)

NewGCPSQLAdminClient returns a GCPSQLAdminClient interface wrapping sqladmin.Service.

type SSHKeyRequest

type SSHKeyRequest struct {
	// Instance is the instance to add/remove keys form.
	Instance *Instance
	// PublicKey is the key to add. Ignored when removing a key.
	PublicKey ssh.PublicKey
	// Expires is the expiration time of the key. Ignored when removing a key.
	Expires time.Time
}

SSHKeyRequest contains parameters to add/removed SSH keys from an instance.

func (*SSHKeyRequest) CheckAndSetDefaults

func (req *SSHKeyRequest) CheckAndSetDefaults() error

Jump to

Keyboard shortcuts

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