fileclient

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionFileName                  string = "kl-session.yaml"
	ExtraDataFileName                string = "kl-extra-data.yaml"
	CompleteFileName                 string = "kl-completion"
	DeviceFileName                   string = "kl-device.yaml"
	WGConfigFileName                 string = "kl-wg.yaml"
	WorkspaceWireguardConfigFileName string = "kl-workspace-wg.conf"
	K3sTrackerFileName                      = "k3s-status.json"

	KLWGProxyIp   = "198.18.0.1"
	KLHostIp      = "198.18.0.2"
	KLWorkspaceIp = "198.18.0.3"
	KLWGAllowedIp = "100.64.0.0/10"
	LocalHostIP   = "127.0.0.1"
)
View Source
const (
	Res_config resType = "config"
	Res_secret resType = "secret"
	Res_mres   resType = "mres"
)

Variables

View Source
var NoEnvSelected = fn.Errorf("no selected environment")

Functions

func GenerateWireGuardKeys

func GenerateWireGuardKeys() (wgtypes.Key, wgtypes.Key, error)

func GetAuthSession

func GetAuthSession() (string, error)

func GetBaseURL

func GetBaseURL() (string, error)

func GetConfigFolder

func GetConfigFolder() (configFolder string, err error)

func GetCookieString

func GetCookieString(options ...fn.Option) (string, error)

func GetUserHomeDir

func GetUserHomeDir() (string, error)

func OnlyInsideBox

func OnlyInsideBox(cmd *cobra.Command)

func OnlyOutsideBox

func OnlyOutsideBox(cmd *cobra.Command)

func ReadFile

func ReadFile(name string) ([]byte, error)

func SaveAuthSession

func SaveAuthSession(session string) error

func SaveBaseURL

func SaveBaseURL(url string) error

func SaveExtraData

func SaveExtraData(extraData *ExtraData) error

Types

type CSType

type CSType string
const (
	ConfigType CSType = "config"
	SecretType CSType = "secret"
)

type DeviceContext

type DeviceContext struct {
	DisplayName string `json:"display_name"`
	DeviceName  string `json:"device_name"`
}

type Env

type Env struct {
	Name    string `json:"name"`
	SSHPort int    `json:"sshPort"`
}

type EnvType

type EnvType struct {
	Key       string  `json:"key" yaml:"key"`
	Value     *string `json:"value,omitempty" yaml:"value,omitempty"`
	ConfigRef *string `json:"configRef,omitempty" yaml:"configRef,omitempty"`
	SecretRef *string `json:"secretRef,omitempty" yaml:"secretRef,omitempty"`
	MresRef   *string `json:"mresRef,omitempty" yaml:"mresRef,omitempty"`
}

type EnvVars

type EnvVars []EnvType

func (*EnvVars) AddResTypes

func (e *EnvVars) AddResTypes(rt []ResType, rtype resType)

func (*EnvVars) GetConfigs

func (e *EnvVars) GetConfigs() []ResType

func (*EnvVars) GetEnvs

func (e *EnvVars) GetEnvs() []NormalEnv

func (*EnvVars) GetMreses

func (e *EnvVars) GetMreses() []ResType

func (*EnvVars) GetSecrets

func (e *EnvVars) GetSecrets() []ResType

type ExtraData

type ExtraData struct {
	BaseUrl       string          `json:"baseUrl"`
	SelectedTeam  string          `json:"selectedTeam"`
	DnsHostSuffix string          `json:"dnsHostSuffix"`
	SelectedEnvs  map[string]*Env `json:"selectedEnvs"`
}

func GetExtraData

func GetExtraData() (*ExtraData, error)

type FileClient

type FileClient interface {
	GetHostWgConfig() (string, error)
	GetWGConfig() (*WGConfig, error)
	SetWGConfig(config string) error
	CurrentTeamName() (string, error)
	Logout() error
	GetK3sTracker() (*K3sTracker, error)
	GetVpnTeamConfig(team string) (*TeamVpnConfig, error)
	SetVpnTeamConfig(team string, config *TeamVpnConfig) error
	GetClusterConfig(team string) (*TeamClusterConfig, error)
	SetClusterConfig(team string, accClusterConfig *TeamClusterConfig) error
	GetDevice() (*DeviceContext, error)
	SetDevice(device *DeviceContext) error

	WriteKLFile(fileObj KLFileType) error
	GetKlFile(filePath string) (*KLFileType, error)
	SelectEnv(ev Env) error
	SelectEnvOnPath(pth string, ev Env) error
	EnvOfPath(pth string) (*Env, error)
	CurrentEnv() (*Env, error)
}

func New

func New() (FileClient, error)

type FileEntry

type FileEntry struct {
	Path string `json:"path"`
	Type CSType `json:"type"`
	Name string `json:"Name"`
	Key  string `json:"key"`
}

