Skip to content

Commit

Permalink
Merge pull request #45 from stahnma/issue40
Browse files Browse the repository at this point in the history
chore(cspp): Stop hardcoding slack team id.
  • Loading branch information
Michael Stahnke authored Feb 8, 2024
2 parents f1367c9 + d0907d7 commit 40f5e0c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cspp/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ func loadApiEntryFromFile(filePath string) (ApiEntry, error) {
func issueNewApiKey(slackId string) bool {
log.Debugln("(issueNewApiKey) slackId", slackId)
var keyBlob ApiEntry
b := validateSlackId(slackId, "TTEGY45PB")
teamId := viper.GetString("slack_team_id")
b := validateSlackId(slackId, teamId)
log.Debugln("(issueNewApiKey) validateSlackId returned: ", b)
// at this point we know the slack id is valid
if b {
Expand Down
7 changes: 5 additions & 2 deletions cspp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func init() {
// Bind the command line flags to Viper
viper.BindPFlags(pflag.CommandLine)

// FIXME move other config here: slackToken, slackChannel, etc.
viper.SetDefault("port", "8080")
viper.SetDefault("data_dir", "data")
viper.BindEnv("port", "PORT")
Expand All @@ -37,12 +36,17 @@ func init() {
fmt.Println("SLACK_CHANNEL environment variable not set.")
bugout = true
}
if value := os.Getenv("SLACK_TEAM_ID"); value == "" {
fmt.Println("SLACK_TEAM_ID environment variable not set.")
bugout = true
}
if bugout == true {
os.Exit(1)
}

viper.MustBindEnv("slack_token", "SLACK_TOKEN")
viper.MustBindEnv("slack_channel", "SLACK_CHANNEL")
viper.MustBindEnv("slack_team_id", "SLACK_TEAM_ID")

viper.SetDefault("discard_dir", viper.GetString("data_dir")+"/discard")
viper.SetDefault("processed_dir", viper.GetString("data_dir")+"/processed")
Expand All @@ -60,7 +64,6 @@ func init() {
setupDirectory(viper.GetString("processed_dir"))
setupDirectory(viper.GetString("uploads_dir"))
setupDirectory(viper.GetString("credentials_dir"))

}

func main() {
Expand Down

0 comments on commit 40f5e0c

Please sign in to comment.