2021-04-01 08:13:24 +03:00
|
|
|
package metadataobject
|
|
|
|
|
|
|
|
import (
|
2021-07-23 12:49:44 +03:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v2"
|
2021-04-01 08:13:24 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type Objects []Object
|
|
|
|
|
|
|
|
type Object interface {
|
2021-07-23 12:49:44 +03:00
|
|
|
Build(metadata *yaml.MapSlice) ErrParsingMetadataObject
|
|
|
|
Export(metadata yaml.MapSlice) (map[string][]byte, ErrParsingMetadataObject)
|
2021-04-01 08:13:24 +03:00
|
|
|
CreateFiles() error
|
2021-07-23 12:49:44 +03:00
|
|
|
Key() string
|
|
|
|
Filename() string
|
2021-04-01 08:13:24 +03:00
|
|
|
}
|
|
|
|
|
2021-07-23 12:49:44 +03:00
|
|
|
type ErrParsingMetadataObject interface {
|
|
|
|
// ObjectName corresponds to metadata object in JSON format
|
|
|
|
// eg: source, api_limits etc
|
|
|
|
ObjectName() string
|
|
|
|
// Filename corresponding to metadata object
|
|
|
|
// eg: databases.yaml, actions.yaml
|
|
|
|
Filename() string
|
|
|
|
// ErrorContext will contain any additional information regarding error
|
|
|
|
ErrorContext() string
|
|
|
|
|
|
|
|
Unwrap() error
|
|
|
|
error
|
|
|
|
}
|
2021-05-14 22:09:01 +03:00
|
|
|
|
2021-07-23 12:49:44 +03:00
|
|
|
func NewErrParsingMetadataObject(o Object, err error, context ...string) ErrParsingMetadataObject {
|
|
|
|
return &errParsingMetadataObjectFile{o.Key(), o.Filename(), context, err}
|
|
|
|
}
|
|
|
|
|
|
|
|
type errParsingMetadataObjectFile struct {
|
|
|
|
objectName string
|
|
|
|
fileName string
|
|
|
|
context []string
|
|
|
|
err error
|
|
|
|
}
|
2021-05-14 22:09:01 +03:00
|
|
|
|
2021-07-23 12:49:44 +03:00
|
|
|
func (e *errParsingMetadataObjectFile) ObjectName() string {
|
|
|
|
return e.objectName
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *errParsingMetadataObjectFile) Filename() string {
|
|
|
|
return e.fileName
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *errParsingMetadataObjectFile) ErrorContext() string {
|
|
|
|
if len(e.context) != 0 {
|
|
|
|
return fmt.Sprintf("context: %v\n", strings.Join(e.context, "\n"))
|
2021-04-01 08:13:24 +03:00
|
|
|
}
|
2021-07-23 12:49:44 +03:00
|
|
|
return ""
|
|
|
|
}
|
2021-04-01 08:13:24 +03:00
|
|
|
|
2021-07-23 12:49:44 +03:00
|
|
|
func (e *errParsingMetadataObjectFile) Error() string {
|
|
|
|
return strings.Trim(fmt.Sprintf(
|
|
|
|
"\nerror parsing metadata \nobject: %v\nfile: %v\nerror: %v\n%v",
|
|
|
|
e.ObjectName(),
|
|
|
|
e.Filename(),
|
|
|
|
e.err.Error(),
|
|
|
|
e.ErrorContext(),
|
|
|
|
), "\n")
|
2021-04-01 08:13:24 +03:00
|
|
|
}
|
2021-07-23 12:49:44 +03:00
|
|
|
|
|
|
|
func (e *errParsingMetadataObjectFile) Unwrap() error { return e.err }
|