2024-11-14 04:56:19 +00:00
|
|
|
// File Definition fetcher
|
|
|
|
//
|
|
|
|
// Handles extracting service definitions from local files.
|
|
|
|
|
|
|
|
package service_definition
|
|
|
|
|
|
|
|
import (
|
2024-11-14 04:59:55 +00:00
|
|
|
"fmt"
|
2024-11-14 04:56:19 +00:00
|
|
|
"github.com/goccy/go-yaml"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FileDefinitionFetcher struct{}
|
|
|
|
|
|
|
|
func NewFileDefinitionFetcher() *FileDefinitionFetcher {
|
|
|
|
return &FileDefinitionFetcher{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieves a service definition from the given filepath.
|
|
|
|
func (f FileDefinitionFetcher) GetDefinition(path string) (ServiceDefinition, error) {
|
|
|
|
var definition ServiceDefinition
|
|
|
|
|
|
|
|
defData, err := os.ReadFile(path)
|
|
|
|
|
|
|
|
if err != nil {
|
2024-11-14 04:59:55 +00:00
|
|
|
return ServiceDefinition{}, fmt.Errorf("Could not find service configuration file: %s", path)
|
2024-11-14 04:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err = yaml.Unmarshal(defData, &definition); err != nil {
|
2024-11-14 04:59:55 +00:00
|
|
|
return ServiceDefinition{}, fmt.Errorf("Service definition does not satisfy expected schema: %s", path)
|
2024-11-14 04:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return definition, nil
|
|
|
|
}
|