github.com/wtfutil/wtf@v0.43.0/modules/digitalocean/settings.go (about)

     1  package digitalocean
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/olebedev/config"
     7  	"github.com/wtfutil/wtf/cfg"
     8  	"github.com/wtfutil/wtf/utils"
     9  	"github.com/wtfutil/wtf/wtf"
    10  )
    11  
    12  const (
    13  	defaultFocusable = true
    14  	defaultTitle     = "DigitalOcean"
    15  )
    16  
    17  // defaultColumns defines the default set of columns to display in the widget
    18  // This can be over-ridden in the cofig by explicitly defining a set of columns
    19  var defaultColumns = []interface{}{
    20  	"Name",
    21  	"Status",
    22  	"Region.Slug",
    23  }
    24  
    25  // Settings defines the configuration properties for this module
    26  type Settings struct {
    27  	*cfg.Common
    28  
    29  	apiKey     string   `help:"Your DigitalOcean API key."`
    30  	columns    []string `help:"A list of the droplet properties to display."`
    31  	dateFormat string   `help:"The format to display dates and times in."`
    32  }
    33  
    34  // NewSettingsFromYAML creates a new settings instance from a YAML config block
    35  func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
    36  
    37  	settings := Settings{
    38  		Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
    39  
    40  		apiKey:     ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_DIGITALOCEAN_API_KEY"))),
    41  		columns:    utils.ToStrs(ymlConfig.UList("columns", defaultColumns)),
    42  		dateFormat: ymlConfig.UString("dateFormat", wtf.DateFormat),
    43  	}
    44  
    45  	cfg.ModuleSecret(name, globalConfig, &settings.apiKey).Load()
    46  
    47  	return &settings
    48  }