mirror of https://github.com/goharbor/harbor.git
Merge branch 'main' into dependabot/go_modules/src/helm.sh/helm/v3-3.18.3
Code scanning - action / CodeQL-Build (push) Has been cancelled
Details
Code scanning - action / CodeQL-Build (push) Has been cancelled
Details
This commit is contained in:
commit
2b42b55c47
|
@ -56,7 +56,7 @@ require (
|
|||
github.com/stretchr/testify v1.10.0
|
||||
github.com/tencentcloud/tencentcloud-sdk-go v3.0.233+incompatible
|
||||
github.com/vmihailenco/msgpack/v5 v5.4.1
|
||||
github.com/volcengine/volcengine-go-sdk v1.1.17
|
||||
github.com/volcengine/volcengine-go-sdk v1.1.19
|
||||
go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.59.0
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0
|
||||
go.opentelemetry.io/otel v1.35.0
|
||||
|
|
|
@ -564,8 +564,8 @@ github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAh
|
|||
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
|
||||
github.com/volcengine/volc-sdk-golang v1.0.23 h1:anOslb2Qp6ywnsbyq9jqR0ljuO63kg9PY+4OehIk5R8=
|
||||
github.com/volcengine/volc-sdk-golang v1.0.23/go.mod h1:AfG/PZRUkHJ9inETvbjNifTDgut25Wbkm2QoYBTbvyU=
|
||||
github.com/volcengine/volcengine-go-sdk v1.1.17 h1:Izrcx/FERzGvpY3ufPjt4GR7Ak6y94aMVXbnLmeuw2g=
|
||||
github.com/volcengine/volcengine-go-sdk v1.1.17/go.mod h1:EyKoi6t6eZxoPNGr2GdFCZti2Skd7MO3eUzx7TtSvNo=
|
||||
github.com/volcengine/volcengine-go-sdk v1.1.19 h1:+jLVMqDtdtiAt8QGBk6AMiEg22Br5SZGu2FSHUrIcU0=
|
||||
github.com/volcengine/volcengine-go-sdk v1.1.19/go.mod h1:EyKoi6t6eZxoPNGr2GdFCZti2Skd7MO3eUzx7TtSvNo=
|
||||
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
||||
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
package job
|
||||
|
||||
import "github.com/goharbor/harbor/src/lib"
|
||||
|
||||
// Define the register name constants of known jobs
|
||||
|
||||
const (
|
||||
|
@ -53,19 +55,19 @@ const (
|
|||
var (
|
||||
// executionSweeperCount stores the count for execution retained
|
||||
executionSweeperCount = map[string]int64{
|
||||
ImageScanJobVendorType: 1,
|
||||
SBOMJobVendorType: 1,
|
||||
ScanAllVendorType: 1,
|
||||
PurgeAuditVendorType: 10,
|
||||
ExecSweepVendorType: 10,
|
||||
GarbageCollectionVendorType: 50,
|
||||
SlackJobVendorType: 50,
|
||||
WebhookJobVendorType: 50,
|
||||
ReplicationVendorType: 50,
|
||||
ScanDataExportVendorType: 50,
|
||||
SystemArtifactCleanupVendorType: 50,
|
||||
P2PPreheatVendorType: 50,
|
||||
RetentionVendorType: 50,
|
||||
ImageScanJobVendorType: lib.GetEnvInt64("IMAGE_SCAN_EXECUTION_RETENTION_COUNT", 1),
|
||||
SBOMJobVendorType: lib.GetEnvInt64("SBOM_EXECUTION_RETENTION_COUNT", 1),
|
||||
ScanAllVendorType: lib.GetEnvInt64("SCAN_ALL_EXECUTION_RETENTION_COUNT", 1),
|
||||
PurgeAuditVendorType: lib.GetEnvInt64("PURGE_AUDIT_EXECUTION_RETENTION_COUNT", 10),
|
||||
ExecSweepVendorType: lib.GetEnvInt64("EXECUTION_SWEEP_EXECUTION_RETENTION_COUNT", 10),
|
||||
GarbageCollectionVendorType: lib.GetEnvInt64("GARBAGE_COLLECTION_EXECUTION_RETENTION_COUNT", 50),
|
||||
SlackJobVendorType: lib.GetEnvInt64("SLACK_EXECUTION_RETENTION_COUNT", 50),
|
||||
WebhookJobVendorType: lib.GetEnvInt64("WEBHOOK_EXECUTION_RETENTION_COUNT", 50),
|
||||
ReplicationVendorType: lib.GetEnvInt64("REPLICATION_EXECUTION_RETENTION_COUNT", 50),
|
||||
ScanDataExportVendorType: lib.GetEnvInt64("SCAN_DATA_EXPORT_EXECUTION_RETENTION_COUNT", 50),
|
||||
SystemArtifactCleanupVendorType: lib.GetEnvInt64("SYSTEM_ARTIFACT_CLEANUP_EXECUTION_RETENTION_COUNT", 50),
|
||||
P2PPreheatVendorType: lib.GetEnvInt64("P2P_PREHEAT_EXECUTION_RETENTION_COUNT", 50),
|
||||
RetentionVendorType: lib.GetEnvInt64("RETENTION_EXECUTION_RETENTION_COUNT", 50),
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright Project Harbor Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package lib
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// GetEnvInt64 reads an environment variable and converts it to an int64, returning the default value if not set or invalid.
|
||||
func GetEnvInt64(envKey string, defaultValue int64) int64 {
|
||||
value := os.Getenv(envKey)
|
||||
if value == "" {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
intValue, err := strconv.ParseInt(value, 10, 64)
|
||||
if err != nil {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
return intValue
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package lib
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetEnvInt64(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
envKey string
|
||||
envValue string
|
||||
defaultValue int64
|
||||
setEnv bool
|
||||
expectedValue int64
|
||||
}{
|
||||
{
|
||||
name: "env set with valid value",
|
||||
envKey: "TEST_ENV",
|
||||
envValue: "100",
|
||||
defaultValue: 50,
|
||||
setEnv: true,
|
||||
expectedValue: 100,
|
||||
},
|
||||
{
|
||||
name: "env not set",
|
||||
envKey: "UNSET_ENV",
|
||||
envValue: "",
|
||||
defaultValue: 50,
|
||||
setEnv: false,
|
||||
expectedValue: 50,
|
||||
},
|
||||
{
|
||||
name: "env set with invalid value",
|
||||
envKey: "INVALID_ENV",
|
||||
envValue: "not_a_number",
|
||||
defaultValue: 50,
|
||||
setEnv: true,
|
||||
expectedValue: 50,
|
||||
},
|
||||
{
|
||||
name: "env set with zero",
|
||||
envKey: "ZERO_ENV",
|
||||
envValue: "0",
|
||||
defaultValue: 50,
|
||||
setEnv: true,
|
||||
expectedValue: 0,
|
||||
},
|
||||
{
|
||||
name: "env set with negative value",
|
||||
envKey: "NEGATIVE_ENV",
|
||||
envValue: "-10",
|
||||
defaultValue: 50,
|
||||
setEnv: true,
|
||||
expectedValue: -10,
|
||||
},
|
||||
{
|
||||
name: "env set with large value",
|
||||
envKey: "LARGE_ENV",
|
||||
envValue: "9223372036854775807",
|
||||
defaultValue: 50,
|
||||
setEnv: true,
|
||||
expectedValue: 9223372036854775807,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.setEnv {
|
||||
os.Setenv(tt.envKey, tt.envValue)
|
||||
} else {
|
||||
os.Unsetenv(tt.envKey)
|
||||
}
|
||||
|
||||
result := GetEnvInt64(tt.envKey, tt.defaultValue)
|
||||
if result != tt.expectedValue {
|
||||
t.Errorf("GetEnvInt64(%q, %d) = %d; want %d", tt.envKey, tt.defaultValue, result, tt.expectedValue)
|
||||
}
|
||||
|
||||
os.Unsetenv(tt.envKey)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue