Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Unified Diff: dm/api/distributor/swarming/v1/normalize.go

Issue 2267143002: Add additional validation to swarming v1 distributor. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@dump_all_stacks
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dm/api/distributor/swarming/v1/config.pb.go ('k') | dm/api/distributor/swarming/v1/params.proto » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dm/api/distributor/swarming/v1/normalize.go
diff --git a/dm/api/distributor/swarming/v1/normalize.go b/dm/api/distributor/swarming/v1/normalize.go
index b72e2cecd9a271773effdb74bdc023379b64dfdc..f1bef718a92507775b4375a49fe69ff9d90bbf11 100644
--- a/dm/api/distributor/swarming/v1/normalize.go
+++ b/dm/api/distributor/swarming/v1/normalize.go
@@ -7,6 +7,9 @@ package swarmingV1
import (
"errors"
"fmt"
+ "net/url"
+ "strings"
+ "unicode"
)
// DefaultSwarmingPriority is the priority used if
@@ -77,5 +80,65 @@ func (i *Parameters_Job_Inputs) Normalize() (err error) {
return errors.New(
"job.inputs: at least one of packages and isolated must be specified")
}
+ if len(i.Packages) > 0 {
+ if err = schemaHostURLValidate(i.CipdServer); err != nil {
+ return fmt.Errorf("job.inputs.cipd_server: %s", err)
+ }
+ for i, p := range i.Packages {
+ if p.Name == "" {
+ return fmt.Errorf("job.inputs.packages[%d]: missing name", i)
+ }
+ if p.Version == "" {
+ return fmt.Errorf("job.inputs.packages[%d]: missing version", i)
+ }
+ }
+ }
+ return
+}
+
+func schemaHostURLValidate(uStr string) error {
+ if uStr == "" {
+ return errors.New("required")
+ }
+ if strings.IndexFunc(uStr, unicode.IsUpper) != -1 {
+ return errors.New("must be lower-case")
+ }
+ u, err := url.Parse(uStr)
+ if err != nil {
+ return fmt.Errorf("invalid url: %s", err)
+ }
+ if u.Scheme != "http" && u.Scheme != "https" {
+ return fmt.Errorf("unsupported scheme: %s", u.Scheme)
+ }
+ if fmt.Sprintf("%s://%s", u.Scheme, u.Host) != uStr {
+ return fmt.Errorf("unsupported url: %s", uStr)
+ }
+ return nil
+}
+
+// Normalize normalizes and checks for input violations.
+func (c *Config) Normalize() (err error) {
+ if err = c.Swarming.Normalize(); err != nil {
+ return
+ }
+ if err = c.Isolate.Normalize(); err != nil {
+ return
+ }
+ return
+}
+
+// Normalize normalizes and checks for input violations.
+func (s *Config_Swarming) Normalize() (err error) {
+ if err = schemaHostURLValidate(s.Url); err != nil {
+ return fmt.Errorf("config.swarming.host: %s", err)
+ }
+ return
+}
+
+// Normalize normalizes and checks for input violations.
+func (i *Config_Isolate) Normalize() (err error) {
+ if err = schemaHostURLValidate(i.Url); err != nil {
+ return fmt.Errorf("config.isolate.host: %s", err)
+ }
return
}
« no previous file with comments | « dm/api/distributor/swarming/v1/config.pb.go ('k') | dm/api/distributor/swarming/v1/params.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698