You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2021/11/24 12:52:48 UTC
[camel-k] branch main updated (44618f2 -> 7efe4ff)
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git.
from 44618f2 Fix #2638: fix condition for external kit and add test
new a4ca4f8 chore(ci): update golangci-lint to v1.43.0
new 66ded60 chore(ci): use the same go version in all jobs
new 53e8014 fix(gosec): Implicit memory aliasing in for loop (G601)
new 14bb820 fix(gosec): Expect WriteFile permissions to be 0600 or less (G306)
new a0747e1 fix(gosec): Use of weak random number generator (G404)
new 2d3458f fix(gosec): disable rule G101
new 70b51b0 fix(gosec): potential file inclusion via variable (G304)
new b44621d fix(gosec): expect directory permissions to be 0750 or less (G301)
new 612620c fix(gosec): deferring unsafe method "Close" on type "*os.File" (G307)
new 32b8c69 fix(gosec): errrs unhandled (G104)
new 2ad218f fix(lint): remove unused function
new 11e3f64 fix(lint): use interface when possible
new ae5e1a5 fix(lint): using the variable on range scope in function literal
new d90c770 fix(lint): same name as predeclared identifier
new 25a10c6 fix(lint): rename StrimziBindingProvider
new 9e1d4cc fix(lint): goimport
new c0d6913 fix(lint): tweak golangci-lint
new d537ccf fix(gosec): expect directory permissions to be 0750 or less (G301)
new 7efe4ff fix(lint): put a space between and comment text (gocritic)
The 19 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.github/workflows/validate.yml | 12 +-
.golangci.yml | 82 +++++-----
addons/register_strimzi.go | 2 +-
addons/strimzi/strimzi.go | 13 +-
addons/strimzi/strimzi_test.go | 4 +-
cmd/util/doc-gen/generators/traitdocgen.go | 62 +++-----
cmd/util/doc-gen/generators/traitmetadatagen.go | 31 ++--
cmd/util/json-schema-gen/main.go | 8 +-
cmd/util/license-check/main.go | 10 +-
cmd/util/vfs-gen/main.go | 10 +-
pkg/builder/image.go | 9 +-
pkg/builder/project.go | 2 +-
pkg/builder/s2i.go | 10 +-
pkg/builder/spectrum.go | 14 +-
pkg/client/client.go | 9 +-
pkg/cmd/bind.go | 2 +-
pkg/cmd/builder/builder.go | 1 +
pkg/cmd/debug.go | 2 +-
pkg/cmd/dump.go | 28 ++--
pkg/cmd/get.go | 3 +-
pkg/cmd/init.go | 11 +-
pkg/cmd/kamelet_get.go | 3 +-
pkg/cmd/kit_get.go | 3 +-
pkg/cmd/modeline_test.go | 72 ++++-----
pkg/cmd/run.go | 3 +-
pkg/cmd/run_help_test.go | 4 +-
pkg/cmd/run_test.go | 4 +-
pkg/cmd/uninstall.go | 11 +-
pkg/cmd/util_config.go | 4 +-
pkg/cmd/util_content.go | 6 +-
pkg/cmd/util_content_test.go | 8 +-
pkg/cmd/util_dependencies.go | 2 +-
pkg/cmd/util_dependencies_test.go | 4 +-
pkg/cmd/util_sources.go | 3 +-
pkg/controller/integration/build_kit.go | 7 +-
.../integration/integration_controller.go | 5 +-
pkg/controller/integration/kits.go | 7 +-
pkg/controller/integration/monitor.go | 9 +-
pkg/event/manager.go | 120 +++++++-------
pkg/install/kamelets.go | 4 +-
pkg/install/secret.go | 4 +-
pkg/resources/resources.go | 4 +-
pkg/trait/environment.go | 2 +-
pkg/trait/openapi.go | 4 +-
pkg/trait/route_test.go | 7 +-
pkg/util/bindings/bindings_test.go | 3 +-
pkg/util/bindings/kamelet_test.go | 3 +-
pkg/util/camel/catalog.go | 4 +-
pkg/util/digest/digest.go | 30 ++--
pkg/util/kubernetes/log/annotation_scraper.go | 12 +-
pkg/util/kubernetes/log/pod_scraper.go | 13 +-
pkg/util/kubernetes/sanitize.go | 4 +-
pkg/util/maven/maven_command.go | 4 +-
pkg/util/maven/maven_log.go | 7 +-
pkg/util/olm/operator.go | 4 +-
pkg/util/source/inspector_groovy_test.go | 3 +-
pkg/util/source/inspector_java_script_test.go | 3 +-
pkg/util/source/inspector_java_source_test.go | 3 +-
pkg/util/source/inspector_kotlin_test.go | 3 +-
pkg/util/source/inspector_xml_test.go | 3 +-
pkg/util/source/inspector_yaml_test.go | 13 +-
pkg/util/sync/file_test.go | 12 +-
pkg/util/uri/uri_test.go | 6 +-
pkg/util/util.go | 175 +++++++++++++++------
64 files changed, 515 insertions(+), 415 deletions(-)
[camel-k] 07/19: fix(gosec): potential file inclusion via variable (G304)
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 70b51b073515c66e2dd279a97201fa7f6ccd2352
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Mon Nov 22 15:14:00 2021 +0100
fix(gosec): potential file inclusion via variable (G304)
---
.golangci.yml | 64 +++++++------------------
cmd/util/doc-gen/generators/traitdocgen.go | 6 +--
cmd/util/doc-gen/generators/traitmetadatagen.go | 3 +-
cmd/util/json-schema-gen/main.go | 5 +-
cmd/util/license-check/main.go | 6 +--
cmd/util/vfs-gen/main.go | 3 +-
pkg/builder/s2i.go | 5 +-
pkg/client/client.go | 3 +-
pkg/cmd/dump.go | 3 +-
pkg/cmd/init.go | 3 +-
pkg/cmd/run.go | 3 +-
pkg/cmd/util_content.go | 3 +-
pkg/cmd/util_sources.go | 3 +-
pkg/install/kamelets.go | 3 +-
pkg/install/secret.go | 5 +-
pkg/trait/environment.go | 2 +-
pkg/trait/openapi.go | 2 +-
pkg/util/camel/catalog.go | 3 +-
pkg/util/digest/digest.go | 5 +-
pkg/util/util.go | 23 +++++++--
20 files changed, 72 insertions(+), 81 deletions(-)
diff --git a/.golangci.yml b/.golangci.yml
index eb4e5e2..94f64cc 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -19,54 +19,22 @@ linters-settings:
lll:
line-length: 170
linters:
- disable-all: true
- enable:
- - asciicheck
- - bodyclose
- - deadcode
- - depguard
- - dogsled
- - durationcheck
- - errcheck
- - errname
- - errorlint
- - exportloopref
- - forcetypeassert
- - gocritic
- - gofmt
- - gofumpt
- - goheader
- - goimports
- - gomodguard
- - goprintffuncname
- - gosimple
- - govet
- - ifshort
- - importas
- - ineffassign
-# - lll
- - makezero
- - misspell
- - nakedret
- - nilerr
- - nolintlint
- - prealloc
- - promlinter
- - revive
- - rowserrcheck
- - sqlclosecheck
- - staticcheck
- - structcheck
- - stylecheck
- - thelper
- - tparallel
- - typecheck
- - unconvert
- - unparam
- - unused
- - varcheck
- - wastedassign
- - gosec
+ enable-all: true
+ disable:
+ - dupl
+ - forbidigo
+ - funlen
+ - gomoddirectives
+ - godox
+ - gomnd
+ - gochecknoinits
+ - gocognit
+ - godot
+ - lll
+ - nestif
+ - cyclop
+ - exhaustivestruct
+ - gochecknoglobals
issues:
exclude-rules:
diff --git a/cmd/util/doc-gen/generators/traitdocgen.go b/cmd/util/doc-gen/generators/traitdocgen.go
index f695b69..93c20c5 100644
--- a/cmd/util/doc-gen/generators/traitdocgen.go
+++ b/cmd/util/doc-gen/generators/traitdocgen.go
@@ -19,8 +19,8 @@ package generators
import (
"fmt"
+ "github.com/apache/camel-k/pkg/util"
"io"
- "io/ioutil"
"os"
"path"
"reflect"
@@ -275,11 +275,11 @@ func split(doc []string, startMarker, endMarker string) (pre []string, post []st
}
func readFile(filename string) (file *os.File, content []string, err error) {
- if file, err = os.OpenFile(filename, os.O_RDWR|os.O_CREATE, 0o777); err != nil {
+ if file, err = util.OpenFile(filename, os.O_RDWR|os.O_CREATE, 0o777); err != nil {
return file, content, err
}
- bytes, err := ioutil.ReadFile(filename)
+ bytes, err := util.ReadFile(filename)
if err != nil {
return file, content, err
}
diff --git a/cmd/util/doc-gen/generators/traitmetadatagen.go b/cmd/util/doc-gen/generators/traitmetadatagen.go
index 3dffe87..5358883 100644
--- a/cmd/util/doc-gen/generators/traitmetadatagen.go
+++ b/cmd/util/doc-gen/generators/traitmetadatagen.go
@@ -19,6 +19,7 @@ package generators
import (
"fmt"
+ "github.com/apache/camel-k/pkg/util"
"io"
"os"
"path"
@@ -94,7 +95,7 @@ func (g *traitMetaDataGen) Finalize(c *generator.Context, w io.Writer) error {
var file *os.File
var err error
- if file, err = os.OpenFile(filename, os.O_RDWR|os.O_CREATE, 0o777); err != nil {
+ if file, err = util.OpenFile(filename, os.O_RDWR|os.O_CREATE, 0o777); err != nil {
return err
}
if err = file.Truncate(0); err != nil {
diff --git a/cmd/util/json-schema-gen/main.go b/cmd/util/json-schema-gen/main.go
index 8d03510..27bebd7 100644
--- a/cmd/util/json-schema-gen/main.go
+++ b/cmd/util/json-schema-gen/main.go
@@ -20,6 +20,7 @@ package main
import (
"encoding/json"
"fmt"
+ "github.com/apache/camel-k/pkg/util"
"io/ioutil"
"os"
"reflect"
@@ -122,7 +123,7 @@ func rebaseRefs(schema map[string]interface{}) {
}
func loadDslSchema(filename string) (map[string]interface{}, error) {
- bytes, err := ioutil.ReadFile(filename)
+ bytes, err := util.ReadFile(filename)
if err != nil {
return nil, err
}
@@ -134,7 +135,7 @@ func loadDslSchema(filename string) (map[string]interface{}, error) {
}
func loadCrdSchema(filename string) (*apiextensionsv1.JSONSchemaProps, error) {
- bytes, err := ioutil.ReadFile(filename)
+ bytes, err := util.ReadFile(filename)
if err != nil {
return nil, err
}
diff --git a/cmd/util/license-check/main.go b/cmd/util/license-check/main.go
index bcf5960..ae94655 100644
--- a/cmd/util/license-check/main.go
+++ b/cmd/util/license-check/main.go
@@ -19,7 +19,7 @@ package main
import (
"fmt"
- "io/ioutil"
+ "github.com/apache/camel-k/pkg/util"
"os"
"strings"
)
@@ -33,14 +33,14 @@ func main() {
fileName := os.Args[1]
licenseName := os.Args[2]
- fileBin, err := ioutil.ReadFile(fileName)
+ fileBin, err := util.ReadFile(fileName)
if err != nil {
os.Stderr.WriteString(fmt.Sprintf("cannot read file %s: %v\n", fileName, err))
os.Exit(1)
}
file := string(fileBin)
- licenseBin, err := ioutil.ReadFile(licenseName)
+ licenseBin, err := util.ReadFile(licenseName)
if err != nil {
os.Stderr.WriteString(fmt.Sprintf("cannot read file %s: %v\n", licenseName, err))
os.Exit(1)
diff --git a/cmd/util/vfs-gen/main.go b/cmd/util/vfs-gen/main.go
index 3a01401..89b9cd8 100644
--- a/cmd/util/vfs-gen/main.go
+++ b/cmd/util/vfs-gen/main.go
@@ -20,6 +20,7 @@ package main
import (
"flag"
"fmt"
+ "github.com/apache/camel-k/pkg/util"
"io/ioutil"
"log"
"net/http"
@@ -139,7 +140,7 @@ limitations under the License.
*/
`
- content, err := ioutil.ReadFile(resourceFile)
+ content, err := util.ReadFile(resourceFile)
if err != nil {
log.Fatalln(err)
}
diff --git a/pkg/builder/s2i.go b/pkg/builder/s2i.go
index 00a6fdf..42669a7 100644
--- a/pkg/builder/s2i.go
+++ b/pkg/builder/s2i.go
@@ -22,6 +22,7 @@ import (
"compress/gzip"
"context"
"fmt"
+ "github.com/apache/camel-k/pkg/util"
"io"
"io/ioutil"
"os"
@@ -171,7 +172,7 @@ func (t *s2iTask) Do(ctx context.Context) v1.BuildStatus {
return status.Failed(errors.Wrap(err, "cannot tar context directory"))
}
- resource, err := ioutil.ReadFile(archive)
+ resource, err := util.ReadFile(archive)
if err != nil {
return status.Failed(errors.Wrap(err, "cannot read tar file "+archive))
}
@@ -321,7 +322,7 @@ func tarDir(src string, writers ...io.Writer) error {
return err
}
- f, err := os.Open(file)
+ f, err := util.Open(file)
if err != nil {
return err
}
diff --git a/pkg/client/client.go b/pkg/client/client.go
index f38f43a..f806266 100644
--- a/pkg/client/client.go
+++ b/pkg/client/client.go
@@ -19,6 +19,7 @@ package client
import (
"fmt"
+ "github.com/apache/camel-k/pkg/util"
"io/ioutil"
"os"
"path/filepath"
@@ -231,7 +232,7 @@ func GetCurrentNamespace(kubeconfig string) (string, error) {
return "default", nil
}
- data, err := ioutil.ReadFile(kubeconfig)
+ data, err := util.ReadFile(kubeconfig)
if err != nil {
return "", err
}
diff --git a/pkg/cmd/dump.go b/pkg/cmd/dump.go
index 9ffba00..fcdc6da 100644
--- a/pkg/cmd/dump.go
+++ b/pkg/cmd/dump.go
@@ -21,6 +21,7 @@ import (
"bufio"
"context"
"fmt"
+ "github.com/apache/camel-k/pkg/util"
"io"
"os"
@@ -61,7 +62,7 @@ func (o *dumpCmdOptions) dump(cmd *cobra.Command, args []string) error {
}
if len(args) == 1 {
fileName := args[0]
- writer, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0o777)
+ writer, err := util.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0o777)
if err != nil {
return err
}
diff --git a/pkg/cmd/init.go b/pkg/cmd/init.go
index 7c48947..0b30b0b 100644
--- a/pkg/cmd/init.go
+++ b/pkg/cmd/init.go
@@ -19,6 +19,7 @@ package cmd
import (
"fmt"
+ "github.com/apache/camel-k/pkg/util"
"os"
"path/filepath"
"strings"
@@ -98,7 +99,7 @@ func (o *initCmdOptions) writeFromTemplate(language v1.Language, fileName string
if err != nil {
return err
}
- out, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0o777)
+ out, err := util.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0o777)
if err != nil {
return err
}
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 1d9063e..261c530 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -21,7 +21,6 @@ import (
"context"
"encoding/json"
"fmt"
- "io/ioutil"
"os"
"os/signal"
"path"
@@ -754,7 +753,7 @@ func (o *runCmdOptions) configureTraits(integration *v1.Integration, options []s
}
func loadPropertyFile(fileName string) (*properties.Properties, error) {
- file, err := ioutil.ReadFile(fileName)
+ file, err := util.ReadFile(fileName)
if err != nil {
return nil, err
}
diff --git a/pkg/cmd/util_content.go b/pkg/cmd/util_content.go
index 84edd4c..9611ae1 100644
--- a/pkg/cmd/util_content.go
+++ b/pkg/cmd/util_content.go
@@ -19,6 +19,7 @@ package cmd
import (
"fmt"
+ "github.com/apache/camel-k/pkg/util"
"io/ioutil"
"net/http"
"net/url"
@@ -50,7 +51,7 @@ func loadRawContent(source string) ([]byte, string, error) {
}
if ok {
- content, err = ioutil.ReadFile(source)
+ content, err = util.ReadFile(source)
} else {
var u *url.URL
u, err = url.Parse(source)
diff --git a/pkg/cmd/util_sources.go b/pkg/cmd/util_sources.go
index 3be66de..fc9e624 100644
--- a/pkg/cmd/util_sources.go
+++ b/pkg/cmd/util_sources.go
@@ -20,7 +20,6 @@ package cmd
import (
"context"
"fmt"
- "io/ioutil"
"net/http"
"net/url"
"os"
@@ -206,7 +205,7 @@ func ResolveLocalSource(location string, compress bool) (Source, error) {
Local: true,
}
- content, err := ioutil.ReadFile(location)
+ content, err := util.ReadFile(location)
if err != nil {
return Source{}, err
}
diff --git a/pkg/install/kamelets.go b/pkg/install/kamelets.go
index a8a4dfe..2641003 100644
--- a/pkg/install/kamelets.go
+++ b/pkg/install/kamelets.go
@@ -20,6 +20,7 @@ package install
import (
"context"
"fmt"
+ "github.com/apache/camel-k/pkg/util"
"io/ioutil"
"os"
"path"
@@ -66,7 +67,7 @@ func KameletCatalog(ctx context.Context, c client.Client, namespace string) erro
continue
}
- content, err := ioutil.ReadFile(path.Join(kameletDir, file.Name()))
+ content, err := util.ReadFile(path.Join(kameletDir, file.Name()))
if err != nil {
return err
}
diff --git a/pkg/install/secret.go b/pkg/install/secret.go
index 6d403bf..016b336 100644
--- a/pkg/install/secret.go
+++ b/pkg/install/secret.go
@@ -19,8 +19,7 @@ package install
import (
"context"
- "io/ioutil"
-
+ "github.com/apache/camel-k/pkg/util"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -43,7 +42,7 @@ func RegistrySecretOrCollect(ctx context.Context, c client.Client, namespace str
// RegistrySecretFromFileOrCollect generates a secret from a docker-config.json file and creates it on the cluster (or appends it to the collection)
func RegistrySecretFromFileOrCollect(ctx context.Context, c client.Client, namespace string, file string, collection *kubernetes.Collection, force bool) (string, error) {
- secretData, err := ioutil.ReadFile(file)
+ secretData, err := util.ReadFile(file)
if err != nil {
return "", err
}
diff --git a/pkg/trait/environment.go b/pkg/trait/environment.go
index b4ebfa8..ead510f 100644
--- a/pkg/trait/environment.go
+++ b/pkg/trait/environment.go
@@ -48,7 +48,7 @@ const (
// pkg/trait/environment.go:41: G101: Potential hardcoded credentials (gosec)
// envVarMountPathSecrets = "CAMEL_K_MOUNT_PATH_SECRETS"
//
- // nolint: gosec
+ // #nosec G101
envVarMountPathSecrets = "CAMEL_K_MOUNT_PATH_SECRETS"
)
diff --git a/pkg/trait/openapi.go b/pkg/trait/openapi.go
index 1048f30..6a7a9ed 100644
--- a/pkg/trait/openapi.go
+++ b/pkg/trait/openapi.go
@@ -239,7 +239,7 @@ func (t *openAPITrait) createNewOpenAPIConfigMap(e *Environment, resource v1.Res
return err
}
- content, err = ioutil.ReadFile(out)
+ content, err = util.ReadFile(out)
if err != nil {
return err
}
diff --git a/pkg/util/camel/catalog.go b/pkg/util/camel/catalog.go
index 97c71a4..81dac2e 100644
--- a/pkg/util/camel/catalog.go
+++ b/pkg/util/camel/catalog.go
@@ -19,6 +19,7 @@ package camel
import (
"context"
+ "github.com/apache/camel-k/pkg/util"
"io/ioutil"
"os"
"path"
@@ -137,7 +138,7 @@ func GenerateCatalogCommon(
return nil, err
}
- content, err := ioutil.ReadFile(path.Join(tmpDir, "catalog.yaml"))
+ content, err := util.ReadFile(path.Join(tmpDir, "catalog.yaml"))
if err != nil {
return nil, err
}
diff --git a/pkg/util/digest/digest.go b/pkg/util/digest/digest.go
index 6b2bf59..f364b5c 100644
--- a/pkg/util/digest/digest.go
+++ b/pkg/util/digest/digest.go
@@ -25,7 +25,6 @@ import (
"encoding/json"
"fmt"
"io"
- "os"
"path"
"sort"
"strconv"
@@ -263,13 +262,13 @@ func sortedTraitAnnotationsKeys(it *v1.Integration) []string {
func ComputeSHA1(elem ...string) (string, error) {
file := path.Join(elem...)
- f, err := os.Open(file)
+ f, err := util.Open(file)
if err != nil {
return "", err
}
defer f.Close()
- // nolint: gosec
+ // #nosec G401
h := sha1.New()
if _, err := io.Copy(h, f); err != nil {
return "", err
diff --git a/pkg/util/util.go b/pkg/util/util.go
index 274ef2d..4d10edc 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -26,6 +26,7 @@ import (
"io/ioutil"
"os"
"path"
+ "path/filepath"
"regexp"
"sort"
"strings"
@@ -217,7 +218,7 @@ func CopyFile(src, dst string) (int64, error) {
return 0, fmt.Errorf("%s is not a regular file", src)
}
- source, err := os.Open(src)
+ source, err := Open(src)
if err != nil {
return 0, err
}
@@ -228,7 +229,7 @@ func CopyFile(src, dst string) (int64, error) {
return 0, err
}
- destination, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, stat.Mode())
+ destination, err := OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, stat.Mode())
if err != nil {
return 0, err
}
@@ -320,7 +321,7 @@ func DirectoryExists(directory string) (bool, error) {
}
func DirectoryEmpty(directory string) (bool, error) {
- f, err := os.Open(directory)
+ f, err := Open(directory)
if err != nil {
return false, err
}
@@ -761,3 +762,19 @@ func CopyAppFile(localDependenciesDirectory string, localAppDirectory string) er
return nil
}
+
+// Open a safe wrapper of os.Open.
+func Open(name string) (*os.File, error) {
+ return os.Open(filepath.Clean(name))
+}
+
+// OpenFile a safe wrapper of os.OpenFile.
+func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) {
+ // #nosec G304
+ return os.OpenFile(filepath.Clean(name), flag, perm)
+}
+
+// ReadFile a safe wrapper of os.ReadFile.
+func ReadFile(filename string) ([]byte, error) {
+ return os.ReadFile(filepath.Clean(filename))
+}
[camel-k] 13/19: fix(lint): using the variable on range scope in function literal
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit ae5e1a5d4088f8b8c22d377b507df8336e2c5acd
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Mon Nov 22 23:35:35 2021 +0100
fix(lint): using the variable on range scope in function literal
---
cmd/util/vfs-gen/main.go | 4 ++--
pkg/util/bindings/bindings_test.go | 3 ++-
pkg/util/bindings/kamelet_test.go | 3 ++-
pkg/util/source/inspector_groovy_test.go | 3 ++-
pkg/util/source/inspector_java_script_test.go | 3 ++-
pkg/util/source/inspector_java_source_test.go | 3 ++-
pkg/util/source/inspector_kotlin_test.go | 3 ++-
pkg/util/source/inspector_xml_test.go | 3 ++-
pkg/util/source/inspector_yaml_test.go | 12 ++++++++----
pkg/util/uri/uri_test.go | 6 ++++--
10 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/cmd/util/vfs-gen/main.go b/cmd/util/vfs-gen/main.go
index 89b9cd8..72eed43 100644
--- a/cmd/util/vfs-gen/main.go
+++ b/cmd/util/vfs-gen/main.go
@@ -189,8 +189,8 @@ func BigFilesFilter(size int) func(path string, fi os.FileInfo) bool {
func calcExclusions(root string, dirNames []string) []string {
var exclusions []string
- for _, dirName := range dirNames {
- dirName = filepath.Join(root, dirName)
+ for _, name := range dirNames {
+ dirName := filepath.Join(root, name)
if err := filepath.Walk(dirName, func(resPath string, info os.FileInfo, err error) error {
if info.IsDir() {
ignoreFileName := path.Join(resPath, ".vfsignore")
diff --git a/pkg/util/bindings/bindings_test.go b/pkg/util/bindings/bindings_test.go
index 5fde9a5..f9c1017 100644
--- a/pkg/util/bindings/bindings_test.go
+++ b/pkg/util/bindings/bindings_test.go
@@ -202,7 +202,8 @@ func TestBindings(t *testing.T) {
},
}
- for i, tc := range testcases {
+ for i := range testcases {
+ tc := testcases[i]
t.Run(fmt.Sprintf("test-%d-%s", i, tc.uri), func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
diff --git a/pkg/util/bindings/kamelet_test.go b/pkg/util/bindings/kamelet_test.go
index f29099c..b43fd4d 100644
--- a/pkg/util/bindings/kamelet_test.go
+++ b/pkg/util/bindings/kamelet_test.go
@@ -57,7 +57,8 @@ func TestKameletBindingProvider(t *testing.T) {
},
}
- for i, tc := range testcases {
+ for i := range testcases {
+ tc := testcases[i]
t.Run(fmt.Sprintf("test-%d-%s", i, tc.uri), func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
diff --git a/pkg/util/source/inspector_groovy_test.go b/pkg/util/source/inspector_groovy_test.go
index 8d90dfe..7f091f3 100644
--- a/pkg/util/source/inspector_groovy_test.go
+++ b/pkg/util/source/inspector_groovy_test.go
@@ -71,7 +71,8 @@ func TestGroovyKamelet(t *testing.T) {
},
}
- for i, test := range tc {
+ for i := range tc {
+ test := tc[i]
t.Run(fmt.Sprintf("TestGroovyKamelet-%d", i), func(t *testing.T) {
code := v1.SourceSpec{
DataSpec: v1.DataSpec{
diff --git a/pkg/util/source/inspector_java_script_test.go b/pkg/util/source/inspector_java_script_test.go
index 58596a5..f9e1634 100644
--- a/pkg/util/source/inspector_java_script_test.go
+++ b/pkg/util/source/inspector_java_script_test.go
@@ -52,7 +52,8 @@ func TestJavaScriptKamelet(t *testing.T) {
},
}
- for i, test := range tc {
+ for i := range tc {
+ test := tc[i]
t.Run(fmt.Sprintf("TestJavaScriptKamelet-%d", i), func(t *testing.T) {
code := v1.SourceSpec{
DataSpec: v1.DataSpec{
diff --git a/pkg/util/source/inspector_java_source_test.go b/pkg/util/source/inspector_java_source_test.go
index 22cae7a..3536431 100644
--- a/pkg/util/source/inspector_java_source_test.go
+++ b/pkg/util/source/inspector_java_source_test.go
@@ -52,7 +52,8 @@ func TestJavaSourceKamelet(t *testing.T) {
},
}
- for i, test := range tc {
+ for i := range tc {
+ test := tc[i]
t.Run(fmt.Sprintf("TestJavaSourceKamelet-%d", i), func(t *testing.T) {
code := v1.SourceSpec{
DataSpec: v1.DataSpec{
diff --git a/pkg/util/source/inspector_kotlin_test.go b/pkg/util/source/inspector_kotlin_test.go
index 8964731..d94ee7f 100644
--- a/pkg/util/source/inspector_kotlin_test.go
+++ b/pkg/util/source/inspector_kotlin_test.go
@@ -52,7 +52,8 @@ func TestKotlinKamelet(t *testing.T) {
},
}
- for i, test := range tc {
+ for i := range tc {
+ test := tc[i]
t.Run(fmt.Sprintf("TestKotlinKamelet-%d", i), func(t *testing.T) {
code := v1.SourceSpec{
DataSpec: v1.DataSpec{
diff --git a/pkg/util/source/inspector_xml_test.go b/pkg/util/source/inspector_xml_test.go
index 7b3b8de..52445e8 100644
--- a/pkg/util/source/inspector_xml_test.go
+++ b/pkg/util/source/inspector_xml_test.go
@@ -61,7 +61,8 @@ func TestXMLKamelet(t *testing.T) {
},
}
- for i, test := range tc {
+ for i := range tc {
+ test := tc[i]
t.Run(fmt.Sprintf("TestXMLKamelet-%d", i), func(t *testing.T) {
code := v1.SourceSpec{
DataSpec: v1.DataSpec{
diff --git a/pkg/util/source/inspector_yaml_test.go b/pkg/util/source/inspector_yaml_test.go
index 12e186c..88d77d5 100644
--- a/pkg/util/source/inspector_yaml_test.go
+++ b/pkg/util/source/inspector_yaml_test.go
@@ -126,7 +126,8 @@ func TestYAMLDependencies(t *testing.T) {
},
},
}
- for _, test := range tests {
+ for i := range tests {
+ test := tests[i]
t.Run(test.name, func(t *testing.T) {
code := v1.SourceSpec{
DataSpec: v1.DataSpec{
@@ -329,7 +330,8 @@ func TestYAMLJson(t *testing.T) {
},
}
- for i, test := range tc {
+ for i := range tc {
+ test := tc[i]
t.Run(fmt.Sprintf("%s-%d", test.dependency, i), func(t *testing.T) {
code := v1.SourceSpec{
DataSpec: v1.DataSpec{
@@ -417,7 +419,8 @@ func TestYAMLKamelet(t *testing.T) {
},
}
- for i, test := range tc {
+ for i := range tc {
+ test := tc[i]
t.Run(fmt.Sprintf("TestYAMLKamelet-%d", i), func(t *testing.T) {
code := v1.SourceSpec{
DataSpec: v1.DataSpec{
@@ -484,7 +487,8 @@ func TestYAMLExplicitParameters(t *testing.T) {
},
}
- for i, test := range tc {
+ for i := range tc {
+ test := tc[i]
t.Run(fmt.Sprintf("TestYAMLExplicitParameters-%d", i), func(t *testing.T) {
code := v1.SourceSpec{
DataSpec: v1.DataSpec{
diff --git a/pkg/util/uri/uri_test.go b/pkg/util/uri/uri_test.go
index 068184c..4000bf3 100644
--- a/pkg/util/uri/uri_test.go
+++ b/pkg/util/uri/uri_test.go
@@ -134,7 +134,8 @@ func TestAppendParameters(t *testing.T) {
},
}
- for i, test := range tests {
+ for i := range tests {
+ test := tests[i]
t.Run(fmt.Sprintf("appendParameters-%d-%s", i, test.expected), func(t *testing.T) {
uri := AppendParameters(test.prefix, test.params)
assert.Equal(t, test.expected, uri)
@@ -172,7 +173,8 @@ func TestCamelURIFormat(t *testing.T) {
},
}
- for i, tc := range tests {
+ for i := range tests {
+ tc := tests[i]
t.Run(fmt.Sprintf("%d-%s", i, tc.uri), func(t *testing.T) {
assert.Equal(t, !tc.invalid, HasCamelURIFormat(tc.uri))
})
[camel-k] 15/19: fix(lint): rename StrimziBindingProvider
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 25a10c63bd3ff94e279e716266c90e8724622272
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Tue Nov 23 00:20:51 2021 +0100
fix(lint): rename StrimziBindingProvider
---
addons/register_strimzi.go | 2 +-
addons/strimzi/strimzi.go | 13 ++++++-------
addons/strimzi/strimzi_test.go | 4 ++--
3 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/addons/register_strimzi.go b/addons/register_strimzi.go
index 9eac795..de9c90d 100644
--- a/addons/register_strimzi.go
+++ b/addons/register_strimzi.go
@@ -23,5 +23,5 @@ import (
)
func init() {
- bindings.RegisterBindingProvider(strimzi.StrimziBindingProvider{})
+ bindings.RegisterBindingProvider(strimzi.BindingProvider{})
}
diff --git a/addons/strimzi/strimzi.go b/addons/strimzi/strimzi.go
index a8329af..5d2413a 100644
--- a/addons/strimzi/strimzi.go
+++ b/addons/strimzi/strimzi.go
@@ -30,17 +30,16 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
)
-// StrimziBindingProvider allows to connect to a Kafka topic via KameletBinding
-// nolint: revive
-type StrimziBindingProvider struct {
+// BindingProvider allows to connect to a Kafka topic via KameletBinding
+type BindingProvider struct {
Client internalclientset.Interface
}
-func (s StrimziBindingProvider) ID() string {
+func (s BindingProvider) ID() string {
return "strimzi"
}
-func (s StrimziBindingProvider) Translate(ctx bindings.BindingContext, _ bindings.EndpointContext, endpoint v1alpha1.Endpoint) (*bindings.Binding, error) {
+func (s BindingProvider) Translate(ctx bindings.BindingContext, _ bindings.EndpointContext, endpoint v1alpha1.Endpoint) (*bindings.Binding, error) {
if endpoint.Ref == nil {
// React only on refs
return nil, nil
@@ -100,7 +99,7 @@ func (s StrimziBindingProvider) Translate(ctx bindings.BindingContext, _ binding
}, nil
}
-func (s StrimziBindingProvider) getBootstrapServers(ctx bindings.BindingContext, clusterName string) (string, error) {
+func (s BindingProvider) getBootstrapServers(ctx bindings.BindingContext, clusterName string) (string, error) {
cluster, err := s.Client.KafkaV1beta2().Kafkas(ctx.Namespace).Get(ctx.Ctx, clusterName, v1.GetOptions{})
if err != nil {
return "", err
@@ -119,6 +118,6 @@ func (s StrimziBindingProvider) getBootstrapServers(ctx bindings.BindingContext,
return "", fmt.Errorf("cluster %q has no listeners of type %q", clusterName, v1beta2.StrimziListenerTypePlain)
}
-func (s StrimziBindingProvider) Order() int {
+func (s BindingProvider) Order() int {
return bindings.OrderStandard
}
diff --git a/addons/strimzi/strimzi_test.go b/addons/strimzi/strimzi_test.go
index 34b9d08..1ef679d 100644
--- a/addons/strimzi/strimzi_test.go
+++ b/addons/strimzi/strimzi_test.go
@@ -58,7 +58,7 @@ func TestStrimziDirect(t *testing.T) {
}),
}
- binding, err := StrimziBindingProvider{}.Translate(bindingContext, bindings.EndpointContext{
+ binding, err := BindingProvider{}.Translate(bindingContext, bindings.EndpointContext{
Type: v1alpha1.EndpointTypeSink,
}, endpoint)
assert.NoError(t, err)
@@ -100,7 +100,7 @@ func TestStrimziLookup(t *testing.T) {
}
client := fake.NewSimpleClientset(&cluster, &topic)
- provider := StrimziBindingProvider{
+ provider := BindingProvider{
Client: client,
}
[camel-k] 03/19: fix(gosec): Implicit memory aliasing in for loop (G601)
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 53e8014fd40e6e0c42eb5c60cba6dbee6aa98db2
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Mon Nov 22 12:18:16 2021 +0100
fix(gosec): Implicit memory aliasing in for loop (G601)
---
.golangci.yml | 1 +
pkg/cmd/uninstall.go | 11 +++++------
pkg/controller/integration/build_kit.go | 7 ++++---
pkg/controller/integration/integration_controller.go | 5 +++--
pkg/controller/integration/kits.go | 7 ++++---
pkg/controller/integration/monitor.go | 9 +++++----
6 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/.golangci.yml b/.golangci.yml
index 34ab844..eb4e5e2 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -66,6 +66,7 @@ linters:
- unused
- varcheck
- wastedassign
+ - gosec
issues:
exclude-rules:
diff --git a/pkg/cmd/uninstall.go b/pkg/cmd/uninstall.go
index 43fbff4..2cc76d9 100644
--- a/pkg/cmd/uninstall.go
+++ b/pkg/cmd/uninstall.go
@@ -359,12 +359,11 @@ func (o *uninstallCmdOptions) removeSubjectFromClusterRoleBindings(ctx context.C
}
// Remove the subject corresponding to this operator install
- for _, clusterRoleBinding := range clusterRoleBindings.Items {
+ for crbIndex, clusterRoleBinding := range clusterRoleBindings.Items {
for i, subject := range clusterRoleBinding.Subjects {
if subject.Name == "camel-k-operator" && subject.Namespace == namespace {
clusterRoleBinding.Subjects = append(clusterRoleBinding.Subjects[:i], clusterRoleBinding.Subjects[i+1:]...)
- crb := &clusterRoleBinding
- _, err = api.ClusterRoleBindings().Update(ctx, crb, metav1.UpdateOptions{})
+ _, err = api.ClusterRoleBindings().Update(ctx, &clusterRoleBindings.Items[crbIndex], metav1.UpdateOptions{})
if err != nil {
return err
}
@@ -470,10 +469,10 @@ func (o *uninstallCmdOptions) uninstallKamelets(ctx context.Context, c client.Cl
return err
}
- for _, kamelet := range kameletList.Items {
+ for i := range kameletList.Items {
// remove only platform Kamelets (use-defined Kamelets should be skipped)
- if kamelet.Labels[v1alpha1.KameletBundledLabel] == "true" {
- err := c.Delete(ctx, &kamelet)
+ if kameletList.Items[i].Labels[v1alpha1.KameletBundledLabel] == "true" {
+ err := c.Delete(ctx, &kameletList.Items[i])
if err != nil {
return err
}
diff --git a/pkg/controller/integration/build_kit.go b/pkg/controller/integration/build_kit.go
index eb392af..0feddc9 100644
--- a/pkg/controller/integration/build_kit.go
+++ b/pkg/controller/integration/build_kit.go
@@ -107,8 +107,9 @@ func (action *buildKitAction) Handle(ctx context.Context, integration *v1.Integr
kits:
for _, kit := range env.IntegrationKits {
kit := kit
- for i, k := range existingKits {
- match, err := kitMatches(&kit, &k)
+ for i := range existingKits {
+ k := &existingKits[i]
+ match, err := kitMatches(&kit, k)
if err != nil {
return nil, err
}
@@ -116,7 +117,7 @@ kits:
if integrationKit == nil ||
integrationKit.Status.Phase != v1.IntegrationKitPhaseReady && k.Status.Phase == v1.IntegrationKitPhaseReady ||
integrationKit.Status.Phase == v1.IntegrationKitPhaseReady && k.Status.Phase == v1.IntegrationKitPhaseReady && k.HasHigherPriorityThan(integrationKit) {
- integrationKit = &existingKits[i]
+ integrationKit = k
}
continue kits
diff --git a/pkg/controller/integration/integration_controller.go b/pkg/controller/integration/integration_controller.go
index bfd7fbe..342db8c 100644
--- a/pkg/controller/integration/integration_controller.go
+++ b/pkg/controller/integration/integration_controller.go
@@ -139,8 +139,9 @@ func add(mgr manager.Manager, c client.Client, r reconcile.Reconciler) error {
return requests
}
- for _, integration := range list.Items {
- if match, err := integrationMatches(&integration, kit); err != nil {
+ for i := range list.Items {
+ integration := &list.Items[i]
+ if match, err := integrationMatches(integration, kit); err != nil {
log.Errorf(err, "Error matching integration %q with kit %q", integration.Name, kit.Name)
continue
diff --git a/pkg/controller/integration/kits.go b/pkg/controller/integration/kits.go
index f28723d..f31fabf 100644
--- a/pkg/controller/integration/kits.go
+++ b/pkg/controller/integration/kits.go
@@ -67,14 +67,15 @@ func lookupKitsForIntegration(ctx context.Context, c ctrl.Reader, integration *v
}
kits := make([]v1.IntegrationKit, 0)
- for _, kit := range list.Items {
- match, err := integrationMatches(integration, &kit)
+ for i := range list.Items {
+ kit := &list.Items[i]
+ match, err := integrationMatches(integration, kit)
if err != nil {
return nil, err
} else if !match {
continue
}
- kits = append(kits, kit)
+ kits = append(kits, *kit)
}
return kits, nil
diff --git a/pkg/controller/integration/monitor.go b/pkg/controller/integration/monitor.go
index 2c59130..492cb97 100644
--- a/pkg/controller/integration/monitor.go
+++ b/pkg/controller/integration/monitor.go
@@ -369,16 +369,17 @@ func (action *monitorAction) updateIntegrationPhaseAndReadyCondition(ctx context
// Finally, call the readiness probes of the non-ready Pods directly,
// to retrieve insights from the Camel runtime.
var runtimeNotReadyMessages []string
- for _, pod := range unreadyPods {
- if ready := kubernetes.GetPodCondition(pod, corev1.PodReady); ready.Reason != "ContainersNotReady" {
+ for i := range unreadyPods {
+ pod := &unreadyPods[i]
+ if ready := kubernetes.GetPodCondition(*pod, corev1.PodReady); ready.Reason != "ContainersNotReady" {
continue
}
- container := getIntegrationContainer(environment, &pod)
+ container := getIntegrationContainer(environment, pod)
if container == nil {
return fmt.Errorf("integration container not found in Pod %s/%s", pod.Namespace, pod.Name)
}
if probe := container.ReadinessProbe; probe != nil && probe.HTTPGet != nil {
- body, err := proxyGetHTTPProbe(ctx, action.client, probe, &pod, container)
+ body, err := proxyGetHTTPProbe(ctx, action.client, probe, pod, container)
if err == nil {
continue
}
[camel-k] 02/19: chore(ci): use the same go version in all jobs
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 66ded60b16e5120b22c2fb01f450351bebfa24f9
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Tue Nov 23 17:33:07 2021 +0100
chore(ci): use the same go version in all jobs
---
.github/workflows/validate.yml | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml
index ad54dc1..a4a27ef 100644
--- a/.github/workflows/validate.yml
+++ b/.github/workflows/validate.yml
@@ -37,10 +37,15 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v2
+ - name: Install Go
+ uses: actions/setup-go@v1
+ with:
+ go-version: 1.16.x
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
env:
GOGC: 20
with:
version: v1.43.0
+ skip-go-installation: true
args: --verbose --deadline 15m --config .golangci.yml
[camel-k] 08/19: fix(gosec): expect directory permissions to be 0750 or less (G301)
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit b44621d781057a3e5071b74d6e80f783af2f564a
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Mon Nov 22 15:25:47 2021 +0100
fix(gosec): expect directory permissions to be 0750 or less (G301)
---
pkg/builder/image.go | 2 +-
pkg/builder/project.go | 2 +-
pkg/util/util.go | 18 +++++++++---------
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/pkg/builder/image.go b/pkg/builder/image.go
index 35c7139..1eec4a7 100644
--- a/pkg/builder/image.go
+++ b/pkg/builder/image.go
@@ -161,7 +161,7 @@ func imageContext(ctx *builderContext, selector artifactsSelector) error {
contextDir := path.Join(ctx.Path, ContextDir)
- err = os.MkdirAll(contextDir, 0o777)
+ err = os.MkdirAll(contextDir, 0o700)
if err != nil {
return err
}
diff --git a/pkg/builder/project.go b/pkg/builder/project.go
index dbe8a07..609769d 100644
--- a/pkg/builder/project.go
+++ b/pkg/builder/project.go
@@ -65,7 +65,7 @@ func cleanUpBuildDir(ctx *builderContext) error {
return err
}
- return os.MkdirAll(ctx.Build.BuildDir, 0o777)
+ return os.MkdirAll(ctx.Build.BuildDir, 0o700)
}
func generateJavaKeystore(ctx *builderContext) error {
diff --git a/pkg/util/util.go b/pkg/util/util.go
index 4d10edc..903c9fb 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -224,7 +224,7 @@ func CopyFile(src, dst string) (int64, error) {
}
defer source.Close()
- err = os.MkdirAll(path.Dir(dst), 0o777)
+ err = os.MkdirAll(path.Dir(dst), 0o700)
if err != nil {
return 0, err
}
@@ -244,7 +244,7 @@ func WriteFileWithContent(buildDir string, relativePath string, content []byte)
filePath := path.Join(buildDir, relativePath)
fileDir := path.Dir(filePath)
// Create dir if not present
- err := os.MkdirAll(fileDir, 0o777)
+ err := os.MkdirAll(fileDir, 0o700)
if err != nil {
return errors.Wrap(err, "could not create dir for file "+relativePath)
}
@@ -343,7 +343,7 @@ func CreateDirectory(directory string) error {
}
if !directoryExists {
- err := os.MkdirAll(directory, 0o777)
+ err := os.MkdirAll(directory, 0o700)
if err != nil {
return err
}
@@ -487,7 +487,7 @@ func CreateLocalPropertiesDirectory() error {
}
if !directoryExists {
- err := os.MkdirAll(GetLocalPropertiesDir(), 0o777)
+ err := os.MkdirAll(GetLocalPropertiesDir(), 0o700)
if err != nil {
return err
}
@@ -507,7 +507,7 @@ func CreateLocalDependenciesDirectory() error {
}
if !directoryExists {
- err := os.MkdirAll(GetLocalDependenciesDir(), 0o777)
+ err := os.MkdirAll(GetLocalDependenciesDir(), 0o700)
if err != nil {
return err
}
@@ -527,7 +527,7 @@ func CreateLocalRoutesDirectory() error {
}
if !directoryExists {
- err := os.MkdirAll(GetLocalRoutesDir(), 0o777)
+ err := os.MkdirAll(GetLocalRoutesDir(), 0o700)
if err != nil {
return err
}
@@ -547,7 +547,7 @@ func CreateLocalQuarkusDirectory() error {
}
if !directoryExists {
- err := os.MkdirAll(GetLocalQuarkusDir(), 0o777)
+ err := os.MkdirAll(GetLocalQuarkusDir(), 0o700)
if err != nil {
return err
}
@@ -567,7 +567,7 @@ func CreateLocalAppDirectory() error {
}
if !directoryExists {
- err := os.MkdirAll(GetLocalAppDir(), 0o777)
+ err := os.MkdirAll(GetLocalAppDir(), 0o700)
if err != nil {
return err
}
@@ -587,7 +587,7 @@ func CreateLocalLibDirectory() error {
}
if !directoryExists {
- err := os.MkdirAll(GetLocalLibDir(), 0o777)
+ err := os.MkdirAll(GetLocalLibDir(), 0o700)
if err != nil {
return err
}
[camel-k] 17/19: fix(lint): tweak golangci-lint
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit c0d69139c5c5a1114e3f030c487397a892b3abfa
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Tue Nov 23 00:23:36 2021 +0100
fix(lint): tweak golangci-lint
---
.golangci.yml | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/.golangci.yml b/.golangci.yml
index 94f64cc..d9979d7 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -18,6 +18,8 @@
linters-settings:
lll:
line-length: 170
+ goconst:
+ ignore-tests: true
linters:
enable-all: true
disable:
@@ -35,6 +37,27 @@ linters:
- cyclop
- exhaustivestruct
- gochecknoglobals
+ - testpackage
+ - goerr113
+ - varnamelen
+ - tagliatelle
+ - paralleltest
+ - wrapcheck
+ - ireturn
+ - gofumpt
+ - gci
+ - wsl
+ - goconst
+ - tenv
+ - whitespace
+ - gocyclo
+ - nlreturn
+ - nilnil
+ - exhaustive
+ - noctx
+ - nakedret
+ - contextcheck
+ - maligned
issues:
exclude-rules:
[camel-k] 01/19: chore(ci): update golangci-lint to v1.43.0
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit a4ca4f8fad413188a07e2f9d327f4a50ef3109d1
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Mon Nov 22 13:50:21 2021 +0100
chore(ci): update golangci-lint to v1.43.0
---
.github/workflows/validate.yml | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml
index bf87a65..ad54dc1 100644
--- a/.github/workflows/validate.yml
+++ b/.github/workflows/validate.yml
@@ -37,17 +37,10 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v2
- - name: Cache modules
- uses: actions/cache@v1
- with:
- path: ~/go/pkg/mod
- key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
- restore-keys: |
- ${{ runner.os }}-go-
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
env:
GOGC: 20
with:
- version: v1.42
+ version: v1.43.0
args: --verbose --deadline 15m --config .golangci.yml
[camel-k] 11/19: fix(lint): remove unused function
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 2ad218fc2e7bcc29dfa44edf48faa7fcf29fa634
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Mon Nov 22 22:50:34 2021 +0100
fix(lint): remove unused function
---
cmd/util/doc-gen/generators/traitdocgen.go | 13 -------------
1 file changed, 13 deletions(-)
diff --git a/cmd/util/doc-gen/generators/traitdocgen.go b/cmd/util/doc-gen/generators/traitdocgen.go
index ad07dd3..9005bbc 100644
--- a/cmd/util/doc-gen/generators/traitdocgen.go
+++ b/cmd/util/doc-gen/generators/traitdocgen.go
@@ -270,19 +270,6 @@ func split(doc []string, startMarker, endMarker string) (pre []string, post []st
return pre, post
}
-func readFile(filename string) (file *os.File, content []string, err error) {
- if file, err = util.OpenFile(filename, os.O_RDWR|os.O_CREATE, 0o777); err != nil {
- return file, content, err
- }
-
- bytes, err := util.ReadFile(filename)
- if err != nil {
- return file, content, err
- }
- content = strings.Split(string(bytes), "\n")
- return file, content, nil
-}
-
func writeFile(file *os.File, content []string) error {
if err := file.Truncate(0); err != nil {
return err
[camel-k] 04/19: fix(gosec): Expect WriteFile permissions to be 0600 or less (G306)
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 14bb820850cd9cd8c8a0f7a8f21d5e9e169e7e27
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Mon Nov 22 12:26:19 2021 +0100
fix(gosec): Expect WriteFile permissions to be 0600 or less (G306)
---
cmd/util/json-schema-gen/main.go | 2 +-
cmd/util/vfs-gen/main.go | 2 +-
pkg/builder/image.go | 4 +--
pkg/cmd/builder/builder.go | 1 +
pkg/cmd/modeline_test.go | 72 +++++++++++++++++++--------------------
pkg/cmd/run_help_test.go | 4 +--
pkg/cmd/run_test.go | 4 +--
pkg/cmd/util_config.go | 4 +--
pkg/cmd/util_content_test.go | 8 ++---
pkg/cmd/util_dependencies.go | 2 +-
pkg/cmd/util_dependencies_test.go | 4 +--
pkg/trait/openapi.go | 2 +-
pkg/util/sync/file_test.go | 2 +-
pkg/util/util.go | 2 +-
14 files changed, 57 insertions(+), 56 deletions(-)
diff --git a/cmd/util/json-schema-gen/main.go b/cmd/util/json-schema-gen/main.go
index db48078..8d03510 100644
--- a/cmd/util/json-schema-gen/main.go
+++ b/cmd/util/json-schema-gen/main.go
@@ -97,7 +97,7 @@ func generate(crdFilename, dslFilename, path string, isArray bool, destination s
if err != nil {
return err
}
- return ioutil.WriteFile(destination, result, 0o666)
+ return ioutil.WriteFile(destination, result, 0o600)
}
func remapRef(ref string) string {
diff --git a/cmd/util/vfs-gen/main.go b/cmd/util/vfs-gen/main.go
index a3734f3..3a01401 100644
--- a/cmd/util/vfs-gen/main.go
+++ b/cmd/util/vfs-gen/main.go
@@ -146,7 +146,7 @@ limitations under the License.
var finalContent []byte
finalContent = append(finalContent, []byte(header)...)
finalContent = append(finalContent, content...)
- if err := ioutil.WriteFile(resourceFile, finalContent, 0o777); err != nil {
+ if err := ioutil.WriteFile(resourceFile, finalContent, 0o600); err != nil {
log.Fatalln(err)
}
}
diff --git a/pkg/builder/image.go b/pkg/builder/image.go
index 68ee0eb..35c7139 100644
--- a/pkg/builder/image.go
+++ b/pkg/builder/image.go
@@ -87,7 +87,7 @@ func executableDockerfile(ctx *builderContext) error {
USER nonroot
`)
- err := ioutil.WriteFile(path.Join(ctx.Path, ContextDir, "Dockerfile"), dockerfile, 0o777)
+ err := ioutil.WriteFile(path.Join(ctx.Path, ContextDir, "Dockerfile"), dockerfile, 0o400)
if err != nil {
return err
}
@@ -111,7 +111,7 @@ func jvmDockerfile(ctx *builderContext) error {
USER 1000
`)
- err := ioutil.WriteFile(path.Join(ctx.Path, ContextDir, "Dockerfile"), dockerfile, 0o777)
+ err := ioutil.WriteFile(path.Join(ctx.Path, ContextDir, "Dockerfile"), dockerfile, 0o400)
if err != nil {
return err
}
diff --git a/pkg/cmd/builder/builder.go b/pkg/cmd/builder/builder.go
index 5b23e2d..73447c4 100644
--- a/pkg/cmd/builder/builder.go
+++ b/pkg/cmd/builder/builder.go
@@ -107,6 +107,7 @@ func exitOnError(err error, msg string) {
}
func writeTerminationMessage(message string) {
+ // #nosec G306
err := ioutil.WriteFile(terminationMessagePath, []byte(message), 0o644)
if err != nil {
log.Error(err, "cannot write termination message")
diff --git a/pkg/cmd/modeline_test.go b/pkg/cmd/modeline_test.go
index cc18d29..966a737 100644
--- a/pkg/cmd/modeline_test.go
+++ b/pkg/cmd/modeline_test.go
@@ -37,7 +37,7 @@ func TestModelineRunSimple(t *testing.T) {
// camel-k: dependency=mvn:org.my:lib:1.0
`
fileName := path.Join(dir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
@@ -68,7 +68,7 @@ func TestModelineRunChain(t *testing.T) {
// camel-k: dependency=mvn:org.my:lib:2.0
`
fileName := path.Join(dir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", "-d", "mvn:org.my:lib2:1.0", fileName})
@@ -86,14 +86,14 @@ func TestModelineRunMultipleFiles(t *testing.T) {
// camel-k: dependency=mvn:org.my:lib1:3.0
`
fileName := path.Join(dir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
file2 := `
// camel-k: dependency=mvn:org.my:lib2:3.0
`
fileName2 := path.Join(dir, "ext.groovy")
- err = ioutil.WriteFile(fileName2, []byte(file2), 0o777)
+ err = ioutil.WriteFile(fileName2, []byte(file2), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName, fileName2})
@@ -108,14 +108,14 @@ func TestModelineRunProperty(t *testing.T) {
defer os.RemoveAll(dir)
subDir := path.Join(dir, "sub")
- err = os.Mkdir(subDir, 0o777)
+ err = os.Mkdir(subDir, 0o700)
assert.NoError(t, err)
file := `
// camel-k: property=my-prop=my-val
`
fileName := path.Join(subDir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
@@ -130,7 +130,7 @@ func TestModelineRunDuplicatedProperties(t *testing.T) {
defer os.RemoveAll(dir)
subDir := path.Join(dir, "sub")
- err = os.Mkdir(subDir, 0o777)
+ err = os.Mkdir(subDir, 0o700)
assert.NoError(t, err)
file := `
@@ -139,7 +139,7 @@ func TestModelineRunDuplicatedProperties(t *testing.T) {
// camel-k: property=foo=bar
`
fileName := path.Join(subDir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName, "-p", "prop1=true", "--property", "prop2=true"})
@@ -154,7 +154,7 @@ func TestModelineRunDuplicatedBuildProperties(t *testing.T) {
defer os.RemoveAll(dir)
subDir := path.Join(dir, "sub")
- err = os.Mkdir(subDir, 0o777)
+ err = os.Mkdir(subDir, 0o700)
assert.NoError(t, err)
file := `
@@ -163,7 +163,7 @@ func TestModelineRunDuplicatedBuildProperties(t *testing.T) {
// camel-k: build-property=foo=bar
`
fileName := path.Join(subDir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{
@@ -184,21 +184,21 @@ func TestModelineRunPropertyFiles(t *testing.T) {
defer os.RemoveAll(dir)
subDir := path.Join(dir, "sub")
- err = os.Mkdir(subDir, 0o777)
+ err = os.Mkdir(subDir, 0o700)
assert.NoError(t, err)
file := `
// camel-k: property=file:application.properties
`
fileName := path.Join(subDir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
propFile := `
a=b
`
propFileName := path.Join(subDir, "application.properties")
- err = ioutil.WriteFile(propFileName, []byte(propFile), 0o777)
+ err = ioutil.WriteFile(propFileName, []byte(propFile), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
@@ -213,14 +213,14 @@ func TestModelineRunBuildProperty(t *testing.T) {
defer os.RemoveAll(dir)
subDir := path.Join(dir, "sub")
- err = os.Mkdir(subDir, 0o777)
+ err = os.Mkdir(subDir, 0o700)
assert.NoError(t, err)
file := `
// camel-k: build-property=my-build-prop=my-val
`
fileName := path.Join(subDir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
@@ -235,21 +235,21 @@ func TestModelineRunBuildPropertyFiles(t *testing.T) {
defer os.RemoveAll(dir)
subDir := path.Join(dir, "sub")
- err = os.Mkdir(subDir, 0o777)
+ err = os.Mkdir(subDir, 0o700)
assert.NoError(t, err)
file := `
// camel-k: build-property=file:application.properties
`
fileName := path.Join(subDir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
propFile := `
a=b
`
propFileName := path.Join(subDir, "application.properties")
- err = ioutil.WriteFile(propFileName, []byte(propFile), 0o777)
+ err = ioutil.WriteFile(propFileName, []byte(propFile), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
@@ -264,7 +264,7 @@ func TestModelineRunDuplicateTraits(t *testing.T) {
defer os.RemoveAll(dir)
subDir := path.Join(dir, "sub")
- err = os.Mkdir(subDir, 0o777)
+ err = os.Mkdir(subDir, 0o700)
assert.NoError(t, err)
file := `
@@ -273,7 +273,7 @@ func TestModelineRunDuplicateTraits(t *testing.T) {
// camel-k: trait=foo=bar
`
fileName := path.Join(subDir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName, "-t", "trait1=true", "--trait", "trait2=true"})
@@ -288,14 +288,14 @@ func TestModelineRunConfigConfigmap(t *testing.T) {
defer os.RemoveAll(dir)
subDir := path.Join(dir, "sub")
- err = os.Mkdir(subDir, 0o777)
+ err = os.Mkdir(subDir, 0o700)
assert.NoError(t, err)
file := `
// camel-k: config=configmap:my-cm
`
fileName := path.Join(subDir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
@@ -310,14 +310,14 @@ func TestModelineRunConfigSecret(t *testing.T) {
defer os.RemoveAll(dir)
subDir := path.Join(dir, "sub")
- err = os.Mkdir(subDir, 0o777)
+ err = os.Mkdir(subDir, 0o700)
assert.NoError(t, err)
file := `
// camel-k: config=secret:my-secret
`
fileName := path.Join(subDir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
@@ -332,21 +332,21 @@ func TestModelineRunConfigFile(t *testing.T) {
defer os.RemoveAll(dir)
subDir := path.Join(dir, "sub")
- err = os.Mkdir(subDir, 0o777)
+ err = os.Mkdir(subDir, 0o700)
assert.NoError(t, err)
file := `
// camel-k: config=file:application.properties
`
fileName := path.Join(subDir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
propFile := `
a=b
`
propFileName := path.Join(subDir, "application.properties")
- err = ioutil.WriteFile(propFileName, []byte(propFile), 0o777)
+ err = ioutil.WriteFile(propFileName, []byte(propFile), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
@@ -361,14 +361,14 @@ func TestModelineRunResourceConfigmap(t *testing.T) {
defer os.RemoveAll(dir)
subDir := path.Join(dir, "sub")
- err = os.Mkdir(subDir, 0o777)
+ err = os.Mkdir(subDir, 0o700)
assert.NoError(t, err)
file := `
// camel-k: resource=configmap:my-cm
`
fileName := path.Join(subDir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
@@ -383,14 +383,14 @@ func TestModelineRunResourceSecret(t *testing.T) {
defer os.RemoveAll(dir)
subDir := path.Join(dir, "sub")
- err = os.Mkdir(subDir, 0o777)
+ err = os.Mkdir(subDir, 0o700)
assert.NoError(t, err)
file := `
// camel-k: resource=secret:my-secret
`
fileName := path.Join(subDir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
@@ -405,21 +405,21 @@ func TestModelineRunResourceFile(t *testing.T) {
defer os.RemoveAll(dir)
subDir := path.Join(dir, "sub")
- err = os.Mkdir(subDir, 0o777)
+ err = os.Mkdir(subDir, 0o700)
assert.NoError(t, err)
file := `
// camel-k: resource=file:application.properties
`
fileName := path.Join(subDir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
propFile := `
a=b
`
propFileName := path.Join(subDir, "application.properties")
- err = ioutil.WriteFile(propFileName, []byte(propFile), 0o777)
+ err = ioutil.WriteFile(propFileName, []byte(propFile), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
@@ -437,7 +437,7 @@ func TestModelineInspectSimple(t *testing.T) {
// camel-k: dependency=mvn:org.my:lib:1.0
`
fileName := path.Join(dir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "local", "inspect", fileName})
@@ -456,7 +456,7 @@ func TestModelineInspectMultipleDeps(t *testing.T) {
// camel-k: dependency=camel-k:camel-dep
`
fileName := path.Join(dir, "simple.groovy")
- err = ioutil.WriteFile(fileName, []byte(file), 0o777)
+ err = ioutil.WriteFile(fileName, []byte(file), 0o400)
assert.NoError(t, err)
cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "local", "inspect", fileName})
diff --git a/pkg/cmd/run_help_test.go b/pkg/cmd/run_help_test.go
index 11645ff..0763c06 100644
--- a/pkg/cmd/run_help_test.go
+++ b/pkg/cmd/run_help_test.go
@@ -199,7 +199,7 @@ func TestExtractProperties_FromFile(t *testing.T) {
key=value
#key2=value2
my.key=value
- `), 0o644))
+ `), 0o400))
props, err := extractProperties("file:" + tmpFile1.Name())
assert.Nil(t, err)
@@ -223,7 +223,7 @@ func TestExtractPropertiesFromFileAndSingleValue(t *testing.T) {
key=value
#key2=value2
my.key=value
- `), 0o644))
+ `), 0o400))
properties := []string{"key=override", "file:" + tmpFile1.Name(), "my.key = override"}
props, err := mergePropertiesWithPrecedence(properties)
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go
index 0aaec8e..67c0453 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/run_test.go
@@ -255,7 +255,7 @@ func TestAddPropertyFile(t *testing.T) {
}
assert.Nil(t, tmpFile.Close())
- assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(TestPropertyFileContent), 0o644))
+ assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(TestPropertyFileContent), 0o400))
properties, err := convertToTraitParameter("file:"+tmpFile.Name(), "trait.properties")
assert.Nil(t, err)
@@ -273,7 +273,7 @@ func TestRunPropertyFileFlag(t *testing.T) {
}
assert.Nil(t, tmpFile.Close())
- assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(TestPropertyFileContent), 0o644))
+ assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(TestPropertyFileContent), 0o400))
runCmdOptions, rootCmd, _ := initializeRunCmdOptions(t)
_, errExecute := test.ExecuteCommand(rootCmd, cmdRun,
diff --git a/pkg/cmd/util_config.go b/pkg/cmd/util_config.go
index 72a35c2..9c4239e 100644
--- a/pkg/cmd/util_config.go
+++ b/pkg/cmd/util_config.go
@@ -139,7 +139,7 @@ func (cfg *Config) Delete(path string) {
func (cfg *Config) Save() error {
root := filepath.Dir(cfg.location)
if _, err := os.Stat(root); os.IsNotExist(err) {
- if e := os.MkdirAll(root, 0o700); e != nil {
+ if e := os.MkdirAll(root, 0o600); e != nil {
return e
}
}
@@ -148,7 +148,7 @@ func (cfg *Config) Save() error {
if err != nil {
return err
}
- return ioutil.WriteFile(cfg.location, data, 0o644)
+ return ioutil.WriteFile(cfg.location, data, 0o600)
}
func (cfg *Config) navigate(values map[string]interface{}, prefix string, create bool) map[string]interface{} {
diff --git a/pkg/cmd/util_content_test.go b/pkg/cmd/util_content_test.go
index 155fa10..ae34b1d 100644
--- a/pkg/cmd/util_content_test.go
+++ b/pkg/cmd/util_content_test.go
@@ -37,7 +37,7 @@ func TestRawBinaryContentType(t *testing.T) {
t.Error(err)
}
assert.Nil(t, tmpFile.Close())
- assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte{1, 2, 3, 4, 5, 6}, 0o644))
+ assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte{1, 2, 3, 4, 5, 6}, 0o400))
data, contentType, err := loadRawContent(tmpFile.Name())
assert.Nil(t, err)
@@ -52,7 +52,7 @@ func TestRawApplicationContentType(t *testing.T) {
t.Error(err)
}
assert.Nil(t, tmpFile.Close())
- assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(`{"hello":"world"}`), 0o644))
+ assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(`{"hello":"world"}`), 0o400))
data, contentType, err := loadRawContent(tmpFile.Name())
assert.Nil(t, err)
@@ -67,7 +67,7 @@ func TestTextContentType(t *testing.T) {
t.Error(err)
}
assert.Nil(t, tmpFile.Close())
- assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(`{"hello":"world"}`), 0o644))
+ assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(`{"hello":"world"}`), 0o400))
data, contentType, compressed, err := loadTextContent(tmpFile.Name(), false)
assert.Nil(t, err)
@@ -83,7 +83,7 @@ func TestTextCompressed(t *testing.T) {
t.Error(err)
}
assert.Nil(t, tmpFile.Close())
- assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(`{"hello":"world"}`), 0o644))
+ assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(`{"hello":"world"}`), 0o400))
data, contentType, compressed, err := loadTextContent(tmpFile.Name(), true)
assert.Nil(t, err)
diff --git a/pkg/cmd/util_dependencies.go b/pkg/cmd/util_dependencies.go
index 2a54fc9..351091f 100644
--- a/pkg/cmd/util_dependencies.go
+++ b/pkg/cmd/util_dependencies.go
@@ -394,7 +394,7 @@ func updateIntegrationProperties(properties []string, propertyFiles []string, ha
// Output list of properties to property file if any CLI properties were given.
if len(properties) > 0 {
propertyFilePath := path.Join(util.GetLocalPropertiesDir(), "CLI.properties")
- err = ioutil.WriteFile(propertyFilePath, []byte(strings.Join(properties, "\n")), 0o777)
+ err = ioutil.WriteFile(propertyFilePath, []byte(strings.Join(properties, "\n")), 0o600)
if err != nil {
return nil, err
}
diff --git a/pkg/cmd/util_dependencies_test.go b/pkg/cmd/util_dependencies_test.go
index efa4335..2f44490 100644
--- a/pkg/cmd/util_dependencies_test.go
+++ b/pkg/cmd/util_dependencies_test.go
@@ -34,7 +34,7 @@ func TestValidatePropertyFiles_ShouldSucceed(t *testing.T) {
}
assert.Nil(t, tmpFile1.Close())
- assert.Nil(t, ioutil.WriteFile(tmpFile1.Name(), []byte("key=value"), 0o644))
+ assert.Nil(t, ioutil.WriteFile(tmpFile1.Name(), []byte("key=value"), 0o400))
inputValues := []string{tmpFile1.Name()}
err = validatePropertyFiles(inputValues)
@@ -50,7 +50,7 @@ func TestValidatePropertyFiles_ShouldFailNotAPropertiesFile(t *testing.T) {
}
assert.Nil(t, tmpFile1.Close())
- assert.Nil(t, ioutil.WriteFile(tmpFile1.Name(), []byte("key=value"), 0o644))
+ assert.Nil(t, ioutil.WriteFile(tmpFile1.Name(), []byte("key=value"), 0o400))
inputValues := []string{tmpFile1.Name()}
err = validatePropertyFiles(inputValues)
diff --git a/pkg/trait/openapi.go b/pkg/trait/openapi.go
index 36a43e9..1048f30 100644
--- a/pkg/trait/openapi.go
+++ b/pkg/trait/openapi.go
@@ -192,7 +192,7 @@ func (t *openAPITrait) createNewOpenAPIConfigMap(e *Environment, resource v1.Res
in := path.Join(tmpDir, resource.Name)
out := path.Join(tmpDir, "openapi-dsl.xml")
- err = ioutil.WriteFile(in, content, 0o644)
+ err = ioutil.WriteFile(in, content, 0o400)
if err != nil {
return err
}
diff --git a/pkg/util/sync/file_test.go b/pkg/util/sync/file_test.go
index 13cc81c..5c1e2b2 100644
--- a/pkg/util/sync/file_test.go
+++ b/pkg/util/sync/file_test.go
@@ -45,7 +45,7 @@ func TestFile(t *testing.T) {
time.Sleep(100 * time.Millisecond)
expectedNumChanges := 3
for i := 0; i < expectedNumChanges; i++ {
- if err := ioutil.WriteFile(fileName, []byte("data-"+strconv.Itoa(i)), 0o777); err != nil {
+ if err := ioutil.WriteFile(fileName, []byte("data-"+strconv.Itoa(i)), 0o600); err != nil {
t.Error(err)
}
time.Sleep(350 * time.Millisecond)
diff --git a/pkg/util/util.go b/pkg/util/util.go
index 97b93b3..274ef2d 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -434,7 +434,7 @@ func MapToYAML(src map[string]interface{}) ([]byte, error) {
}
func WriteToFile(filePath string, fileContents string) error {
- err := ioutil.WriteFile(filePath, []byte(fileContents), 0o777)
+ err := ioutil.WriteFile(filePath, []byte(fileContents), 0o400)
if err != nil {
return errors.Errorf("error writing file: %v", filePath)
}
[camel-k] 14/19: fix(lint): same name as predeclared identifier
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit d90c770a10e66daf6773583e8a8746176147d6b5
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Tue Nov 23 00:13:30 2021 +0100
fix(lint): same name as predeclared identifier
---
pkg/event/manager.go | 120 ++++++++++++++++++++--------------------
pkg/util/kubernetes/sanitize.go | 4 +-
pkg/util/maven/maven_log.go | 7 +--
3 files changed, 65 insertions(+), 66 deletions(-)
diff --git a/pkg/event/manager.go b/pkg/event/manager.go
index 19d1861..0f03c5b 100644
--- a/pkg/event/manager.go
+++ b/pkg/event/manager.go
@@ -82,10 +82,10 @@ const (
)
// NotifyIntegrationError automatically generates error events when the integration reconcile cycle phase has an error
-func NotifyIntegrationError(ctx context.Context, c client.Client, recorder record.EventRecorder, old, new *v1.Integration, err error) {
+func NotifyIntegrationError(ctx context.Context, c client.Client, recorder record.EventRecorder, old, newResource *v1.Integration, err error) {
it := old
- if new != nil {
- it = new
+ if newResource != nil {
+ it = newResource
}
if it == nil {
return
@@ -94,8 +94,8 @@ func NotifyIntegrationError(ctx context.Context, c client.Client, recorder recor
}
// NotifyIntegrationUpdated automatically generates events when the integration changes
-func NotifyIntegrationUpdated(ctx context.Context, c client.Client, recorder record.EventRecorder, old, new *v1.Integration) {
- if new == nil {
+func NotifyIntegrationUpdated(ctx context.Context, c client.Client, recorder record.EventRecorder, old, newResource *v1.Integration) {
+ if newResource == nil {
return
}
oldPhase := ""
@@ -104,15 +104,15 @@ func NotifyIntegrationUpdated(ctx context.Context, c client.Client, recorder rec
oldPhase = string(old.Status.Phase)
oldConditions = old.Status.GetConditions()
}
- if new.Status.Phase != v1.IntegrationPhaseNone {
- notifyIfConditionUpdated(recorder, new, oldConditions, new.Status.GetConditions(), "Integration", new.Name, ReasonIntegrationConditionChanged)
+ if newResource.Status.Phase != v1.IntegrationPhaseNone {
+ notifyIfConditionUpdated(recorder, newResource, oldConditions, newResource.Status.GetConditions(), "Integration", newResource.Name, ReasonIntegrationConditionChanged)
}
- notifyIfPhaseUpdated(ctx, c, recorder, new, oldPhase, string(new.Status.Phase), "Integration", new.Name, ReasonIntegrationPhaseUpdated, "")
+ notifyIfPhaseUpdated(ctx, c, recorder, newResource, oldPhase, string(newResource.Status.Phase), "Integration", newResource.Name, ReasonIntegrationPhaseUpdated, "")
}
// NotifyIntegrationKitUpdated automatically generates events when an integration kit changes
-func NotifyIntegrationKitUpdated(ctx context.Context, c client.Client, recorder record.EventRecorder, old, new *v1.IntegrationKit) {
- if new == nil {
+func NotifyIntegrationKitUpdated(ctx context.Context, c client.Client, recorder record.EventRecorder, old, newResource *v1.IntegrationKit) {
+ if newResource == nil {
return
}
oldPhase := ""
@@ -121,17 +121,17 @@ func NotifyIntegrationKitUpdated(ctx context.Context, c client.Client, recorder
oldPhase = string(old.Status.Phase)
oldConditions = old.Status.GetConditions()
}
- if new.Status.Phase != v1.IntegrationKitPhaseNone {
- notifyIfConditionUpdated(recorder, new, oldConditions, new.Status.GetConditions(), "Integration Kit", new.Name, ReasonIntegrationKitConditionChanged)
+ if newResource.Status.Phase != v1.IntegrationKitPhaseNone {
+ notifyIfConditionUpdated(recorder, newResource, oldConditions, newResource.Status.GetConditions(), "Integration Kit", newResource.Name, ReasonIntegrationKitConditionChanged)
}
- notifyIfPhaseUpdated(ctx, c, recorder, new, oldPhase, string(new.Status.Phase), "Integration Kit", new.Name, ReasonIntegrationKitPhaseUpdated, "")
+ notifyIfPhaseUpdated(ctx, c, recorder, newResource, oldPhase, string(newResource.Status.Phase), "Integration Kit", newResource.Name, ReasonIntegrationKitPhaseUpdated, "")
}
// NotifyIntegrationKitError automatically generates error events when the integration kit reconcile cycle phase has an error
-func NotifyIntegrationKitError(ctx context.Context, c client.Client, recorder record.EventRecorder, old, new *v1.IntegrationKit, err error) {
+func NotifyIntegrationKitError(ctx context.Context, c client.Client, recorder record.EventRecorder, old, newResource *v1.IntegrationKit, err error) {
kit := old
- if new != nil {
- kit = new
+ if newResource != nil {
+ kit = newResource
}
if kit == nil {
return
@@ -140,8 +140,8 @@ func NotifyIntegrationKitError(ctx context.Context, c client.Client, recorder re
}
// NotifyIntegrationPlatformUpdated automatically generates events when an integration platform changes
-func NotifyIntegrationPlatformUpdated(ctx context.Context, c client.Client, recorder record.EventRecorder, old, new *v1.IntegrationPlatform) {
- if new == nil {
+func NotifyIntegrationPlatformUpdated(ctx context.Context, c client.Client, recorder record.EventRecorder, old, newResource *v1.IntegrationPlatform) {
+ if newResource == nil {
return
}
oldPhase := ""
@@ -150,17 +150,17 @@ func NotifyIntegrationPlatformUpdated(ctx context.Context, c client.Client, reco
oldPhase = string(old.Status.Phase)
oldConditions = old.Status.GetConditions()
}
- if new.Status.Phase != v1.IntegrationPlatformPhaseNone {
- notifyIfConditionUpdated(recorder, new, oldConditions, new.Status.GetConditions(), "Integration Platform", new.Name, ReasonIntegrationPlatformConditionChanged)
+ if newResource.Status.Phase != v1.IntegrationPlatformPhaseNone {
+ notifyIfConditionUpdated(recorder, newResource, oldConditions, newResource.Status.GetConditions(), "Integration Platform", newResource.Name, ReasonIntegrationPlatformConditionChanged)
}
- notifyIfPhaseUpdated(ctx, c, recorder, new, oldPhase, string(new.Status.Phase), "Integration Platform", new.Name, ReasonIntegrationPlatformPhaseUpdated, "")
+ notifyIfPhaseUpdated(ctx, c, recorder, newResource, oldPhase, string(newResource.Status.Phase), "Integration Platform", newResource.Name, ReasonIntegrationPlatformPhaseUpdated, "")
}
// NotifyIntegrationPlatformError automatically generates error events when the integration Platform reconcile cycle phase has an error
-func NotifyIntegrationPlatformError(ctx context.Context, c client.Client, recorder record.EventRecorder, old, new *v1.IntegrationPlatform, err error) {
+func NotifyIntegrationPlatformError(ctx context.Context, c client.Client, recorder record.EventRecorder, old, newResource *v1.IntegrationPlatform, err error) {
p := old
- if new != nil {
- p = new
+ if newResource != nil {
+ p = newResource
}
if p == nil {
return
@@ -169,8 +169,8 @@ func NotifyIntegrationPlatformError(ctx context.Context, c client.Client, record
}
// NotifyKameletUpdated automatically generates events when a Kamelet changes
-func NotifyKameletUpdated(ctx context.Context, c client.Client, recorder record.EventRecorder, old, new *v1alpha1.Kamelet) {
- if new == nil {
+func NotifyKameletUpdated(ctx context.Context, c client.Client, recorder record.EventRecorder, old, newResource *v1alpha1.Kamelet) {
+ if newResource == nil {
return
}
oldPhase := ""
@@ -179,17 +179,17 @@ func NotifyKameletUpdated(ctx context.Context, c client.Client, recorder record.
oldPhase = string(old.Status.Phase)
oldConditions = old.Status.GetConditions()
}
- if new.Status.Phase != v1alpha1.KameletPhaseNone {
- notifyIfConditionUpdated(recorder, new, oldConditions, new.Status.GetConditions(), "Kamelet", new.Name, ReasonKameletConditionChanged)
+ if newResource.Status.Phase != v1alpha1.KameletPhaseNone {
+ notifyIfConditionUpdated(recorder, newResource, oldConditions, newResource.Status.GetConditions(), "Kamelet", newResource.Name, ReasonKameletConditionChanged)
}
- notifyIfPhaseUpdated(ctx, c, recorder, new, oldPhase, string(new.Status.Phase), "Kamelet", new.Name, ReasonKameletPhaseUpdated, "")
+ notifyIfPhaseUpdated(ctx, c, recorder, newResource, oldPhase, string(newResource.Status.Phase), "Kamelet", newResource.Name, ReasonKameletPhaseUpdated, "")
}
// NotifyKameletError automatically generates error events when the kamelet reconcile cycle phase has an error
-func NotifyKameletError(ctx context.Context, c client.Client, recorder record.EventRecorder, old, new *v1alpha1.Kamelet, err error) {
+func NotifyKameletError(ctx context.Context, c client.Client, recorder record.EventRecorder, old, newResource *v1alpha1.Kamelet, err error) {
k := old
- if new != nil {
- k = new
+ if newResource != nil {
+ k = newResource
}
if k == nil {
return
@@ -198,8 +198,8 @@ func NotifyKameletError(ctx context.Context, c client.Client, recorder record.Ev
}
// NotifyKameletBindingUpdated automatically generates events when a KameletBinding changes
-func NotifyKameletBindingUpdated(ctx context.Context, c client.Client, recorder record.EventRecorder, old, new *v1alpha1.KameletBinding) {
- if new == nil {
+func NotifyKameletBindingUpdated(ctx context.Context, c client.Client, recorder record.EventRecorder, old, newResource *v1alpha1.KameletBinding) {
+ if newResource == nil {
return
}
oldPhase := ""
@@ -208,17 +208,17 @@ func NotifyKameletBindingUpdated(ctx context.Context, c client.Client, recorder
oldPhase = string(old.Status.Phase)
oldConditions = old.Status.GetConditions()
}
- if new.Status.Phase != v1alpha1.KameletBindingPhaseNone {
- notifyIfConditionUpdated(recorder, new, oldConditions, new.Status.GetConditions(), "KameletBinding", new.Name, ReasonKameletBindingConditionChanged)
+ if newResource.Status.Phase != v1alpha1.KameletBindingPhaseNone {
+ notifyIfConditionUpdated(recorder, newResource, oldConditions, newResource.Status.GetConditions(), "KameletBinding", newResource.Name, ReasonKameletBindingConditionChanged)
}
- notifyIfPhaseUpdated(ctx, c, recorder, new, oldPhase, string(new.Status.Phase), "KameletBinding", new.Name, ReasonKameletBindingPhaseUpdated, "")
+ notifyIfPhaseUpdated(ctx, c, recorder, newResource, oldPhase, string(newResource.Status.Phase), "KameletBinding", newResource.Name, ReasonKameletBindingPhaseUpdated, "")
}
// NotifyKameletBindingError automatically generates error events when the kameletBinding reconcile cycle phase has an error
-func NotifyKameletBindingError(ctx context.Context, c client.Client, recorder record.EventRecorder, old, new *v1alpha1.KameletBinding, err error) {
+func NotifyKameletBindingError(ctx context.Context, c client.Client, recorder record.EventRecorder, old, newResource *v1alpha1.KameletBinding, err error) {
k := old
- if new != nil {
- k = new
+ if newResource != nil {
+ k = newResource
}
if k == nil {
return
@@ -227,8 +227,8 @@ func NotifyKameletBindingError(ctx context.Context, c client.Client, recorder re
}
// NotifyBuildUpdated automatically generates events when a build changes
-func NotifyBuildUpdated(ctx context.Context, c client.Client, recorder record.EventRecorder, old, new *v1.Build) {
- if new == nil {
+func NotifyBuildUpdated(ctx context.Context, c client.Client, recorder record.EventRecorder, old, newResource *v1.Build) {
+ if newResource == nil {
return
}
oldPhase := ""
@@ -237,23 +237,23 @@ func NotifyBuildUpdated(ctx context.Context, c client.Client, recorder record.Ev
oldPhase = string(old.Status.Phase)
oldConditions = old.Status.GetConditions()
}
- if new.Status.Phase != v1.BuildPhaseNone {
- notifyIfConditionUpdated(recorder, new, oldConditions, new.Status.GetConditions(), "Build", new.Name, ReasonBuildConditionChanged)
+ if newResource.Status.Phase != v1.BuildPhaseNone {
+ notifyIfConditionUpdated(recorder, newResource, oldConditions, newResource.Status.GetConditions(), "Build", newResource.Name, ReasonBuildConditionChanged)
}
info := ""
- if new.Status.Failure != nil {
- attempt := new.Status.Failure.Recovery.Attempt
- attemptMax := new.Status.Failure.Recovery.AttemptMax
+ if newResource.Status.Failure != nil {
+ attempt := newResource.Status.Failure.Recovery.Attempt
+ attemptMax := newResource.Status.Failure.Recovery.AttemptMax
info = fmt.Sprintf(" (recovery %d of %d)", attempt, attemptMax)
}
- notifyIfPhaseUpdated(ctx, c, recorder, new, oldPhase, string(new.Status.Phase), "Build", new.Name, ReasonBuildPhaseUpdated, info)
+ notifyIfPhaseUpdated(ctx, c, recorder, newResource, oldPhase, string(newResource.Status.Phase), "Build", newResource.Name, ReasonBuildPhaseUpdated, info)
}
// NotifyBuildError automatically generates error events when the build reconcile cycle phase has an error
-func NotifyBuildError(ctx context.Context, c client.Client, recorder record.EventRecorder, old, new *v1.Build, err error) {
+func NotifyBuildError(ctx context.Context, c client.Client, recorder record.EventRecorder, old, newResource *v1.Build, err error) {
p := old
- if new != nil {
- p = new
+ if newResource != nil {
+ p = newResource
}
if p == nil {
return
@@ -262,7 +262,7 @@ func NotifyBuildError(ctx context.Context, c client.Client, recorder record.Even
}
// nolint:lll
-func notifyIfPhaseUpdated(ctx context.Context, c client.Client, recorder record.EventRecorder, new ctrl.Object, oldPhase, newPhase string, resourceType, name, reason, info string) {
+func notifyIfPhaseUpdated(ctx context.Context, c client.Client, recorder record.EventRecorder, newResource ctrl.Object, oldPhase, newPhase string, resourceType, name, reason, info string) {
if oldPhase == newPhase {
return
}
@@ -272,10 +272,10 @@ func notifyIfPhaseUpdated(ctx context.Context, c client.Client, recorder record.
if phase == "" {
phase = "[none]"
}
- recorder.Eventf(new, corev1.EventTypeNormal, reason, "%s %q in phase %q%s", resourceType, name, phase, info)
+ recorder.Eventf(newResource, corev1.EventTypeNormal, reason, "%s %q in phase %q%s", resourceType, name, phase, info)
- if creatorRef, creator := getCreatorObject(ctx, c, new); creatorRef != nil && creator != nil {
- if namespace := new.GetNamespace(); namespace == creatorRef.Namespace {
+ if creatorRef, creator := getCreatorObject(ctx, c, newResource); creatorRef != nil && creator != nil {
+ if namespace := newResource.GetNamespace(); namespace == creatorRef.Namespace {
recorder.Eventf(creator, corev1.EventTypeNormal, ReasonRelatedObjectChanged, "%s %q, created by %s %q, changed phase to %q%s", resourceType, name, creatorRef.Kind, creatorRef.Name, phase, info)
} else {
recorder.Eventf(creator, corev1.EventTypeNormal, ReasonRelatedObjectChanged, "%s \"%s/%s\", created by %s %q, changed phase to %q%s", resourceType, namespace, name, creatorRef.Kind, creatorRef.Name, phase, info)
@@ -283,24 +283,24 @@ func notifyIfPhaseUpdated(ctx context.Context, c client.Client, recorder record.
}
}
-func notifyIfConditionUpdated(recorder record.EventRecorder, new runtime.Object, oldConditions, newConditions []v1.ResourceCondition, resourceType, name, reason string) {
+func notifyIfConditionUpdated(recorder record.EventRecorder, newResource runtime.Object, oldConditions, newConditions []v1.ResourceCondition, resourceType, name, reason string) {
// Update information about changes in conditions
for _, cond := range getCommonChangedConditions(oldConditions, newConditions) {
tail := ""
if cond.GetMessage() != "" {
tail = fmt.Sprintf(": %s", cond.GetMessage())
}
- recorder.Eventf(new, corev1.EventTypeNormal, reason, "Condition %q is %q for %s %s%s", cond.GetType(), cond.GetStatus(), resourceType, name, tail)
+ recorder.Eventf(newResource, corev1.EventTypeNormal, reason, "Condition %q is %q for %s %s%s", cond.GetType(), cond.GetStatus(), resourceType, name, tail)
}
}
-func getCommonChangedConditions(old, new []v1.ResourceCondition) (res []v1.ResourceCondition) {
+func getCommonChangedConditions(oldConditions, newConditions []v1.ResourceCondition) (res []v1.ResourceCondition) {
oldState := make(map[string]v1.ResourceCondition)
- for _, c := range old {
+ for _, c := range oldConditions {
oldState[c.GetType()] = c
}
- for _, newCond := range new {
+ for _, newCond := range newConditions {
oldCond := oldState[newCond.GetType()]
if oldCond == nil || oldCond.GetStatus() != newCond.GetStatus() || oldCond.GetMessage() != newCond.GetMessage() {
res = append(res, newCond)
diff --git a/pkg/util/kubernetes/sanitize.go b/pkg/util/kubernetes/sanitize.go
index c7f5fed..7e35f57 100644
--- a/pkg/util/kubernetes/sanitize.go
+++ b/pkg/util/kubernetes/sanitize.go
@@ -47,6 +47,6 @@ func SanitizeLabel(name string) string {
return name
}
-func isDisallowedStartEndChar(rune rune) bool {
- return !unicode.IsLetter(rune) && !unicode.IsNumber(rune)
+func isDisallowedStartEndChar(r rune) bool {
+ return !unicode.IsLetter(r) && !unicode.IsNumber(r)
}
diff --git a/pkg/util/maven/maven_log.go b/pkg/util/maven/maven_log.go
index 2d5fc72..c7f6b6b 100644
--- a/pkg/util/maven/maven_log.go
+++ b/pkg/util/maven/maven_log.go
@@ -47,10 +47,9 @@ const (
var mavenLogger = log.WithName("maven.build")
-func parseLog(line string) (mavenLog mavenLog, error error) {
- error = json.Unmarshal([]byte(line), &mavenLog)
-
- return mavenLog, error
+func parseLog(line string) (l mavenLog, err error) {
+ err = json.Unmarshal([]byte(line), &l)
+ return
}
func normalizeLog(mavenLog mavenLog) {
[camel-k] 12/19: fix(lint): use interface when possible
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 11e3f6439a38dde1c6c77ab46c210249e78712d0
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Mon Nov 22 23:31:26 2021 +0100
fix(lint): use interface when possible
---
pkg/builder/spectrum.go | 3 ++-
pkg/cmd/bind.go | 2 +-
pkg/cmd/debug.go | 2 +-
pkg/cmd/util_content.go | 2 +-
pkg/resources/resources.go | 4 ++--
pkg/util/olm/operator.go | 4 +++-
6 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/pkg/builder/spectrum.go b/pkg/builder/spectrum.go
index bb5bfb1..9202e70 100644
--- a/pkg/builder/spectrum.go
+++ b/pkg/builder/spectrum.go
@@ -21,6 +21,7 @@ import (
"bufio"
"context"
"go.uber.org/multierr"
+ "io"
"io/ioutil"
"os"
"path"
@@ -138,7 +139,7 @@ func (t *spectrumTask) Do(ctx context.Context) v1.BuildStatus {
return status
}
-func readSpectrumLogs(newStdOut *os.File) {
+func readSpectrumLogs(newStdOut io.Reader) {
scanner := bufio.NewScanner(newStdOut)
for scanner.Scan() {
diff --git a/pkg/cmd/bind.go b/pkg/cmd/bind.go
index 0a1b36e..355f00d 100644
--- a/pkg/cmd/bind.go
+++ b/pkg/cmd/bind.go
@@ -220,7 +220,7 @@ func (o *bindCmdOptions) run(cmd *cobra.Command, args []string) error {
return nil
}
-func showOutput(cmd *cobra.Command, binding *v1alpha1.KameletBinding, outputFormat string, scheme *runtime.Scheme) error {
+func showOutput(cmd *cobra.Command, binding *v1alpha1.KameletBinding, outputFormat string, scheme runtime.ObjectTyper) error {
printer := printers.NewTypeSetter(scheme)
printer.Delegate = &kubernetes.CLIPrinter{
Format: outputFormat,
diff --git a/pkg/cmd/debug.go b/pkg/cmd/debug.go
index fd3c3a7..e0702c4 100644
--- a/pkg/cmd/debug.go
+++ b/pkg/cmd/debug.go
@@ -132,7 +132,7 @@ func (o *debugCmdOptions) run(cmd *cobra.Command, args []string) error {
}
// nolint: unparam
-func (o *debugCmdOptions) toggleDebug(c *camelv1.CamelV1Client, it *v1.Integration, active bool) (*v1.Integration, error) {
+func (o *debugCmdOptions) toggleDebug(c camelv1.IntegrationsGetter, it *v1.Integration, active bool) (*v1.Integration, error) {
if it.Spec.Traits == nil {
it.Spec.Traits = make(map[string]v1.TraitSpec)
}
diff --git a/pkg/cmd/util_content.go b/pkg/cmd/util_content.go
index 9611ae1..0d73610 100644
--- a/pkg/cmd/util_content.go
+++ b/pkg/cmd/util_content.go
@@ -99,7 +99,7 @@ func loadTextContent(source string, base64Compression bool) (string, string, boo
return string(content), contentType, false, nil
}
-func loadContentHTTP(u *url.URL) ([]byte, error) {
+func loadContentHTTP(u fmt.Stringer) ([]byte, error) {
resp, err := http.Get(u.String())
if err != nil {
return []byte{}, err
diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go
index f486ed7..c285994 100644
--- a/pkg/resources/resources.go
+++ b/pkg/resources/resources.go
@@ -138,9 +138,9 @@ var assets = func() http.FileSystem {
"/crd/bases/camel.apache.org_integrationplatforms.yaml": &vfsgen۰CompressedFileInfo{
name: "camel.apache.org_integrationplatforms.yaml",
modTime: time.Time{},
- uncompressedSize: 25962,
+ uncompressedSize: 26080,
- compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x5c\xdf\x93\xe2\xb8\xf1\x7f\xe7\xaf\xe8\x5a\x1e\xf6\xae\x6a\x30\x77\xdf\x6f\x52\x49\xc8\x43\x8a\x63\x77\x2b\x64\x76\x67\xa8\x81\xbd\xcb\x3d\x0a\xbb\x01\x1d\xb2\xe4\x48\xf2\xb0\x5c\x2a\xff\x7b\xaa\x25\x1b\xec\xc1\xbf\x98\x99\xab\x24\x77\xd6\xcb\xee\x60\xa9\xd5\xdd\xea\x9f\xf2\x07\x86\x30\x7a\xbd\x31\x18\xc2\x47\x1e\xa2\x34\x18\x81\x55\x60\x77\x08\xd3\x84\x85\x3b\x84\xa5\xda\xd8\x03\xd3\x08\x1f\x54\x2a\x23\x66\xb9\x [...]
+ compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x3c\x4b\x93\xe3\xb6\xd1\x77\xfd\x8a\xae\xd5\x61\xed\xaa\x11\x65\x7f\x8f\x4a\xa2\x1c\x52\xb2\x76\xb7\xa2\xec\xee\xcc\xd4\x4a\x6b\xc7\x47\x88\x6c\x49\xb0\x48\x80\x01\xc0\xd1\xca\xa9\xfc\xf7\x54\x37\x48\x89\x1a\xf1\xa5\x99\x71\x25\xb6\x89\xcb\x8c\x44\xa0\xd1\xef\x07\xd0\xe2\x10\x46\x2f\x37\x06\x43\xf8\x20\x43\x54\x16\x23\x70\x1a\xdc\x16\x61\x9a\x8a\x70\x8b\xb0\xd0\x6b\xb7\x17\x06\xe1\x9d\xce\x54\x24\x9c\xd4\x0a\xbe\x [...]
},
"/crd/bases/camel.apache.org_integrations.yaml": &vfsgen۰CompressedFileInfo{
name: "camel.apache.org_integrations.yaml",
diff --git a/pkg/util/olm/operator.go b/pkg/util/olm/operator.go
index 23ca3fd..9028dc6 100644
--- a/pkg/util/olm/operator.go
+++ b/pkg/util/olm/operator.go
@@ -27,6 +27,8 @@ import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubectl/pkg/cmd/set/env"
+ k8sclient "k8s.io/client-go/kubernetes"
+
runtime "sigs.k8s.io/controller-runtime/pkg/client"
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
@@ -344,7 +346,7 @@ func findOperatorGroup(ctx context.Context, client client.Client, namespace stri
return nil, nil
}
-func fillDefaults(o Options, client client.Client) (Options, error) {
+func fillDefaults(o Options, client k8sclient.Interface) (Options, error) {
if o.OperatorName == "" {
o.OperatorName = DefaultOperatorName
}
[camel-k] 10/19: fix(gosec): errrs unhandled (G104)
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 32b8c6998c24f4bb0ce03c50e2eb00fb9a6d5361
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Mon Nov 22 22:19:45 2021 +0100
fix(gosec): errrs unhandled (G104)
---
cmd/util/license-check/main.go | 3 +++
pkg/builder/s2i.go | 4 +---
pkg/builder/spectrum.go | 9 +++++++--
pkg/client/client.go | 5 ++++-
pkg/cmd/get.go | 3 +--
pkg/cmd/kamelet_get.go | 3 +--
pkg/cmd/kit_get.go | 3 +--
pkg/util/kubernetes/log/annotation_scraper.go | 11 ++++++++---
pkg/util/kubernetes/log/pod_scraper.go | 12 +++++++++---
9 files changed, 35 insertions(+), 18 deletions(-)
diff --git a/cmd/util/license-check/main.go b/cmd/util/license-check/main.go
index ae94655..3b8f37a 100644
--- a/cmd/util/license-check/main.go
+++ b/cmd/util/license-check/main.go
@@ -35,6 +35,7 @@ func main() {
fileBin, err := util.ReadFile(fileName)
if err != nil {
+ // #nosec G104
os.Stderr.WriteString(fmt.Sprintf("cannot read file %s: %v\n", fileName, err))
os.Exit(1)
}
@@ -42,12 +43,14 @@ func main() {
licenseBin, err := util.ReadFile(licenseName)
if err != nil {
+ // #nosec G104
os.Stderr.WriteString(fmt.Sprintf("cannot read file %s: %v\n", licenseName, err))
os.Exit(1)
}
license := string(licenseBin)
if !strings.Contains(file, license) {
+ // #nosec G104
os.Stderr.WriteString(fmt.Sprintf("file %s does not contain license\n", fileName))
os.Exit(1)
}
diff --git a/pkg/builder/s2i.go b/pkg/builder/s2i.go
index 42669a7..d6e23a1 100644
--- a/pkg/builder/s2i.go
+++ b/pkg/builder/s2i.go
@@ -333,8 +333,6 @@ func tarDir(src string, writers ...io.Writer) error {
// manually close here after each file operation; deferring would cause each file close
// to wait until all operations have completed.
- f.Close()
-
- return nil
+ return f.Close()
})
}
diff --git a/pkg/builder/spectrum.go b/pkg/builder/spectrum.go
index 06f0ead..bb5bfb1 100644
--- a/pkg/builder/spectrum.go
+++ b/pkg/builder/spectrum.go
@@ -20,6 +20,7 @@ package builder
import (
"bufio"
"context"
+ "go.uber.org/multierr"
"io/ioutil"
"os"
"path"
@@ -154,13 +155,17 @@ func mountSecret(ctx context.Context, c client.Client, namespace, name string) (
secret, err := c.CoreV1().Secrets(namespace).Get(ctx, name, metav1.GetOptions{})
if err != nil {
- os.RemoveAll(dir)
+ if removeErr := os.RemoveAll(dir); removeErr != nil {
+ err = multierr.Append(err, removeErr)
+ }
return "", err
}
for file, content := range secret.Data {
if err := ioutil.WriteFile(filepath.Join(dir, remap(file)), content, 0o600); err != nil {
- os.RemoveAll(dir)
+ if removeErr := os.RemoveAll(dir); removeErr != nil {
+ err = multierr.Append(err, removeErr)
+ }
return "", err
}
}
diff --git a/pkg/client/client.go b/pkg/client/client.go
index f806266..83c9fc0 100644
--- a/pkg/client/client.go
+++ b/pkg/client/client.go
@@ -198,7 +198,10 @@ func initialize(kubeconfig string) {
panic(err)
}
}
- os.Setenv(kubeConfigEnvVar, kubeconfig)
+
+ if err := os.Setenv(kubeConfigEnvVar, kubeconfig); err != nil {
+ panic(err)
+ }
}
func getDefaultKubeConfigFile() (string, error) {
diff --git a/pkg/cmd/get.go b/pkg/cmd/get.go
index 8d963ed..7898ba8 100644
--- a/pkg/cmd/get.go
+++ b/pkg/cmd/get.go
@@ -88,7 +88,6 @@ func (o *getCmdOptions) run(cmd *cobra.Command, args []string) error {
}
fmt.Fprintf(w, "%s\t%s\t%s\n", integration.Name, string(integration.Status.Phase), kit)
}
- w.Flush()
- return nil
+ return w.Flush()
}
diff --git a/pkg/cmd/kamelet_get.go b/pkg/cmd/kamelet_get.go
index d082341..5fb19f0 100644
--- a/pkg/cmd/kamelet_get.go
+++ b/pkg/cmd/kamelet_get.go
@@ -133,7 +133,6 @@ func (command *kameletGetCommandOptions) run(cmd *cobra.Command) error {
readOnly,
kl.Spec.Definition.Title)
}
- w.Flush()
- return nil
+ return w.Flush()
}
diff --git a/pkg/cmd/kit_get.go b/pkg/cmd/kit_get.go
index b3063cf..ac67882 100644
--- a/pkg/cmd/kit_get.go
+++ b/pkg/cmd/kit_get.go
@@ -90,7 +90,6 @@ func (command *kitGetCommandOptions) run(cmd *cobra.Command) error {
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", ctx.Name, string(ctx.Status.Phase), t, ctx.Status.Image)
}
}
- w.Flush()
- return nil
+ return w.Flush()
}
diff --git a/pkg/util/kubernetes/log/annotation_scraper.go b/pkg/util/kubernetes/log/annotation_scraper.go
index 08dfebf..ff6f166 100644
--- a/pkg/util/kubernetes/log/annotation_scraper.go
+++ b/pkg/util/kubernetes/log/annotation_scraper.go
@@ -20,6 +20,7 @@ package log
import (
"bufio"
"context"
+ "go.uber.org/multierr"
"io"
"strconv"
"sync"
@@ -61,8 +62,9 @@ func (s *SelectorScraper) Start(ctx context.Context) *bufio.Reader {
bufPipeIn := bufio.NewReader(pipeIn)
bufPipeOut := bufio.NewWriter(pipeOut)
closeFun := func() error {
- bufPipeOut.Flush()
- return pipeOut.Close()
+ return multierr.Append(
+ bufPipeOut.Flush(),
+ pipeOut.Close())
}
go s.periodicSynchronize(ctx, bufPipeOut, closeFun)
return bufPipeIn
@@ -152,7 +154,10 @@ func (s *SelectorScraper) addPodScraper(ctx context.Context, podName string, out
s.L.Error(err, "Cannot write to output")
return
}
- out.Flush()
+ if err := out.Flush(); err != nil {
+ s.L.Error(err, "Cannot flush output")
+ return
+ }
if podCtx.Err() != nil {
return
}
diff --git a/pkg/util/kubernetes/log/pod_scraper.go b/pkg/util/kubernetes/log/pod_scraper.go
index 19164a9..2e55c67 100644
--- a/pkg/util/kubernetes/log/pod_scraper.go
+++ b/pkg/util/kubernetes/log/pod_scraper.go
@@ -20,6 +20,7 @@ package log
import (
"bufio"
"context"
+ "go.uber.org/multierr"
"io"
"time"
@@ -65,8 +66,9 @@ func (s *PodScraper) Start(ctx context.Context) *bufio.Reader {
bufPipeIn := bufio.NewReader(pipeIn)
bufPipeOut := bufio.NewWriter(pipeOut)
closeFun := func() error {
- bufPipeOut.Flush()
- return pipeOut.Close()
+ return multierr.Append(
+ bufPipeOut.Flush(),
+ pipeOut.Close())
}
go s.doScrape(ctx, bufPipeOut, closeFun)
return bufPipeIn
@@ -101,7 +103,11 @@ func (s *PodScraper) doScrape(ctx context.Context, out *bufio.Writer, clientClos
if err != nil {
break
}
- out.Flush()
+
+ err = out.Flush()
+ if err != nil {
+ break
+ }
}
s.handleAndRestart(ctx, err, 5*time.Second, out, clientCloser)
[camel-k] 18/19: fix(gosec): expect directory permissions to be 0750 or less (G301)
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit d537ccf09e6413d4433a71349cf1090ab5343195
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Tue Nov 23 10:56:35 2021 +0100
fix(gosec): expect directory permissions to be 0750 or less (G301)
---
pkg/util/util.go | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/pkg/util/util.go b/pkg/util/util.go
index 36d98ce..b468db4 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -230,7 +230,11 @@ func CopyFile(src, dst string) (nBytes int64, err error) {
err = Close(err, source)
}()
- err = os.MkdirAll(path.Dir(dst), 0o700)
+ // we need to have group and other to be able to access the directory as the user
+ //in the container may not be the same as the one owning the files
+ //
+ // #nosec G301
+ err = os.MkdirAll(path.Dir(dst), 0o755)
if err != nil {
return
}
@@ -334,7 +338,8 @@ func CreateDirectory(directory string) error {
}
if !directoryExists {
- err := os.MkdirAll(directory, 0o700)
+ // #nosec G301
+ err := os.MkdirAll(directory, 0o755)
if err != nil {
return err
}
[camel-k] 19/19: fix(lint): put a space between and comment text (gocritic)
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 7efe4ffbfd82050acf89821846db1137c231d554
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Tue Nov 23 17:12:52 2021 +0100
fix(lint): put a space between and comment text (gocritic)
---
pkg/util/util.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pkg/util/util.go b/pkg/util/util.go
index b468db4..745ac7c 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -231,7 +231,7 @@ func CopyFile(src, dst string) (nBytes int64, err error) {
}()
// we need to have group and other to be able to access the directory as the user
- //in the container may not be the same as the one owning the files
+ // in the container may not be the same as the one owning the files
//
// #nosec G301
err = os.MkdirAll(path.Dir(dst), 0o755)
[camel-k] 09/19: fix(gosec): deferring unsafe method "Close" on type "*os.File" (G307)
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 612620c7be0a7c515e6da359c46517aa7a4a2148
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Mon Nov 22 21:12:20 2021 +0100
fix(gosec): deferring unsafe method "Close" on type "*os.File" (G307)
---
cmd/util/doc-gen/generators/traitdocgen.go | 46 ++++-----
cmd/util/doc-gen/generators/traitmetadatagen.go | 29 +++---
pkg/builder/image.go | 3 +-
pkg/builder/spectrum.go | 1 +
pkg/cmd/dump.go | 26 ++---
pkg/cmd/init.go | 9 +-
pkg/util/digest/digest.go | 27 +++--
pkg/util/maven/maven_command.go | 4 +-
pkg/util/util.go | 128 +++++++++++++++++-------
9 files changed, 157 insertions(+), 116 deletions(-)
diff --git a/cmd/util/doc-gen/generators/traitdocgen.go b/cmd/util/doc-gen/generators/traitdocgen.go
index 93c20c5..ad07dd3 100644
--- a/cmd/util/doc-gen/generators/traitdocgen.go
+++ b/cmd/util/doc-gen/generators/traitdocgen.go
@@ -90,17 +90,15 @@ func (g *traitDocGen) GenerateType(context *generator.Context, t *types.Type, ou
g.generatedTraitFiles = append(g.generatedTraitFiles, traitFile)
- file, content, err := readFile(filename)
- if err != nil {
- return err
- }
- defer file.Close()
+ return util.WithFileContent(filename, func(file *os.File, data []byte) error {
+ content := strings.Split(string(data), "\n")
- writeTitle(traitID, &content)
- writeDescription(t, traitID, &content)
- writeFields(t, traitID, &content)
+ writeTitle(traitID, &content)
+ writeDescription(t, traitID, &content)
+ writeFields(t, traitID, &content)
- return writeFile(file, content)
+ return writeFile(file, content)
+ })
}
func (g *traitDocGen) Finalize(c *generator.Context, w io.Writer) error {
@@ -112,25 +110,23 @@ func (g *traitDocGen) FinalizeNav(*generator.Context) error {
navPath := g.arguments.CustomArgs.(*CustomArgs).NavPath
filename := path.Join(docDir, navPath)
- file, content, err := readFile(filename)
- if err != nil {
- return err
- }
- defer file.Close()
+ return util.WithFileContent(filename, func(file *os.File, data []byte) error {
+ content := strings.Split(string(data), "\n")
- pre, post := split(content, adocNavMarkerStart, adocNavMarkerEnd)
+ pre, post := split(content, adocNavMarkerStart, adocNavMarkerEnd)
- content = append([]string(nil), pre...)
- content = append(content, adocNavMarkerStart)
- sort.Strings(g.generatedTraitFiles)
- for _, t := range g.generatedTraitFiles {
- name := traitNameFromFile(t)
- content = append(content, "** xref:traits:"+t+"["+name+"]")
- }
- content = append(content, adocNavMarkerEnd)
- content = append(content, post...)
+ content = append([]string(nil), pre...)
+ content = append(content, adocNavMarkerStart)
+ sort.Strings(g.generatedTraitFiles)
+ for _, t := range g.generatedTraitFiles {
+ name := traitNameFromFile(t)
+ content = append(content, "** xref:traits:"+t+"["+name+"]")
+ }
+ content = append(content, adocNavMarkerEnd)
+ content = append(content, post...)
- return writeFile(file, content)
+ return writeFile(file, content)
+ })
}
func traitNameFromFile(file string) string {
diff --git a/cmd/util/doc-gen/generators/traitmetadatagen.go b/cmd/util/doc-gen/generators/traitmetadatagen.go
index 5358883..681b46a 100644
--- a/cmd/util/doc-gen/generators/traitmetadatagen.go
+++ b/cmd/util/doc-gen/generators/traitmetadatagen.go
@@ -88,27 +88,24 @@ func (g *traitMetaDataGen) GenerateType(context *generator.Context, t *types.Typ
return nil
}
-func (g *traitMetaDataGen) Finalize(c *generator.Context, w io.Writer) error {
+func (g *traitMetaDataGen) Finalize(c *generator.Context, w io.Writer) (err error) {
deployDir := g.arguments.CustomArgs.(*CustomArgs).ResourceDir
traitFile := "traits.yaml"
filename := path.Join(deployDir, traitFile)
- var file *os.File
- var err error
- if file, err = util.OpenFile(filename, os.O_RDWR|os.O_CREATE, 0o777); err != nil {
- return err
- }
- if err = file.Truncate(0); err != nil {
- return err
- }
- defer file.Close()
+ return util.WithFile(filename, os.O_RDWR|os.O_CREATE, 0o777, func(file *os.File) error {
+ if err := file.Truncate(0); err != nil {
+ return err
+ }
- data, err := yaml.Marshal(g.Root)
- if err != nil {
- fmt.Fprintf(file, "error: %v", err)
- }
- fmt.Fprintf(file, "%s", string(data))
- return nil
+ data, err := yaml.Marshal(g.Root)
+ if err != nil {
+ fmt.Fprintf(file, "error: %v", err)
+ }
+ fmt.Fprintf(file, "%s", string(data))
+
+ return nil
+ })
}
func (g *traitMetaDataGen) getTraitID(t *types.Type) string {
diff --git a/pkg/builder/image.go b/pkg/builder/image.go
index 1eec4a7..3a200be 100644
--- a/pkg/builder/image.go
+++ b/pkg/builder/image.go
@@ -175,7 +175,8 @@ func imageContext(ctx *builderContext, selector artifactsSelector) error {
for _, entry := range ctx.Resources {
filePath, fileName := path.Split(entry.Target)
- if err := util.WriteFileWithContent(path.Join(contextDir, filePath), fileName, entry.Content); err != nil {
+ fullPath := path.Join(contextDir, filePath, fileName)
+ if err := util.WriteFileWithContent(fullPath, entry.Content); err != nil {
return err
}
}
diff --git a/pkg/builder/spectrum.go b/pkg/builder/spectrum.go
index 95d3fa9..06f0ead 100644
--- a/pkg/builder/spectrum.go
+++ b/pkg/builder/spectrum.go
@@ -104,6 +104,7 @@ func (t *spectrumTask) Do(ctx context.Context) v1.BuildStatus {
}
newStdR, newStdW, pipeErr := os.Pipe()
+ // #nosec G307
defer newStdW.Close()
if pipeErr != nil {
diff --git a/pkg/cmd/dump.go b/pkg/cmd/dump.go
index fcdc6da..71cfbca 100644
--- a/pkg/cmd/dump.go
+++ b/pkg/cmd/dump.go
@@ -55,29 +55,21 @@ type dumpCmdOptions struct {
LogLines int `mapstructure:"logLines"`
}
-func (o *dumpCmdOptions) dump(cmd *cobra.Command, args []string) error {
+func (o *dumpCmdOptions) dump(cmd *cobra.Command, args []string) (err error) {
c, err := o.GetCmdClient()
if err != nil {
- return err
+ return
}
+
if len(args) == 1 {
- fileName := args[0]
- writer, err := util.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0o777)
- if err != nil {
- return err
- }
- err = dumpNamespace(o.Context, c, o.Namespace, writer, o.LogLines)
- if err != nil {
- return err
- }
- defer writer.Close()
+ err = util.WithFile(args[0], os.O_RDWR|os.O_CREATE, 0o644, func(file *os.File) error {
+ return dumpNamespace(o.Context, c, o.Namespace, file, o.LogLines)
+ })
} else {
- err := dumpNamespace(o.Context, c, o.Namespace, cmd.OutOrStdout(), o.LogLines)
- if err != nil {
- return err
- }
+ err = dumpNamespace(o.Context, c, o.Namespace, cmd.OutOrStdout(), o.LogLines)
}
- return nil
+
+ return
}
func dumpNamespace(ctx context.Context, c client.Client, ns string, out io.Writer, logLines int) error {
diff --git a/pkg/cmd/init.go b/pkg/cmd/init.go
index 0b30b0b..0a669e1 100644
--- a/pkg/cmd/init.go
+++ b/pkg/cmd/init.go
@@ -99,13 +99,10 @@ func (o *initCmdOptions) writeFromTemplate(language v1.Language, fileName string
if err != nil {
return err
}
- out, err := util.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0o777)
- if err != nil {
- return err
- }
- defer out.Close()
- return tmpl.Execute(out, params)
+ return util.WithFile(fileName, os.O_RDWR|os.O_CREATE, 0o644, func(file *os.File) error {
+ return tmpl.Execute(file, params)
+ })
}
func (o *initCmdOptions) extractLanguage(fileName string) *v1.Language {
diff --git a/pkg/util/digest/digest.go b/pkg/util/digest/digest.go
index f364b5c..1e62e02 100644
--- a/pkg/util/digest/digest.go
+++ b/pkg/util/digest/digest.go
@@ -18,7 +18,8 @@ limitations under the License.
package digest
import (
- // nolint: gosec
+ // this is needed to generate an SHA1 sum for Jars
+ // #nosec G505
"crypto/sha1"
"crypto/sha256"
"encoding/base64"
@@ -262,17 +263,21 @@ func sortedTraitAnnotationsKeys(it *v1.Integration) []string {
func ComputeSHA1(elem ...string) (string, error) {
file := path.Join(elem...)
- f, err := util.Open(file)
- if err != nil {
- return "", err
- }
- defer f.Close()
-
// #nosec G401
h := sha1.New()
- if _, err := io.Copy(h, f); err != nil {
- return "", err
- }
- return base64.StdEncoding.EncodeToString(h.Sum(nil)), nil
+ err := util.WithFileReader(file, func(file io.Reader) error {
+ if _, err := io.Copy(h, file); err != nil {
+ return err
+ }
+
+ return nil
+ })
+
+ var sum string
+
+ if err != nil {
+ sum = base64.StdEncoding.EncodeToString(h.Sum(nil))
+ }
+ return sum, err
}
diff --git a/pkg/util/maven/maven_command.go b/pkg/util/maven/maven_command.go
index b4ec58e..e42d9cd 100644
--- a/pkg/util/maven/maven_command.go
+++ b/pkg/util/maven/maven_command.go
@@ -198,7 +198,7 @@ func generateProjectStructure(context Context, project Project) error {
}
if context.SettingsContent != nil {
- if err := util.WriteFileWithContent(context.Path, "settings.xml", context.SettingsContent); err != nil {
+ if err := util.WriteFileWithContent(path.Join(context.Path, "settings.xml"), context.SettingsContent); err != nil {
return err
}
}
@@ -221,7 +221,7 @@ func generateProjectStructure(context Context, project Project) error {
if len(bytes) > 0 {
Log.Infof("write entry: %s (%d bytes)", k, len(bytes))
- err = util.WriteFileWithContent(context.Path, k, bytes)
+ err = util.WriteFileWithContent(path.Join(context.Path, k), bytes)
if err != nil {
return err
}
diff --git a/pkg/util/util.go b/pkg/util/util.go
index 903c9fb..2ceb69c 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -22,6 +22,7 @@ import (
"encoding/json"
"encoding/xml"
"fmt"
+ "go.uber.org/multierr"
"io"
"io/ioutil"
"os"
@@ -208,67 +209,52 @@ func EncodeXML(content interface{}) ([]byte, error) {
return w.Bytes(), nil
}
-func CopyFile(src, dst string) (int64, error) {
+func CopyFile(src, dst string) (nBytes int64, err error) {
stat, err := os.Stat(src)
if err != nil {
- return 0, err
+ return
}
if !stat.Mode().IsRegular() {
- return 0, fmt.Errorf("%s is not a regular file", src)
+ err = fmt.Errorf("%s is not a regular file", src)
+ return
}
source, err := Open(src)
if err != nil {
- return 0, err
+ return
}
- defer source.Close()
+
+ defer func() {
+ err = Close(err, source)
+ }()
err = os.MkdirAll(path.Dir(dst), 0o700)
if err != nil {
- return 0, err
+ return
}
destination, err := OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, stat.Mode())
if err != nil {
- return 0, err
+ return
}
- defer destination.Close()
- nBytes, err := io.Copy(destination, source)
-
- return nBytes, err
-}
+ defer func() {
+ err = Close(err, destination)
+ }()
-func WriteFileWithContent(buildDir string, relativePath string, content []byte) error {
- filePath := path.Join(buildDir, relativePath)
- fileDir := path.Dir(filePath)
- // Create dir if not present
- err := os.MkdirAll(fileDir, 0o700)
- if err != nil {
- return errors.Wrap(err, "could not create dir for file "+relativePath)
- }
- // Create file
- file, err := os.Create(filePath)
- if err != nil {
- return errors.Wrap(err, "could not create file "+relativePath)
- }
- defer file.Close()
+ nBytes, err = io.Copy(destination, source)
- _, err = file.Write(content)
- if err != nil {
- return errors.Wrap(err, "could not write to file "+relativePath)
- }
- return nil
+ return
}
-func WriteFileWithBytesMarshallerContent(buildDir string, relativePath string, content BytesMarshaller) error {
+func WriteFileWithBytesMarshallerContent(basePath string, filePath string, content BytesMarshaller) error {
data, err := content.MarshalBytes()
if err != nil {
return err
}
- return WriteFileWithContent(buildDir, relativePath, data)
+ return WriteFileWithContent(path.Join(basePath, filePath), data)
}
func FindAllDistinctStringSubmatch(data string, regexps ...*regexp.Regexp) []string {
@@ -320,18 +306,22 @@ func DirectoryExists(directory string) (bool, error) {
return info.IsDir(), nil
}
-func DirectoryEmpty(directory string) (bool, error) {
+func DirectoryEmpty(directory string) (ok bool, err error) {
f, err := Open(directory)
if err != nil {
- return false, err
+ return
}
- defer f.Close()
+
+ defer func() {
+ err = Close(err, f)
+ }()
_, err = f.Readdirnames(1)
if errors.Is(err, io.EOF) {
- return true, nil
+ ok = true
}
- return false, err
+
+ return
}
func CreateDirectory(directory string) error {
@@ -778,3 +768,65 @@ func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) {
func ReadFile(filename string) ([]byte, error) {
return os.ReadFile(filepath.Clean(filename))
}
+
+func Close(err error, closer io.Closer) error {
+ return multierr.Append(err, closer.Close())
+}
+
+// WithFile a safe wrapper to process a file.
+func WithFile(name string, flag int, perm os.FileMode, consumer func(file *os.File) error) error {
+ // #nosec G304
+ file, err := os.OpenFile(filepath.Clean(name), flag, perm)
+ if err == nil {
+ err = consumer(file)
+ }
+
+ return Close(err, file)
+}
+
+// WithFileReader a safe wrapper to process a file.
+func WithFileReader(name string, consumer func(reader io.Reader) error) error {
+ // #nosec G304
+ file, err := os.Open(filepath.Clean(name))
+ if err == nil {
+ err = consumer(file)
+ }
+
+ return Close(err, file)
+}
+
+// WithFileContent a safe wrapper to process a file content.
+func WithFileContent(name string, consumer func(file *os.File, data []byte) error) error {
+ return WithFile(name, os.O_RDWR|os.O_CREATE, 0o644, func(file *os.File) error {
+ content, err := ReadFile(name)
+ if err != nil {
+ return err
+ }
+
+ return consumer(file, content)
+ })
+}
+
+// WriteFileWithContent a safe wrapper to write content to a file.
+func WriteFileWithContent(filePath string, content []byte) error {
+ fileDir := path.Dir(filePath)
+
+ // Create dir if not present
+ err := os.MkdirAll(fileDir, 0o700)
+ if err != nil {
+ return errors.Wrap(err, "could not create dir for file "+filePath)
+ }
+
+ // Create file
+ file, err := os.Create(filePath)
+ if err != nil {
+ return errors.Wrap(err, "could not create file "+filePath)
+ }
+
+ _, err = file.Write(content)
+ if err != nil {
+ err = errors.Wrap(err, "could not write to file "+filePath)
+ }
+
+ return Close(err, file)
+}
[camel-k] 16/19: fix(lint): goimport
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 9e1d4cc612357ddc780e24b3a108952b07326ce8
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Tue Nov 23 00:22:11 2021 +0100
fix(lint): goimport
---
cmd/util/doc-gen/generators/traitdocgen.go | 3 ++-
cmd/util/doc-gen/generators/traitmetadatagen.go | 3 ++-
cmd/util/json-schema-gen/main.go | 3 ++-
cmd/util/license-check/main.go | 3 ++-
cmd/util/vfs-gen/main.go | 3 ++-
pkg/builder/s2i.go | 3 ++-
pkg/builder/spectrum.go | 3 ++-
pkg/client/client.go | 3 ++-
pkg/cmd/dump.go | 3 ++-
pkg/cmd/init.go | 3 ++-
pkg/cmd/util_content.go | 3 ++-
pkg/install/kamelets.go | 3 ++-
pkg/install/secret.go | 1 +
pkg/util/camel/catalog.go | 3 ++-
pkg/util/kubernetes/log/annotation_scraper.go | 3 ++-
pkg/util/kubernetes/log/pod_scraper.go | 3 ++-
pkg/util/util.go | 3 ++-
17 files changed, 33 insertions(+), 16 deletions(-)
diff --git a/cmd/util/doc-gen/generators/traitdocgen.go b/cmd/util/doc-gen/generators/traitdocgen.go
index 9005bbc..57bdd6f 100644
--- a/cmd/util/doc-gen/generators/traitdocgen.go
+++ b/cmd/util/doc-gen/generators/traitdocgen.go
@@ -19,7 +19,6 @@ package generators
import (
"fmt"
- "github.com/apache/camel-k/pkg/util"
"io"
"os"
"path"
@@ -28,6 +27,8 @@ import (
"sort"
"strings"
+ "github.com/apache/camel-k/pkg/util"
+
"k8s.io/gengo/args"
"k8s.io/gengo/generator"
"k8s.io/gengo/types"
diff --git a/cmd/util/doc-gen/generators/traitmetadatagen.go b/cmd/util/doc-gen/generators/traitmetadatagen.go
index 681b46a..aae0da7 100644
--- a/cmd/util/doc-gen/generators/traitmetadatagen.go
+++ b/cmd/util/doc-gen/generators/traitmetadatagen.go
@@ -19,13 +19,14 @@ package generators
import (
"fmt"
- "github.com/apache/camel-k/pkg/util"
"io"
"os"
"path"
"reflect"
"strings"
+ "github.com/apache/camel-k/pkg/util"
+
"gopkg.in/yaml.v2"
"k8s.io/gengo/args"
"k8s.io/gengo/generator"
diff --git a/cmd/util/json-schema-gen/main.go b/cmd/util/json-schema-gen/main.go
index 27bebd7..671bc17 100644
--- a/cmd/util/json-schema-gen/main.go
+++ b/cmd/util/json-schema-gen/main.go
@@ -20,12 +20,13 @@ package main
import (
"encoding/json"
"fmt"
- "github.com/apache/camel-k/pkg/util"
"io/ioutil"
"os"
"reflect"
"strings"
+ "github.com/apache/camel-k/pkg/util"
+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
clientscheme "k8s.io/client-go/kubernetes/scheme"
diff --git a/cmd/util/license-check/main.go b/cmd/util/license-check/main.go
index 3b8f37a..417acc2 100644
--- a/cmd/util/license-check/main.go
+++ b/cmd/util/license-check/main.go
@@ -19,9 +19,10 @@ package main
import (
"fmt"
- "github.com/apache/camel-k/pkg/util"
"os"
"strings"
+
+ "github.com/apache/camel-k/pkg/util"
)
func main() {
diff --git a/cmd/util/vfs-gen/main.go b/cmd/util/vfs-gen/main.go
index 72eed43..1fd428e 100644
--- a/cmd/util/vfs-gen/main.go
+++ b/cmd/util/vfs-gen/main.go
@@ -20,7 +20,6 @@ package main
import (
"flag"
"fmt"
- "github.com/apache/camel-k/pkg/util"
"io/ioutil"
"log"
"net/http"
@@ -30,6 +29,8 @@ import (
"strings"
"time"
+ "github.com/apache/camel-k/pkg/util"
+
"github.com/apache/camel-k/cmd/util/vfs-gen/multifs"
"github.com/apache/camel-k/pkg/base"
"github.com/shurcooL/httpfs/filter"
diff --git a/pkg/builder/s2i.go b/pkg/builder/s2i.go
index d6e23a1..2f7f488 100644
--- a/pkg/builder/s2i.go
+++ b/pkg/builder/s2i.go
@@ -22,7 +22,6 @@ import (
"compress/gzip"
"context"
"fmt"
- "github.com/apache/camel-k/pkg/util"
"io"
"io/ioutil"
"os"
@@ -31,6 +30,8 @@ import (
"strings"
"time"
+ "github.com/apache/camel-k/pkg/util"
+
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
diff --git a/pkg/builder/spectrum.go b/pkg/builder/spectrum.go
index 9202e70..a7c149e 100644
--- a/pkg/builder/spectrum.go
+++ b/pkg/builder/spectrum.go
@@ -20,7 +20,6 @@ package builder
import (
"bufio"
"context"
- "go.uber.org/multierr"
"io"
"io/ioutil"
"os"
@@ -28,6 +27,8 @@ import (
"path/filepath"
"strings"
+ "go.uber.org/multierr"
+
spectrum "github.com/container-tools/spectrum/pkg/builder"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
diff --git a/pkg/client/client.go b/pkg/client/client.go
index 83c9fc0..3d34f1e 100644
--- a/pkg/client/client.go
+++ b/pkg/client/client.go
@@ -19,11 +19,12 @@ package client
import (
"fmt"
- "github.com/apache/camel-k/pkg/util"
"io/ioutil"
"os"
"path/filepath"
+ "github.com/apache/camel-k/pkg/util"
+
camelv1 "github.com/apache/camel-k/pkg/client/camel/clientset/versioned/typed/camel/v1"
camelv1alpha1 "github.com/apache/camel-k/pkg/client/camel/clientset/versioned/typed/camel/v1alpha1"
user "github.com/mitchellh/go-homedir"
diff --git a/pkg/cmd/dump.go b/pkg/cmd/dump.go
index 71cfbca..c0d8f4e 100644
--- a/pkg/cmd/dump.go
+++ b/pkg/cmd/dump.go
@@ -21,10 +21,11 @@ import (
"bufio"
"context"
"fmt"
- "github.com/apache/camel-k/pkg/util"
"io"
"os"
+ "github.com/apache/camel-k/pkg/util"
+
"github.com/spf13/cobra"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
diff --git a/pkg/cmd/init.go b/pkg/cmd/init.go
index 0a669e1..0a2f06c 100644
--- a/pkg/cmd/init.go
+++ b/pkg/cmd/init.go
@@ -19,12 +19,13 @@ package cmd
import (
"fmt"
- "github.com/apache/camel-k/pkg/util"
"os"
"path/filepath"
"strings"
"text/template"
+ "github.com/apache/camel-k/pkg/util"
+
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/resources"
"github.com/spf13/cobra"
diff --git a/pkg/cmd/util_content.go b/pkg/cmd/util_content.go
index 0d73610..289621e 100644
--- a/pkg/cmd/util_content.go
+++ b/pkg/cmd/util_content.go
@@ -19,13 +19,14 @@ package cmd
import (
"fmt"
- "github.com/apache/camel-k/pkg/util"
"io/ioutil"
"net/http"
"net/url"
"os"
"regexp"
"strings"
+
+ "github.com/apache/camel-k/pkg/util"
)
const (
diff --git a/pkg/install/kamelets.go b/pkg/install/kamelets.go
index 2641003..2134a48 100644
--- a/pkg/install/kamelets.go
+++ b/pkg/install/kamelets.go
@@ -20,12 +20,13 @@ package install
import (
"context"
"fmt"
- "github.com/apache/camel-k/pkg/util"
"io/ioutil"
"os"
"path"
"strings"
+ "github.com/apache/camel-k/pkg/util"
+
"github.com/pkg/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
diff --git a/pkg/install/secret.go b/pkg/install/secret.go
index 016b336..c4a2f8b 100644
--- a/pkg/install/secret.go
+++ b/pkg/install/secret.go
@@ -19,6 +19,7 @@ package install
import (
"context"
+
"github.com/apache/camel-k/pkg/util"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
diff --git a/pkg/util/camel/catalog.go b/pkg/util/camel/catalog.go
index 81dac2e..531e791 100644
--- a/pkg/util/camel/catalog.go
+++ b/pkg/util/camel/catalog.go
@@ -19,11 +19,12 @@ package camel
import (
"context"
- "github.com/apache/camel-k/pkg/util"
"io/ioutil"
"os"
"path"
+ "github.com/apache/camel-k/pkg/util"
+
yaml2 "gopkg.in/yaml.v2"
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
diff --git a/pkg/util/kubernetes/log/annotation_scraper.go b/pkg/util/kubernetes/log/annotation_scraper.go
index ff6f166..ff5924a 100644
--- a/pkg/util/kubernetes/log/annotation_scraper.go
+++ b/pkg/util/kubernetes/log/annotation_scraper.go
@@ -20,13 +20,14 @@ package log
import (
"bufio"
"context"
- "go.uber.org/multierr"
"io"
"strconv"
"sync"
"sync/atomic"
"time"
+ "go.uber.org/multierr"
+
klog "github.com/apache/camel-k/pkg/util/log"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
diff --git a/pkg/util/kubernetes/log/pod_scraper.go b/pkg/util/kubernetes/log/pod_scraper.go
index 2e55c67..202c812 100644
--- a/pkg/util/kubernetes/log/pod_scraper.go
+++ b/pkg/util/kubernetes/log/pod_scraper.go
@@ -20,10 +20,11 @@ package log
import (
"bufio"
"context"
- "go.uber.org/multierr"
"io"
"time"
+ "go.uber.org/multierr"
+
klog "github.com/apache/camel-k/pkg/util/log"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
diff --git a/pkg/util/util.go b/pkg/util/util.go
index 2ceb69c..36d98ce 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -22,7 +22,6 @@ import (
"encoding/json"
"encoding/xml"
"fmt"
- "go.uber.org/multierr"
"io"
"io/ioutil"
"os"
@@ -32,6 +31,8 @@ import (
"sort"
"strings"
+ "go.uber.org/multierr"
+
yaml2 "gopkg.in/yaml.v2"
"github.com/pkg/errors"
[camel-k] 05/19: fix(gosec): Use of weak random number generator (G404)
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit a0747e162050fa2e67e59a7eb0cf6b3bfc7c8eb1
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Mon Nov 22 13:47:28 2021 +0100
fix(gosec): Use of weak random number generator (G404)
---
pkg/trait/route_test.go | 7 ++++++-
pkg/util/sync/file_test.go | 12 ++++--------
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/pkg/trait/route_test.go b/pkg/trait/route_test.go
index 3bf5306..96c67a4 100644
--- a/pkg/trait/route_test.go
+++ b/pkg/trait/route_test.go
@@ -90,9 +90,14 @@ pxv6zFeVEkAEEkqIYi0omA9+CjanB/6Bz4n1uw8H
tlsKeySecretName = "tls-test"
tlsKeySecretOnlyKeyName = "tls.key"
- tlsMultipleSecretsName = "tls-multiple-test"
+ // Potential hardcoded credentials
+ // #nosec G101
+ tlsMultipleSecretsName = "tls-multiple-test"
+ // #nosec G101
tlsMultipleSecretsCert1Key = "cert1.crt"
+ // #nosec G101
tlsMultipleSecretsCert2Key = "cert2.crt"
+ // #nosec G101
tlsMultipleSecretsCert3Key = "cert3.crt"
)
diff --git a/pkg/util/sync/file_test.go b/pkg/util/sync/file_test.go
index 5c1e2b2..792cd60 100644
--- a/pkg/util/sync/file_test.go
+++ b/pkg/util/sync/file_test.go
@@ -20,9 +20,7 @@ package sync
import (
"context"
"io/ioutil"
- "math/rand"
"os"
- "path"
"strconv"
"testing"
"time"
@@ -31,21 +29,19 @@ import (
)
func TestFile(t *testing.T) {
- tempdir := os.TempDir()
- fileName := path.Join(tempdir, "camel-k-test-"+strconv.FormatUint(rand.Uint64(), 10))
- _, err := os.Create(fileName)
+ file, err := os.CreateTemp("", "camel-k-test-*")
assert.Nil(t, err)
- defer os.Remove(fileName)
+ defer os.Remove(file.Name())
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(100*time.Second))
defer cancel()
- changes, err := File(ctx, fileName)
+ changes, err := File(ctx, file.Name())
assert.Nil(t, err)
time.Sleep(100 * time.Millisecond)
expectedNumChanges := 3
for i := 0; i < expectedNumChanges; i++ {
- if err := ioutil.WriteFile(fileName, []byte("data-"+strconv.Itoa(i)), 0o600); err != nil {
+ if err := ioutil.WriteFile(file.Name(), []byte("data-"+strconv.Itoa(i)), 0o600); err != nil {
t.Error(err)
}
time.Sleep(350 * time.Millisecond)
[camel-k] 06/19: fix(gosec): disable rule G101
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 2d3458f1d323c13db5a9264993ce04313c33ecb5
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Mon Nov 22 13:49:09 2021 +0100
fix(gosec): disable rule G101
---
pkg/util/source/inspector_yaml_test.go | 1 +
1 file changed, 1 insertion(+)
diff --git a/pkg/util/source/inspector_yaml_test.go b/pkg/util/source/inspector_yaml_test.go
index ae082c4..12e186c 100644
--- a/pkg/util/source/inspector_yaml_test.go
+++ b/pkg/util/source/inspector_yaml_test.go
@@ -372,6 +372,7 @@ const YAMLKameletEipMap = `
name: "foo/bar?baz=test"
`
+// #nosec G101
const YAMLKameletEipMapWithParams = `
- from:
uri: timer:tick