MCPcopy Index your code
hub / github.com/docker/docker-agent / Load

Function Load

pkg/config/config.go:23–72  ·  view source on GitHub ↗
(ctx context.Context, source Source)

Source from the content-addressed store, hash-verified

21)
22
23func Load(ctx context.Context, source Source) (*latest.Config, error) {
24 data, err := source.Read(ctx)
25 if err != nil {
26 return nil, err
27 }
28
29 // Configurations may be authored in HCL as an alternative to YAML.
30 // Detect the format from the source name extension or, when no hint is
31 // available (OCI artifacts, etc.), from the content itself, then
32 // transparently convert to YAML for the rest of the pipeline.
33 if isHCLSource(source.Name(), data) {
34 data, err = hclconv.ToYAML(data, source.Name())
35 if err != nil {
36 return nil, fmt.Errorf("parsing HCL config file: %w", err)
37 }
38 }
39
40 var raw struct {
41 Version string `yaml:"version,omitempty"`
42 }
43 if err := yaml.Unmarshal(data, &raw); err != nil {
44 return nil, fmt.Errorf("looking for version in config file\n%s", yaml.FormatError(err, true, true))
45 }
46 raw.Version = cmp.Or(raw.Version, latest.Version)
47
48 oldConfig, err := parseCurrentVersion(data, raw.Version)
49 if err != nil {
50 return nil, fmt.Errorf("parsing config file\n%s", yaml.FormatError(err, true, true))
51 }
52
53 config, err := migrateToLatestConfig(oldConfig, data)
54 if err != nil {
55 return nil, fmt.Errorf("migrating config: %w", err)
56 }
57
58 config.Version = raw.Version
59
60 if err := resolveInstructionFiles(&config, source); err != nil {
61 return nil, err
62 }
63
64 if err := validateConfig(&config); err != nil {
65 return nil, err
66 }
67
68 warnExpansionMismatches(ctx, slog.Default(), &config)
69 warnMaxTokensVsContextWindow(ctx, slog.Default(), &config)
70
71 return &config, nil
72}
73
74// resolveInstructionFiles replaces every agent's instruction_file reference
75// with the file's contents, loaded relative to the config file's directory.

Callers 15

gatherAgentEnvVarsFunction · 0.92
loadConfigFunction · 0.92
PackageFileAsOCIToStoreFunction · 0.92
getAgentsMethod · 0.92
getAgentConfigMethod · 0.92
LoadWithConfigFunction · 0.92
gatherExampleEnvVarsFunction · 0.92
parseConfigJSFunction · 0.92
listAgentsJSFunction · 0.92

Calls 9

isHCLSourceFunction · 0.85
parseCurrentVersionFunction · 0.85
migrateToLatestConfigFunction · 0.85
resolveInstructionFilesFunction · 0.85
warnExpansionMismatchesFunction · 0.85
validateConfigFunction · 0.70
ReadMethod · 0.65
NameMethod · 0.65