github.com/Axway/agent-sdk@v1.1.101/pkg/config/credentialconfig.go (about)

     1  package config
     2  
     3  import "errors"
     4  
     5  var supportedOAuthMethods = map[string]bool{
     6  	"oauth-secret":     true,
     7  	"oauth-public-key": true,
     8  }
     9  
    10  // SubscriptionConfig - Interface to get subscription config
    11  type CredentialConfig interface {
    12  	SetAllowedOAuthMethods(allowedMethods []string)
    13  	GetAllowedOAuthMethods() []string
    14  	ShouldDeprovisionExpired() bool
    15  	SetShouldDeprovisionExpired(deprovisionExpired bool)
    16  	GetExpirationDays() int
    17  	SetExpirationDays(expirationDays int)
    18  }
    19  
    20  // NotificationConfig -
    21  type CredentialConfiguration struct {
    22  	AllowedOAuthMethods []string `config:"allowedOAuthMethods"`
    23  	ExpirationDays      int      `config:"expirationDays"`
    24  	DeprovisionOnExpire bool     `config:"deprovisionOnExpire"`
    25  }
    26  
    27  // newCredentialConfig - Creates the default credential config
    28  func newCredentialConfig() CredentialConfig {
    29  	return &CredentialConfiguration{
    30  		AllowedOAuthMethods: make([]string, 0),
    31  		ExpirationDays:      0,
    32  		DeprovisionOnExpire: false,
    33  	}
    34  }
    35  
    36  // SetAllowedOAuthMethods -
    37  func (s *CredentialConfiguration) SetAllowedOAuthMethods(allowedOAuthMethods []string) {
    38  	s.AllowedOAuthMethods = allowedOAuthMethods
    39  }
    40  
    41  // GetAllowedOAuthMethods -
    42  func (s *CredentialConfiguration) GetAllowedOAuthMethods() []string {
    43  	return s.AllowedOAuthMethods
    44  }
    45  
    46  // ExpireAction -
    47  func (s *CredentialConfiguration) ShouldDeprovisionExpired() bool {
    48  	return s.DeprovisionOnExpire
    49  }
    50  
    51  // Set ExpireAction -
    52  func (s *CredentialConfiguration) SetShouldDeprovisionExpired(deprovisionExpired bool) {
    53  	s.DeprovisionOnExpire = deprovisionExpired
    54  }
    55  
    56  // GetTimeToLive -
    57  func (s *CredentialConfiguration) GetExpirationDays() int {
    58  	return s.ExpirationDays
    59  }
    60  
    61  // Set GetTimeToLive -
    62  func (s *CredentialConfiguration) SetExpirationDays(expirationDays int) {
    63  	s.ExpirationDays = expirationDays
    64  }
    65  
    66  // ValidateCfg - Validates the config, implementing IConfigInterface
    67  func (s *CredentialConfiguration) ValidateCfg() error {
    68  	for _, method := range s.AllowedOAuthMethods {
    69  		if _, ok := supportedOAuthMethods[method]; !ok {
    70  			return errors.New("credential type in allowed method configuration is not supported")
    71  		}
    72  	}
    73  	// TODO - validate time to live
    74  	return nil
    75  }