fix(permission): globalize and fixes
Permission alert frop OpenGrep is wrong, as the directory must use 0755. To make things working and to ease futur changes, I set the default permission in a constant.
This commit is contained in:
@@ -95,7 +95,7 @@ func (chart *HelmChart) SaveTemplates(templateDir string) {
|
||||
}
|
||||
|
||||
servicename := template.Servicename
|
||||
if err := os.MkdirAll(filepath.Join(templateDir, servicename), 0o600); err != nil {
|
||||
if err := os.MkdirAll(filepath.Join(templateDir, servicename), utils.DirectoryPermission); err != nil {
|
||||
fmt.Println(utils.IconFailure, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
@@ -103,7 +103,7 @@ func (chart *HelmChart) SaveTemplates(templateDir string) {
|
||||
// if the name is a path, create the directory
|
||||
if strings.Contains(name, string(filepath.Separator)) {
|
||||
name = filepath.Join(templateDir, name)
|
||||
err := os.MkdirAll(filepath.Dir(name), 0o600)
|
||||
err := os.MkdirAll(filepath.Dir(name), utils.DirectoryPermission)
|
||||
if err != nil {
|
||||
fmt.Println(utils.IconFailure, err)
|
||||
os.Exit(1)
|
||||
|
@@ -173,9 +173,8 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) error {
|
||||
os.RemoveAll(config.OutputDir)
|
||||
|
||||
// create the chart directory
|
||||
if err := os.MkdirAll(templateDir, 0o600); err != nil {
|
||||
fmt.Println(utils.IconFailure, err)
|
||||
os.Exit(1)
|
||||
if err := os.MkdirAll(templateDir, utils.DirectoryPermission); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add icon from the command line
|
||||
|
@@ -82,7 +82,9 @@ services:
|
||||
AppVersion: appVersion,
|
||||
ChartVersion: chartVersion,
|
||||
}
|
||||
Convert(convertOptions, "compose.yml")
|
||||
if err := Convert(convertOptions, "compose.yml"); err != nil {
|
||||
t.Fatalf("Failed to convert compose file: %s", err)
|
||||
}
|
||||
c, err := os.ReadFile("chart/values.yaml")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@@ -3,6 +3,7 @@ package generator
|
||||
import (
|
||||
"fmt"
|
||||
"katenary/generator/labels"
|
||||
"katenary/utils"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -25,7 +26,7 @@ services:
|
||||
}
|
||||
composeFile := filepath.Join(tmpDir, "compose.yaml")
|
||||
|
||||
os.MkdirAll(tmpDir, 0755)
|
||||
os.MkdirAll(tmpDir, utils.DirectoryPermission)
|
||||
if err := os.WriteFile(composeFile, []byte(composeFileContent), 0644); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
@@ -73,7 +74,7 @@ services:
|
||||
}
|
||||
composeFile := filepath.Join(tmpDir, "compose.yaml")
|
||||
|
||||
os.MkdirAll(tmpDir, 0755)
|
||||
os.MkdirAll(tmpDir, utils.DirectoryPermission)
|
||||
if err := os.WriteFile(composeFile, []byte(composeFileContent), 0644); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"image/color"
|
||||
"image/png"
|
||||
"katenary/generator/labels"
|
||||
"katenary/utils"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -68,7 +69,7 @@ services:
|
||||
|
||||
// create a static directory with an index.html file
|
||||
staticDir := tmpDir + "/static"
|
||||
os.Mkdir(staticDir, 0o755)
|
||||
os.Mkdir(staticDir, utils.DirectoryPermission)
|
||||
indexFile, err := os.Create(staticDir + "/index.html")
|
||||
if err != nil {
|
||||
t.Errorf("Failed to create index.html: %s", err)
|
||||
@@ -128,7 +129,7 @@ services:
|
||||
|
||||
// create a static directory with an index.html file
|
||||
staticDir := tmpDir + "/static"
|
||||
os.Mkdir(staticDir, 0o755)
|
||||
os.Mkdir(staticDir, utils.DirectoryPermission)
|
||||
indexFile, err := os.Create(staticDir + "/index.html")
|
||||
if err != nil {
|
||||
t.Errorf("Failed to create index.html: %s", err)
|
||||
@@ -174,7 +175,7 @@ services:
|
||||
log.Println(tmpDir)
|
||||
defer teardown(tmpDir)
|
||||
|
||||
os.Mkdir(filepath.Join(tmpDir, "images"), 0o755)
|
||||
os.Mkdir(filepath.Join(tmpDir, "images"), utils.DirectoryPermission)
|
||||
|
||||
// create a png image
|
||||
pngFile := tmpDir + "/images/foo.png"
|
||||
@@ -244,7 +245,7 @@ services:
|
||||
log.Println(tmpDir)
|
||||
defer teardown(tmpDir)
|
||||
|
||||
os.Mkdir(filepath.Join(tmpDir, "images"), 0o755)
|
||||
os.Mkdir(filepath.Join(tmpDir, "images"), utils.DirectoryPermission)
|
||||
|
||||
// create a png image
|
||||
pngFile := tmpDir + "/images/foo.png"
|
||||
|
@@ -14,6 +14,9 @@ import (
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
// Default values for permissions apply to created directories.
|
||||
const DirectoryPermission = 0o755
|
||||
|
||||
// TplName returns the name of the kubernetes resource as a template string.
|
||||
// It is used in the templates and defined in _helper.tpl file.
|
||||
func TplName(serviceName, appname string, suffix ...string) string {
|
||||
|
Reference in New Issue
Block a user