Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Reading slack token from env flag #22

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
"encoding/json"
"flag"
"net/http"
"os"
"sync"
"time"

@@ -70,13 +71,17 @@
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

Codecov / codecov/patch

main.go#L80-L83

Added lines #L80 - L83 were not covered by tests

// Initialize metrics
r := prometheus.NewRegistry()
metrics := NewMetrics(r)
@@ -85,10 +90,6 @@
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)