-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Julien Duchesne
committed
Jun 24, 2019
1 parent
fa4ba0e
commit f7ac876
Showing
5 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package credentials | ||
|
||
import ( | ||
"fmt" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// SecretTextCredentials represents credentials composed of a single string value | ||
type AmazonWebServicesCredentials struct { | ||
Base `mapstructure:",squash"` | ||
AccessKey string `mapstructure:"access_key"` | ||
SecretKey string `mapstructure:"secret_key"` | ||
RoleARN string `mapstructure:"role_arn"` | ||
MFASerialNumber string `mapstructure:"mfa_serial"` | ||
} | ||
|
||
// NewSecretText instantiates a SecretTextCredentials struct | ||
func NewAmazonWebServicesCredentials() *AmazonWebServicesCredentials { | ||
cred := &AmazonWebServicesCredentials{} | ||
cred.CredType = "Amazon Web Services" | ||
return cred | ||
} | ||
|
||
// ToString prints out the content of a SecretTextCredentials struct. | ||
// If showSensitive is true, the secret text will be shown | ||
func (cred *AmazonWebServicesCredentials) ToString(showSensitive bool) string { | ||
secretKey := "********" | ||
if showSensitive { | ||
secretKey = cred.SecretKey | ||
} | ||
return fmt.Sprintf("%s - %s:%s", cred.BaseToString(), cred.AccessKey, secretKey) | ||
} | ||
|
||
// Validate verifies that the credentials is valid. | ||
// A SecretTextCredentials is always considered valid, as empty values are accepted. | ||
func (cred *AmazonWebServicesCredentials) Validate() bool { | ||
if cred.AccessKey == "" { | ||
log.Errorf("The credentials with ID %s does not define an access key", cred.ID) | ||
return false | ||
} | ||
if cred.SecretKey == "" { | ||
log.Errorf("The credentials with ID %s does not define an secret key", cred.ID) | ||
return false | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters