zero: use os.UserCacheDir for boostrap config path

This commit is contained in:
Kenneth Jenkins 2023-11-14 13:38:12 -08:00
parent 3c2dc5e0a2
commit 6d46dfc630
2 changed files with 21 additions and 1 deletions

View file

@ -7,6 +7,7 @@ import (
"fmt"
"os"
"os/signal"
"path/filepath"
"syscall"
"github.com/mattn/go-isatty"
@ -28,11 +29,17 @@ func Run(ctx context.Context) error {
return errors.New("no token provided")
}
bootstrapConfigFileName, err := getBootstrapConfigFileName()
if err != nil {
return fmt.Errorf("error getting bootstrap config path: %w", err)
}
return controller.Run(
withInterrupt(ctx),
controller.WithAPIToken(token),
controller.WithClusterAPIEndpoint(getClusterAPIEndpoint()),
controller.WithConnectAPIEndpoint(getConnectAPIEndpoint()),
controller.WithBootstrapConfigFileName(bootstrapConfigFileName),
)
}
@ -81,3 +88,17 @@ func setupLogger() error {
zerolog.DefaultContextLogger = &log.Logger
return nil
}
func getBootstrapConfigFileName() (string, error) {
cacheDir, err := os.UserCacheDir()
if err != nil {
return "", err
}
dir := filepath.Join(cacheDir, "pomerium")
if err := os.MkdirAll(dir, 0644); err != nil {
return "", err
}
return filepath.Join(dir, "bootstrap.dat"), nil
}

View file

@ -72,7 +72,6 @@ func newControllerConfig(opts ...Option) *controllerConfig {
for _, opt := range []Option{
WithClusterAPIEndpoint("https://console.pomerium.com/cluster/v1"),
WithConnectAPIEndpoint("https://connect.pomerium.com"),
WithBootstrapConfigFileName("/var/cache/pomerium-bootstrap.dat"),
WithDatabrokerLeaseDuration(time.Second * 30),
WithDatabrokerRequestTimeout(time.Second * 30),
} {