env

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: GPL-3.0 Imports: 23 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DdlDefDecLength = 20
	DdlMinDecLength = 24
	DdlMaxDecScale  = 24
	DdlMaxDecLength = 38
	DdlMinDecScale  = 6
)

Variables

View Source
var (
	Marker         = "Sling CLI | https://slingdata.io"
	HomeDir        = os.Getenv("SLING_HOME_DIR")
	HomeDirEnvFile = ""
	Env            = &EnvFile{}
	PlausibleURL   = ""
	SentryDsn      = ""
	NoColor        = g.In(os.Getenv("SLING_LOGGING"), "NO_COLOR", "JSON")
	LogSink        func(*g.LogLine)
	TelMap         = g.M("begin_time", time.Now().UnixMicro())
	TelMux         = sync.Mutex{}

	NoDebugKey    = " /* nD */"
	Executable    = ""
	IsThreadChild = cast.ToBool(os.Getenv("SLING_THREAD_CHILD"))
	ExecID        = g.Getenv("SLING_EXEC_ID", NewExecID())
	RunnerID      = g.Getenv("SLING_RUNNER_ID", os.Getenv("SLING_AGENT_ID"))
	IsRunnerMode  = RunnerID != ""

	GetOAuthMap = func() map[string]map[string]any {
		return map[string]map[string]any{}
	}
	ExecFolder      = func() string { return filepath.Join(HomeDir, "executions", ExecID) }
	QueueFolder     = func() string { return filepath.Join(ExecFolder(), "queues") }
	RuntimeFolder   = func() string { return filepath.Join(ExecFolder(), "runtime") }
	RuntimeFilePath = func(name string) string {
		name = strings.ReplaceAll(name, "\\", "_")
		name = strings.ReplaceAll(name, "/", "_")
		name = strings.ReplaceAll(name, ":", "_")
		os.MkdirAll(RuntimeFolder(), 0755)
		return filepath.Join(RuntimeFolder(), g.F("%s.json", name))
	}

	ReservedFields = struct {
		LoadedAt  string
		SyncedAt  string
		SyncedOp  string
		DeletedAt string
		StreamURL string
		RowNum    string
		RowID     string
		ExecID    string
		CDCSeq    string
	}{
		LoadedAt:  "_sling_loaded_at",
		SyncedAt:  "_sling_synced_at",
		SyncedOp:  "_sling_synced_op",
		DeletedAt: "_sling_deleted_at",
		StreamURL: "_sling_stream_url",
		RowNum:    "_sling_row_num",
		RowID:     "_sling_row_id",
		ExecID:    "_sling_exec_id",
		CDCSeq:    "_sling_cdc_seq",
	}
)
View Source
var SecretKeys = []string{
	"access_key_id",
	"account_key",
	"aws_access_key_id",
	"aws_secret_access_key",
	"aws_session_token",
	"azure_account_key",
	"azure_sas_token",
	"conn_str",
	"gcp_credentials_json",
	"gcs_secret_access_key",
	"password",
	"rest_oauth_client_secret",
	"rest_token",
	"s3_secret_access_key",
	"s3_session_token",
	"sas_svc_url",
	"sas_token",
	"secret_access_key",
	"session_token",
	"ssh_passphrase",
	"ssh_private_key",
	"token",
}

SecretKeys is the full set of connection property names whose values are secrets. Clean and parse.Redact redact these. Keep it in sync with `secret: true` in core/dbio/templates/_properties.yaml.

Functions

func BlueString added in v1.1.8

func BlueString(text string) string

func Clean added in v1.2.16

func Clean(props map[string]string, line string) string

Clean removes creds from a log line. CREATE/INSERT/etc. still redact: Redshift COPY/UNLOAD embeds keys in those statements.

func CleanConnData added in v1.6.0

func CleanConnData(data map[string]any, line string) string

CleanConnData redacts registry secrets and every nested secrets: value. Nested API keys are secret even when the key name is not in the registry.

func CleanTableName added in v1.2.22

func CleanTableName(tableName string) string

func CleanWindowsPath added in v1.2.19

func CleanWindowsPath(path string) string

func CloseFileLogging added in v1.5.7

func CloseFileLogging()

CloseFileLogging closes any open log files.

func CyanString added in v1.1.15

func CyanString(text string) string

func DarkGrayString added in v1.1.15

func DarkGrayString(text string) string

func EnvVarRefName added in v1.6.0

func EnvVarRefName(s string) string

EnvVarRefName returns VAR from ${VAR}. It returns "" when s is not a ref.

func ExpandEnvVars added in v1.5.17

func ExpandEnvVars(text string) string

expandEnvVars replaces $KEY or ${KEY} with its environment variable value only if the variable is present in the environment. If not present, $KEY or ${KEY} will remain in the config text.

func GetEnvFilePath added in v1.2.4

func GetEnvFilePath(dir string) string

func GetHomeDirConnsMap added in v1.2.4

func GetHomeDirConnsMap() (connsMap map[string]map[string]any, err error)

func GetTempFolder added in v1.2.4

func GetTempFolder() string

func GreenString added in v1.1.8

func GreenString(text string) string

func HomeBinDir added in v1.2.4

func HomeBinDir() string

func InitLogger

func InitLogger()

InitLogger initializes the Logger

