I written a script that extract some data from an API and build an Excel file. I'm not a dev, it is my first real program ever writted. I hosted the code on Google Colab.
There is API secret keys in clear. I want to share it with a Google Drive sharing link to people needing to generate the Excel file so that they can execute it. However I would prefer not to include API secret keys in clear in order to avoid accidental sharings outside of the entreprise.
I'm wondering how to hide this... Or how to provide users an alternative methode to execute the file without knowing the passwords. I don't have access to a shared webserver internally to the entreprise.
Regards
CLIENT_KEY = u'*****'
CLIENT_SECRET = u'*****'
BASE_URL = u'*****'
access_token_key = '*****'
access_token_secret = '*****'
print ('Getting user profile...',)
oauth = OAuth(CLIENT_KEY, client_secret=CLIENT_SECRET, resource_owner_key=access_token_key,
resource_owner_secret=access_token_secret)
r = requests.get(url=BASE_URL + '1/user/me/profile', auth=oauth)
print (json.dumps(r.json(), sort_keys=True, indent=4, separators=(',', ': ')))
...
You can save the secret key as file on Google Drive. Then read the file into Colab.
Now you can set permission to access the key file in Google Drive. Only you and the people you share the key file can use it.
Update
As @efbbrown suggest, you can create an aws key file and store it in Google Drive, e.g.
But now (2020) you don't need
pydrive
any more. You can justDefault place to store credential is
~/.aws/config
. So you can do this (if your file above is namedaws_config
)Try
getpass
. For example:Then, you can share the notebook and each user can enter a distinct value, which you can then use later in the notebook as a regular Python variable.
To expand on @Korakot Chaovavanich's answer, here is the step by step of that solution:
(Some of this code comes from @wenkesj's answer on this question.)
Now your AWS keys are in the two variables
access_token_key
&access_token_secret
.