cluster

package module
v0.0.0-...-b33adad Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: MIT Imports: 13 Imported by: 17

README

Secman Cluster

secman cluster command source.

Documentation

Index

Constants

View Source
const (
	CONFIG_DIR      = "CONFIG_DIR"
	XDG_CONFIG_HOME = "XDG_CONFIG_HOME"
	XDG_STATE_HOME  = "XDG_STATE_HOME"
	XDG_DATA_HOME   = "XDG_DATA_HOME"
	APP_DATA        = "AppData"      // (windows only)
	LOCAL_APP_DATA  = "LocalAppData" // (windows only)
)
View Source
const (
	SM_GH_HOST                 = "SM_GH_HOST"
	SM_GH_TOKEN                = "SM_GH_TOKEN"
	SM_GITHUB_TOKEN            = "SM_GITHUB_TOKEN"
	SM_GH_ENTERPRISE_TOKEN     = "SM_GH_ENTERPRISE_TOKEN"
	SM_GITHUB_ENTERPRISE_TOKEN = "SM_GITHUB_ENTERPRISE_TOKEN"
)

Variables

View Source
var BackupClusterFile = func(filename string) error {
	return os.Rename(filename, filename+".bak")
}
View Source
var ReadClusterFile = func(filename string) ([]byte, error) {
	f, err := os.Open(filename)
	if err != nil {
		return nil, pathError(err)
	}
	defer f.Close()

	data, err := ioutil.ReadAll(f)
	if err != nil {
		return nil, err
	}

	return data, nil
}
View Source
var WriteClusterFile = func(filename string, data []byte) error {
	err := os.MkdirAll(filepath.Dir(filename), 0771)
	if err != nil {
		return pathError(err)
	}

	cfgFile, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
	if err != nil {
		return err
	}

	defer cfgFile.Close()

	_, err = cfgFile.Write(data)
	return err
}

Functions

func AuthTokenFromEnv

func AuthTokenFromEnv(hostname string) (string, string)

func AuthTokenProvidedFromEnv

func AuthTokenProvidedFromEnv() bool

func ClusterDir

func ClusterDir() string

Cluster path precedence 1. CONFIG_DIR 2. XDG_CONFIG_HOME 3. AppData (windows only) 4. HOME

func ClusterFile

func ClusterFile() string

func DataDir

func DataDir() string

Data path precedence 1. XDG_DATA_HOME 2. LocalAppData (windows only) 3. HOME

func HomeDirPath

func HomeDirPath(subdir string) (string, error)

func HostsClusterFile

func HostsClusterFile() string

func IsEnterpriseEnv

func IsEnterpriseEnv(src string) bool

func IsHostEnv

func IsHostEnv(src string) bool

func NewBlankRoot

func NewBlankRoot() *yaml.Node

func StateDir

func StateDir() string

State path precedence 1. XDG_CONFIG_HOME 2. LocalAppData (windows only) 3. HOME

func StubBackupCluster

func StubBackupCluster() func()

func StubWriteCluster

func StubWriteCluster(wc io.Writer, wh io.Writer) func()

func ValidateKey

func ValidateKey(key string) error

func ValidateValue

func ValidateValue(key, value string) error

Types

type Cluster

type Cluster interface {
	Get(string, string) (string, error)
	GetWithSource(string, string) (string, string, error)
	Set(string, string, string) error
	UnsetHost(string)
	Hosts() ([]string, error)
	DefaultHost() (string, error)
	DefaultHostWithSource() (string, string, error)
	CheckWriteable(string, string) error
	Write() error
}

func InheritEnv

func InheritEnv(c Cluster) Cluster

func NewBlankCluster

func NewBlankCluster() Cluster

NewBlankCluster initializes a cluster file pre-populated with comments and default values

func NewCluster

func NewCluster(root *yaml.Node) Cluster

func NewFromString

func NewFromString(str string) Cluster

NewFromString initializes a Cluster from a yaml string

func ParseDefaultCluster

func ParseDefaultCluster() (Cluster, error)

type ClusterEntry

type ClusterEntry struct {
	KeyNode   *yaml.Node
	ValueNode *yaml.Node
	Index     int
}

type ClusterMap

type ClusterMap struct {
	Root *yaml.Node
}

func (*ClusterMap) Empty

func (cm *ClusterMap) Empty() bool

func (*ClusterMap) FindEntry

func (cm *ClusterMap) FindEntry(key string) (ce *ClusterEntry, err error)

func (*ClusterMap) GetStringValue

func (cm *ClusterMap) GetStringValue(key string) (string, error)

func (*ClusterMap) RemoveEntry

func (cm *ClusterMap) RemoveEntry(key string)

func (*ClusterMap) SetStringValue

func (cm *ClusterMap) SetStringValue(key, value string) error

type ClusterOption

type ClusterOption struct {
	Key           string
	Description   string
	DefaultValue  string
	AllowedValues []string
}

func ClusterOptions

func ClusterOptions() []ClusterOption

type ClusterStub

type ClusterStub map[string]string

func (ClusterStub) CheckWriteable

func (c ClusterStub) CheckWriteable(host, key string) error

func (ClusterStub) DefaultHost

func (c ClusterStub) DefaultHost() (string, error)

func (ClusterStub) DefaultHostWithSource

func (c ClusterStub) DefaultHostWithSource() (string, string, error)

func (ClusterStub) Get

func (c ClusterStub) Get(host, key string) (string, error)

func (ClusterStub) GetWithSource

func (c ClusterStub) GetWithSource(host, key string) (string, string, error)

func (ClusterStub) Hosts

func (c ClusterStub) Hosts() ([]string, error)

func (ClusterStub) Set

func (c ClusterStub) Set(host, key, value string) error

func (ClusterStub) UnsetHost

func (c ClusterStub) UnsetHost(hostname string)

func (ClusterStub) Write

func (c ClusterStub) Write() error

type HostCluster

type HostCluster struct {
	ClusterMap
	Host string
}

type InvalidValueError

type InvalidValueError struct {
	ValidValues []string
}

func (InvalidValueError) Error

func (e InvalidValueError) Error() string

type NotFoundError

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

type ReadOnlyEnvError

type ReadOnlyEnvError struct {
	Variable string
}

func (*ReadOnlyEnvError) Error

func (e *ReadOnlyEnvError) Error() string

Jump to

Keyboard shortcuts

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