1 /* 2 Copyright The ORAS Authors. 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 */ 15 16 package docker 17 18 import ( 19 "context" 20 21 "github.com/docker/cli/cli/config/configfile" 22 23 "oras.land/oras-go/pkg/auth" 24 ) 25 26 // Logout logs out from a docker registry identified by the hostname. 27 func (c *Client) Logout(_ context.Context, hostname string) error { 28 hostname = resolveHostname(hostname) 29 30 var configs []*configfile.ConfigFile 31 for _, config := range c.configs { 32 if _, ok := config.AuthConfigs[hostname]; ok { 33 configs = append(configs, config) 34 } 35 } 36 if len(configs) == 0 { 37 return auth.ErrNotLoggedIn 38 } 39 40 // Log out form the primary config only as backups are read-only. 41 return c.primaryCredentialsStore(hostname).Erase(hostname) 42 } 43