Skip to content

Commit

Permalink
Add API token (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjohnson authored Feb 21, 2024
1 parent 8cccd2d commit defb82e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/fly-autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
fas "github.com/superfly/fly-autoscaler"
fasprom "github.com/superfly/fly-autoscaler/prometheus"
"github.com/superfly/fly-go/flaps"
"github.com/superfly/fly-go/tokens"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -107,6 +108,7 @@ type Config struct {
AppName string `yaml:"app-name"`
Expr string `yaml:"expr"`
Interval time.Duration `yaml:"interval"`
APIToken string `yaml:"api-token"`
Verbose bool `yaml:"verbose"`

MetricCollectors []*MetricCollectorConfig `yaml:"metric-collectors"`
Expand All @@ -122,6 +124,8 @@ func NewConfigFromEnv() (*Config, error) {
c := NewConfig()
c.AppName = os.Getenv("FAS_APP_NAME")
c.Expr = os.Getenv("FAS_EXPR")
c.APIToken = os.Getenv("FAS_API_TOKEN")

if s := os.Getenv("FAS_INTERVAL"); s != "" {
d, err := time.ParseDuration(s)
if err != nil {
Expand Down Expand Up @@ -160,8 +164,13 @@ func (c *Config) Validate() error {
}

func (c *Config) NewFlapsClient(ctx context.Context) (*flaps.Client, error) {
if c.APIToken == "" {
return nil, fmt.Errorf("api token required")
}

return flaps.NewWithOptions(ctx, flaps.NewClientOpts{
AppName: c.AppName,
Tokens: tokens.Parse(c.APIToken),
})
}

Expand Down

0 comments on commit defb82e

Please sign in to comment.