Skip to content

Commit b1ee48b

Browse files
authored
fix(cli): ensure entrypoint targets are valid (#142)
1 parent d8984ad commit b1ee48b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

cli/pkg/schema/validate.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (a *Application) IsValid(options ...ValidationOption) []gojsonschema.Result
4141
violations = append(violations, a.checkNoEnvVarCollisions()...)
4242
violations = append(violations, a.checkAccessPermissions()...)
4343
violations = append(violations, a.checkNoRedundantEntrypointRoutes()...)
44+
violations = append(violations, a.checkEntrypointTargetsExist()...)
4445

4546
if opts.RequireSubtypes {
4647
violations = append(violations, a.checkSubtypesRequired()...)
@@ -49,6 +50,30 @@ func (a *Application) IsValid(options ...ValidationOption) []gojsonschema.Result
4950
return violations
5051
}
5152

53+
func (a *Application) checkEntrypointTargetsExist() []gojsonschema.ResultError {
54+
violations := []gojsonschema.ResultError{}
55+
56+
for entrypointName, intent := range a.EntrypointIntents {
57+
for routePath, route := range intent.Routes {
58+
_, serviceExists := a.ServiceIntents[route.TargetName]
59+
_, bucketExists := a.BucketIntents[route.TargetName]
60+
_, resourceExists := a.GetResourceIntent(route.TargetName)
61+
62+
if !serviceExists && !bucketExists {
63+
key := fmt.Sprintf("entrypoints.%s.routes.%s.name", entrypointName, routePath)
64+
var err = fmt.Sprintf("Route %s targets non-existent resource %s", routePath, route.TargetName)
65+
if resourceExists {
66+
err = fmt.Sprintf("Route %s targets resource %s which is not a service or bucket", routePath, route.TargetName)
67+
}
68+
69+
violations = append(violations, newValidationError(key, err))
70+
}
71+
}
72+
}
73+
74+
return violations
75+
}
76+
5277
func (a *Application) checkAccessPermissions() []gojsonschema.ResultError {
5378
violations := []gojsonschema.ResultError{}
5479

0 commit comments

Comments
 (0)