mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 15:51:43 +00:00
feat/sg/msp: add 'sg msp validate' for validating service specifications (#62973)
This commit is contained in:
parent
27f0d725ac
commit
9e4a8e8033
@ -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
|
||||
}
|
||||
|
||||
@ -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",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user