0

I have a Python project where I am using a Twilio number (201-282-1111), but I do not want this private number to be in my public Git repository. I could make a new repo and just not include the values, but I would like it be easy enough for non techie people to use my script.

My question is, what can I do to mask the fake number provided below? Also, I have Twilio account_sid and auth_token that I would like to mask as well.

client.sms.messages.create(
    body = "Your song was not found",
    to = phoneNum,
    from_ = "+2012821111")

account_sid = "XX1a116061fe67df9ab9eb0bc3c7ed0111"
auth_token = "1x11bc1b6555c52a93762f46d45861xx"
client = TwilioRestClient(account_sid,auth_token)
Undo
  • 25,519
  • 37
  • 106
  • 129
Ace NA
  • 121
  • 1
  • 2
  • 8
  • 2
    There are various options - environment variables, configuration files, etc. If you want it to be easy to use, write a helper to get the user to input the appropriate config if they start the program and it can't find existing values. Also, if you don't want these to be public, maybe posting them on SO wasn't the best idea? – jonrsharpe Nov 10 '15 at 15:33

1 Answers1

2

Use a config file. On one of my projects, this is what I did:

  1. Install ConfigParser.
  2. Create a file named config (or another name, your choice) that looks like this:

    [Config]
    account_sid=<your sid>
    auth_token=<token>
    phone_number=<your number>
    
  3. Edit your .gitignore file and add config to it, this will keep Git from committing your config file to the repository
  4. [optional] Add a config.sample file, which is a copy of the config file but with your values set to defaults or dummy values. Commit this one to Git. This helps other people set up your app later - all they have to do is copy the file to config and put in their credentials.
  5. To access the config values, use this code:

    config = ConfigParser.RawConfigParser()
    config.read('config')
    
    try:
        your_value = config.get("Config", "your_value")
        print your_value
    except ConfigParser.NoOptionError:
        print "'your_value' isn't defined in the config file!"
    

Another option would be to use an environment variable or to simply ask the user for their credentials when your app starts.

Community
  • 1
  • 1
Undo
  • 25,519
  • 37
  • 106
  • 129