func computeAwsKeyFingerprint(publicKey *fi.ResourceHolder) (string, error) { publicKeyString, err := publicKey.AsString() if err != nil { return "", fmt.Errorf("error reading SSH public key: %v", err) } tokens := strings.Split(publicKeyString, " ") if len(tokens) < 2 { return "", fmt.Errorf("error parsing SSH public key: %s", publicKeyString) } sshPublicKeyBytes, err := base64.StdEncoding.DecodeString(tokens[1]) if len(tokens) < 2 { return "", fmt.Errorf("error decoding SSH public key: %s", publicKeyString) } sshPublicKey, err := ssh.ParsePublicKey(sshPublicKeyBytes) if err != nil { return "", fmt.Errorf("error parsing SSH public key: %v", err) } der, err := toDER(sshPublicKey) if err != nil { return "", fmt.Errorf("error computing fingerprint for SSH public key: %v", err) } h := md5.Sum(der) sshKeyFingerprint := fmt.Sprintf("%x", h) var colonSeparated bytes.Buffer for i := 0; i < len(sshKeyFingerprint); i++ { if (i%2) == 0 && i != 0 { colonSeparated.WriteByte(':') } colonSeparated.WriteByte(sshKeyFingerprint[i]) } return colonSeparated.String(), nil }
func (l *Loader) populateResource(rh *fi.ResourceHolder, resource fi.Resource, args []string) error { if resource == nil { return nil } if len(args) != 0 { templateResource, ok := resource.(fi.TemplateResource) if !ok { return fmt.Errorf("cannot have arguments with resources of type %T", resource) } resource = templateResource.Curry(args) } rh.Resource = resource return nil }