-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: advanced watcher usernames management
This CL introduces a new plugin `watcher` that allows to add new watcher usernames to a task, similar to how the `tag` plugin works. A new field `allowed_watcher_usernames` has also been added to the core model of a task template to allows pre-defined watchers usernames at the template level. The pre-defined list of usernames of the template is merged with the input list given during the creation of a task, ignoring any duplicate values.
- Loading branch information
Showing
13 changed files
with
138 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# `watcher` Plugin | ||
|
||
This plugin updates the watcher usernames of the current task. New usernames are added to the list of existing one, ignoring any duplicate. | ||
|
||
## Configuration | ||
|
||
| Fields | Description | | ||
| ----------- | ------------------ | | ||
| `usernames` | an array of string | | ||
|
||
## Example | ||
|
||
An action of type `watcher` requires only one field, the list of watcher usernames to add to the current task. | ||
|
||
```yaml | ||
action: | ||
type: watcher | ||
configuration: | ||
usernames: | ||
- foo | ||
- bar | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package pluginwatcher | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/ovh/utask/pkg/plugins/taskplugin" | ||
) | ||
|
||
// The watcher plugin allow to update the allowed watcher usernames of a task. | ||
var ( | ||
Plugin = taskplugin.New("watcher", "0.1", exec, | ||
taskplugin.WithConfig(validConfig, Config{}), | ||
taskplugin.WithWatchers(watchers), | ||
) | ||
) | ||
|
||
// Config represents the configuration of the plugin. | ||
type Config struct { | ||
Usernames []string `json:"usernames"` | ||
} | ||
|
||
func validConfig(config interface{}) error { | ||
cfg := config.(*Config) | ||
|
||
for i, v := range cfg.Usernames { | ||
if strings.TrimSpace(v) == "" { | ||
return fmt.Errorf("invalid watcher username at position %d", i) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func exec(stepName string, config interface{}, ctx interface{}) (interface{}, interface{}, error) { | ||
return nil, nil, nil | ||
} | ||
|
||
func watchers(config, _, _, _ interface{}, _ error) []string { | ||
if config == nil { | ||
return nil | ||
} | ||
cfg := config.(*Config) | ||
|
||
return cfg.Usernames | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- +migrate Up | ||
|
||
ALTER TABLE "task_template" ADD COLUMN "allowed_watcher_usernames" JSONB NOT NULL DEFAULT '[]'; | ||
|
||
-- +migrate Down | ||
|
||
ALTER TABLE "task_template" DROP COLUMN "allowed_watcher_usernames"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters