NewResolver returns a new resolver to a Docker registry
(options ResolverOptions)
| 148 | |
| 149 | // NewResolver returns a new resolver to a Docker registry |
| 150 | func NewResolver(options ResolverOptions) remotes.Resolver { |
| 151 | if options.Tracker == nil { |
| 152 | options.Tracker = NewInMemoryTracker() |
| 153 | } |
| 154 | |
| 155 | if options.Headers == nil { |
| 156 | options.Headers = make(http.Header) |
| 157 | } else { |
| 158 | // make a copy of the headers to avoid race due to concurrent map write |
| 159 | options.Headers = options.Headers.Clone() |
| 160 | } |
| 161 | |
| 162 | resolveHeader := http.Header{} |
| 163 | if _, ok := options.Headers["Accept"]; !ok { |
| 164 | // set headers for all the types we support for resolution. |
| 165 | resolveHeader.Set("Accept", strings.Join([]string{ |
| 166 | images.MediaTypeDockerSchema2Manifest, |
| 167 | images.MediaTypeDockerSchema2ManifestList, |
| 168 | ocispec.MediaTypeImageManifest, |
| 169 | ocispec.MediaTypeImageIndex, "*/*", |
| 170 | }, ", ")) |
| 171 | } else { |
| 172 | resolveHeader["Accept"] = options.Headers["Accept"] |
| 173 | delete(options.Headers, "Accept") |
| 174 | } |
| 175 | |
| 176 | if options.Hosts == nil { |
| 177 | opts := []RegistryOpt{} |
| 178 | if options.Host != nil { |
| 179 | opts = append(opts, WithHostTranslator(options.Host)) |
| 180 | } |
| 181 | |
| 182 | if options.Authorizer == nil { |
| 183 | options.Authorizer = NewDockerAuthorizer( |
| 184 | WithAuthClient(options.Client), |
| 185 | WithAuthHeader(options.Headers), |
| 186 | WithAuthCreds(options.Credentials)) |
| 187 | } |
| 188 | opts = append(opts, WithAuthorizer(options.Authorizer)) |
| 189 | |
| 190 | if options.Client != nil { |
| 191 | opts = append(opts, WithClient(options.Client)) |
| 192 | } |
| 193 | if options.PlainHTTP { |
| 194 | opts = append(opts, WithPlainHTTP(MatchAllHosts)) |
| 195 | } else { |
| 196 | opts = append(opts, WithPlainHTTP(MatchLocalhost)) |
| 197 | } |
| 198 | options.Hosts = ConfigureDefaultRegistries(opts...) |
| 199 | } |
| 200 | return &dockerResolver{ |
| 201 | hosts: options.Hosts, |
| 202 | header: options.Headers, |
| 203 | resolveHeader: resolveHeader, |
| 204 | tracker: options.Tracker, |
| 205 | } |
| 206 | } |
| 207 |
searching dependent graphs…