mirror of
https://github.com/goharbor/harbor
synced 2025-04-17 01:33:58 +00:00
Fix typos in src/common (#20861)
Signed-off-by: BruceAko <chongzhi@hust.edu.cn>
This commit is contained in:
parent
146443e4d7
commit
234cd4ffc2
|
@ -116,9 +116,9 @@ func (b *BaseAPI) DecodeJSONReqAndValidate(v interface{}) (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect does redirection to resource URI with http header status code.
|
// 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
|
requestURI := b.Ctx.Request.RequestURI
|
||||||
resourceURI := requestURI + "/" + resouceID
|
resourceURI := requestURI + "/" + resourceID
|
||||||
|
|
||||||
b.Ctx.Redirect(statusCode, resourceURI)
|
b.Ctx.Redirect(statusCode, resourceURI)
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ func (b *BaseAPI) GetIDFromURL() (int64, error) {
|
||||||
return id, nil
|
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) {
|
func (b *BaseAPI) SetPaginationHeader(total, page, pageSize int64) {
|
||||||
b.Ctx.ResponseWriter.Header().Set("X-Total-Count", strconv.FormatInt(total, 10))
|
b.Ctx.ResponseWriter.Header().Set("X-Total-Count", strconv.FormatInt(total, 10))
|
||||||
|
|
||||||
|
|
|
@ -152,7 +152,7 @@ const (
|
||||||
OIDCCallbackPath = "/c/oidc/callback"
|
OIDCCallbackPath = "/c/oidc/callback"
|
||||||
OIDCLoginPath = "/c/oidc/login"
|
OIDCLoginPath = "/c/oidc/login"
|
||||||
|
|
||||||
AuthProxyRediretPath = "/c/authproxy/redirect"
|
AuthProxyRedirectPath = "/c/authproxy/redirect"
|
||||||
|
|
||||||
// Global notification enable configuration
|
// Global notification enable configuration
|
||||||
NotificationEnable = "notification_enable"
|
NotificationEnable = "notification_enable"
|
||||||
|
|
|
@ -48,7 +48,7 @@ func GetInternalCertPair() (tls.Certificate, error) {
|
||||||
|
|
||||||
// GetInternalTLSConfig return a tls.Config for internal https communicate
|
// GetInternalTLSConfig return a tls.Config for internal https communicate
|
||||||
func GetInternalTLSConfig() (*tls.Config, error) {
|
func GetInternalTLSConfig() (*tls.Config, error) {
|
||||||
// genrate key pair
|
// generate key pair
|
||||||
cert, err := GetInternalCertPair()
|
cert, err := GetInternalCertPair()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("internal TLS enabled but can't get cert file %w", err)
|
return nil, fmt.Errorf("internal TLS enabled but can't get cert file %w", err)
|
||||||
|
|
|
@ -151,7 +151,7 @@ func (d *DefaultClient) SubmitJob(jd *models.JobData) (string, error) {
|
||||||
return stats.Stats.JobID, nil
|
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) {
|
func (d *DefaultClient) GetJobLog(uuid string) ([]byte, error) {
|
||||||
url := d.endpoint + "/api/v1/jobs/" + uuid + "/log"
|
url := d.endpoint + "/api/v1/jobs/" + uuid + "/log"
|
||||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
|
|
|
@ -62,7 +62,7 @@ type StatsInfo struct {
|
||||||
UpstreamJobID string `json:"upstream_job_id,omitempty"` // Ref the upstream job if existing
|
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
|
NumericPID int64 `json:"numeric_policy_id,omitempty"` // The numeric policy ID of the periodic job
|
||||||
Parameters Parameters `json:"parameters,omitempty"`
|
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.
|
// JobPoolStats represents the healthy and status of all the running worker pools.
|
||||||
|
@ -70,7 +70,7 @@ type JobPoolStats struct {
|
||||||
Pools []*JobPoolStatsData `json:"worker_pools"`
|
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 {
|
type JobPoolStatsData struct {
|
||||||
WorkerPoolID string `json:"worker_pool_id"`
|
WorkerPoolID string `json:"worker_pool_id"`
|
||||||
StartedAt int64 `json:"started_at"`
|
StartedAt int64 `json:"started_at"`
|
||||||
|
|
|
@ -29,7 +29,7 @@ const (
|
||||||
JobCanceled string = "canceled"
|
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 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"
|
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"
|
JobContinue string = "_continue"
|
||||||
// JobScheduled ...
|
// JobScheduled ...
|
||||||
JobScheduled string = "scheduled"
|
JobScheduled string = "scheduled"
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
package models
|
package models
|
||||||
|
|
||||||
// UAASettings wraps the configuraations to access UAA service
|
// UAASettings wraps the configurations to access UAA service
|
||||||
type UAASettings struct {
|
type UAASettings struct {
|
||||||
Endpoint string
|
Endpoint string
|
||||||
ClientID string
|
ClientID string
|
||||||
|
|
|
@ -87,8 +87,8 @@ func TestProjectRoleAccess(t *testing.T) {
|
||||||
Username: "username",
|
Username: "username",
|
||||||
}
|
}
|
||||||
evaluator := NewEvaluator(ctl, NewBuilderForUser(user, ctl))
|
evaluator := NewEvaluator(ctl, NewBuilderForUser(user, ctl))
|
||||||
resorce := NewNamespace(public.ProjectID).Resource(rbac.ResourceRepository)
|
resource := NewNamespace(public.ProjectID).Resource(rbac.ResourceRepository)
|
||||||
assert.True(evaluator.HasPermission(context.TODO(), resorce, rbac.ActionPush))
|
assert.True(evaluator.HasPermission(context.TODO(), resource, rbac.ActionPush))
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -101,8 +101,8 @@ func TestProjectRoleAccess(t *testing.T) {
|
||||||
Username: "username",
|
Username: "username",
|
||||||
}
|
}
|
||||||
evaluator := NewEvaluator(ctl, NewBuilderForUser(user, ctl))
|
evaluator := NewEvaluator(ctl, NewBuilderForUser(user, ctl))
|
||||||
resorce := NewNamespace(public.ProjectID).Resource(rbac.ResourceRepository)
|
resource := NewNamespace(public.ProjectID).Resource(rbac.ResourceRepository)
|
||||||
assert.False(evaluator.HasPermission(context.TODO(), resorce, rbac.ActionPush))
|
assert.False(evaluator.HasPermission(context.TODO(), resource, rbac.ActionPush))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ import (
|
||||||
const HeaderPrefix = "Harbor-Secret "
|
const HeaderPrefix = "Harbor-Secret "
|
||||||
|
|
||||||
// FromRequest tries to get Harbor Secret from request header.
|
// 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 {
|
func FromRequest(req *http.Request) string {
|
||||||
if req == nil {
|
if req == nil {
|
||||||
return ""
|
return ""
|
||||||
|
|
|
@ -70,7 +70,7 @@ func Send(addr, identity, username, password string,
|
||||||
|
|
||||||
// Ping tests the connection and authentication with email server
|
// Ping tests the connection and authentication with email server
|
||||||
// If tls is true, a secure connection is established, or Ping
|
// 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.
|
// email server supports it.
|
||||||
// Ping doesn't verify the server's certificate and hostname when
|
// Ping doesn't verify the server's certificate and hostname when
|
||||||
// needed if the parameter insecure is ture
|
// needed if the parameter insecure is ture
|
||||||
|
@ -119,7 +119,7 @@ func newClient(addr, identity, username, password string,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to swith to SSL/TLS
|
// try to switch to SSL/TLS
|
||||||
if !tls {
|
if !tls {
|
||||||
if ok, _ := client.Extension("STARTTLS"); ok {
|
if ok, _ := client.Extension("STARTTLS"); ok {
|
||||||
log.Debugf("switching the connection with %s to SSL/TLS ...", addr)
|
log.Debugf("switching the connection with %s to SSL/TLS ...", addr)
|
||||||
|
|
|
@ -38,7 +38,7 @@ func TestSend(t *testing.T) {
|
||||||
err := Send(addr, identity, username, password,
|
err := Send(addr, identity, username, password,
|
||||||
timeout, tls, insecure, from, to,
|
timeout, tls, insecure, from, to,
|
||||||
subject, message)
|
subject, message)
|
||||||
// bypass the check due to securty policy change on gmail
|
// bypass the check due to security policy change on gmail
|
||||||
// TODO
|
// TODO
|
||||||
// assert.Nil(t, err)
|
// assert.Nil(t, err)
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ func TestPing(t *testing.T) {
|
||||||
// tls connection
|
// tls connection
|
||||||
err := Ping(addr, identity, username, password,
|
err := Ping(addr, identity, username, password,
|
||||||
timeout, tls, insecure)
|
timeout, tls, insecure)
|
||||||
// bypass the check due to securty policy change on gmail
|
// bypass the check due to security policy change on gmail
|
||||||
// TODO
|
// TODO
|
||||||
// assert.Nil(t, err)
|
// assert.Nil(t, err)
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,8 @@ var HashAlg = map[string]func() hash.Hash{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encrypt encrypts the content with salt
|
// Encrypt encrypts the content with salt
|
||||||
func Encrypt(content string, salt string, encrptAlg string) string {
|
func Encrypt(content string, salt string, encryptAlg string) string {
|
||||||
return fmt.Sprintf("%x", pbkdf2.Key([]byte(content), []byte(salt), 4096, 16, HashAlg[encrptAlg]))
|
return fmt.Sprintf("%x", pbkdf2.Key([]byte(content), []byte(salt), 4096, 16, HashAlg[encryptAlg]))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReversibleEncrypt encrypts the str with aes/base64
|
// ReversibleEncrypt encrypts the str with aes/base64
|
||||||
|
|
|
@ -72,7 +72,7 @@ func (p *passportsPool) Revoke() bool {
|
||||||
type LimitedConcurrentRunner interface {
|
type LimitedConcurrentRunner interface {
|
||||||
// AddTask adds a task to run
|
// AddTask adds a task to run
|
||||||
AddTask(task func() error)
|
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)
|
Wait() (err error)
|
||||||
// Cancel cancels all tasks, tasks that already started will continue to run
|
// Cancel cancels all tasks, tasks that already started will continue to run
|
||||||
Cancel(err error)
|
Cancel(err error)
|
||||||
|
@ -106,7 +106,7 @@ func (r *limitedConcurrentRunner) AddTask(task func() error) {
|
||||||
r.wg.Done()
|
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.
|
// For example, some crucial errors happened and all tasks should be cancelled.
|
||||||
if ok := r.passportsPool.Apply(); !ok {
|
if ok := r.passportsPool.Apply(); !ok {
|
||||||
return
|
return
|
||||||
|
|
|
@ -65,7 +65,7 @@ var defaultConfig = map[string]interface{}{
|
||||||
common.RobotNamePrefix: "robot$",
|
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{} {
|
func GetDefaultConfigMap() map[string]interface{} {
|
||||||
return defaultConfig
|
return defaultConfig
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,11 +55,11 @@ type Response struct {
|
||||||
StatusCode int
|
StatusCode int
|
||||||
// Headers are the headers of the response
|
// Headers are the headers of the response
|
||||||
Headers map[string]string
|
Headers map[string]string
|
||||||
// Boby is the body of the response
|
// Body is the body of the response
|
||||||
Body []byte
|
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
|
// the response provided
|
||||||
func Handler(resp *Response) func(http.ResponseWriter, *http.Request) {
|
func Handler(resp *Response) func(http.ResponseWriter, *http.Request) {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -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 {
|
func NewServer(mappings ...*RequestHandlerMapping) *httptest.Server {
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ func GenerateRandomString() string {
|
||||||
// TestTCPConn tests TCP connection
|
// TestTCPConn tests TCP connection
|
||||||
// timeout: the total time before returning if something is wrong
|
// timeout: the total time before returning if something is wrong
|
||||||
// with the connection, in second
|
// 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 {
|
func TestTCPConn(addr string, timeout, interval int) error {
|
||||||
success := make(chan int, 1)
|
success := make(chan int, 1)
|
||||||
cancel := make(chan int, 1)
|
cancel := make(chan int, 1)
|
||||||
|
@ -176,7 +176,7 @@ func ParseProjectIDOrName(value interface{}) (int64, string, error) {
|
||||||
return id, name, nil
|
return id, name, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SafeCastString -- cast a object to string saftely
|
// SafeCastString -- cast an object to string safely
|
||||||
func SafeCastString(value interface{}) string {
|
func SafeCastString(value interface{}) string {
|
||||||
if result, ok := value.(string); ok {
|
if result, ok := value.(string); ok {
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -42,7 +42,7 @@ func registerRoutes() {
|
||||||
web.Router(common.OIDCLoginPath, &controllers.OIDCController{}, "get:RedirectLogin")
|
web.Router(common.OIDCLoginPath, &controllers.OIDCController{}, "get:RedirectLogin")
|
||||||
web.Router("/c/oidc/onboard", &controllers.OIDCController{}, "post:Onboard")
|
web.Router("/c/oidc/onboard", &controllers.OIDCController{}, "post:Onboard")
|
||||||
web.Router(common.OIDCCallbackPath, &controllers.OIDCController{}, "get:Callback")
|
web.Router(common.OIDCCallbackPath, &controllers.OIDCController{}, "get:Callback")
|
||||||
web.Router(common.AuthProxyRediretPath, &controllers.AuthProxyController{}, "get:HandleRedirect")
|
web.Router(common.AuthProxyRedirectPath, &controllers.AuthProxyController{}, "get:HandleRedirect")
|
||||||
|
|
||||||
web.Router("/api/internal/renameadmin", &api.InternalAPI{}, "post:RenameAdmin")
|
web.Router("/api/internal/renameadmin", &api.InternalAPI{}, "post:RenameAdmin")
|
||||||
web.Router("/api/internal/syncquota", &api.InternalAPI{}, "post:SyncQuota")
|
web.Router("/api/internal/syncquota", &api.InternalAPI{}, "post:SyncQuota")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user