...

Source file src/github.com/google/go-containerregistry/pkg/authn/multikeychain.go

Documentation: github.com/google/go-containerregistry/pkg/authn

     1  // Copyright 2018 Google LLC All Rights Reserved.
     2  //
     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  package authn
    16  
    17  type multiKeychain struct {
    18  	keychains []Keychain
    19  }
    20  
    21  // Assert that our multi-keychain implements Keychain.
    22  var _ (Keychain) = (*multiKeychain)(nil)
    23  
    24  // NewMultiKeychain composes a list of keychains into one new keychain.
    25  func NewMultiKeychain(kcs ...Keychain) Keychain {
    26  	return &multiKeychain{keychains: kcs}
    27  }
    28  
    29  // Resolve implements Keychain.
    30  func (mk *multiKeychain) Resolve(target Resource) (Authenticator, error) {
    31  	for _, kc := range mk.keychains {
    32  		auth, err := kc.Resolve(target)
    33  		if err != nil {
    34  			return nil, err
    35  		}
    36  		if auth != Anonymous {
    37  			return auth, nil
    38  		}
    39  	}
    40  	return Anonymous, nil
    41  }
    42  

View as plain text