| 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
|
| }
|
|
|