Skip to content

Commit

Permalink
feat(task): allow to get watchers (#439)
Browse files Browse the repository at this point in the history
closes #188

Signed-off-by: Thomas Bétrancourt <thomas@betrancourt.net>
  • Loading branch information
rclsilver authored May 2, 2023
1 parent 0c55dbf commit 263ddea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
8 changes: 7 additions & 1 deletion models/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,18 @@ func (t *Task) ExportTaskInfos(values *values.Values) {
m["task_id"] = t.PublicID
m["created"] = t.Created
m["requester_username"] = t.RequesterUsername
if t.RequesterGroups != nil && len(t.RequesterGroups) > 0 {
if len(t.RequesterGroups) > 0 {
m["requester_groups"] = strings.Join(t.RequesterGroups, utask.GroupsSeparator)
}
if t.ResolverUsername != nil {
m["resolver_username"] = t.ResolverUsername
}
if len(t.WatcherUsernames) > 0 {
m["watcher_usernames"] = strings.Join(t.WatcherUsernames, utask.UsernamesSeparator)
}
if len(t.WatcherGroups) > 0 {
m["watcher_groups"] = strings.Join(t.WatcherGroups, utask.GroupsSeparator)
}
m["last_activity"] = t.LastActivity
m["region"] = utask.FRegion
if t.Resolution != nil {
Expand Down
17 changes: 9 additions & 8 deletions models/tasktemplate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func validTemplate(template string, inputs, resolverInputs []string, steps map[s
}

stepNames := stepNames(steps)
taskInfoKeys := []string{"resolver_username", "created", "requester_username", "requester_groups", "task_id", "region", "resolution_id"}
taskInfoKeys := []string{"resolver_username", "created", "requester_username", "requester_groups", "task_id", "region", "resolution_id", "watcher_usernames", "watcher_groups"}
for _, m := range matches {
parts := strings.Split(m[1], ".")
if len(parts) >= 3 {
Expand Down Expand Up @@ -138,13 +138,14 @@ func stepNames(stepMap map[string]*step.Step) []string {

// tryVariablePath tries to match a chain of variables with the given properties.
// For example:
// given properties = map[foo:[bar] bar:[bar] qux:[foo] utaskRootKey:[qux]]
// and parts = [qux foo bar bar bar]
// "qux.foo.bar.bar.bar" is valid since "qux" makes "foo", "foo" makes "bar"
// and "bar" makes "bar".
// "qux.foo.bar.foo" is not valid since we cannot make "foo" from "bar".
// "foo.bar.bar" is not valid either since we start looping on parts using
// utaskRootKey map, which contains root properties of the json schema.
//
// given properties = map[foo:[bar] bar:[bar] qux:[foo] utaskRootKey:[qux]]
// and parts = [qux foo bar bar bar]
// "qux.foo.bar.bar.bar" is valid since "qux" makes "foo", "foo" makes "bar"
// and "bar" makes "bar".
// "qux.foo.bar.foo" is not valid since we cannot make "foo" from "bar".
// "foo.bar.bar" is not valid either since we start looping on parts using
// utaskRootKey map, which contains root properties of the json schema.
func tryVariablePath(properties map[string][]string, parts []string) error {
// start with root properties
lastKey := jsonschema.RootKey
Expand Down
3 changes: 3 additions & 0 deletions utask.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ const (
// NotificationStrategyFailureOnly corresponds to the mode where notifications will only be sent if the state is BLOCKED
NotificationStrategyFailureOnly = "failure_only"

// UsernamesSeparator corresponds to the separator used to break a string into a list of usernames and vice versa.
UsernamesSeparator = ","

// GroupsSeparator corresponds to the separator used to break a string into a list of groups and vice versa.
GroupsSeparator = ","

Expand Down

0 comments on commit 263ddea

Please sign in to comment.