newImageSourceAttempt is an internal helper for newImageSource. Everyone else must call newImageSource. Given a logicalReference and a pullSource, return a dockerImageSource if it is reachable. The caller must call .Close() on the returned ImageSource.
(ctx context.Context, sys *types.SystemContext, logicalRef dockerReference, pullSource sysregistriesv2.PullSource, registryConfig *registryConfiguration)
| 129 | // Given a logicalReference and a pullSource, return a dockerImageSource if it is reachable. |
| 130 | // The caller must call .Close() on the returned ImageSource. |
| 131 | func newImageSourceAttempt(ctx context.Context, sys *types.SystemContext, logicalRef dockerReference, pullSource sysregistriesv2.PullSource, |
| 132 | registryConfig *registryConfiguration) (*dockerImageSource, error) { |
| 133 | physicalRef, err := newReference(pullSource.Reference, false) |
| 134 | if err != nil { |
| 135 | return nil, err |
| 136 | } |
| 137 | |
| 138 | endpointSys := sys |
| 139 | // sys.DockerAuthConfig does not explicitly specify a registry; we must not blindly send the credentials intended for the primary endpoint to mirrors. |
| 140 | if endpointSys != nil && endpointSys.DockerAuthConfig != nil && reference.Domain(physicalRef.ref) != reference.Domain(logicalRef.ref) { |
| 141 | copy := *endpointSys |
| 142 | copy.DockerAuthConfig = nil |
| 143 | copy.DockerBearerRegistryToken = "" |
| 144 | endpointSys = © |
| 145 | } |
| 146 | |
| 147 | client, err := newDockerClientFromRef(endpointSys, physicalRef, registryConfig, false, "pull") |
| 148 | if err != nil { |
| 149 | return nil, err |
| 150 | } |
| 151 | client.tlsClientConfig.InsecureSkipVerify = pullSource.Endpoint.Insecure |
| 152 | |
| 153 | s := &dockerImageSource{ |
| 154 | PropertyMethodsInitialize: impl.PropertyMethods(impl.Properties{ |
| 155 | HasThreadSafeGetBlob: true, |
| 156 | }), |
| 157 | |
| 158 | logicalRef: logicalRef, |
| 159 | physicalRef: physicalRef, |
| 160 | c: client, |
| 161 | } |
| 162 | s.Compat = impl.AddCompat(s) |
| 163 | |
| 164 | if err := s.ensureManifestIsLoaded(ctx); err != nil { |
| 165 | client.Close() |
| 166 | return nil, err |
| 167 | } |
| 168 | |
| 169 | if h, err := sysregistriesv2.AdditionalLayerStoreAuthHelper(endpointSys); err == nil && h != "" { |
| 170 | acf := map[string]struct { |
| 171 | Username string `json:"username,omitempty"` |
| 172 | Password string `json:"password,omitempty"` |
| 173 | IdentityToken string `json:"identityToken,omitempty"` |
| 174 | }{ |
| 175 | physicalRef.ref.String(): { |
| 176 | Username: client.auth.Username, |
| 177 | Password: client.auth.Password, |
| 178 | IdentityToken: client.auth.IdentityToken, |
| 179 | }, |
| 180 | } |
| 181 | acfD, err := json.Marshal(acf) |
| 182 | if err != nil { |
| 183 | logrus.Warnf("failed to marshal auth config: %v", err) |
| 184 | } else { |
| 185 | cmd := exec.Command(h) |
| 186 | cmd.Stdin = bytes.NewReader(acfD) |
| 187 | if err := cmd.Run(); err != nil { |
| 188 | var stderr string |
no test coverage detected
searching dependent graphs…