diff --git a/dev/managedservicesplatform/spec/spec.go b/dev/managedservicesplatform/spec/spec.go index bf991acca8c..e3fedc03407 100644 --- a/dev/managedservicesplatform/spec/spec.go +++ b/dev/managedservicesplatform/spec/spec.go @@ -61,7 +61,7 @@ func Open(specPath string) (*Spec, error) { } spec, err := parse(specData) if err != nil { - return nil, errors.Wrap(err, "spec.parse") + return spec, errors.Wrap(err, "spec.parse") } // Load extraneous resources @@ -134,7 +134,7 @@ func parse(data []byte) (*Spec, error) { } if validationErrs := s.Validate(); len(validationErrs) > 0 { - return nil, errors.Append(nil, validationErrs...) + return &s, errors.Append(nil, validationErrs...) } return &s, nil } diff --git a/dev/sg/msp/sg_msp.go b/dev/sg/msp/sg_msp.go index a1ff9959d75..aef70738052 100644 --- a/dev/sg/msp/sg_msp.go +++ b/dev/sg/msp/sg_msp.go @@ -1043,6 +1043,44 @@ This command supports completions on services and environments. }, }, }, + { + Name: "validate", + Usage: "Validate MSP configurations", + Before: msprepo.UseManagedServicesRepo, + Action: func(c *cli.Context) error { + services, err := msprepo.ListServices() + if err != nil { + return err + } + for _, svc := range services { + s, err := spec.Open(msprepo.ServiceYAMLPath(svc)) + // HACK: Check nil instead of error so that we can get the + // itemized list of errors instead with s.Validate() for + // validation errors. + if s == nil { + std.Out.WriteFailuref("[%s] Could not open spec: %s", svc, err.Error()) + continue + } + errs := s.Validate() + if len(errs) == 0 { + std.Out.WriteSuccessf("[%s] Validated", svc) + continue + } + + std.Out.WriteFailuref("[%s] Found valdiation errors", svc) + var messages []string + for _, err := range errs { + messages = append(messages, fmt.Sprintf("- %s", err.Error())) + } + if err := std.Out.WriteMarkdown(strings.Join(messages, "\n")); err != nil { + return err + } + } + + std.Out.Writef("Checked %d service specifications", len(services)) + return nil + }, + }, { Name: "fleet", Usage: "Summarize aspects of the MSP fleet",