Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package swarmingV1 | 5 package swarmingV1 |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "fmt" | 9 "fmt" |
| 10 "net/url" | |
| 11 "strings" | |
| 12 "unicode" | |
| 10 ) | 13 ) |
| 11 | 14 |
| 12 // DefaultSwarmingPriority is the priority used if | 15 // DefaultSwarmingPriority is the priority used if |
| 13 // Parameters.scheduling.priority == 0. | 16 // Parameters.scheduling.priority == 0. |
| 14 const DefaultSwarmingPriority = 100 | 17 const DefaultSwarmingPriority = 100 |
| 15 | 18 |
| 16 // Normalize normalizes and checks for input violations. | 19 // Normalize normalizes and checks for input violations. |
| 17 func (p *Parameters) Normalize() (err error) { | 20 func (p *Parameters) Normalize() (err error) { |
| 18 if err = p.Scheduling.Normalize(); err != nil { | 21 if err = p.Scheduling.Normalize(); err != nil { |
| 19 return | 22 return |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 } | 73 } |
| 71 return | 74 return |
| 72 } | 75 } |
| 73 | 76 |
| 74 // Normalize normalizes and checks for input violations. | 77 // Normalize normalizes and checks for input violations. |
| 75 func (i *Parameters_Job_Inputs) Normalize() (err error) { | 78 func (i *Parameters_Job_Inputs) Normalize() (err error) { |
| 76 if len(i.Packages) == 0 && len(i.Isolated) == 0 { | 79 if len(i.Packages) == 0 && len(i.Isolated) == 0 { |
| 77 return errors.New( | 80 return errors.New( |
| 78 "job.inputs: at least one of packages and isolated must be specified") | 81 "job.inputs: at least one of packages and isolated must be specified") |
| 79 } | 82 } |
| 83 if len(i.Packages) > 0 { | |
| 84 if err = schemaHostURLValidate(i.CipdServer); err != nil { | |
| 85 return fmt.Errorf("job.inputs.cipd_server: %s", err) | |
| 86 } | |
| 87 for i, p := range i.Packages { | |
| 88 if p.Name == "" { | |
| 89 return fmt.Errorf("job.inputs.packages[%d]: miss ing name", i) | |
| 90 } | |
| 91 if p.Version == "" { | |
| 92 return fmt.Errorf("job.inputs.packages[%d]: miss ing version", i) | |
| 93 } | |
| 94 } | |
| 95 } | |
| 80 return | 96 return |
| 81 } | 97 } |
| 98 | |
| 99 func schemaHostURLValidate(uStr string) error { | |
| 100 if uStr == "" { | |
| 101 return errors.New("required") | |
| 102 } | |
| 103 if strings.IndexFunc(uStr, unicode.IsUpper) != -1 { | |
| 104 return errors.New("must be lower-case") | |
| 105 } | |
| 106 u, err := url.Parse(uStr) | |
| 107 if err != nil { | |
| 108 return fmt.Errorf("invalid url: %s", err) | |
| 109 } | |
| 110 if u.Scheme != "http" && u.Scheme != "https" { | |
|
Vadim Sh.
2016/08/22 22:32:42
I thought you were against specifying URLs instead
iannucci
2016/08/26 00:20:04
you convinced me otherwise :)
| |
| 111 return fmt.Errorf("unsupported scheme: %s", u.Scheme) | |
| 112 } | |
| 113 if fmt.Sprintf("%s://%s", u.Scheme, u.Host) != uStr { | |
|
Vadim Sh.
2016/08/22 22:32:42
is custom port (if any) part of u.Host?
iannucci
2016/08/26 00:20:04
yep (I just checked): https://golang.org/pkg/net/u
| |
| 114 return fmt.Errorf("unsupported url: %s", uStr) | |
| 115 } | |
| 116 return nil | |
| 117 } | |
| 118 | |
| 119 // Normalize normalizes and checks for input violations. | |
| 120 func (c *Config) Normalize() (err error) { | |
| 121 if err = c.Swarming.Normalize(); err != nil { | |
| 122 return | |
| 123 } | |
| 124 if err = c.Isolate.Normalize(); err != nil { | |
| 125 return | |
| 126 } | |
| 127 return | |
| 128 } | |
| 129 | |
| 130 // Normalize normalizes and checks for input violations. | |
| 131 func (s *Config_Swarming) Normalize() (err error) { | |
| 132 if err = schemaHostURLValidate(s.Url); err != nil { | |
| 133 return fmt.Errorf("config.swarming.host: %s", err) | |
| 134 } | |
| 135 return | |
| 136 } | |
| 137 | |
| 138 // Normalize normalizes and checks for input violations. | |
| 139 func (i *Config_Isolate) Normalize() (err error) { | |
| 140 if err = schemaHostURLValidate(i.Url); err != nil { | |
| 141 return fmt.Errorf("config.isolate.host: %s", err) | |
| 142 } | |
| 143 return | |
| 144 } | |
| OLD | NEW |