Skip to content

Commit 3a85dc6

Browse files
committed
Pass context
Signed-off-by: David Gageot <david.gageot@docker.com>
1 parent bc553fe commit 3a85dc6

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

pkg/model/provider/dmr/client.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type Client struct {
2929
}
3030

3131
// NewClient creates a new DMR client from the provided configuration
32-
func NewClient(_ context.Context, cfg *latest.ModelConfig, opts ...options.Opt) (*Client, error) {
32+
func NewClient(ctx context.Context, cfg *latest.ModelConfig, opts ...options.Opt) (*Client, error) {
3333
if cfg == nil {
3434
slog.Error("DMR client creation failed", "error", "model configuration is required")
3535
return nil, errors.New("model configuration is required")
@@ -48,7 +48,7 @@ func NewClient(_ context.Context, cfg *latest.ModelConfig, opts ...options.Opt)
4848
// Resolve base_url for DMR models. If not provided, configure with the docker model plugin, else fallback.
4949
baseURL := cfg.BaseURL
5050
if baseURL == "" {
51-
endpoint, engine, err := getDockerModelEndpointAndEngine()
51+
endpoint, engine, err := getDockerModelEndpointAndEngine(ctx)
5252
if err != nil {
5353
slog.Debug("docker model status query failed", "error", err)
5454
}
@@ -61,7 +61,7 @@ func NewClient(_ context.Context, cfg *latest.ModelConfig, opts ...options.Opt)
6161
slog.Warn(w)
6262
}
6363
slog.Debug("DMR provider_opts parsed", "model", cfg.Model, "context_size", contextSize, "runtime_flags", finalFlags, "engine", engine)
64-
if err := configureDockerModel(cfg.Model, contextSize, finalFlags); err != nil {
64+
if err := configureDockerModel(ctx, cfg.Model, contextSize, finalFlags); err != nil {
6565
slog.Debug("docker model configure skipped or failed", "error", err)
6666
}
6767

@@ -464,10 +464,10 @@ func parseDMRProviderOpts(cfg *latest.ModelConfig) (contextSize int, runtimeFlag
464464
return contextSize, runtimeFlags
465465
}
466466

467-
func configureDockerModel(model string, contextSize int, runtimeFlags []string) error {
467+
func configureDockerModel(ctx context.Context, model string, contextSize int, runtimeFlags []string) error {
468468
args := buildDockerModelConfigureArgs(model, contextSize, runtimeFlags)
469469

470-
cmd := exec.Command("docker", args...)
470+
cmd := exec.CommandContext(ctx, "docker", args...)
471471
slog.Debug("Running docker model configure", "model", model, "args", args)
472472
var stdout, stderr bytes.Buffer
473473
cmd.Stdout = &stdout
@@ -494,8 +494,8 @@ func buildDockerModelConfigureArgs(model string, contextSize int, runtimeFlags [
494494
return args
495495
}
496496

497-
func getDockerModelEndpointAndEngine() (endpoint, engine string, err error) {
498-
cmd := exec.Command("docker", "model", "status", "--json")
497+
func getDockerModelEndpointAndEngine(ctx context.Context) (endpoint, engine string, err error) {
498+
cmd := exec.CommandContext(ctx, "docker", "model", "status", "--json")
499499
var stdout, stderr bytes.Buffer
500500
cmd.Stdout = &stdout
501501
cmd.Stderr = &stderr

pkg/oauth/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (m *manager) performOAuthAuthorization(ctx context.Context, sessionID strin
121121

122122
// Open the browser to the authorization URL
123123
slog.Info("Opening browser for OAuth authorization", "url", authURL)
124-
err = OpenBrowser(authURL)
124+
err = OpenBrowser(ctx, authURL)
125125
if err != nil {
126126
slog.Warn("Failed to open browser automatically", "error", err, "url", authURL)
127127
}

pkg/oauth/utils.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package oauth
22

33
import (
4+
"context"
45
"crypto/rand"
56
"encoding/base64"
67
"encoding/json"
@@ -190,7 +191,7 @@ func ValidateAndSanitizeURL(rawURL string) (string, error) {
190191
// - URL validation and sanitization using ValidateAndSanitizeURL
191192
// - Logging of security events (blocked URLs, successful opens)
192193
// - Maintains backward compatibility for legitimate OAuth URLs
193-
func OpenBrowser(urlToOpen string) error {
194+
func OpenBrowser(ctx context.Context, urlToOpen string) error {
194195
// Validate and sanitize the URL before opening
195196
validatedURL, err := ValidateAndSanitizeURL(urlToOpen)
196197
if err != nil {
@@ -217,7 +218,7 @@ func OpenBrowser(urlToOpen string) error {
217218

218219
slog.Info("Opening browser with validated URL", "url", validatedURL, "platform", runtime.GOOS)
219220

220-
err = exec.Command(cmd, args...).Start()
221+
err = exec.CommandContext(ctx, cmd, args...).Start()
221222
if err != nil {
222223
slog.Error("Failed to execute browser command", "cmd", cmd, "args", args, "error", err)
223224
return fmt.Errorf("failed to open browser: %w", err)

0 commit comments

Comments
 (0)