airshipctl/pkg/document/dochelper_baremetalhost.go
Alan Meadows e2cca32748 Add Redfish Authentication Support
This commit also introduces a dochelper concept.  This provides
some convenience methods to the document pkg that help extract data
from known document types as well as walk document relationships to
discover related information such as BMC credentials for baremetal
hosts.

Once merged, a follow up patchset will leverage these within the
cloud-init code to deduplicate some of these lookups.

Change-Id: Ie6a770ce4b34adbea30281917f0cb2fdc460b4fb
2020-03-27 15:29:07 -07:00

61 lines
1.6 KiB
Go

package document
// GetBMHNetworkData retrieves the associated network data string
// for the bmh document supplied from the bundle supplied
func GetBMHNetworkData(bmh Document, bundle Bundle) (string, error) {
// try and find these documents in our bundle
selector, err := NewNetworkDataSelector(bmh)
if err != nil {
return "", err
}
doc, err := bundle.SelectOne(selector)
if err != nil {
return "", err
}
networkData, err := GetSecretDataKey(doc, "networkData")
if err != nil {
return "", err
}
return networkData, nil
}
// GetBMHBMCAddress returns the bmc address for a particular the document supplied
func GetBMHBMCAddress(bmh Document) (string, error) {
bmcAddress, err := bmh.GetString("spec.bmc.address")
if err != nil {
return "", err
}
return bmcAddress, nil
}
// GetBMHBMCCredentials returns the BMC credentials for the bmh document supplied from
// the supplied bundle
func GetBMHBMCCredentials(bmh Document, bundle Bundle) (username string, password string, err error) {
// extract the secret document name
bmcCredentialsName, err := bmh.GetString("spec.bmc.credentialsName")
if err != nil {
return "", "", err
}
// find the secret within the bundle supplied
selector := NewBMCCredentialsSelector(bmcCredentialsName)
doc, err := bundle.SelectOne(selector)
if err != nil {
return "", "", err
}
username, err = GetSecretDataKey(doc, "username")
if err != nil {
return "", "", err
}
password, err = GetSecretDataKey(doc, "password")
if err != nil {
return "", "", err
}
// extract the username and password from them
return username, password, nil
}