chore(pkger): refactor influx pkg cmd to not validate in CLI and have server validate
the pkger.ValidSkipParseError option allows our server to be the one to validate the the pkg is accurate. If a user has an older version of the UI and our cloud gets updated with new validation rules,they'll get immediate access to that change without having to rol their CLI build. also fixes issue where we swallow initial errors when check setup middleware fails.pull/17419/head
parent
9ce2af7fdf
commit
7d8bd1e055
|
@ -327,6 +327,7 @@ func checkSetupRunEMiddleware(f *globalFlags) cobraRunEMiddleware {
|
|||
}
|
||||
|
||||
if setupErr := checkSetup(f.Host, f.skipVerify); setupErr != nil && influxdb.EUnauthorized != influxdb.ErrorCode(setupErr) {
|
||||
cmd.OutOrStderr().Write([]byte(fmt.Sprintf("Error: %s\n", internal.ErrorFmt(err).Error())))
|
||||
return internal.ErrorFmt(setupErr)
|
||||
}
|
||||
|
||||
|
|
|
@ -318,8 +318,9 @@ func (b *cmdPkgBuilder) cmdPkgSummary() *cobra.Command {
|
|||
return nil
|
||||
}
|
||||
|
||||
cmd := b.newCmd("summary", runE)
|
||||
cmd := b.newCmd("summary", nil)
|
||||
cmd.Short = "Summarize the provided package"
|
||||
cmd.RunE = runE
|
||||
|
||||
b.registerPkgFileFlags(cmd)
|
||||
cmd.Flags().BoolVarP(&b.disableColor, "disable-color", "c", false, "Disable color in output")
|
||||
|
@ -337,8 +338,9 @@ func (b *cmdPkgBuilder) cmdPkgValidate() *cobra.Command {
|
|||
return pkg.Validate()
|
||||
}
|
||||
|
||||
cmd := b.newCmd("validate", runE)
|
||||
cmd := b.newCmd("validate", nil)
|
||||
cmd.Short = "Validate the provided package"
|
||||
cmd.RunE = runE
|
||||
|
||||
b.registerPkgFileFlags(cmd)
|
||||
|
||||
|
@ -428,8 +430,13 @@ func (b *cmdPkgBuilder) readPkg() (*pkger.Pkg, bool, error) {
|
|||
}
|
||||
pkgs = append(pkgs, urlPkgs...)
|
||||
|
||||
// the pkger.ValidSkipParseError option allows our server to be the one to validate the
|
||||
// the pkg is accurate. If a user has an older version of the CLI and cloud gets updated
|
||||
// with new validation rules,they'll get immediate access to that change without having to
|
||||
// rol their CLI build.
|
||||
|
||||
if _, err := b.inStdIn(); err != nil {
|
||||
pkg, err := pkger.Combine(pkgs...)
|
||||
pkg, err := pkger.Combine(pkgs, pkger.ValidSkipParseError())
|
||||
return pkg, false, err
|
||||
}
|
||||
|
||||
|
@ -437,7 +444,7 @@ func (b *cmdPkgBuilder) readPkg() (*pkger.Pkg, bool, error) {
|
|||
if err != nil {
|
||||
return nil, true, err
|
||||
}
|
||||
pkg, err := pkger.Combine(append(pkgs, stdinPkg)...)
|
||||
pkg, err := pkger.Combine(append(pkgs, stdinPkg), pkger.ValidSkipParseError())
|
||||
return pkg, true, err
|
||||
}
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ func (r ReqApplyPkg) Pkgs(encoding Encoding) (*Pkg, error) {
|
|||
rawPkgs = append(rawPkgs, pkg)
|
||||
}
|
||||
|
||||
return Combine(rawPkgs...)
|
||||
return Combine(rawPkgs)
|
||||
}
|
||||
|
||||
// RespApplyPkg is the response body for the apply pkg endpoint.
|
||||
|
|
|
@ -370,13 +370,13 @@ func (p *Pkg) applySecrets(secrets map[string]string) {
|
|||
|
||||
// Combine combines pkgs together. Is useful when you want to take multiple disparate pkgs
|
||||
// and compile them into one to take advantage of the parser and service guarantees.
|
||||
func Combine(pkgs ...*Pkg) (*Pkg, error) {
|
||||
func Combine(pkgs []*Pkg, validationOpts ...ValidateOptFn) (*Pkg, error) {
|
||||
newPkg := new(Pkg)
|
||||
for _, p := range pkgs {
|
||||
newPkg.Objects = append(newPkg.Objects, p.Objects...)
|
||||
}
|
||||
|
||||
return newPkg, newPkg.Validate()
|
||||
return newPkg, newPkg.Validate(validationOpts...)
|
||||
}
|
||||
|
||||
type (
|
||||
|
|
|
@ -4038,7 +4038,7 @@ spec:
|
|||
name: label_2
|
||||
`, APIVersion)))
|
||||
|
||||
combinedPkg, err := Combine(pkgs...)
|
||||
combinedPkg, err := Combine(pkgs)
|
||||
require.NoError(t, err)
|
||||
|
||||
sum := combinedPkg.Summary()
|
||||
|
|
Loading…
Reference in New Issue