func IsEnvVarRef added in v1.6.0

func IsEnvVarRef(s string) bool

IsEnvVarRef is true when s is a whole-string ${VAR} reference.

func IsInteractiveTerminal added in v1.4.10

func IsInteractiveTerminal() bool

IsInteractiveTerminal checks if the current process is running in an interactive terminal

func LoadDotEnvSling added in v1.5.10

func LoadDotEnvSling() map[string]string

LoadDotEnvSling reads a `.env.sling` file from the current working directory and injects its key=value pairs into os environment variables. Existing env vars are not overwritten.

func LoadDotEnvSlingFrom added in v1.5.16

func LoadDotEnvSlingFrom(dir string) map[string]string

LoadDotEnvSlingFrom reads a `.env.sling` file from the specified directory and injects its key=value pairs into os environment variables. Existing env vars are not overwritten.

func LoadHomeDir added in v1.5.12

func LoadHomeDir()

func LogSQL added in v1.2.16

func LogSQL(props map[string]string, query string, args ...any)

func MagentaString added in v1.2.2

func MagentaString(text string) string

func MergeDeclaredEnv added in v1.6.0

func MergeDeclaredEnv(declared map[string]any) map[string]any

MergeDeclaredEnv starts from the process environment and overlays declared pipeline/replication env keys. Bare {env.X} then renders even when the YAML has no env: block.

func NewExecID added in v1.5.9

func NewExecID() string

func ParseDotEnv added in v1.5.11

func ParseDotEnv(content string) map[string]string

ParseDotEnv parses a .env file content into key-value pairs. It supports single-line and multi-line values enclosed in matching quotes (' or ").

func Print added in v1.1.6

func Print(text string)

func PrintFatal added in v1.6.0

func PrintFatal(E error, args ...interface{})

PrintFatal prints the fatal error (same text as g.PrintFatal) and captures it in the run-log buffer via Println, so stderr.log includes it.

func Println added in v1.1.6

func Println(text string)

func RecentLogs added in v1.6.0

func RecentLogs() string

RecentLogs returns the buffered tail, oldest first.

func RedString added in v1.1.8

func RedString(text string) string

func RemoveAllLocalTempFile added in v1.2.16

func RemoveAllLocalTempFile(localPath string)

RemoveAllLocalTempFile deletes the local folder

func RemoveLocalTempFile added in v1.2.16

func RemoveLocalTempFile(localPath string)

RemoveLocalTempFile deletes the local file

func ScrubLine added in v1.6.0

func ScrubLine(line string) string

ScrubLine redacts secrets from every local connection in Env.

func SetLogger added in v1.1.6

func SetLogger()

func SetTelVal added in v1.2.2

func SetTelVal(key string, value any)

func StartLogCapture added in v1.6.0

func StartLogCapture()

StartLogCapture begins buffering log lines for the failure snapshot.

func StopLogCapture added in v1.6.0

func StopLogCapture()

StopLogCapture stops buffering and drops what was kept.

func UnsetEnvKeys added in v1.5.10

func UnsetEnvKeys(keys []string)

func UseDuckDbCompute added in v1.4.24

func UseDuckDbCompute() bool

func Vars added in v1.2.4

func Vars() (vars map[string]string)

Vars are the variables we are using

func YellowString added in v1.4.21

func YellowString(text string) string

Types

type ConnLocation added in v1.6.0

type ConnLocation struct {
	Path       string       `json:"path"`
	Line       int          `json:"line"`
	Connection string       `json:"connection"`
	Missing    []MissingRef `json:"missing"`
}

ConnLocation is a deep-link into env.yaml for one connection.

type EnvFile added in v0.86.56

type EnvFile struct {
	Connections map[string]map[string]any `json:"connections,omitempty" yaml:"connections,omitempty"`
	Env         map[string]any            `json:"env,omitempty" yaml:"env,omitempty"`
	Variables   map[string]any            `json:"variables,omitempty" yaml:"variables,omitempty"` // legacy

	Path       string `json:"-" yaml:"-"`
	TopComment string `json:"-" yaml:"-"`
	Body       string `json:"-" yaml:"-"`
}

func LoadEnvFile added in v0.86.56

func LoadEnvFile(path string) (ef EnvFile)

func LoadSlingEnvFile added in v0.86.56

func LoadSlingEnvFile() (ef EnvFile)

func LoadSlingEnvFileBody added in v1.2.15

func LoadSlingEnvFileBody(body string) (ef EnvFile, err error)

func (*EnvFile) LookupConnection added in v1.6.0

func (ef *EnvFile) LookupConnection(name string) (ConnLocation, error)

LookupConnection re-parses ef.Path and returns line numbers for connections.<NAME> and each ${VAR} field under it.

func (*EnvFile) MarshalBody added in v1.5.14

func (ef *EnvFile) MarshalBody() (string, error)

MarshalBody returns the EnvFile as a formatted YAML string

func (*EnvFile) WriteEnvFile added in v1.2.4

func (ef *EnvFile) WriteEnvFile() (err error)

type MissingRef added in v1.6.0

type MissingRef struct {
	Key  string `json:"key"`
	Var  string `json:"var"`
	Line int    `json:"line"`
}

MissingRef is one ${VAR} field that still needs a value (or an env var).

Jump to

Keyboard shortcuts

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