(contextStore store.Reader, config map[string]string)
| 89 | } |
| 90 | |
| 91 | func getDockerEndpoint(contextStore store.Reader, config map[string]string) (docker.Endpoint, error) { |
| 92 | if err := validateConfig(config, allowedDockerConfigKeys); err != nil { |
| 93 | return docker.Endpoint{}, err |
| 94 | } |
| 95 | if contextName, ok := config[keyFrom]; ok { |
| 96 | metadata, err := contextStore.GetMetadata(contextName) |
| 97 | if err != nil { |
| 98 | return docker.Endpoint{}, err |
| 99 | } |
| 100 | if ep, ok := metadata.Endpoints[docker.DockerEndpoint].(docker.EndpointMeta); ok { |
| 101 | return docker.Endpoint{EndpointMeta: ep}, nil |
| 102 | } |
| 103 | return docker.Endpoint{}, fmt.Errorf("unable to get endpoint from context %q", contextName) |
| 104 | } |
| 105 | tlsData, err := context.TLSDataFromFiles(config[keyCA], config[keyCert], config[keyKey]) |
| 106 | if err != nil { |
| 107 | return docker.Endpoint{}, err |
| 108 | } |
| 109 | skipTLSVerify, err := parseBool(config, keySkipTLSVerify) |
| 110 | if err != nil { |
| 111 | return docker.Endpoint{}, err |
| 112 | } |
| 113 | ep := docker.Endpoint{ |
| 114 | EndpointMeta: docker.EndpointMeta{ |
| 115 | Host: config[keyHost], |
| 116 | SkipTLSVerify: skipTLSVerify, |
| 117 | }, |
| 118 | TLSData: tlsData, |
| 119 | } |
| 120 | // try to resolve a docker client, validating the configuration |
| 121 | opts, err := ep.ClientOpts() |
| 122 | if err != nil { |
| 123 | return docker.Endpoint{}, fmt.Errorf("invalid docker endpoint options: %w", err) |
| 124 | } |
| 125 | // FIXME(thaJeztah): this creates a new client (but discards it) only to validate the options; are the validation steps above not enough? |
| 126 | if _, err := client.New(opts...); err != nil { |
| 127 | return docker.Endpoint{}, fmt.Errorf("unable to apply docker endpoint options: %w", err) |
| 128 | } |
| 129 | return ep, nil |
| 130 | } |
| 131 | |
| 132 | func getDockerEndpointMetadataAndTLS(contextStore store.Reader, config map[string]string) (docker.EndpointMeta, *store.EndpointTLSData, error) { |
| 133 | ep, err := getDockerEndpoint(contextStore, config) |
no test coverage detected
searching dependent graphs…