Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds support for ${TMP} ${TEMP} and ${TMPDIR} in configs #2655

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion common/config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,39 @@

package config

import "os"
import (
"github.com/michaelquigley/pfxlog"
"os"
"sync"
)

var ensureTmpDirEnvOnce sync.Once

func EnsureTempDirEnv() {
defaultTemp := os.TempDir()

err := os.Setenv("TMP", defaultTemp)

if err != nil {
pfxlog.Logger().WithError(err).Warn("Could not set TMP environment variable")
}

err = os.Setenv("TEMP", defaultTemp)

if err != nil {
pfxlog.Logger().WithError(err).Warn("Could not set TEMP environment variable")
}

err = os.Setenv("TMPDIR", defaultTemp)

if err != nil {
pfxlog.Logger().WithError(err).Warn("Could not set TMPDIR environment variable")
}
}

func InjectEnv(config map[interface{}]interface{}) {
ensureTmpDirEnvOnce.Do(EnsureTempDirEnv)

for key, v := range config {
if str, ok := v.(string); ok {
config[key] = os.ExpandEnv(str)
Expand Down
4 changes: 2 additions & 2 deletions etc/ctrl.with.edge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ additionalTrustDomains: []

profile:
# cpu:
# path: /home/plorenz/tmp/ctrl.cpu.pprof
# path: ${TMPDIR}/ziti.ctrl.cpu.pprof
# memory:
# path: ctrl.memprof

Expand Down Expand Up @@ -108,7 +108,7 @@ events:
handler:
type: file
format: json
path: /tmp/ziti-events.log
path: ${TMPDIR}/ziti-events.log
# usageLogger:
# subscriptions:
# - type: fabric.usage
Expand Down
4 changes: 2 additions & 2 deletions zititest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ require (
github.com/go-openapi/strfmt v0.23.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
github.com/go-resty/resty/v2 v2.16.2 // indirect
github.com/go-resty/resty/v2 v2.16.3 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/gomarkdown/markdown v0.0.0-20230922112808-5421fefb8386 // indirect
Expand All @@ -96,7 +96,7 @@ require (
github.com/hashicorp/golang-lru v0.6.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/raft v1.7.1 // indirect
github.com/hashicorp/raft v1.7.2 // indirect
github.com/hashicorp/raft-boltdb v0.0.0-20220329195025-15018e9b97e0 // indirect
github.com/iancoleman/strcase v0.1.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions zititest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ github.com/go-openapi/validate v0.24.0 h1:LdfDKwNbpB6Vn40xhTdNZAnfLECL81w+VX3Bum
github.com/go-openapi/validate v0.24.0/go.mod h1:iyeX1sEufmv3nPbBdX3ieNviWnOZaJ1+zquzJEf2BAQ=
github.com/go-resty/resty/v2 v2.16.2 h1:CpRqTjIzq/rweXUt9+GxzzQdlkqMdt8Lm/fuK/CAbAg=
github.com/go-resty/resty/v2 v2.16.2/go.mod h1:0fHAoK7JoBy/Ch36N8VFeMsK7xQOHhvWaC3iOktwmIU=
github.com/go-resty/resty/v2 v2.16.3/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
Expand Down Expand Up @@ -395,6 +396,7 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p
github.com/hashicorp/raft v1.1.0/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM=
github.com/hashicorp/raft v1.7.1 h1:ytxsNx4baHsRZrhUcbt3+79zc4ly8qm7pi0393pSchY=
github.com/hashicorp/raft v1.7.1/go.mod h1:hUeiEwQQR/Nk2iKDD0dkEhklSsu3jcAcqvPzPoZSAEM=
github.com/hashicorp/raft v1.7.2/go.mod h1:DfvCGFxpAUPE0L4Uc8JLlTPtc3GzSbdH0MTJCLgnmJQ=
github.com/hashicorp/raft-boltdb v0.0.0-20220329195025-15018e9b97e0 h1:CO8dBMLH6dvE1jTn/30ZZw3iuPsNfajshWoJTnVc5cc=
github.com/hashicorp/raft-boltdb v0.0.0-20220329195025-15018e9b97e0/go.mod h1:nTakvJ4XYq45UXtn0DbwR4aU9ZdjlnIenpbs6Cd+FM0=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
Expand Down
Loading