mirror of
https://github.com/Quiq/docker-registry-ui.git
synced 2025-07-17 15:51:27 +00:00
Add 'insecure' option to enforce use of HTTP protocol for registry requests (#78)
This commit is contained in:
parent
1af4694889
commit
6dc1408576
@ -21,6 +21,7 @@ performance:
|
|||||||
registry:
|
registry:
|
||||||
# Registry hostname (without protocol but may include port).
|
# Registry hostname (without protocol but may include port).
|
||||||
hostname: docker-registry.local
|
hostname: docker-registry.local
|
||||||
|
insecure: false
|
||||||
|
|
||||||
# Registry credentials.
|
# Registry credentials.
|
||||||
# They need to have a full access to the registry.
|
# They need to have a full access to the registry.
|
||||||
|
@ -27,6 +27,7 @@ type Client struct {
|
|||||||
tagCountsMux sync.Mutex
|
tagCountsMux sync.Mutex
|
||||||
tagCounts map[string]int
|
tagCounts map[string]int
|
||||||
isCatalogReady bool
|
isCatalogReady bool
|
||||||
|
nameOptions []name.Option
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImageInfo struct {
|
type ImageInfo struct {
|
||||||
@ -74,12 +75,19 @@ func NewClient() *Client {
|
|||||||
puller, _ := remote.NewPuller(authOpt, remote.WithUserAgent(userAgent), remote.WithPageSize(pageSize))
|
puller, _ := remote.NewPuller(authOpt, remote.WithUserAgent(userAgent), remote.WithPageSize(pageSize))
|
||||||
pusher, _ := remote.NewPusher(authOpt, remote.WithUserAgent(userAgent))
|
pusher, _ := remote.NewPusher(authOpt, remote.WithUserAgent(userAgent))
|
||||||
|
|
||||||
|
insecure := viper.GetBool("registry.insecure")
|
||||||
|
nameOptions := []name.Option{}
|
||||||
|
if insecure {
|
||||||
|
nameOptions = append(nameOptions, name.Insecure)
|
||||||
|
}
|
||||||
|
|
||||||
c := &Client{
|
c := &Client{
|
||||||
puller: puller,
|
puller: puller,
|
||||||
pusher: pusher,
|
pusher: pusher,
|
||||||
logger: SetupLogging("registry.client"),
|
logger: SetupLogging("registry.client"),
|
||||||
repos: []string{},
|
repos: []string{},
|
||||||
tagCounts: map[string]int{},
|
tagCounts: map[string]int{},
|
||||||
|
nameOptions: nameOptions,
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
@ -108,7 +116,7 @@ func (c *Client) RefreshCatalog() {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
c.logger.Info("[RefreshCatalog] Started reading catalog...")
|
c.logger.Info("[RefreshCatalog] Started reading catalog...")
|
||||||
registry, _ := name.NewRegistry(viper.GetString("registry.hostname"))
|
registry, _ := name.NewRegistry(viper.GetString("registry.hostname"), c.nameOptions...)
|
||||||
cat, err := c.puller.Catalogger(ctx, registry)
|
cat, err := c.puller.Catalogger(ctx, registry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Errorf("[RefreshCatalog] Error fetching catalog: %s", err)
|
c.logger.Errorf("[RefreshCatalog] Error fetching catalog: %s", err)
|
||||||
@ -156,7 +164,7 @@ func (c *Client) GetRepos() []string {
|
|||||||
// ListTags get tags for the repo
|
// ListTags get tags for the repo
|
||||||
func (c *Client) ListTags(repoName string) []string {
|
func (c *Client) ListTags(repoName string) []string {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
repo, _ := name.NewRepository(viper.GetString("registry.hostname") + "/" + repoName)
|
repo, _ := name.NewRepository(viper.GetString("registry.hostname")+"/"+repoName, c.nameOptions...)
|
||||||
tags, err := c.puller.List(ctx, repo)
|
tags, err := c.puller.List(ctx, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Errorf("Error listing tags for repo %s: %s", repoName, err)
|
c.logger.Errorf("Error listing tags for repo %s: %s", repoName, err)
|
||||||
@ -170,7 +178,7 @@ func (c *Client) ListTags(repoName string) []string {
|
|||||||
// GetImageInfo get image info by the reference - tag name or digest sha256.
|
// GetImageInfo get image info by the reference - tag name or digest sha256.
|
||||||
func (c *Client) GetImageInfo(imageRef string) (ImageInfo, error) {
|
func (c *Client) GetImageInfo(imageRef string) (ImageInfo, error) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ref, err := name.ParseReference(viper.GetString("registry.hostname") + "/" + imageRef)
|
ref, err := name.ParseReference(viper.GetString("registry.hostname")+"/"+imageRef, c.nameOptions...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Errorf("Error parsing image reference %s: %s", imageRef, err)
|
c.logger.Errorf("Error parsing image reference %s: %s", imageRef, err)
|
||||||
return ImageInfo{}, err
|
return ImageInfo{}, err
|
||||||
@ -252,7 +260,7 @@ func structToMap(obj interface{}) map[string]interface{} {
|
|||||||
func (c *Client) GetImageCreated(imageRef string) time.Time {
|
func (c *Client) GetImageCreated(imageRef string) time.Time {
|
||||||
zeroTime := new(time.Time)
|
zeroTime := new(time.Time)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ref, err := name.ParseReference(viper.GetString("registry.hostname") + "/" + imageRef)
|
ref, err := name.ParseReference(viper.GetString("registry.hostname")+"/"+imageRef, c.nameOptions...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Errorf("Error parsing image reference %s: %s", imageRef, err)
|
c.logger.Errorf("Error parsing image reference %s: %s", imageRef, err)
|
||||||
return *zeroTime
|
return *zeroTime
|
||||||
@ -310,7 +318,7 @@ func (c *Client) CountTags(interval int) {
|
|||||||
func (c *Client) DeleteTag(repoPath, tag string) {
|
func (c *Client) DeleteTag(repoPath, tag string) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
imageRef := repoPath + ":" + tag
|
imageRef := repoPath + ":" + tag
|
||||||
ref, err := name.ParseReference(viper.GetString("registry.hostname") + "/" + imageRef)
|
ref, err := name.ParseReference(viper.GetString("registry.hostname")+"/"+imageRef, c.nameOptions...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Errorf("Error parsing image reference %s: %s", imageRef, err)
|
c.logger.Errorf("Error parsing image reference %s: %s", imageRef, err)
|
||||||
return
|
return
|
||||||
@ -323,7 +331,7 @@ func (c *Client) DeleteTag(repoPath, tag string) {
|
|||||||
}
|
}
|
||||||
// Parse image reference by digest now
|
// Parse image reference by digest now
|
||||||
imageRefDigest := ref.Context().RepositoryStr() + "@" + descr.Digest.String()
|
imageRefDigest := ref.Context().RepositoryStr() + "@" + descr.Digest.String()
|
||||||
ref, err = name.ParseReference(viper.GetString("registry.hostname") + "/" + imageRefDigest)
|
ref, err = name.ParseReference(viper.GetString("registry.hostname")+"/"+imageRefDigest, c.nameOptions...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Errorf("Error parsing image reference %s: %s", imageRefDigest, err)
|
c.logger.Errorf("Error parsing image reference %s: %s", imageRefDigest, err)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user