This repository has been archived by the owner on May 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first load of changes * fix lint * scheduled tasks work * generate some help * make logging better * make linter happy * plugin commands filter * add version info in log fields
- Loading branch information
1 parent
39522d8
commit 1371ace
Showing
37 changed files
with
1,654 additions
and
833 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,9 @@ dist | |
# Dependency directories | ||
vendor/ | ||
|
||
# config file | ||
config/config.yaml | ||
|
||
# IDE | ||
.vscode | ||
|
||
|
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,25 @@ | ||
- command: "helloworld" | ||
name: "Hello Who?" | ||
description: "Print a hello world, but getting the name from a modal" | ||
vars: | ||
- name: HELLO | ||
value: "hello" | ||
dialog: | ||
title: Hello world | ||
introduction_text: Say hello to whoever is passed | ||
elements: | ||
- name: WORLD | ||
display_name: World | ||
type: text | ||
subtype: text | ||
optional: false | ||
default: world | ||
help_text: How are we say hello to | ||
exec: | ||
- scripts/helloworld/helloworld.sh | ||
response: | ||
type: "ephemeral" | ||
colors: | ||
- color: "#ff0000" | ||
... | ||
|
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,108 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
|
||
"github.com/pkg/errors" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type RawMessage struct { | ||
unmarshal func(interface{}) error | ||
} | ||
|
||
func (msg *RawMessage) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
msg.unmarshal = unmarshal | ||
return nil | ||
} | ||
|
||
func (msg *RawMessage) Unmarshal(v interface{}) error { | ||
return msg.unmarshal(v) | ||
} | ||
|
||
type Config struct { | ||
Listen string `yaml:"listen"` | ||
BaseURL string `yaml:"base_url"` | ||
PluginsConfig []PluginConfig `yaml:"plugins"` | ||
CommandConfigurations []CommandConfig `yaml:"commands"` | ||
ScheduledCommands []ScheduledCommandConfig `yaml:"scheduler"` | ||
} | ||
|
||
type PluginConfig struct { | ||
Name string `yaml:"name"` | ||
File string `yaml:"file"` | ||
Config RawMessage `yaml:"config"` | ||
} | ||
|
||
type CommandConfig struct { | ||
Command string `yaml:"command"` | ||
Token string `yaml:"token"` | ||
DialogURL string `yaml:"dialog_url"` | ||
DialogResponseURL string `yaml:"dialog_response_url"` | ||
SchedulerResponseURL string `yaml:"scheduler_response_url"` | ||
Plugins []CommandPlugin `yaml:"plugins"` | ||
} | ||
|
||
type ScheduledCommandConfig struct { | ||
Name string `yaml:"name"` | ||
Cron string `yaml:"cron"` | ||
Command string `yaml:"command"` | ||
Channel string `yaml:"channel"` | ||
ResponseURL string `yaml:"response_url"` | ||
} | ||
|
||
func Load(path string) (*Config, error) { | ||
fmt.Println("Loading config from", path) | ||
content, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to read config file %s", path) | ||
} | ||
|
||
fmt.Println("Parsing config") | ||
var config Config | ||
err = yaml.Unmarshal(content, &config) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to unmarshal config file %s", path) | ||
} | ||
|
||
return &config, nil | ||
} | ||
|
||
type CommandPlugin struct { | ||
Name string | ||
Only []string | ||
Exclude []string | ||
} | ||
|
||
type plainCommandPlugin struct { | ||
Name string `yaml:"name"` | ||
Only []string `yaml:"only"` | ||
Exclude []string `yaml:"exclude"` | ||
} | ||
|
||
// UnmarshalYAML implements the Unmarshaler interface. | ||
// The CommandPlugin can either be a string corresponding to the name, or a CommandPlugin | ||
func (cp *CommandPlugin) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
name := "" | ||
err := unmarshal(&name) | ||
if err == nil { | ||
*cp = CommandPlugin{Name: name} | ||
return nil | ||
} | ||
|
||
plugin := plainCommandPlugin{} | ||
err = unmarshal(&plugin) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cp.Name = plugin.Name | ||
cp.Only = plugin.Only | ||
cp.Exclude = plugin.Exclude | ||
|
||
if len(cp.Only) > 0 && len(cp.Exclude) > 0 { | ||
return errors.New("only and exclude cannot be both set") | ||
} | ||
return nil | ||
} |
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 |
---|---|---|
@@ -1,19 +1,47 @@ | ||
--- | ||
|
||
listen: "0.0.0.0:8080" | ||
token: "TOKEN" # Mattermost slash command token | ||
commands: | ||
- commands/gitlab/gitlab.yaml | ||
- commands/docker/docker.yaml | ||
- commands/fun/fun.yaml | ||
- commands/k8s/k8s.yaml | ||
- commands/release/release.yaml | ||
base_url: "https://op-tools-address.com" | ||
plugins: | ||
- name: bash_useful | ||
file: plugins/bash.so | ||
config: | ||
files: | ||
- commands/gitlab/gitlab.yaml | ||
- commands/docker/docker.yaml | ||
- commands/k8s/k8s.yaml | ||
- commands/release/release.yaml | ||
- name: bash_fun | ||
file: plugins/bash.so | ||
config: | ||
files: | ||
- commands/helloworld/helloworld.yaml | ||
- commands/fun/fun.yaml | ||
commands: | ||
- command: jops | ||
plugins: | ||
- name: bash_useful | ||
- name: bash_fun | ||
exclude: ["fun figlet"] | ||
- name: bash_fun | ||
only: ["fun figlet"] | ||
token: "MATTERMOST_SLASHCOMMAND_TOKEN" | ||
dialog_url: https://my-mattermost-instance.cloud.mattermost.com/api/v4/actions/dialogs/open | ||
dialog_response_url: https://my-mattermost-instance.cloud.mattermost.com/hooks/random-id | ||
scheduler_response_url: https://my-mattermost-instance.cloud.mattermost.com/hooks/random-id | ||
scheduler: | ||
- name: "Check Gitlab Version" | ||
command: "jops gitlab version --check" | ||
channel: "ops-tool-notifications" | ||
cron: "0 * * * *" | ||
- name: "Joke" | ||
channel: "fun" | ||
provider: "fun" | ||
command: "joke" | ||
command: "jops fun joke" | ||
cron: "*/5 * * * *" | ||
hook: "TOKEN" | ||
- name: "Fortune" | ||
channel: "fun" | ||
command: "jops fun fortune" | ||
cron: "*/6 * * *" | ||
|
||
... | ||
|
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.