| 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" | 10 "net/url" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 } | 68 } |
| 69 for k := range j.Env { | 69 for k := range j.Env { |
| 70 if k == "" { | 70 if k == "" { |
| 71 return errors.New("job.env: environment key is empty") | 71 return errors.New("job.env: environment key is empty") |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 return | 74 return |
| 75 } | 75 } |
| 76 | 76 |
| 77 // Normalize normalizes and checks for input violations. | 77 // Normalize normalizes and checks for input violations. |
| 78 func (p *CipdPackage) Normalize() error { |
| 79 if p.Name == "" { |
| 80 return errors.New("missing name") |
| 81 } |
| 82 if p.Version == "" { |
| 83 return errors.New("missing version") |
| 84 } |
| 85 return nil |
| 86 } |
| 87 |
| 88 // Normalize normalizes and checks for input violations. |
| 89 func (c *CipdSpec) Normalize() error { |
| 90 if err := schemaHostURLValidate(c.Server); err != nil { |
| 91 return fmt.Errorf("job.inputs.cipd.server: %s", err) |
| 92 } |
| 93 if c.Client != nil { |
| 94 if err := c.Client.Normalize(); err != nil { |
| 95 return fmt.Errorf("job.inputs.cipd.client: %s", err) |
| 96 } |
| 97 } |
| 98 for path, pkgs := range c.ByPath { |
| 99 for i, p := range pkgs.Pkg { |
| 100 if err := p.Normalize(); err != nil { |
| 101 return fmt.Errorf("job.inputs.cipd.by_path[%s].p
kg[%d]: %s", path, i, err) |
| 102 } |
| 103 } |
| 104 } |
| 105 return nil |
| 106 } |
| 107 |
| 108 // Normalize normalizes and checks for input violations. |
| 78 func (i *Parameters_Job_Inputs) Normalize() (err error) { | 109 func (i *Parameters_Job_Inputs) Normalize() (err error) { |
| 79 » if len(i.Packages) == 0 && len(i.Isolated) == 0 { | 110 » if i.Cipd == nil && len(i.Isolated) == 0 { |
| 80 return errors.New( | 111 return errors.New( |
| 81 "job.inputs: at least one of packages and isolated must
be specified") | 112 "job.inputs: at least one of packages and isolated must
be specified") |
| 82 } | 113 } |
| 83 » if len(i.Packages) > 0 { | 114 » if i.Cipd != nil { |
| 84 » » if err = schemaHostURLValidate(i.CipdServer); err != nil { | 115 » » if err = i.Cipd.Normalize(); err != nil { |
| 85 » » » return fmt.Errorf("job.inputs.cipd_server: %s", err) | 116 » » » return |
| 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 } | 117 } |
| 95 } | 118 } |
| 96 return | 119 return |
| 97 } | 120 } |
| 98 | 121 |
| 99 func schemaHostURLValidate(uStr string) error { | 122 func schemaHostURLValidate(uStr string) error { |
| 100 if uStr == "" { | 123 if uStr == "" { |
| 101 return errors.New("required") | 124 return errors.New("required") |
| 102 } | 125 } |
| 103 if strings.IndexFunc(uStr, unicode.IsUpper) != -1 { | 126 if strings.IndexFunc(uStr, unicode.IsUpper) != -1 { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 return | 158 return |
| 136 } | 159 } |
| 137 | 160 |
| 138 // Normalize normalizes and checks for input violations. | 161 // Normalize normalizes and checks for input violations. |
| 139 func (i *Config_Isolate) Normalize() (err error) { | 162 func (i *Config_Isolate) Normalize() (err error) { |
| 140 if err = schemaHostURLValidate(i.Url); err != nil { | 163 if err = schemaHostURLValidate(i.Url); err != nil { |
| 141 return fmt.Errorf("config.isolate.host: %s", err) | 164 return fmt.Errorf("config.isolate.host: %s", err) |
| 142 } | 165 } |
| 143 return | 166 return |
| 144 } | 167 } |
| OLD | NEW |