type InfraContext

type InfraContext struct {
	Name        string `json:"name"`
	TeamName    string `json:"teamName"`
	ClusterName string `json:"ClusterName"`
	DeviceName  string `json:"deviceName"`
}

type InfraContexts

type InfraContexts struct {
	InfraContexts map[string]*InfraContext `json:"infraContexts"`
	ActiveContext string                   `json:"activeContext"`
}

type InstallCommand

type InstallCommand struct {
	ChartRepo    string `json:"chart-repo"`
	ChartVersion string `json:"chart-version"`
	CRDsURL      string `json:"crds-url"`
	HelmValues   InstallHelmValues
}

type InstallHelmValues

type InstallHelmValues struct {
	TeamName              string `json:"accountName"`
	ClusterName           string `json:"clusterName"`
	ClusterToken          string `json:"clusterToken"`
	KloudliteDNSSuffix    string `json:"kloudliteDNSSuffix"`
	MessageOfficeGRPCAddr string `json:"messageOfficeGRPCAddr"`
}

type K3sTracker

type K3sTracker struct {
	Compute      bool `json:"compute"`
	Gateway      bool `json:"gateway"`
	WgConnection bool `json:"wgConnection"`
	DeviceRouter struct {
		IP      string `json:"ip"`
		Service struct {
			Spec struct {
				Ports []Port `json:"ports"`
			} `json:"spec"`
		} `json:"service"`
	} `json:"deviceRouter"`
	LastCheckedAt string `json:"lastCheckedAt"`
}

type KLFileType

type KLFileType struct {
	Version    string   `json:"version" yaml:"version"`
	DefaultEnv string   `json:"defaultEnv" yaml:"defaultEnv"`
	Packages   []string `json:"packages" yaml:"packages"`

	EnvVars EnvVars `json:"envVars" yaml:"envVars"`
	Mounts  Mounts  `json:"mounts" yaml:"mounts"`

	// InitScripts []string `json:"initScripts" yaml:"initScripts"`
	TeamName string `json:"teamName" yaml:"teamName"`
}

type Keys

type Keys struct {
	PrivateKey string `json:"privateKey"`
	PublicKey  string `json:"publicKey"`
}

type MainContext

type MainContext struct {
	TeamName string `json:"teamName"`
}

type Mount

type Mount struct {
	Path      string  `json:"path"`
	ConfigRef *string `json:"configRef,omitempty" yaml:"configRef,omitempty"`
	SecretRef *string `json:"secretRef,omitempty" yaml:"secretRef,omitempty"`
}

type Mounts

type Mounts []Mount

func (*Mounts) AddMounts

func (m *Mounts) AddMounts(fes []FileEntry)

func (*Mounts) GetMounts

func (m *Mounts) GetMounts() []FileEntry

type NormalEnv

type NormalEnv struct {
	Key   string
	Value string
}

type Port

type Port struct {
	Name       string `json:"name"`
	Port       int    `json:"port"`
	Protocol   string `json:"protocol"`
	TargetPort int    `json:"targetPort"`
}

type ResEnvType

type ResEnvType struct {
	Name   string `json:"name" yaml:"name"`
	Key    string `json:"key"`
	RefKey string `json:"refKey" yaml:"refKey"`
}

type ResType

type ResType struct {
	Name string       `json:"name"`
	Env  []ResEnvType `json:"env"`
}

type Session

type Session struct {
	Session string `json:"session"`
}

type TeamClusterConfig

type TeamClusterConfig struct {
	ClusterToken   string `json:"clusterToken"`
	ClusterName    string `json:"cluster"`
	InstallCommand InstallCommand
	Installed      bool
	WGConfig       WGConfig
	Version        string
	GatewayIP      string
	ClusterCIDR    string
}

func (*TeamClusterConfig) Marshal

func (a *TeamClusterConfig) Marshal() ([]byte, error)

func (*TeamClusterConfig) Unmarshal

func (a *TeamClusterConfig) Unmarshal(b []byte) error

type TeamVpnConfig

type TeamVpnConfig struct {
	WGconf     string `json:"wg"`
	IpAddress  string `json:"ip"`
	DeviceName string `json:"device"`
}

func (*TeamVpnConfig) Marshal

func (a *TeamVpnConfig) Marshal() ([]byte, error)

func (*TeamVpnConfig) Unmarshal

func (a *TeamVpnConfig) Unmarshal(b []byte) error

type WGConfig

type WGConfig struct {
	UUID      string `json:"uuid"`
	Host      Keys   `json:"host"`
	Workspace Keys   `json:"workspace"`
	Proxy     Keys   `json:"wg-proxy"`
}

Jump to

Keyboard shortcuts

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