From c90c8eb088c46c1ffbd4e7c539c1be4c610bcf28 Mon Sep 17 00:00:00 2001 From: Jamie Sinn Date: Tue, 13 Feb 2024 15:02:21 -0500 Subject: [PATCH] Fix call to chmod to include octal formatting. --- options.go | 8 ++++---- options_test.go | 4 ++-- proxy.go | 10 +++++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/options.go b/options.go index 1015e62..8ec21e6 100644 --- a/options.go +++ b/options.go @@ -23,7 +23,7 @@ type ProxyConfig struct { type ProxyInstance struct { UnixSocketPath string `json:"unixSocketPath" envconfig:"UNIX_SOCKET_PATH" desc:"The path to the Unix socket."` - UnixSocketPermissions int `json:"unixSocketPermissions" envconfig:"UNIX_SOCKET_PERMISSIONS" default:"755" desc:"The permissions to set on the Unix socket. Defaults to 0755"` + UnixSocketPermissions string `json:"unixSocketPermissions" envconfig:"UNIX_SOCKET_PERMISSIONS" default:"0755" desc:"The permissions to set on the Unix socket. Defaults to 0755"` UnixSocketEnabled bool `json:"unixSocketEnabled" envconfig:"UNIX_SOCKET_ENABLED" default:"false" desc:"Whether to enable the Unix socket. Defaults to false."` HTTPPort int `json:"httpPort" envconfig:"HTTP_PORT" default:"8080" desc:"The port to listen on for HTTP requests. Defaults to 8080."` HTTPEnabled bool `json:"httpEnabled" envconfig:"HTTP_ENABLED" default:"true" desc:"Whether to enable the HTTP server. Defaults to true."` @@ -85,8 +85,8 @@ func (i *ProxyInstance) Default() { if i.UnixSocketPath == "" { i.UnixSocketPath = "/tmp/devcycle.sock" } - if i.UnixSocketPermissions == 0 { - i.UnixSocketPermissions = 755 + if i.UnixSocketPermissions == "" { + i.UnixSocketPermissions = "0755" } } } @@ -196,7 +196,7 @@ func SampleProxyConfig() ProxyConfig { UnixSocketPath: "/tmp/devcycle.sock", HTTPPort: 8080, UnixSocketEnabled: false, - UnixSocketPermissions: 755, + UnixSocketPermissions: "0755", HTTPEnabled: true, SDKKey: "", PlatformData: devcycle.PlatformData{ diff --git a/options_test.go b/options_test.go index 31eaa6b..3b1512b 100644 --- a/options_test.go +++ b/options_test.go @@ -36,7 +36,7 @@ func TestParseConfig(t *testing.T) { Instances: []*ProxyInstance{ { UnixSocketPath: "", - UnixSocketPermissions: 755, + UnixSocketPermissions: "0755", HTTPPort: 8080, UnixSocketEnabled: false, HTTPEnabled: true, @@ -79,7 +79,7 @@ func TestParseConfig(t *testing.T) { UnixSocketPath: "/tmp/dvc2.sock", HTTPPort: 1234, UnixSocketEnabled: true, - UnixSocketPermissions: 755, + UnixSocketPermissions: "0755", HTTPEnabled: false, SDKKey: "dvc-test-key", LogFile: "/var/log/devcycle.log", diff --git a/proxy.go b/proxy.go index 11adf4e..c84d8e8 100644 --- a/proxy.go +++ b/proxy.go @@ -71,15 +71,19 @@ func NewBucketingProxyInstance(instance *ProxyInstance) (*ProxyInstance, error) log.Printf("Error running Unix socket server: %s", err) } }() - fileMode := os.FileMode(instance.UnixSocketPermissions) _, err = os.Stat(instance.UnixSocketPath) for ; err != nil; _, err = os.Stat(instance.UnixSocketPath) { time.Sleep(1 * time.Second) } - if err = os.Chmod(instance.UnixSocketPath, fileMode); err != nil { + fileModeOctal, err := strconv.ParseUint(instance.UnixSocketPermissions, 8, 32) + if err != nil { + log.Printf("error parsing Unix socket permissions: %s", err) + return nil, err + } + if err = os.Chmod(instance.UnixSocketPath, os.FileMode(fileModeOctal)); err != nil { log.Printf("Error setting Unix socket permissions: %s", err) } - log.Printf("Running on unix socket: %s with file permissions %d", instance.UnixSocketPath, instance.UnixSocketPermissions) + log.Printf("Running on unix socket: %s with file permissions %s", instance.UnixSocketPath, instance.UnixSocketPermissions) } return instance, err }