forked from encoredev/encore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate_config.go
41 lines (37 loc) · 1.02 KB
/
validate_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package app
import (
"encr.dev/pkg/errors"
"encr.dev/v2/internals/parsectx"
"encr.dev/v2/parser"
"encr.dev/v2/parser/infra/config"
)
func (d *Desc) validateConfigs(pc *parsectx.Context, result *parser.Result) {
// validate all config loads
for _, res := range result.Resources() {
switch res := res.(type) {
case *config.Load:
d.validateConfig(pc, result, res)
}
}
}
func (d *Desc) validateConfig(pc *parsectx.Context, result *parser.Result, cfg *config.Load) {
// Verify the config
svc, ok := d.ServiceForPath(cfg.File.FSPath)
if !ok {
pc.Errs.Add(config.ErrConfigUsedOutsideOfService.AtGoNode(cfg))
return
}
if svc.FSRoot != cfg.File.Pkg.FSPath {
pc.Errs.Add(config.ErrConfigUsedInSubPackage.AtGoNode(cfg))
}
// Verify usages are in the same service
for _, use := range result.Usages(cfg) {
if !use.DeclaredIn().FSPath.HasPrefix(svc.FSRoot) {
pc.Errs.Add(
config.ErrCrossServiceConfigUse.
AtGoNode(use, errors.AsError("used here")).
AtGoNode(cfg, errors.AsHelp("defined here")),
)
}
}
}