aws_query: fix output

This commit is contained in:
themighty1
2021-11-21 19:49:40 +03:00
parent 7e83183f21
commit 292304909f

View File

@@ -5,13 +5,13 @@ import hashlib
from urllib import parse
if len(sys.argv) != 6:
print ('Output HTTPS GET links in JSON to be used to check the oracle status')
print ('Outputs HTTPS GET links in JSON to be used to check the oracle status')
print ('The default availability zone is ec2.us-east-1.amazonaws.com')
print ('Usage: ami-id instance-id volume-id AWS-ID AWS-secret')
print('Where:')
print('ami-id is the AMI from which the instance was launched,')
print('instance-id is the notary server instance, and')
print('volume-id is the volume attached to it.')
print ('Where:')
print ('ami-id is the AMI from which the instance was launched,')
print ('instance-id is the notary server instance, and')
print ('volume-id is the volume attached to it.')
exit(0)
common_args = [('Expires=2030-01-01'), ('SignatureMethod=HmacSHA256'), ('SignatureVersion=2')]
@@ -21,8 +21,10 @@ instance_id = sys.argv[2]
volume_id = sys.argv[3]
key = sys.argv[4]
secret = sys.argv[5]
output = ''
def makeurl(args, endpoint, abbr):
global output
# sorting is essential, otherwise AWS will refuse the signature
args.sort()
argstr = ''
@@ -34,10 +36,10 @@ def makeurl(args, endpoint, abbr):
base64str = base64.b64encode(mhmac.digest()).strip().decode('utf-8')
urlenc_sig = parse.quote_plus(base64str)
final_string='https://'+endpoint+'/?'+argstr+'&Signature='+urlenc_sig
print ('"' + final_string + '",', end = '')
output += '"' + final_string + '",'
print('The JSON below is an input for URLFetcher:')
print('[', end = '')
output += '['
args = []
args.extend(common_args)
args.append('Action=DescribeInstances')
@@ -105,4 +107,6 @@ args.append('ImageId.1='+ami_id)
args.append('AWSAccessKeyId='+key)
args.append('Version=2014-10-01')
makeurl(args, availability_zone, 'DImg')
print(']')
output = output[:-1]
output += ']'
print(output)