mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
chore(util): Fix modernize linter (#26323)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
@@ -79,8 +79,8 @@ func CheckOutOfBoundsSymlinks(basePath string) error {
|
||||
currentDir := filepath.Dir(path)
|
||||
|
||||
// walk each part of the symlink target to make sure it never leaves basePath
|
||||
parts := strings.Split(linkTarget, string(os.PathSeparator))
|
||||
for _, part := range parts {
|
||||
parts := strings.SplitSeq(linkTarget, string(os.PathSeparator))
|
||||
for part := range parts {
|
||||
newDir := filepath.Join(currentDir, part)
|
||||
rel, err := filepath.Rel(absBasePath, newDir)
|
||||
if err != nil {
|
||||
@@ -116,7 +116,7 @@ func GetSourceRefreshPaths(app *v1alpha1.Application, source v1alpha1.Applicatio
|
||||
|
||||
var paths []string
|
||||
if hasAnnotation && annotationPaths != "" {
|
||||
for _, item := range strings.Split(annotationPaths, ";") {
|
||||
for item := range strings.SplitSeq(annotationPaths, ";") {
|
||||
// skip empty paths
|
||||
if item == "" {
|
||||
continue
|
||||
|
||||
@@ -1028,7 +1028,7 @@ func TestRaceConditionInRepoCredsOperations(t *testing.T) {
|
||||
errChan := make(chan error, concurrentOps*2) // Channel to collect errors
|
||||
|
||||
// Launch goroutines that perform concurrent operations
|
||||
for i := 0; i < concurrentOps; i++ {
|
||||
for range concurrentOps {
|
||||
wg.Add(2)
|
||||
|
||||
// One goroutine converts from RepoCreds to Secret
|
||||
@@ -1111,7 +1111,7 @@ func TestRaceConditionInRepositoryOperations(t *testing.T) {
|
||||
errChan := make(chan error, concurrentOps*2) // Channel to collect errors
|
||||
|
||||
// Launch goroutines that perform concurrent operations
|
||||
for i := 0; i < concurrentOps; i++ {
|
||||
for range concurrentOps {
|
||||
wg.Add(2)
|
||||
|
||||
// One goroutine converts from Repository to Secret
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -72,13 +73,7 @@ func TestHTTPSCreds_Environ_insecure_true(t *testing.T) {
|
||||
utilio.Close(closer)
|
||||
})
|
||||
require.NoError(t, err)
|
||||
found := false
|
||||
for _, envVar := range env {
|
||||
if envVar == "GIT_SSL_NO_VERIFY=true" {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
found := slices.Contains(env, "GIT_SSL_NO_VERIFY=true")
|
||||
assert.True(t, found)
|
||||
}
|
||||
|
||||
@@ -89,13 +84,7 @@ func TestHTTPSCreds_Environ_insecure_false(t *testing.T) {
|
||||
utilio.Close(closer)
|
||||
})
|
||||
require.NoError(t, err)
|
||||
found := false
|
||||
for _, envVar := range env {
|
||||
if envVar == "GIT_SSL_NO_VERIFY=true" {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
found := slices.Contains(env, "GIT_SSL_NO_VERIFY=true")
|
||||
assert.False(t, found)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package jwt
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -123,10 +124,8 @@ func IsMember(claims jwtgo.Claims, groups []string, scopes []string) bool {
|
||||
}
|
||||
// O(n^2) loop
|
||||
for _, userGroup := range GetGroups(mapClaims, scopes) {
|
||||
for _, group := range groups {
|
||||
if userGroup == group {
|
||||
return true
|
||||
}
|
||||
if slices.Contains(groups, userGroup) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package expression
|
||||
|
||||
import (
|
||||
"maps"
|
||||
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
||||
service "github.com/argoproj/argo-cd/v3/util/notification/argocd"
|
||||
@@ -27,9 +29,7 @@ func Spawn(app *unstructured.Unstructured, argocdService service.Service, vars m
|
||||
for k := range vars {
|
||||
clone[k] = vars[k]
|
||||
}
|
||||
for namespace, helper := range helpers {
|
||||
clone[namespace] = helper
|
||||
}
|
||||
maps.Copy(clone, helpers)
|
||||
clone["repo"] = repo.NewExprs(argocdService, app)
|
||||
|
||||
return clone
|
||||
|
||||
@@ -3,6 +3,7 @@ package settings
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -86,12 +87,7 @@ func (a *Account) TokenIndex(id string) int {
|
||||
|
||||
// HasCapability return true if the account has the specified capability.
|
||||
func (a *Account) HasCapability(capability AccountCapability) bool {
|
||||
for _, c := range a.Capabilities {
|
||||
if c == capability {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(a.Capabilities, capability)
|
||||
}
|
||||
|
||||
func (mgr *SettingsManager) saveAccount(name string, account Account) error {
|
||||
@@ -263,7 +259,7 @@ func parseAccounts(secret *corev1.Secret, cm *corev1.ConfigMap) (map[string]Acco
|
||||
}
|
||||
switch suffix {
|
||||
case "":
|
||||
for _, capability := range strings.Split(val, ",") {
|
||||
for capability := range strings.SplitSeq(val, ",") {
|
||||
capability = strings.TrimSpace(capability)
|
||||
if capability == "" {
|
||||
continue
|
||||
|
||||
@@ -3,6 +3,7 @@ package versions
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
@@ -29,10 +30,8 @@ func MaxVersion(revision string, tags []string) (string, error) {
|
||||
if err != nil {
|
||||
log.Debugf("Revision '%s' is not a valid semver constraint, resolving via basic string equality.", revision)
|
||||
// If this is also an invalid constraint, we just iterate over available tags to determine if it is valid/invalid.
|
||||
for _, tag := range tags {
|
||||
if tag == revision {
|
||||
return revision, nil
|
||||
}
|
||||
if slices.Contains(tags, revision) {
|
||||
return revision, nil
|
||||
}
|
||||
return "", fmt.Errorf("failed to determine semver constraint: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user