Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/src/github.com/dghubbl…
Browse files Browse the repository at this point in the history
…e/sling-1.4.2
  • Loading branch information
MinerYang authored Sep 4, 2024
2 parents 29692f8 + 9ad8094 commit 74c9085
Show file tree
Hide file tree
Showing 32 changed files with 327 additions and 66 deletions.
6 changes: 3 additions & 3 deletions src/common/api/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ func (b *BaseAPI) DecodeJSONReqAndValidate(v interface{}) (bool, error) {
}

// Redirect does redirection to resource URI with http header status code.
func (b *BaseAPI) Redirect(statusCode int, resouceID string) {
func (b *BaseAPI) Redirect(statusCode int, resourceID string) {
requestURI := b.Ctx.Request.RequestURI
resourceURI := requestURI + "/" + resouceID
resourceURI := requestURI + "/" + resourceID

b.Ctx.Redirect(statusCode, resourceURI)
}
Expand All @@ -138,7 +138,7 @@ func (b *BaseAPI) GetIDFromURL() (int64, error) {
return id, nil
}

// SetPaginationHeader set"Link" and "X-Total-Count" header for pagination request
// SetPaginationHeader set "Link" and "X-Total-Count" header for pagination request
func (b *BaseAPI) SetPaginationHeader(total, page, pageSize int64) {
b.Ctx.ResponseWriter.Header().Set("X-Total-Count", strconv.FormatInt(total, 10))

Expand Down
2 changes: 1 addition & 1 deletion src/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const (
OIDCCallbackPath = "/c/oidc/callback"
OIDCLoginPath = "/c/oidc/login"

AuthProxyRediretPath = "/c/authproxy/redirect"
AuthProxyRedirectPath = "/c/authproxy/redirect"

// Global notification enable configuration
NotificationEnable = "notification_enable"
Expand Down
2 changes: 1 addition & 1 deletion src/common/http/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func GetInternalCertPair() (tls.Certificate, error) {

// GetInternalTLSConfig return a tls.Config for internal https communicate
func GetInternalTLSConfig() (*tls.Config, error) {
// genrate key pair
// generate key pair
cert, err := GetInternalCertPair()
if err != nil {
return nil, fmt.Errorf("internal TLS enabled but can't get cert file %w", err)
Expand Down
2 changes: 1 addition & 1 deletion src/common/job/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (d *DefaultClient) SubmitJob(jd *models.JobData) (string, error) {
return stats.Stats.JobID, nil
}

// GetJobLog call jobserivce API to get the log of a job. It only accepts the UUID of the job
// GetJobLog call jobservice API to get the log of a job. It only accepts the UUID of the job
func (d *DefaultClient) GetJobLog(uuid string) ([]byte, error) {
url := d.endpoint + "/api/v1/jobs/" + uuid + "/log"
req, err := http.NewRequest(http.MethodGet, url, nil)
Expand Down
4 changes: 2 additions & 2 deletions src/common/job/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ type StatsInfo struct {
UpstreamJobID string `json:"upstream_job_id,omitempty"` // Ref the upstream job if existing
NumericPID int64 `json:"numeric_policy_id,omitempty"` // The numeric policy ID of the periodic job
Parameters Parameters `json:"parameters,omitempty"`
Revision int64 `json:"revision,omitempty"` // For differentiating the each retry of the same job
Revision int64 `json:"revision,omitempty"` // For differentiating each retry of the same job
}

// JobPoolStats represents the healthy and status of all the running worker pools.
type JobPoolStats struct {
Pools []*JobPoolStatsData `json:"worker_pools"`
}

// JobPoolStatsData represent the healthy and status of the worker worker.
// JobPoolStatsData represent the healthy and status of the worker.
type JobPoolStatsData struct {
WorkerPoolID string `json:"worker_pool_id"`
StartedAt int64 `json:"started_at"`
Expand Down
2 changes: 1 addition & 1 deletion src/common/models/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
JobCanceled string = "canceled"
// JobRetrying indicate the job needs to be retried, it will be scheduled to the end of job queue by statemachine after an interval.
JobRetrying string = "retrying"
// JobContinue is the status returned by statehandler to tell statemachine to move to next possible state based on trasition table.
// JobContinue is the status returned by statehandler to tell statemachine to move to next possible state based on transition table.
JobContinue string = "_continue"
// JobScheduled ...
JobScheduled string = "scheduled"
Expand Down
2 changes: 1 addition & 1 deletion src/common/models/uaa.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package models

// UAASettings wraps the configuraations to access UAA service
// UAASettings wraps the configurations to access UAA service
type UAASettings struct {
Endpoint string
ClientID string
Expand Down
8 changes: 4 additions & 4 deletions src/common/rbac/project/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func TestProjectRoleAccess(t *testing.T) {
Username: "username",
}
evaluator := NewEvaluator(ctl, NewBuilderForUser(user, ctl))
resorce := NewNamespace(public.ProjectID).Resource(rbac.ResourceRepository)
assert.True(evaluator.HasPermission(context.TODO(), resorce, rbac.ActionPush))
resource := NewNamespace(public.ProjectID).Resource(rbac.ResourceRepository)
assert.True(evaluator.HasPermission(context.TODO(), resource, rbac.ActionPush))
}

{
Expand All @@ -101,8 +101,8 @@ func TestProjectRoleAccess(t *testing.T) {
Username: "username",
}
evaluator := NewEvaluator(ctl, NewBuilderForUser(user, ctl))
resorce := NewNamespace(public.ProjectID).Resource(rbac.ResourceRepository)
assert.False(evaluator.HasPermission(context.TODO(), resorce, rbac.ActionPush))
resource := NewNamespace(public.ProjectID).Resource(rbac.ResourceRepository)
assert.False(evaluator.HasPermission(context.TODO(), resource, rbac.ActionPush))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/secret/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
const HeaderPrefix = "Harbor-Secret "

// FromRequest tries to get Harbor Secret from request header.
// It will return empty string if the reqeust is nil.
// It will return empty string if the request is nil.
func FromRequest(req *http.Request) string {
if req == nil {
return ""
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils/email/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func Send(addr, identity, username, password string,

// Ping tests the connection and authentication with email server
// If tls is true, a secure connection is established, or Ping
// trys to upgrate the insecure connection to a secure one if
// trys to upgrade the insecure connection to a secure one if
// email server supports it.
// Ping doesn't verify the server's certificate and hostname when
// needed if the parameter insecure is ture
Expand Down Expand Up @@ -119,7 +119,7 @@ func newClient(addr, identity, username, password string,
return nil, err
}

// try to swith to SSL/TLS
// try to switch to SSL/TLS
if !tls {
if ok, _ := client.Extension("STARTTLS"); ok {
log.Debugf("switching the connection with %s to SSL/TLS ...", addr)
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils/email/mail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestSend(t *testing.T) {
err := Send(addr, identity, username, password,
timeout, tls, insecure, from, to,
subject, message)
// bypass the check due to securty policy change on gmail
// bypass the check due to security policy change on gmail
// TODO
// assert.Nil(t, err)

Expand Down Expand Up @@ -78,7 +78,7 @@ func TestPing(t *testing.T) {
// tls connection
err := Ping(addr, identity, username, password,
timeout, tls, insecure)
// bypass the check due to securty policy change on gmail
// bypass the check due to security policy change on gmail
// TODO
// assert.Nil(t, err)

Expand Down
4 changes: 2 additions & 2 deletions src/common/utils/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ var HashAlg = map[string]func() hash.Hash{
}

// Encrypt encrypts the content with salt
func Encrypt(content string, salt string, encrptAlg string) string {
return fmt.Sprintf("%x", pbkdf2.Key([]byte(content), []byte(salt), 4096, 16, HashAlg[encrptAlg]))
func Encrypt(content string, salt string, encryptAlg string) string {
return fmt.Sprintf("%x", pbkdf2.Key([]byte(content), []byte(salt), 4096, 16, HashAlg[encryptAlg]))
}

// ReversibleEncrypt encrypts the str with aes/base64
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils/passports.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (p *passportsPool) Revoke() bool {
type LimitedConcurrentRunner interface {
// AddTask adds a task to run
AddTask(task func() error)
// Wait waits all the tasks to be finished, returns error if the any of the tasks gets error
// Wait waits all the tasks to be finished, returns error if any of the tasks gets error
Wait() (err error)
// Cancel cancels all tasks, tasks that already started will continue to run
Cancel(err error)
Expand Down Expand Up @@ -106,7 +106,7 @@ func (r *limitedConcurrentRunner) AddTask(task func() error) {
r.wg.Done()
}()

// Return false means no passport acquired, and no valid passport will be dispatched any more.
// Return false means no passport acquired, and no valid passport will be dispatched anymore.
// For example, some crucial errors happened and all tasks should be cancelled.
if ok := r.passportsPool.Apply(); !ok {
return
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils/test/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var defaultConfig = map[string]interface{}{
common.RobotNamePrefix: "robot$",
}

// GetDefaultConfigMap returns the defailt config map for easier modification.
// GetDefaultConfigMap returns the default config map for easier modification.
func GetDefaultConfigMap() map[string]interface{} {
return defaultConfig
}
6 changes: 3 additions & 3 deletions src/common/utils/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ type Response struct {
StatusCode int
// Headers are the headers of the response
Headers map[string]string
// Boby is the body of the response
// Body is the body of the response
Body []byte
}

// Handler returns a handler function which handle requst according to
// Handler returns a handler function which handle request according to
// the response provided
func Handler(resp *Response) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -82,7 +82,7 @@ func Handler(resp *Response) func(http.ResponseWriter, *http.Request) {
}
}

// NewServer creates a HTTP server for unit test
// NewServer creates an HTTP server for unit test
func NewServer(mappings ...*RequestHandlerMapping) *httptest.Server {
r := mux.NewRouter()

Expand Down
4 changes: 2 additions & 2 deletions src/common/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func GenerateRandomString() string {
// TestTCPConn tests TCP connection
// timeout: the total time before returning if something is wrong
// with the connection, in second
// interval: the interval time for retring after failure, in second
// interval: the interval time for retrying after failure, in second
func TestTCPConn(addr string, timeout, interval int) error {
success := make(chan int, 1)
cancel := make(chan int, 1)
Expand Down Expand Up @@ -176,7 +176,7 @@ func ParseProjectIDOrName(value interface{}) (int64, string, error) {
return id, name, nil
}

// SafeCastString -- cast a object to string saftely
// SafeCastString -- cast an object to string safely
func SafeCastString(value interface{}) string {
if result, ok := value.(string); ok {
return result
Expand Down
8 changes: 4 additions & 4 deletions src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ require (
github.com/vmihailenco/msgpack/v5 v5.4.1
github.com/volcengine/volcengine-go-sdk v1.0.138
go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.51.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0
go.opentelemetry.io/otel v1.29.0
go.opentelemetry.io/otel/exporters/jaeger v1.0.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0
go.opentelemetry.io/otel/sdk v1.27.0
go.opentelemetry.io/otel/trace v1.28.0
go.opentelemetry.io/otel/trace v1.29.0
go.uber.org/ratelimit v0.3.1
golang.org/x/crypto v0.25.0
golang.org/x/net v0.26.0
Expand Down Expand Up @@ -166,7 +166,7 @@ require (
github.com/volcengine/volc-sdk-golang v1.0.23 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
Expand Down
16 changes: 8 additions & 8 deletions src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -569,25 +569,25 @@ go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.51.0 h1:rXpHmgy1pMXlfv3W1T5ctoDA3QeTFjNq/YwCmwrfr8Q=
go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.51.0/go.mod h1:9uIRD3NZrM7QMQEGeKhr7V4xSDTMku3MPOVs8iZ3VVk=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 h1:TT4fX+nBOA/+LUkobKGW1ydGcn+G3vRw9+g5HwCphpk=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0/go.mod h1:L7UH0GbB0p47T4Rri3uHjbpCFYrVrwc1I25QhNPiGK8=
go.opentelemetry.io/otel v1.0.0/go.mod h1:AjRVh9A5/5DE7S+mZtTR6t8vpKKryam+0lREnfmS4cg=
go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw=
go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8=
go.opentelemetry.io/otel/exporters/jaeger v1.0.0 h1:cLhx8llHw02h5JTqGqaRbYn+QVKHmrzD9vEbKnSPk5U=
go.opentelemetry.io/otel/exporters/jaeger v1.0.0/go.mod h1:q10N1AolE1JjqKrFJK2tYw0iZpmX+HBaXBtuCzRnBGQ=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 h1:R9DE4kQ4k+YtfLI2ULwX82VtNQ2J8yZmA7ZIF/D+7Mc=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0/go.mod h1:OQFyQVrDlbe+R7xrEyDr/2Wr67Ol0hRUgsfA+V5A95s=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0 h1:QY7/0NeRPKlzusf40ZE4t1VlMKbqSNT7cJRYzWuja0s=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0/go.mod h1:HVkSiDhTM9BoUJU8qE6j2eSWLLXvi1USXjyd2BXT8PY=
go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q=
go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s=
go.opentelemetry.io/otel/metric v1.29.0 h1:vPf/HFWTNkPu1aYeIsc98l4ktOQaL6LeSoeV2g+8YLc=
go.opentelemetry.io/otel/metric v1.29.0/go.mod h1:auu/QWieFVWx+DmQOUMgj0F8LHWdgalxXqvp7BII/W8=
go.opentelemetry.io/otel/sdk v1.0.0/go.mod h1:PCrDHlSy5x1kjezSdL37PhbFUMjrsLRshJ2zCzeXwbM=
go.opentelemetry.io/otel/sdk v1.27.0 h1:mlk+/Y1gLPLn84U4tI8d3GNJmGT/eXe3ZuOXN9kTWmI=
go.opentelemetry.io/otel/sdk v1.27.0/go.mod h1:Ha9vbLwJE6W86YstIywK2xFfPjbWlCuwPtMkKdz/Y4A=
go.opentelemetry.io/otel/trace v1.0.0/go.mod h1:PXTWqayeFUlJV1YDNhsJYB184+IvAH814St6o6ajzIs=
go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g=
go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI=
go.opentelemetry.io/otel/trace v1.29.0 h1:J/8ZNK4XgR7a21DZUAsbF8pZ5Jcw1VhACmnYt39JTi4=
go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ=
go.opentelemetry.io/proto/otlp v1.2.0 h1:pVeZGk7nXDC9O2hncA6nHldxEjm6LByfA2aN8IOkz94=
go.opentelemetry.io/proto/otlp v1.2.0/go.mod h1:gGpR8txAl5M03pDhMC79G6SdqNV26naRm/KDsgaHD8A=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
Expand Down
9 changes: 3 additions & 6 deletions src/jobservice/job/impl/scandataexport/scan_data_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,17 @@ func (sde *ScanDataExport) updateExecAttributes(ctx job.Context, params job.Para
}

func (sde *ScanDataExport) writeCsvFile(ctx job.Context, params job.Parameters, fileName string) error {
logger := ctx.GetLogger()
csvFile, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, os.ModePerm)
if err != nil {
logger.Errorf("Failed to create CSV export file %s. Error : %v", fileName, err)
return err
}
systemContext := ctx.SystemContext()
defer csvFile.Close()

logger := ctx.GetLogger()
if err != nil {
logger.Errorf("Failed to create CSV export file %s. Error : %v", fileName, err)
return err
}
logger.Infof("Created CSV export file %s", csvFile.Name())

systemContext := ctx.SystemContext()
var exportParams export.Params
var artIDGroups [][]int64

Expand Down
29 changes: 29 additions & 0 deletions src/pkg/exporter/collector_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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 exporter

import (
"github.com/stretchr/testify/suite"
"testing"
)

func TestCollectorsTestSuite(t *testing.T) {
setupTest(t)
defer tearDownTest(t)
suite.Run(t, new(ProjectCollectorTestSuite))
suite.Run(t, &StatisticsCollectorTestSuite{
collector: NewStatisticsCollector(),
})
}
4 changes: 3 additions & 1 deletion src/pkg/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ func NewExporter(opt *Opt) *Exporter {
err := exporter.RegisterCollector(NewHealthCollect(hbrCli),
NewSystemInfoCollector(hbrCli),
NewProjectCollector(),
NewJobServiceCollector())
NewJobServiceCollector(),
NewStatisticsCollector(),
)
if err != nil {
log.Warningf("calling RegisterCollector() errored out, error: %v", err)
}
Expand Down
Loading

0 comments on commit 74c9085

Please sign in to comment.