clientconfig

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultConfigPath is the default path for the config file in user's home directory
	DefaultConfigPath = ".config/miren/clientconfig.yaml"

	// EnvConfigPath is the environment variable name for custom config path
	EnvConfigPath = "MIREN_CONFIG"
)

Variables

View Source
var ErrNoConfig = fmt.Errorf("no config file found")

Functions

func AuthenticateWithKey

func AuthenticateWithKey(ctx context.Context, hostname string, keyPair *cloudauth.KeyPair) (string, error)

AuthenticateWithKey performs the challenge-response authentication flow

func GetActiveConfigPath

func GetActiveConfigPath() string

GetActiveConfigPath returns the path to the active configuration file

func GetConfigDirPath

func GetConfigDirPath() string

GetConfigDirPath returns the path to the configuration directory

Types

type BeginAuthRequest

type BeginAuthRequest struct {
	Fingerprint string `json:"fingerprint"`
}

BeginAuthRequest is the request to begin authentication

type BeginAuthResponse

type BeginAuthResponse struct {
	Envelope  string `json:"envelope"`
	Challenge string `json:"challenge"`
}

BeginAuthResponse is the response from begin authentication

type ClusterConfig

type ClusterConfig struct {
	Hostname     string   `yaml:"hostname"`
	AllAddresses []string `yaml:"all_addresses,omitempty"` // All available addresses for this cluster
	Identity     string   `yaml:"identity,omitempty"`      // Reference to an identity in the Identities section
	XID          string   `yaml:"xid,omitempty"`           // Cloud cluster XID for permission checks
	CACert       string   `yaml:"ca_cert,omitempty"`       // PEM encoded CA certificate
	ClientCert   string   `yaml:"client_cert,omitempty"`   // PEM encoded client certificate (deprecated, use identity)
	ClientKey    string   `yaml:"client_key,omitempty"`    // PEM encoded client key (deprecated, use identity)
	Insecure     bool     `yaml:"insecure,omitempty"`      // Skip TLS verification
	CloudAuth    bool     `yaml:"cloud_auth,omitempty"`    // Use cloud authentication (deprecated, use identity)
}

ClusterConfig holds the configuration for a single cluster

func (*ClusterConfig) RPCOptions

func (c *ClusterConfig) RPCOptions(ctx context.Context, config *Config) ([]rpc.StateOption, error)

RPCOptions returns RPC options without a cluster name (deprecated, use RPCOptionsWithName)

func (*ClusterConfig) RPCOptionsWithName

func (c *ClusterConfig) RPCOptionsWithName(ctx context.Context, config *Config, clusterName string) ([]rpc.StateOption, error)

RPCOptionsWithName returns RPC options with cluster name for caching

func (*ClusterConfig) State

func (c *ClusterConfig) State(ctx context.Context, config *Config, opts ...rpc.StateOption) (*rpc.State, error)

type CompleteAuthRequest

type CompleteAuthRequest struct {
	Envelope  string `json:"envelope"`
	Signature string `json:"signature"`
}

CompleteAuthRequest is the request to complete authentication

type CompleteAuthResponse

type CompleteAuthResponse struct {
	User  interface{} `json:"user"`
	Token string      `json:"token"`
}

CompleteAuthResponse is the response from complete authentication

type Config

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

Config represents the complete client configuration

func DecodeConfig

func DecodeConfig(data []byte) (*Config, error)

LoadConfig loads the configuration from disk

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig loads the configuration from disk

func LoadConfigFrom

func LoadConfigFrom(configPath string) (*Config, error)

LoadConfig loads the configuration from disk

func Local

func Local(cc *caauth.ClientCertificate, listenAddr string) *Config

func NewConfig

func NewConfig() *Config

func (*Config) ActiveCluster

func (c *Config) ActiveCluster() string

ActiveCluster returns the name of the active cluster

func (*Config) GetActiveCluster

func (c *Config) GetActiveCluster() (*ClusterConfig, error)

GetActiveCluster returns the active cluster configuration

func (*Config) GetCluster

func (c *Config) GetCluster(name string) (*ClusterConfig, error)

GetCluster returns the configuration for a specific cluster

func (*Config) GetClusterCount

func (c *Config) GetClusterCount() int

GetClusterCount returns the number of clusters in the configuration

func (*Config) GetClusterNames

func (c *Config) GetClusterNames() []string

GetClusterNames returns a sorted list of all cluster names

func (*Config) GetClusterSource added in v0.2.1

func (c *Config) GetClusterSource(name string) string

GetClusterSource returns the source file path for a cluster. For clusters in the main config, returns the main config path. For clusters in leaf configs, returns the leaf config path.

func (*Config) GetIdentity

func (c *Config) GetIdentity(name string) (*IdentityConfig, error)

GetIdentity returns an identity configuration by name

func (*Config) GetIdentityCount

func (c *Config) GetIdentityCount() int

GetIdentityCount returns the number of configured identities

func (*Config) GetIdentityNames

func (c *Config) GetIdentityNames() []string

GetIdentityNames returns a sorted list of all identity names

func (*Config) GetKey

func (c *Config) GetKey(name string) (*KeyConfig, error)

GetKey returns a key configuration by name

func (*Config) GetKeyNames

func (c *Config) GetKeyNames() []string

GetKeyNames returns a sorted list of all key names

func (*Config) GetLeafConfigNames

func (c *Config) GetLeafConfigNames() []string

GetLeafConfigNames returns the names of all leaf configs

func (*Config) GetPrivateKeyPEM

func (c *Config) GetPrivateKeyPEM(identity *IdentityConfig) (string, error)

GetPrivateKeyPEM resolves and returns the private key PEM for an identity. It handles both direct PrivateKey fields and KeyRef references.

func (*Config) HasAnyClusters

func (c *Config) HasAnyClusters() bool

HasAnyClusters checks if any clusters are configured

func (*Config) HasCluster

func (c *Config) HasCluster(name string) bool

HasCluster checks if a cluster exists in the configuration

func (*Config) HasIdentities

func (c *Config) HasIdentities() bool

HasIdentities returns true if there are any identities configured

func (*Config) HasIdentity

func (c *Config) HasIdentity(name string) bool

HasIdentity checks if an identity exists in the configuration

func (*Config) HasKey

func (c *Config) HasKey(name string) bool

HasKey checks if a key exists in the configuration

func (*Config) IsEmpty

func (c *Config) IsEmpty() bool

IsEmpty checks if the configuration has no clusters defined

func (*Config) IterateClusters

func (c *Config) IterateClusters(fn func(name string, cluster *ClusterConfig) error) error

IterateClusters calls the provided function for each cluster in sorted order If the function returns an error, iteration stops and the error is returned

func (*Config) MarshalYAML

func (c *Config) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface

func (*Config) RPCOptions

func (c *Config) RPCOptions(ctx context.Context) ([]rpc.StateOption, error)

func (*Config) RemoveCluster

func (c *Config) RemoveCluster(name string) error

RemoveCluster removes a cluster from the configuration

func (*Config) Save

func (c *Config) Save() error

SaveConfig saves the configuration to disk

func (*Config) SaveTo

func (c *Config) SaveTo(path string) error

func (*Config) SaveToHome

func (c *Config) SaveToHome() error

func (*Config) SetActiveCluster

func (c *Config) SetActiveCluster(name string) error

SetActiveCluster sets the active cluster

func (*Config) SetCluster

func (c *Config) SetCluster(name string, cluster *ClusterConfig)

SetCluster adds or updates a cluster in the configuration

func (*Config) SetIdentity

func (c *Config) SetIdentity(name string, identity *IdentityConfig)

SetIdentity adds or updates an identity configuration

func (*Config) SetKey

func (c *Config) SetKey(name string, key *KeyConfig)

SetKey adds or updates a key configuration

func (*Config) SetLeafConfig

func (c *Config) SetLeafConfig(name string, configData *ConfigData)

SetLeafConfig adds or updates a leaf config that will be saved to clientconfig.d/name.yaml

func (*Config) SourcePath

func (c *Config) SourcePath() string

SourcePath returns the path to the config file that was loaded, if any.

func (*Config) State

func (c *Config) State(ctx context.Context, opts ...rpc.StateOption) (*rpc.State, error)

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid

type ConfigData

type ConfigData struct {
	Active     string                     `yaml:"active_cluster,omitempty"`
	Clusters   map[string]*ClusterConfig  `yaml:"clusters,omitempty"`
	Identities map[string]*IdentityConfig `yaml:"identities,omitempty"`
	Keys       map[string]*KeyConfig      `yaml:"keys,omitempty"`
}

ConfigData is used for YAML unmarshaling to handle private fields

type IdentityConfig

type IdentityConfig struct {
	Type       string `yaml:"type"`                  // Type of identity: "keypair", "certificate", etc.
	Issuer     string `yaml:"issuer,omitempty"`      // The auth server that issued this identity (e.g., "https://miren.cloud")
	KeyRef     string `yaml:"key_ref,omitempty"`     // Reference to a key in the Keys section (for keypair auth)
	PrivateKey string `yaml:"private_key,omitempty"` // PEM encoded private key (for keypair auth, deprecated - use KeyRef)
	ClientCert string `yaml:"client_cert,omitempty"` // PEM encoded client certificate (for cert auth)
	ClientKey  string `yaml:"client_key,omitempty"`  // PEM encoded client key (for cert auth)
}

IdentityConfig holds authentication credentials that can be used across clusters

type KeyConfig

type KeyConfig struct {
	Name        string            `yaml:"name"`                  // Name of the key (e.g., "miren-cli@hostname")
	Type        string            `yaml:"type"`                  // Type of key: "ed25519", etc.
	PrivateKey  string            `yaml:"private_key"`           // PEM encoded private key
	Fingerprint string            `yaml:"fingerprint,omitempty"` // Fingerprint of the public key
	Metadata    map[string]string `yaml:"metadata,omitempty"`    // Arbitrary metadata about the key
}

KeyConfig holds a reusable cryptographic key

Jump to

Keyboard shortcuts

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