1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

WTF-986 User-definable DigitalOcean columns (#1001)

* WTF-986 Wrap the DigitalOcean droplet in our own droplet

This gives us something to build off while still providing the
underlying functionality of the original droplet instance.

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-986 Dynamically display droplet attributes based on defined column names

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-986 Read DigitalOcean column configuration from settings

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-986 Extract the reflection bits into a Reflective package

Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
Chris Cummer
2020-10-14 09:29:58 -07:00
committed by GitHub
parent b2e0c520e8
commit f84142553c
7 changed files with 175 additions and 28 deletions

View File

@@ -5,6 +5,7 @@ import (
"github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/wtf"
)
@@ -13,12 +14,21 @@ const (
defaultTitle = "DigitalOcean"
)
// defaultColumns defines the default set of columns to display in the widget
// This can be over-ridden in the cofig by explicitly defining a set of columns
var defaultColumns = []interface{}{
"Name",
"Status",
"Region.Slug",
}
// Settings defines the configuration properties for this module
type Settings struct {
common *cfg.Common
apiKey string `help:"Your DigitalOcean API key."`
dateFormat string `help:"The format to display dates and times in."`
apiKey string `help:"Your DigitalOcean API key."`
columns []string `help:"A list of the droplet properties to display."`
dateFormat string `help:"The format to display dates and times in."`
}
// NewSettingsFromYAML creates a new settings instance from a YAML config block
@@ -28,6 +38,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_DIGITALOCEAN_API_KEY"))),
columns: utils.ToStrs(ymlConfig.UList("columns", defaultColumns)),
dateFormat: ymlConfig.UString("dateFormat", wtf.DateFormat),
}