Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Twilio option to configure Account SID and Auth SID #51

Open
ngaugler opened this issue Sep 22, 2020 · 5 comments
Open

Twilio option to configure Account SID and Auth SID #51

ngaugler opened this issue Sep 22, 2020 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ngaugler
Copy link

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.

@ianmarmour ianmarmour added enhancement New feature or request help wanted Extra attention is needed labels Sep 22, 2020
@penguinologist
Copy link
Contributor

@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
Copy link
Owner

ianmarmour commented Sep 23, 2020

@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
Copy link
Contributor

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
Copy link
Author

ngaugler commented Sep 23, 2020

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
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants