Esempio n. 1
0
func getUserKey(user string, svc *iam.IAM, k []*iam.SSHPublicKeyMetadata) ([]string, error) {
	encoding := "SSH"
	publicKeys := []string{}
	for _, key := range k {
		kresp, err := svc.GetSSHPublicKey(&iam.GetSSHPublicKeyInput{
			Encoding:       aws.String(encoding),
			SSHPublicKeyId: key.SSHPublicKeyId,
			UserName:       aws.String(user),
		})
		log.Debug(fmt.Sprintf("Called AWS GetSSHPublicKey: user %v for %v using encoding %v", user, key.SSHPublicKeyId, encoding))
		if err != nil {
			return publicKeys, err
		}
		if *kresp.SSHPublicKey.Status == "Active" {
			log.Debug(fmt.Sprintf("Got active key from AWS %v", *kresp.SSHPublicKey.SSHPublicKeyBody))
			publicKeys = append(publicKeys, *kresp.SSHPublicKey.SSHPublicKeyBody)
		}
	}
	return publicKeys, nil
}