mirror of
https://github.com/crazy-max/diun.git
synced 2026-01-04 03:55:00 +01:00
Set user agent for Docker registry client
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -20,14 +23,15 @@ import (
|
||||
|
||||
// Diun represents an active diun object
|
||||
type Diun struct {
|
||||
cfg *config.Config
|
||||
cron *cron.Cron
|
||||
db *db.Client
|
||||
notif *notif.Client
|
||||
jobID cron.EntryID
|
||||
locker uint32
|
||||
pool *ants.PoolWithFunc
|
||||
wg *sync.WaitGroup
|
||||
cfg *config.Config
|
||||
cron *cron.Cron
|
||||
db *db.Client
|
||||
notif *notif.Client
|
||||
userAgent string
|
||||
jobID cron.EntryID
|
||||
locker uint32
|
||||
pool *ants.PoolWithFunc
|
||||
wg *sync.WaitGroup
|
||||
}
|
||||
|
||||
// New creates new diun instance
|
||||
@@ -49,8 +53,9 @@ func New(cfg *config.Config, location *time.Location) (*Diun, error) {
|
||||
cron: cron.New(cron.WithLocation(location), cron.WithParser(cron.NewParser(
|
||||
cron.SecondOptional|cron.Minute|cron.Hour|cron.Dom|cron.Month|cron.Dow|cron.Descriptor),
|
||||
)),
|
||||
db: dbcli,
|
||||
notif: notifcli,
|
||||
db: dbcli,
|
||||
notif: notifcli,
|
||||
userAgent: fmt.Sprintf("diun/%s go/%s %s", cfg.App.Version, runtime.Version()[2:], strings.Title(runtime.GOOS)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ func (di *Diun) createJob(job model.Job) {
|
||||
Password: regPassword,
|
||||
Timeout: time.Duration(regOpts.Timeout) * time.Second,
|
||||
InsecureTLS: regOpts.InsecureTLS,
|
||||
UserAgent: di.userAgent,
|
||||
})
|
||||
if err != nil {
|
||||
sublog.Error().Err(err).Msg("Cannot create registry client")
|
||||
|
||||
@@ -24,6 +24,7 @@ type RegistryOptions struct {
|
||||
Password string
|
||||
InsecureTLS bool
|
||||
Timeout time.Duration
|
||||
UserAgent string
|
||||
}
|
||||
|
||||
// NewRegistryClient creates new docker registry client instance
|
||||
@@ -44,6 +45,7 @@ func NewRegistryClient(opts RegistryOptions) (*RegistryClient, error) {
|
||||
DockerAuthConfig: auth,
|
||||
DockerDaemonInsecureSkipTLSVerify: opts.InsecureTLS,
|
||||
DockerInsecureSkipTLSVerify: types.NewOptionalBool(opts.InsecureTLS),
|
||||
DockerRegistryUserAgent: opts.UserAgent,
|
||||
}
|
||||
|
||||
return &RegistryClient{
|
||||
|
||||
Reference in New Issue
Block a user