github.com/containerd/nerdctl/v2@v2.0.0-beta.5.0.20240520001846-b5758f54fa28/pkg/imgutil/dockerconfigresolver/dockerconfigresolver_util.go (about) 1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 /* 18 Portions from https://github.com/moby/moby/blob/v20.10.18/registry/auth.go#L154-L167 19 Copyright (C) Docker/Moby authors. 20 Licensed under the Apache License, Version 2.0 21 NOTICE: https://github.com/moby/moby/blob/v20.10.18/NOTICE 22 */ 23 24 package dockerconfigresolver 25 26 import ( 27 "strings" 28 ) 29 30 // IndexServer is used for user auth and image search 31 // 32 // From https://github.com/moby/moby/blob/v20.10.18/registry/config.go#L36-L39 33 const IndexServer = "https://index.docker.io/v1/" 34 35 // ConvertToHostname converts a registry url which has http|https prepended 36 // to just an hostname. 37 // 38 // From https://github.com/moby/moby/blob/v20.10.18/registry/auth.go#L154-L167 39 func ConvertToHostname(url string) string { 40 stripped := url 41 if strings.HasPrefix(url, "http://") { 42 stripped = strings.TrimPrefix(url, "http://") 43 } else if strings.HasPrefix(url, "https://") { 44 stripped = strings.TrimPrefix(url, "https://") 45 } 46 47 nameParts := strings.SplitN(stripped, "/", 2) 48 49 return nameParts[0] 50 }