diff --git a/cmd/cou.go b/cmd/cou.go index 018cb99..e0a9c2d 100644 --- a/cmd/cou.go +++ b/cmd/cou.go @@ -1,9 +1,10 @@ package cmd import ( + "os" + "entrypoint/pkg/cou" "entrypoint/utils" - "os" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" diff --git a/cmd/root.go b/cmd/root.go index ef16393..4773e5c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -2,10 +2,11 @@ package cmd import ( "fmt" + "os" + easy "github.com/ruiztulio/logrus-easy-formatter" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "os" ) // rootCmd represents the base command when called without any subcommands diff --git a/cmd/run.go b/cmd/run.go index 53025a2..a4d6262 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -1,9 +1,10 @@ package cmd import ( - "entrypoint/utils" "os" + "entrypoint/utils" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" diff --git a/cmd/start.go b/cmd/start.go index 7c47693..21228d0 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -1,9 +1,10 @@ package cmd import ( - "entrypoint/utils" "os" + "entrypoint/utils" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/pkg/cou/cou.go b/pkg/cou/cou.go index 00af596..3859e2d 100644 --- a/pkg/cou/cou.go +++ b/pkg/cou/cou.go @@ -1,9 +1,10 @@ package cou import ( + "os" + "entrypoint/utils" log "github.com/sirupsen/logrus" - "os" ) // RunCou will execute click-odoo-update to update the database, if you want to save the logs pass stream=false else the diff --git a/utils/bash.go b/utils/bash.go index b95ee14..e175733 100644 --- a/utils/bash.go +++ b/utils/bash.go @@ -16,7 +16,6 @@ import ( // GetUserUIDs returns the user UID and default GID func GetUserUIDs(username string) (uint32, uint32, error) { u, err := user.Lookup(username) - if err != nil { return 0, 0, err } @@ -80,7 +79,6 @@ func RunAndLogCmdAs(cmd string, userName string, env []string) error { return err } return nil - } // Copy copies a single file from src to dst diff --git a/utils/docker_secrets.go b/utils/docker_secrets.go index 7878ecc..67f456e 100644 --- a/utils/docker_secrets.go +++ b/utils/docker_secrets.go @@ -20,7 +20,7 @@ func readDockerSecrets() (map[string]string, error) { continue } - filePath := filepath.Join(secretsPath, e.Name()) + filePath := filepath.Clean(filepath.Join(secretsPath, e.Name())) content, err := os.ReadFile(filePath) if err != nil { diff --git a/utils/files.go b/utils/files.go index 6de65a5..edf7e24 100644 --- a/utils/files.go +++ b/utils/files.go @@ -51,7 +51,7 @@ func appendFiles(odooConfig, filesPath string) error { } content := []byte(strings.Join(odooLines, "\n")) log.Info("Saving Odoo config file content") - if err := os.WriteFile(odooConfig, content, 0644); err != nil { + if err := os.WriteFile(odooConfig, content, 0o600); err != nil { return err } return nil diff --git a/utils/files_test.go b/utils/files_test.go index 39c2c0a..32a0ae8 100644 --- a/utils/files_test.go +++ b/utils/files_test.go @@ -1,8 +1,10 @@ package utils import ( - "github.com/stretchr/testify/assert" + "os" "testing" + + "github.com/stretchr/testify/assert" ) func TestReadLines(t *testing.T) { @@ -14,9 +16,19 @@ func TestReadLines(t *testing.T) { func TestAppendFiles(t *testing.T) { expected := []string{"0", "1", "2", "3", "4", "5", "6"} - err := appendFiles("testdata/odoo_cfg", "testdata/odoo.d") + tmpCopy, err := os.CreateTemp("", "odoo_cfg") + assert.NoError(t, err) + defer os.Remove(tmpCopy.Name()) + + content, err := os.ReadFile("testdata/odoo_cfg") + assert.NoError(t, err) + + _, err = tmpCopy.Write(content) + assert.NoError(t, err) + + err = appendFiles(tmpCopy.Name(), "testdata/odoo.d") assert.NoError(t, err) - res, err := readLines("testdata/odoo_cfg") + res, err := readLines(tmpCopy.Name()) assert.NoError(t, err) assert.Equal(t, expected, res) } diff --git a/utils/odoo_test.go b/utils/odoo_test.go index 79aecf0..231d344 100644 --- a/utils/odoo_test.go +++ b/utils/odoo_test.go @@ -79,7 +79,7 @@ func TestGetOdooUser(t *testing.T) { func TestGetConfigFile(t *testing.T) { res := GetConfigFile() - assert.Equal(t, "/home/odoo/.openerp_serverrc", res) + assert.Equal(t, "/home/odoo/.odoorc", res) err := os.Setenv("ODOO_CONFIG_FILE", "/etc/odoo.conf") assert.NoError(t, err) res = GetConfigFile() diff --git a/utils/randstr_test.go b/utils/randstr_test.go index 1449c61..0748700 100644 --- a/utils/randstr_test.go +++ b/utils/randstr_test.go @@ -1,8 +1,9 @@ package utils import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestRandStringRunes(t *testing.T) {