Skip to content

Commit

Permalink
Fix call to chmod to include octal formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieSinn committed Feb 13, 2024
1 parent 50e506f commit c90c8eb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
8 changes: 4 additions & 4 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."`
Expand Down Expand Up @@ -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"
}
}
}
Expand Down Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestParseConfig(t *testing.T) {
Instances: []*ProxyInstance{
{
UnixSocketPath: "",
UnixSocketPermissions: 755,
UnixSocketPermissions: "0755",
HTTPPort: 8080,
UnixSocketEnabled: false,
HTTPEnabled: true,
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit c90c8eb

Please sign in to comment.