Skip to content

Commit

Permalink
Merge pull request #38 from astr0n8t/v1.1
Browse files Browse the repository at this point in the history
feat: add AuthHeaderName and AuthHeaderValue
  • Loading branch information
astr0n8t authored Aug 27, 2023
2 parents 1fb5ee9 + 6e61106 commit a144641
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
4 changes: 3 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
token: my_secret
guild_id: 0
guild_id: ""
commands:
test:
description: my pretty command
response: my lovely response
response_code: 200
url: https://google.com
auth_header_name: Authorization
auth_header_value: "Bearer token"
headers:
- name: X-Forwarded-For
value: somevalue
Expand Down
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"strings"
"time"

"github.com/fsnotify/fsnotify"
Expand Down Expand Up @@ -61,7 +62,14 @@ func readViperConfig(appName string) *viper.Viper {
v.ReadInConfig()

v.SetEnvPrefix(appName)
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
v.AutomaticEnv()

// workaround because viper does not treat env vars the same as other config
for _, key := range v.AllKeys() {
val := v.Get(key)
v.Set(key, val)
}

return v
}
5 changes: 5 additions & 0 deletions internal/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ func (w *WebhookSlashCommand) request() error {
// Create our new request using our method, url, and payload
req, err := http.NewRequest(method, w.URL, bytes.NewBuffer(payload))

// Add auth headers if they exist
if w.AuthHeaderName != "" {
req.Header.Add(w.AuthHeaderName, w.AuthHeaderValue)
}

// Add any headers for the webhook
for _, header := range w.Headers {
req.Header.Add(header.Name, header.Value)
Expand Down
24 changes: 13 additions & 11 deletions internal/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import "github.com/bwmarrin/discordgo"

// Overall struct to hold webhook command data
type WebhookSlashCommand struct {
Name string `mapstructure:"name"`
Desc string `mapstructure:"description"`
Resp string `mapstructure:"response"`
RespCode int `mapstructure:"response_code"`
URL string `mapstructure:"url"`
Method string `mapstructure:"method"`
Headers []WebhookHeader `mapstructure:"headers"`
SubCmd map[string]WebhookSlashCommand `mapstructure:"subcommands"`
SubCmdGrp map[string]WebhookSlashCommand `mapstructure:"subcommand_groups"`
Arguments []WebhookArgument `mapstructure:"arguments"`
Data map[string]interface{} `mapstructure:"data"`
Name string `mapstructure:"name"`
Desc string `mapstructure:"description"`
Resp string `mapstructure:"response"`
RespCode int `mapstructure:"response_code"`
URL string `mapstructure:"url"`
Method string `mapstructure:"method"`
AuthHeaderName string `mapstructure:"auth_header_name"`
AuthHeaderValue string `mapstructure:"auth_header_value"`
Headers []WebhookHeader `mapstructure:"headers"`
SubCmd map[string]WebhookSlashCommand `mapstructure:"subcommands"`
SubCmdGrp map[string]WebhookSlashCommand `mapstructure:"subcommand_groups"`
Arguments []WebhookArgument `mapstructure:"arguments"`
Data map[string]interface{} `mapstructure:"data"`
// These fields are context specific
CalledOptions []*discordgo.ApplicationCommandInteractionDataOption
CalledUser *discordgo.Member
Expand Down

0 comments on commit a144641

Please sign in to comment.