Skip to content

Commit

Permalink
fix private key auth (#2170)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-swinkler authored Nov 3, 2023
1 parent ee0f6af commit 01a774c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,11 @@ func ConfigureProvider(s *schema.ResourceData) (interface{}, error) {
privateKeyPath := s.Get("private_key_path").(string)
privateKey := s.Get("private_key").(string)
privateKeyPassphrase := s.Get("private_key_passphrase").(string)
if v, err := getPrivateKey(privateKeyPath, privateKey, privateKeyPassphrase); err != nil && v != nil {
v, err := getPrivateKey(privateKeyPath, privateKey, privateKeyPassphrase)
if err != nil {
return nil, fmt.Errorf("could not retrieve private key: %w", err)
}
if v != nil {
config.PrivateKey = v
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/provider/provider_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func mergeSchemas(schemaCollections ...map[string]*schema.Resource) map[string]*
}

func getPrivateKey(privateKeyPath, privateKeyString, privateKeyPassphrase string) (*rsa.PrivateKey, error) {
if privateKeyPath == "" && privateKeyString == "" {
return nil, nil
}
privateKeyBytes := []byte(privateKeyString)
var err error
if len(privateKeyBytes) == 0 && privateKeyPath != "" {
Expand Down

0 comments on commit 01a774c

Please sign in to comment.