helpers for colab

save aws pw

saveAwsPw[source]

saveAwsPw(awskey:bytes, awssecret:bytes, path:str='/content/drive/MyDrive/.awskey', password:bytes=b'')

save your aws password in your

def test_saveAwsPw():
  # enter password == test ##
  saveAwsPw(awskey = b'test', awssecret=b'password', path = '/tmp/test', password = b'test')
  with open ('/tmp/test', 'rb') as f:
    r = pickle.load(f)
  print(r)
test_saveAwsPw()
saving the AES encrypted credentials to /tmp/test
(b'\xe3\xd5\xd1#', b'&\xd5\xd6b\xd6+[j', b"'\x0e.\x99M;\\\x9f`$=v\xf0\x8b\x19\xec", b'`\xf8+\xd3jd8\xc5\x9a\x7fK\x93\xb8esm')

load aws pw

loadAwsPw[source]

loadAwsPw(path='/content/drive/MyDrive/.awskey', password:Optional[bytes]=b'')

load key and secret from path

def test_loadAwsPw():
  r = loadAwsPw(path = '/tmp/test', password = b'test')
  print(r)
test_loadAwsPw()
loading password from /tmp/test
(b'test', b'password')

set up aws

setUpAws[source]

setUpAws(awsKey:str, awsSecret:str, profile:Optional[str]=None, region:str='ap-southeast-1')

this code generate a string to be executed to the shell you can do this with, however, its not a bad idea to check before executing

(exec(c) for c in setUpAws(...))

response: (setupKey, setupSecret, setupRegion)

def testSetUpAws():
  r = setUpAws('test', 'secret', 'testProfile')
  print(r)
testSetUpAws()
('aws configure --profile testProfile set aws_access_key_id test', 'aws configure --profile testProfile set aws_secret_access_key secret', 'aws configure --profile testProfile set default.region ap-southeast-1')

setUpAws2[source]

setUpAws2(awsKey:str, awsSecret:str, profile:Optional[str]=None, region:str='ap-southeast-1')

Shield strings

shield the secrets

shieldStrings[source]

shieldStrings(strings)

def testSetUpAws2():
  i,j = setUpAws2('test', 'secret', 'testProfile')
  print(shieldStrings(i))
  print(shieldStrings(j))
  
testSetUpAws2()
[testProfile] 
region = **************
output = ****

[testProfile] 
aws_access_key_id = ****
aws_secret_access_key = ******

autosetup aws

autoSetupAws[source]

autoSetupAws(path:str, profile:Optional[str]=None, region:str='ap-southeast-1', mockup:bool=False, password:Optional[bytes]=None)

def testAutoSetupAws():
  autoSetupAws(path = '/tmp/test', password=b'test')
  print('test successful')
  autoSetupAws(path = '/tmp/test', password=b'tst')
testAutoSetupAws()
loading password from /tmp/test
config is :
[default] 
region = **************
output = ****

[default] 
aws_access_key_id = ****
aws_secret_access_key = ********

Not running on colab
awspath is /home/ec2-user/.aws
not colab
test successful
loading password from /tmp/test
cant decode key and secret, maybe the password is wrong