client

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2019 License: BSD-3-Clause Imports: 19 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// RecommendedHomeDir is the default name for the osprey home directory.
	RecommendedHomeDir = ".osprey"
	// RecommendedFileName is the default name for the osprey config file.
	RecommendedFileName = "config"
)

Variables

View Source
var (
	// HomeDir is the user's home directory.
	HomeDir = homeDir()
	// RecommendedOspreyHomeDir is the default full path for the osprey home.
	RecommendedOspreyHomeDir = path.Join(HomeDir, RecommendedHomeDir)
	// RecommendedOspreyConfigFile is the default full path for the osprey config file.
	RecommendedOspreyConfigFile = path.Join(RecommendedOspreyHomeDir, RecommendedFileName)
)

Functions

func SaveConfig

func SaveConfig(config *Config, path string) error

SaveConfig serializes the osprey config to the specified path.

Types

type Client

type Client interface {
	// GetAccessToken returns an access token that is required to authenticate user access against a kubernetes cluster
	GetAccessToken(*LoginCredentials) (*kubeconfig.TokenInfo, error)
}

Client is used to authenticate and generate the configuration

func NewClient

func NewClient(host string, serverCAs ...string) Client

NewClient creates a new Client

type Config

type Config struct {
	// CertificateAuthority is the path to a cert file for the certificate authority.
	// +optional
	CertificateAuthority string `yaml:"certificate-authority,omitempty"`
	// CertificateAuthorityData is base64-encoded CA cert data.
	// This will override any cert file specified in CertificateAuthority.
	// +optional
	CertificateAuthorityData string `yaml:"certificate-authority-data,omitempty"`
	// Kubeconfig specifies the path to read/write the kubeconfig file.
	// +optional
	Kubeconfig string `yaml:"kubeconfig,omitempty"`
	// DefaultGroup specifies the group to log in to if none provided.
	// +optional
	DefaultGroup string `yaml:"default-group,omitempty"`
	// Targets is a map of referenceable names to osprey configs
	Targets map[string]*Osprey `yaml:"targets"`
}

Config holds the information needed to connect to remote osprey servers as a given user

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig reads an osprey Config from the specified path.

func NewConfig

func NewConfig() *Config

NewConfig is a convenience function that returns a new Config object with non-nil maps

func (*Config) GroupOrDefault added in v1.2.0

func (c *Config) GroupOrDefault(group string) string

GroupOrDefault returns the group if it is not empty, or the Config.DefaultGroup if it is.

func (*Config) TargetsByGroup added in v1.2.0

func (c *Config) TargetsByGroup() map[string]map[string]*Osprey

TargetsByGroup returns the Config targets organized by groups. One target may appear in multiple groups.

func (*Config) TargetsInGroup added in v1.2.0

func (c *Config) TargetsInGroup(group string) map[string]*Osprey

TargetsInGroup retrieves the Osprey targets that match the group. If the group is not provided the DefaultGroup for this configuration will be used.

type ConfigSnapshot added in v1.2.0

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

ConfigSnapshot is a snapshot view of the configuration to organize the targets per group. It does not reflect changes to the configuration after it has been taken.

func GetSnapshot added in v1.2.0

func GetSnapshot(config *Config) ConfigSnapshot

GetSnapshot creates a snapshot view of the provided Config

func (*ConfigSnapshot) DefaultGroup added in v1.2.0

func (t *ConfigSnapshot) DefaultGroup() Group

DefaultGroup returns the default group in the configuration. If no specific group is set as default, it will return the special ungrouped ("") group

func (*ConfigSnapshot) GetGroup added in v1.2.0

func (t *ConfigSnapshot) GetGroup(name string) (Group, bool)

GetGroup returns a valid group and true if it exists, an empty group and false if it doesn't.

func (*ConfigSnapshot) Groups added in v1.2.0

func (t *ConfigSnapshot) Groups() []Group

Groups returns all defined groups sorted alphabetically by name.

func (*ConfigSnapshot) HaveGroups added in v1.2.0

func (t *ConfigSnapshot) HaveGroups() bool

HaveGroups returns true if there is at least one defined group.

func (*ConfigSnapshot) Targets added in v1.2.0

func (t *ConfigSnapshot) Targets() []Target

Targets returns all the targets in the configuration in alphabetical order.

type Group added in v1.2.0

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

Group organizes the osprey targets

func (*Group) Contains added in v1.2.0

func (g *Group) Contains(target Target) bool

Contains returns true if it contains the target

func (*Group) IsDefault added in v1.2.0

func (g *Group) IsDefault() bool

IsDefault returns true if this is the default group in the configuration

func (*Group) Name added in v1.2.0

func (g *Group) Name() string

Name returns the name of the group

func (*Group) Targets added in v1.2.0

func (g *Group) Targets() []Target

Targets returns the list of targets belonging to this group

type LoginCredentials

type LoginCredentials struct {
	// Username username of user intending to login
	Username string
	// Password the password for user
	Password string
}

LoginCredentials represents user credentials

func GetCredentials

func GetCredentials() (*LoginCredentials, error)

GetCredentials loads the credentials from the terminal or stdin.

type Osprey

type Osprey struct {
	// Server is the address of the osprey server (hostname:port).
	Server string `yaml:"server"`
	// CertificateAuthority is the path to a cert file for the certificate authority.
	// +optional
	CertificateAuthority string `yaml:"certificate-authority,omitempty"`
	// CertificateAuthorityData is base64-encoded CA cert data.
	// This will override any cert file specified in CertificateAuthority.
	// +optional
	CertificateAuthorityData string `yaml:"certificate-authority-data,omitempty"`
	// Aliases is a list of names that the osprey server can be called.
	// +optional
	Aliases []string `yaml:"aliases,omitempty"`
	// Groups is a list of names that can be used to group different osprey servers.
	// +optional
	Groups []string `yaml:"groups,omitempty"`
}

Osprey contains information about how to communicate with an osprey server

func (*Osprey) IsInGroup added in v1.2.0

func (o *Osprey) IsInGroup(value string) bool

IsInGroup returns true if the Osprey target belongs to the given group

type Target added in v1.2.0

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

Target has the information of an Osprey target server

func (*Target) Aliases added in v1.2.0

func (m *Target) Aliases() []string

Aliases returns the list of aliases of the Target alphabetically sorted

func (*Target) CertificateAuthorityData added in v1.2.0

func (m *Target) CertificateAuthorityData() string

CertificateAuthorityData returns the CertificateAuthorityData of the Target

func (*Target) HasAliases added in v1.2.0

func (m *Target) HasAliases() bool

HasAliases returns true if the Target has at least one alias

func (*Target) Name added in v1.2.0

func (m *Target) Name() string

Name returns the main name of the Target

func (*Target) Server added in v1.2.0

func (m *Target) Server() string

Server returns the server of the Target

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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