ianmarmour / nvidia-clerk

A cross-platform go bot that tracks for availability of stock from Nvidia's store and adds a cart to your checkout.
BSD 3-Clause "New" or "Revised" License
222 stars 64 forks source link

Twilio option to configure Account SID and Auth SID #51

Open ngaugler opened 3 years ago

ngaugler commented 3 years ago

For Twilio, I have an API Key setup that I would prefer to use instead of the primary account. Unfortunately the SMS feature does not work because of this. Can you add a new variable to supply an Auth SID to be used in the SetBasicAuth() call? If AUTH SID is empty you could fall back to Account SID.

penguinologist commented 3 years ago

@ngaugler I've got a PR out for this issue but I don't have an AUTH_SID. Can you pull that branch and test this for me? Thanks!

ianmarmour commented 3 years ago

@ngaugler I actually don't think we even need to make a change here just set the value of ACCOUNT_SID to AUTH_SID and it should already work? Let me know, I'm okay with adding an env for AUTH_SID if we really want.

penguinologist commented 3 years ago

my PR covers both cases, but yes, just setting the value to the AUTH_SID should work. if it does, let me know and I'll update the README (and PR it)

ngaugler commented 3 years ago

Unfortunately, yes it is required. Full disclosure, I was working on something similar yesterday when I discovered I needed both the Account SID and the Auth SID. The PR does not work. I was able to setup a dev environment this evening and below is the code that does work.

diff --git a/internal/alert/sms.go b/internal/alert/sms.go
index 3a48181..a3de241 100644
--- a/internal/alert/sms.go
+++ b/internal/alert/sms.go
@@ -21,7 +21,7 @@ func SendText(item string, config config.TwilioConfig, client *http.Client) erro
        msgDataReader := *strings.NewReader(msgData.Encode())

        req, _ := http.NewRequest("POST", endpoint, &msgDataReader)
-       req.SetBasicAuth(config.AccountSID, config.Token)
+       req.SetBasicAuth(config.AuthSID, config.Token)
        req.Header.Add("Accept", "application/json")
        req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

diff --git a/internal/config/config.go b/internal/config/config.go
index 5b03c86..025a617 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -23,6 +23,7 @@ type TwitterConfig struct {

 type TwilioConfig struct {
        AccountSID        string
+       AuthSID           string
        Token             string
        SourceNumber      string
        DestinationNumber string
@@ -215,6 +216,13 @@ func GetTwilioConfig() TwilioConfig {

        configuration.AccountSID = accountSid

+       authSid, authSidOk := os.LookupEnv("TWILIO_AUTH_SID")
+       if authSidOk == false {
+               authSid = accountSid
+       }
+
+       configuration.AuthSID = authSid
+
        token, tokenOk := os.LookupEnv("TWILIO_TOKEN")
        if tokenOk == false {
                log.Fatal("TWILIO_TOKEN Environment Variable is unset, exiting.")
penguinologist commented 3 years ago

great! PR it :) I'll remove my PR