Skip to content

Commit 6f1fc44

Browse files
committed
fix(cli): Ensure entrypoint targets are valid
1 parent d8984ad commit 6f1fc44

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

cli/pkg/schema/validate.go

Lines changed: 26 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,31 @@ 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+
61+
_, resourceExists := a.GetResourceIntent(route.TargetName)
62+
63+
if !serviceExists && !bucketExists {
64+
key := fmt.Sprintf("entrypoints.%s.routes.%s.name", entrypointName, routePath)
65+
var err = fmt.Sprintf("Route %s targets non-existent resource %s", routePath, route.TargetName)
66+
if resourceExists {
67+
err = fmt.Sprintf("Route %s targets resource %s which is not a service or bucket", routePath, route.TargetName)
68+
}
69+
70+
violations = append(violations, newValidationError(key, err))
71+
}
72+
}
73+
}
74+
75+
return violations
76+
}
77+
5278
func (a *Application) checkAccessPermissions() []gojsonschema.ResultError {
5379
violations := []gojsonschema.ResultError{}
5480

0 commit comments

Comments
 (0)