예제 #1
0
def get_temp_keys():
    session  = bottle.request.environ.get('beaker.session')
    require_login(session)
    
    username = session["username"]
    try:
        user_info = identity.find_user_role(request.app, session["user_id"])
        # This is a vulnerability. We need to check everytime if the access_tokens 
        # are valid and alive with the api.amazon.com
        print user_info
        role      = "klab_public"
        creds     = sts.get_temp_creds(role)
        return template('./views/tempkeys.tpl',
                        username        = username,
                        session         = session,
                        AccessKeyId     = creds["AccessKeyId"],
                        SecretAccessKey = creds["SecretAccessKey"],
                        Token           = creds["SessionToken"],
                        Expiration      = creds["Expiration"],
                        title="Temporary keys",
                        alert=False)
        
    except Exception as e:
        return template('./views/logout.tpl',
                    username=username,
                    session=session,
                    title="Failed to get temporary keys",
                    alert=False)
예제 #2
0
def get_temp_keys():
    session = bottle.request.environ.get('beaker.session')
    require_login(session)

    username = session["username"]
    try:
        user_info = identity.find_user_role(request.app, session["user_id"])
        # This is a vulnerability. We need to check everytime if the access_tokens
        # are valid and alive with the api.amazon.com
        print user_info
        role = "klab_public"
        creds = sts.get_temp_creds(role)
        return template('./views/tempkeys.tpl',
                        username=username,
                        session=session,
                        AccessKeyId=creds["AccessKeyId"],
                        SecretAccessKey=creds["SecretAccessKey"],
                        Token=creds["SessionToken"],
                        Expiration=creds["Expiration"],
                        title="Temporary keys",
                        alert=False)

    except Exception as e:
        return template('./views/logout.tpl',
                        username=username,
                        session=session,
                        title="Failed to get temporary keys",
                        alert=False)
예제 #3
0
def get_inputs(app, inputs, auth):

    try:
        print "Attempting to switch roles to : {0}".format(auth["role"])
        creds = sts.get_temp_creds(auth["role"])
        #sts.print_creds(creds)
        s3conn = s3.get_s3_conn(creds["AccessKeyId"], creds["SecretAccessKey"],
                                creds["SessionToken"])

    except Exception as e:
        print "Caught exception : {0}".format(e)
        raise

    print "In get_inputs"
    if not inputs:
        return

    for i in inputs:
        print "Staging_inputs : ", i

        if i["src"].startswith("http://"):
            print "Downloading {0} via http".format(i["src"])
            utils.download_file(i["src"], i["dest"])

        elif re.search("https://s3.*amazonaws.com/", i["src"]):
            s3_path = re.sub("https://s3.*amazonaws.com/", "", i["src"])
            tmp = s3_path.split('/', 1)
            s3_bucket = tmp[0]
            s3_key = tmp[1]
            print "Downloading {0} via s3 provider".format(i["src"])
            try:
                s3.smart_download_s3_keys(s3conn, s3_bucket, s3_key, i["dest"],
                                          creds)
            except Exception as e:
                print "Download from s3 failed {0}".format(e)
                raise

        elif i["src"].startswith("s3://"):

            s3_path = i["src"].strip("s3://")
            tmp = s3_path.split('/', 1)
            s3_bucket = tmp[0]
            s3_key = tmp[1]
            print "Downloading {0} via s3 provider".format(i["src"])
            try:
                s3.smart_download_s3_keys(s3conn, s3_bucket, s3_key, i["dest"],
                                          creds)
            except Exception as e:
                print "Download from s3 failed {0}".format(e)
                raise

        else:
            print "No match. Could not fetch data"

    return
예제 #4
0
    except Exception, e:
        print "ERROR: Failed to get data/update metadata : ", e
        raise


if __name__ == "__main__":
    import config_manager as cm
    app = cm.load_configs("production.conf")
    import sts
    import s3_utils as s3
    rolestring = ''  # Left out due to security concerns

    if not rolestring:
        print "Fill out rolestring to continue tests"

    creds = sts.get_temp_creds(rolestring)
    s3conn = get_s3_conn(creds["AccessKeyId"], creds["SecretAccessKey"],
                         creds["SessionToken"])

    bucket_name = "klab-webofscience"
    prefix = 'raw_zipfiles/1976_DSSHPSH.zip'
    target = '/tmp/1976_DSSHPSH.zip'

    print "Listing items:"
    bucket = s3conn.get_bucket(bucket_name)
    print "getting keys:"
    keys = bucket.get_all_keys(prefix="raw_zipfiles")
    for key in keys:
        print key, key.size, key.last_modified
    exit(0)
    #test_uploads(app)
예제 #5
0
    except Exception, e :
        print "ERROR: Failed to get data/update metadata : ", e
        raise

    
if __name__ == "__main__":
    import config_manager as cm
    app = cm.load_configs("production.conf")
    import sts
    import s3_utils as s3
    rolestring  = '' # Left out due to security concerns

    if not rolestring :
        print "Fill out rolestring to continue tests"

    creds = sts.get_temp_creds(rolestring)
    s3conn  = get_s3_conn( creds["AccessKeyId"],
                           creds["SecretAccessKey"],
                           creds["SessionToken"] )
    
    
    bucket_name = "klab-webofscience"
    prefix = 'raw_zipfiles/1976_DSSHPSH.zip'
    target = '/tmp/1976_DSSHPSH.zip'
    
    print "Listing items:"
    bucket = s3conn.get_bucket(bucket_name)
    print "getting keys:"
    keys   = bucket.get_all_keys(prefix="raw_zipfiles")
    for key in keys:
        print key , key.size, key.last_modified
예제 #6
0
def get_inputs(app, inputs, auth):

   try:
      print "Attempting to switch roles to : {0}".format(auth["role"])
      creds = sts.get_temp_creds(auth["role"])
      #sts.print_creds(creds)
      s3conn  = s3.get_s3_conn( creds["AccessKeyId"], 
                                creds["SecretAccessKey"],
                                creds["SessionToken"] )
      
   except Exception as e:
      print "Caught exception : {0}".format(e)
      raise
   
   print "In get_inputs"
   if not inputs:
      return

   for i in inputs:
      print "Staging_inputs : ", i

      if i["src"].startswith("http://"):
         print "Downloading {0} via http".format(i["src"])
         utils.download_file(i["src"], i["dest"])
      
      elif re.search("https://s3.*amazonaws.com/", i["src"]):
         s3_path = re.sub("https://s3.*amazonaws.com/", "", i["src"])
         tmp     = s3_path.split('/', 1)
         s3_bucket = tmp[0]
         s3_key    = tmp[1]
         print "Downloading {0} via s3 provider".format(i["src"])
         try:         
            s3.smart_download_s3_keys(s3conn,
                                      s3_bucket,
                                      s3_key,
                                      i["dest"],
                                      creds)
         except Exception as e:
            print "Download from s3 failed {0}".format(e)
            raise

      elif i["src"].startswith("s3://"):
        
         s3_path   = i["src"].strip("s3://")
         tmp       = s3_path.split('/', 1)         
         s3_bucket = tmp[0]
         s3_key    = tmp[1]
         print "Downloading {0} via s3 provider".format(i["src"])
         try:
            s3.smart_download_s3_keys(s3conn,
                                      s3_bucket,
                                      s3_key,
                                      i["dest"],
                                      creds)
         except Exception as e:
            print "Download from s3 failed {0}".format(e)
            raise

      else:
         print "No match. Could not fetch data"
      
   return