github.com/versent/saml2aws@v2.17.0+incompatible/helper/credentials/credentials.go (about)

     1  package credentials
     2  
     3  import (
     4  	"errors"
     5  )
     6  
     7  var (
     8  	// CurrentHelper the currently configured credentials helper
     9  	CurrentHelper Helper = &defaultHelper{}
    10  
    11  	// ErrCredentialsNotFound returned when the credential can't be located in the native store.
    12  	ErrCredentialsNotFound = errors.New("credentials not found in native keychain")
    13  )
    14  
    15  // Credentials holds the information shared between saml2aws and the credentials store.
    16  type Credentials struct {
    17  	ServerURL string
    18  	Username  string
    19  	Secret    string
    20  }
    21  
    22  // CredsLabel saml2aws credentials should be labeled as such in credentials stores that allow labelling.
    23  // That label allows to filter out non-Docker credentials too at lookup/search in macOS keychain,
    24  // Windows credentials manager and Linux libsecret. Default value is "saml2aws Credentials"
    25  var CredsLabel = "saml2aws Credentials"
    26  
    27  // Helper is the interface a credentials store helper must implement.
    28  type Helper interface {
    29  	// Add appends credentials to the store.
    30  	Add(*Credentials) error
    31  	// Delete removes credentials from the store.
    32  	Delete(serverURL string) error
    33  	// Get retrieves credentials from the store.
    34  	// It returns username and secret as strings.
    35  	Get(serverURL string) (string, string, error)
    36  	// SupportsCredentialStorage returns true or false if there is credential storage.
    37  	SupportsCredentialStorage() bool
    38  }
    39  
    40  // IsErrCredentialsNotFound returns true if the error
    41  // was caused by not having a set of credentials in a store.
    42  func IsErrCredentialsNotFound(err error) bool {
    43  	return err == ErrCredentialsNotFound
    44  }
    45  
    46  type defaultHelper struct{}
    47  
    48  func (defaultHelper) Add(*Credentials) error {
    49  	return nil
    50  }
    51  
    52  func (defaultHelper) Delete(serverURL string) error {
    53  	return nil
    54  }
    55  
    56  func (defaultHelper) Get(serverURL string) (string, string, error) {
    57  	return "", "", ErrCredentialsNotFound
    58  }
    59  
    60  func (defaultHelper) SupportsCredentialStorage() bool {
    61  	return false
    62  }