
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
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package document
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// ErrDocNotFound returned if desired document not found
|
|
type ErrDocNotFound struct {
|
|
Selector Selector
|
|
}
|
|
|
|
// ErrDocumentDataKeyNotFound returned if desired key within a document not found
|
|
type ErrDocumentDataKeyNotFound struct {
|
|
DocName string
|
|
Key string
|
|
}
|
|
|
|
// ErrDocumentMalformed returned if the document is structurally malformed
|
|
// (e.g. missing required low level keys)
|
|
type ErrDocumentMalformed struct {
|
|
DocName string
|
|
Message string
|
|
}
|
|
|
|
// ErrMultipleDocsFound returned if desired document not found
|
|
type ErrMultipleDocsFound struct {
|
|
Selector Selector
|
|
}
|
|
|
|
func (e ErrDocNotFound) Error() string {
|
|
return fmt.Sprintf("Document filtered by selector %q found no documents", e.Selector)
|
|
}
|
|
|
|
func (e ErrDocumentDataKeyNotFound) Error() string {
|
|
return fmt.Sprintf("Document %q cannot retrieve data key %q", e.DocName, e.Key)
|
|
}
|
|
|
|
func (e ErrDocumentMalformed) Error() string {
|
|
return fmt.Sprintf("Document %q is malformed: %q", e.DocName, e.Message)
|
|
}
|
|
|
|
func (e ErrMultipleDocsFound) Error() string {
|
|
return fmt.Sprintf("Document filtered by selector %q found more than one document", e.Selector)
|
|
}
|