Skip to content

Commit

Permalink
Merge pull request #46 from stahnma/issue43
Browse files Browse the repository at this point in the history
chore(cspp): Flip env vars to be prefixed by CSPP_
  • Loading branch information
Michael Stahnke authored Feb 8, 2024
2 parents 40f5e0c + 94a2043 commit c3dddf7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
7 changes: 4 additions & 3 deletions cspp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ Have you been making stupid/silly/wonderful AI pictures and art work? Do you wan

You need to set the following enviornment variables.

SLACK_TOKEN
IMAGE_DIRECTORY
SLACK_CHANNEL
CSPP_SLACK_TOKEN
CSPP_DATA_DIRECTORY
CSPP_SLACK_CHANNEL
CSPP_SLACK_TEAM

# License
MIT
Expand Down
2 changes: 1 addition & 1 deletion cspp/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func generateApiKey() string {
}

func validateSlackId(userID, teamID string) bool {
token := viper.GetString("SLACK_TOKEN")
token := viper.GetString("slack_token")
log.Debugln("(validateSlackId) userId: ", userID, " teamId: ", teamID, " token: ", token)
api := slack.New(token)
userInfo, err := api.GetUserInfo(userID)
Expand Down
32 changes: 16 additions & 16 deletions cspp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,40 @@ func init() {

viper.SetDefault("port", "8080")
viper.SetDefault("data_dir", "data")
viper.BindEnv("port", "PORT")
viper.BindEnv("data_dir", "DATA_DIR")
viper.BindEnv("port", "CSPP_PORT")
viper.BindEnv("data_dir", "CSPP_DATA_DIR")

var bugout bool
if value := os.Getenv("SLACK_TOKEN"); value == "" {
fmt.Println("SLACK_TOKEN environment variable not set.")
if value := os.Getenv("CSPP_SLACK_TOKEN"); value == "" {
fmt.Println("CSPP_SLACK_TOKEN environment variable not set.")
bugout = true
}
if value := os.Getenv("SLACK_CHANNEL"); value == "" {
fmt.Println("SLACK_CHANNEL environment variable not set.")
if value := os.Getenv("CSPP_SLACK_CHANNEL"); value == "" {
fmt.Println("CSPP_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.")
if value := os.Getenv("CSPP_SLACK_TEAM_ID"); value == "" {
fmt.Println("CSPP_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.MustBindEnv("slack_token", "CSPP_SLACK_TOKEN")
viper.MustBindEnv("slack_channel", "CSPP_SLACK_CHANNEL")
viper.MustBindEnv("slack_team_id", "CSPP_SLACK_TEAM_ID")

viper.SetDefault("discard_dir", viper.GetString("data_dir")+"/discard")
viper.SetDefault("processed_dir", viper.GetString("data_dir")+"/processed")
viper.SetDefault("uploads_dir", viper.GetString("data_dir")+"/uploads")
viper.SetDefault("credentials_dir", viper.GetString("data_dir")+"/credentials")

viper.BindEnv("data_dir", "DATA_DIR")
viper.BindEnv("discard_dir", "DISCARD_DIR")
viper.BindEnv("processed_dir", "PROCESSED_DIR")
viper.BindEnv("uploads_dir", "UPLOADS_DIR")
viper.BindEnv("credentials_dir", "CREDENTIALS_DIR")
viper.BindEnv("data_dir", "CSPP_DATA_DIR")
viper.BindEnv("discard_dir", "CSPP_DISCARD_DIR")
viper.BindEnv("processed_dir", "CSPP_PROCESSED_DIR")
viper.BindEnv("uploads_dir", "CSPP_UPLOADS_DIR")
viper.BindEnv("credentials_dir", "CSPP_CREDENTIALS_DIR")

setupDirectory(viper.GetString("data_dir"))
setupDirectory(viper.GetString("discard_dir"))
Expand Down
2 changes: 1 addition & 1 deletion cspp/slack_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func getAuthor(apiKey string) string {
if err != nil {
log.Errorln("Unable to load api entry from file: ", apiKey, " error: ", err)
}
token := viper.GetString("SLACK_TOKEN")
token := viper.GetString("slack_token")
slackApi := slack.New(token)
userInfo, err := slackApi.GetUserInfo(ae.SlackId)
if err != nil {
Expand Down

0 comments on commit c3dddf7

Please sign in to comment.