Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | |
| 3 // that can be found in the LICENSE file. | |
| 4 | |
| 5 // Package tasktemplate resolves Swarming task templates. | |
|
nodir
2017/02/18 07:00:54
a swarming task template is a JSON object that is
| |
| 6 // | |
| 7 // Templated strings may be passed to Swarming tasks in order to have them | |
| 8 // resolve task-side parameters. See Params for more information. | |
| 9 package tasktemplate | |
| 10 | |
| 11 import ( | |
| 12 "github.com/luci/luci-go/common/data/text/stringtemplate" | |
| 13 ) | |
| 14 | |
| 15 // Params contains supported Swarming task string substitution parameters. | |
| 16 // | |
| 17 // A template string can be resolved by passing it to a Params instance's | |
| 18 // Resolve method. | |
| 19 type Params struct { | |
|
nodir
2017/02/18 07:00:54
i think DM would use the same log_location swarmin
dnj
2017/02/18 07:42:48
Well, I want Kitchen to import this too, since it
nodir
2017/02/18 15:40:31
you are right, this code has to be extracted to a
| |
| 20 // SwarmingRunID is the substitution to use for the "swarming_run_id" te mplate | |
| 21 // parameter. | |
| 22 // | |
| 23 // Note that this is the Swarming Run ID, not Task ID. The Run ID is the | |
| 24 // combination of the Task ID with the try number. | |
| 25 SwarmingRunID string | |
| 26 } | |
| 27 | |
| 28 func (p *Params) substMap() map[string]string { | |
| 29 res := make(map[string]string, 1) | |
| 30 if p.SwarmingRunID != "" { | |
| 31 res["swarming_run_id"] = p.SwarmingRunID | |
| 32 } | |
| 33 return res | |
| 34 } | |
| 35 | |
| 36 // Resolve resolves v against p's parameters, populating any template fields | |
| 37 // with their respective parameter value. | |
| 38 // | |
| 39 // If the string is invalid, or if it references an undefined template | |
| 40 // parameter, an error will be returned. | |
| 41 func (p *Params) Resolve(v string) (string, error) { | |
| 42 return stringtemplate.Resolve(v, p.substMap()) | |
| 43 } | |
| OLD | NEW |