Skip to content

Commit

Permalink
Feature: Reading slack token from env flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ani1311 committed Oct 27, 2023
1 parent b56b2a6 commit 3d140a6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"flag"
"net/http"
"os"
"sync"
"time"

Expand Down Expand Up @@ -70,13 +71,17 @@ func main() {
flag.StringVar(&slackPostMessageURL, "slackURL", slackPostMessageURL, "Slack Post Message API URL")
flag.IntVar(&maxQueueSize, "queueSize", maxQueueSize, "Maximum number of messages in the queue")
flag.IntVar(&burst, "burst", burst, "Maximum number of burst to allow")
flag.StringVar(&token, "token", "", "Bearer token for the Slack API")
flag.StringVar(&metricsPort, "metricsPort", metricsPort, "Port for the metrics server")
flag.StringVar(&applicationPort, "applicationPort", applicationPort, "Port for the application server")
flag.StringVar(&channelOverride, "channelOverride", "", "Override the channel for all messages - Be careful with this one!")

scli.ServerMain()

token = os.Getenv("SLACK_TOKEN")
if token == "" {
log.Fatalf("SLACK_TOKEN environment variable not set")
}

Check warning on line 83 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L80-L83

Added lines #L80 - L83 were not covered by tests

// Initialize metrics
r := prometheus.NewRegistry()
metrics := NewMetrics(r)
Expand All @@ -85,10 +90,6 @@ func main() {
app := NewApp(maxQueueSize, &http.Client{
Timeout: 10 * time.Second,
}, metrics, channelOverride)
// The only required flag is the token at the moment.
if token == "" {
log.Fatalf("Missing token flag")
}

log.Infof("Starting metrics server.")
StartMetricServer(r, metricsPort)
Expand Down

0 comments on commit 3d140a6

Please sign in to comment.