Skip to content

Commit

Permalink
refactor: cri_server multiple versions of AuthConfig (labring#3507)
Browse files Browse the repository at this point in the history
  • Loading branch information
muicoder committed Jul 14, 2023
1 parent 98f6c0a commit e41feef
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ package server
import (
"context"

"github.com/labring/image-cri-shim/pkg/types"

types2 "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types"

"github.com/google/go-containerregistry/pkg/name"

Expand All @@ -32,8 +30,19 @@ import (

type v1ImageService struct {
imageClient api.ImageServiceClient
CRIConfigs map[string]types2.AuthConfig
OfflineCRIConfigs map[string]types2.AuthConfig
CRIConfigs map[string]types.AuthConfig
OfflineCRIConfigs map[string]types.AuthConfig
}

func ToV1AuthConfig(c *types.AuthConfig) *api.AuthConfig {
return &api.AuthConfig{
Username: c.Username,
Password: c.Password,
Auth: c.Auth,
ServerAddress: c.ServerAddress,
IdentityToken: c.IdentityToken,
RegistryToken: c.RegistryToken,
}
}

func (s *v1ImageService) ListImages(ctx context.Context,
Expand Down Expand Up @@ -73,12 +82,12 @@ func (s *v1ImageService) PullImage(ctx context.Context,
if req.Image != nil {
imageName, ok, auth := replaceImage(req.Image.Image, "PullImage", s.OfflineCRIConfigs)
if ok {
req.Auth = types.ToV1AuthConfig(auth)
req.Auth = ToV1AuthConfig(auth)
} else {
if req.Auth == nil {
ref, _ := name.ParseReference(imageName)
if v, ok := s.CRIConfigs[ref.Context().RegistryStr()]; ok {
req.Auth = types.ToV1AuthConfig(&v)
req.Auth = ToV1AuthConfig(&v)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"

"github.com/docker/docker/api/types"
types2 "github.com/labring/image-cri-shim/pkg/types"

"github.com/google/go-containerregistry/pkg/name"

Expand All @@ -35,6 +34,17 @@ type v1alpha2ImageService struct {
OfflineCRIConfigs map[string]types.AuthConfig
}

func ToV1Alpha2AuthConfig(c *types.AuthConfig) *api.AuthConfig {
return &api.AuthConfig{
Username: c.Username,
Password: c.Password,
Auth: c.Auth,
ServerAddress: c.ServerAddress,
IdentityToken: c.IdentityToken,
RegistryToken: c.RegistryToken,
}
}

func (s *v1alpha2ImageService) ListImages(ctx context.Context,
req *api.ListImagesRequest) (*api.ListImagesResponse, error) {
logger.Debug("ListImages: %+v", req)
Expand Down Expand Up @@ -75,12 +85,12 @@ func (s *v1alpha2ImageService) PullImage(ctx context.Context,
if req.Image != nil {
imageName, ok, auth := replaceImage(req.Image.Image, "PullImage", s.OfflineCRIConfigs)
if ok {
req.Auth = types2.ToV1Alpha2AuthConfig(auth)
req.Auth = ToV1Alpha2AuthConfig(auth)
} else {
if req.Auth == nil {
ref, _ := name.ParseReference(imageName)
if v, ok := s.CRIConfigs[ref.Context().RegistryStr()]; ok {
req.Auth = types2.ToV1Alpha2AuthConfig(&v)
req.Auth = ToV1Alpha2AuthConfig(&v)
}
}
}
Expand Down
45 changes: 0 additions & 45 deletions staging/src/github.com/labring/image-cri-shim/pkg/types/auth.go

This file was deleted.

0 comments on commit e41feef

Please sign in to comment.