-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support new Nutanix-style credentials in "secretdir" (#34)
* Refactored Prism credential types and parsing into own package * Addressed PR feedback * Generated DeepCopy function to satisfy k8s Object interface ``` controller-gen object paths=./environment/credentials/types.go ``` * Made namespace optional in NutanixCredentialReference * Add kubebuilder validations for credential types (#35) Co-authored-by: Yannick Struyf <[email protected]>
- Loading branch information
1 parent
4b76a34
commit 99bc92c
Showing
8 changed files
with
331 additions
and
52 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,37 @@ | ||
package credentials | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/nutanix-cloud-native/prism-go-client/environment/types" | ||
) | ||
|
||
func ParseCredentials(credsData []byte) (*types.ApiCredentials, error) { | ||
creds := &NutanixCredentials{} | ||
err := json.Unmarshal(credsData, &creds.Credentials) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to unmarshal the credentials data. %w", err) | ||
} | ||
// TODO only single API endpoint supported | ||
for _, cred := range creds.Credentials { | ||
switch cred.Type { | ||
case BasicAuthCredentialType: | ||
basicAuthCreds := BasicAuthCredential{} | ||
if err := json.Unmarshal(cred.Data, &basicAuthCreds); err != nil { | ||
return nil, fmt.Errorf("failed to unmarshal the basic-auth data. %w", err) | ||
} | ||
pc := basicAuthCreds.PrismCentral | ||
if pc.Username == "" || pc.Password == "" { | ||
return nil, fmt.Errorf("the PrismCentral credentials data is not set") | ||
} | ||
return &types.ApiCredentials{ | ||
Username: pc.Username, | ||
Password: pc.Password, | ||
}, nil | ||
default: | ||
return nil, fmt.Errorf("unsupported credentials type: %v", cred.Type) | ||
} | ||
} | ||
return nil, fmt.Errorf("no Prism credentials") | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.