ExtractClient returns the DockerClient set on the context. If one can't be found a default client is returned.
(ctx context.Context)
| 30 | // ExtractClient returns the DockerClient set on the context. If one can't be |
| 31 | // found a default client is returned. |
| 32 | func ExtractClient(ctx context.Context) (Client, error) { |
| 33 | client := ctx.Value(clientKey{}) |
| 34 | if client == nil { |
| 35 | client, err := dockerclient.NewClientWithOpts( |
| 36 | dockerclient.FromEnv, |
| 37 | dockerclient.WithAPIVersionNegotiation(), // use daemon's max API (e.g. 1.47) so we don't exceed it |
| 38 | ) |
| 39 | if err != nil { |
| 40 | return nil, xerrors.Errorf("new env client: %w", err) |
| 41 | } |
| 42 | |
| 43 | return client, nil |
| 44 | } |
| 45 | |
| 46 | //nolint we should panic if this isn't the case. |
| 47 | return client.(Client), nil |
| 48 | } |
| 49 | |
| 50 | type AuthConfig registry.AuthConfig |
| 51 |
no test coverage detected