Skip to content

Commit 09ca0ec

Browse files
authored
feat: Support Private Docker Registries (#248)
<!-- Explain what problem this PR addresses --> ---
1 parent a6de6db commit 09ca0ec

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

managedplugin/docker.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func isDockerImageAvailable(ctx context.Context, imageName string) (bool, error)
8989
return len(images) > 0, nil
9090
}
9191

92-
func pullDockerImage(ctx context.Context, imageName string, authToken string, teamName string) error {
92+
func pullDockerImage(ctx context.Context, imageName string, authToken string, teamName string, dockerHubAuth string) error {
9393
// Pull the image
9494
additionalHeaders := make(map[string]string)
9595
opts := types.ImagePullOptions{}
@@ -119,6 +119,8 @@ func pullDockerImage(ctx context.Context, imageName string, authToken string, te
119119
return fmt.Errorf("failed to encode Docker auth config: %v", err)
120120
}
121121
opts.RegistryAuth = encodedAuth
122+
} else if dockerHubAuth != "" {
123+
opts.RegistryAuth = dockerHubAuth
122124
}
123125

124126
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithHTTPHeaders(additionalHeaders))

managedplugin/hub.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func getHubClient(logger zerolog.Logger, ops HubDownloadOptions) (*cloudquery_api.ClientWithResponses, error) {
1313
c, err := cloudquery_api.NewClientWithResponses(APIBaseURL(),
14-
cloudquery_api.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error {
14+
cloudquery_api.WithRequestEditorFn(func(_ context.Context, req *http.Request) error {
1515
if ops.AuthToken != "" {
1616
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", ops.AuthToken))
1717
}

managedplugin/plugin.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type Config struct {
7575
Path string
7676
Version string
7777
Environment []string // environment variables to pass to the plugin in key=value format
78+
DockerAuth string
7879
}
7980

8081
type Client struct {
@@ -98,6 +99,7 @@ type Client struct {
9899
authToken string
99100
teamName string
100101
licenseFile string
102+
dockerAuth string
101103
}
102104

103105
// typ will be deprecated soon but now required for a transition period
@@ -144,6 +146,7 @@ func NewClient(ctx context.Context, typ PluginType, config Config, opts ...Optio
144146
metrics: &Metrics{},
145147
registry: config.Registry,
146148
cqDockerHost: DefaultCloudQueryDockerHost,
149+
dockerAuth: config.DockerAuth,
147150
}
148151
for _, opt := range opts {
149152
opt(c)
@@ -179,7 +182,7 @@ func (c *Client) downloadPlugin(ctx context.Context, typ PluginType) error {
179182
if imageAvailable, err := isDockerImageAvailable(ctx, c.config.Path); err != nil {
180183
return err
181184
} else if !imageAvailable {
182-
return pullDockerImage(ctx, c.config.Path, c.authToken, c.teamName)
185+
return pullDockerImage(ctx, c.config.Path, c.authToken, c.teamName, c.dockerAuth)
183186
}
184187
return nil
185188
case RegistryCloudQuery:
@@ -215,7 +218,7 @@ func (c *Client) downloadPlugin(ctx context.Context, typ PluginType) error {
215218
if imageAvailable, err := isDockerImageAvailable(ctx, path); err != nil {
216219
return err
217220
} else if !imageAvailable {
218-
return pullDockerImage(ctx, path, c.authToken, c.teamName)
221+
return pullDockerImage(ctx, path, c.authToken, c.teamName, "")
219222
}
220223
return nil
221224
}
@@ -269,6 +272,7 @@ func (c *Client) startDockerPlugin(ctx context.Context, configPath string) error
269272
if err != nil {
270273
return fmt.Errorf("failed to create Docker client: %w", err)
271274
}
275+
cli.NegotiateAPIVersion(ctx)
272276
pluginArgs := c.getPluginArgs()
273277
config := &container.Config{
274278
ExposedPorts: nat.PortSet{

0 commit comments

Comments
 (0)