import sys import boto.s3.connection #------------------------------------------------------------------------------ HOST_S3 = 'ss3.scayle.es' PORT_S3 = 443 #------------------------------------------------------------------------------ # FUNCTION: S3 Connection # DESCRIPTION: Connection to Server S3 # PARAMETERS: accessKey: Encoded token to access with AD User #------------------------------------------------------------------------------ def S3Connection (accessKey): global conn try: conn = boto.connect_s3( aws_access_key_id=accessKey, aws_secret_access_key=accessKey, host=HOST_S3, port=PORT_S3, is_secure=True, calling_format=boto.s3.connection.OrdinaryCallingFormat(), ) except: print ("AD User with access data <%s> has not privileges or does not exist." % (accessKey)) sys.exit(-1) #------------------------------------------------------------------------------ # FUNCTION: infoResources # DESCRIPTION: Show all buckets associated to user and their keys #------------------------------------------------------------------------------ def infoResources (): try: for bucket in conn.get_all_buckets(): print ("- BUCKET {name} {created}".format( name=bucket.name, created=bucket.creation_date, )) for key in bucket.list(): print (" - KEY {name}\t{modified}".format( name = key.name, modified = key.last_modified, )) except: print ("Connection to OpenCayle can not be done, please review your AccessKey:") print ("1) Run program s3AccessKey.py") print ("2) Run program s3CheckConnection.py") print ("If problem persists then contact to Scayle through HelpDesk tool.") sys.exit (-4) ######################################################################################################### # PROGRAM ######################################################################################################### # ----------------------------- PARAMETERS EVALUATION ----------------------------- if len(sys.argv) >= 2: accessKey = str(sys.argv[1]) print ("PARAMETERS: Access Key <%s>" % (accessKey)) else: print ("USE: python s3DeleteKey.py ") sys.exit(-1) # ----------------------- CONNECTION ------------------------------------------------ S3Connection (accessKey) print ("-----------------------------------------------------------------------------------------") print (" Open Scayle Resources associated to user. ") print ("-----------------------------------------------------------------------------------------") infoResources () # -------------- END PROCESS -------------------------------------------------------------------- print ("-----------------------------------------------------------------------------------------") print (" END Open Scayle Resources ") print ("-----------------------------------------------------------------------------------------") sys.exit(0)