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

Side by Side 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, 3 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 unified diff | Download patch
OLDNEW
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
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" {
111 return fmt.Errorf("unsupported scheme: %s", u.Scheme)
112 }
113 if fmt.Sprintf("%s://%s", u.Scheme, u.Host) != uStr {
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 }
OLDNEW
« 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