passerelle/passerelle/contrib/toulouse_maelis/tools/check_wsdl.py

65 lines
1.8 KiB
Python
Executable File

#!/usr/bin/python3
import argparse
import os
import subprocess
import sys
import requests
import utils
def check_one(args, service):
wsdl_url = utils.get_wsdl_url(args.env, service)
print(wsdl_url)
# previous result
wsdl_file_path = 'wsdl/%sService.wsdl' % service.title()
if not os.path.exists(wsdl_file_path):
with open(wsdl_file_path, 'w'):
pass
result = requests.get(wsdl_url, verify=False)
assert result.status_code == 200
# result
last_wsdl_file_path = wsdl_file_path + '.new'
with open(last_wsdl_file_path, 'w') as wsdl_last_file:
wsdl_last_file.write(result.text)
# diff
if args.verbose > 1:
stdout = stderr = None
else:
stdout = stderr = subprocess.PIPE
cmd = 'diff %s %s' % (wsdl_file_path, last_wsdl_file_path)
output = subprocess.run(cmd, shell=True, check=False, stdout=stdout, stderr=stderr)
if output.returncode:
print('WSDL change on %s' % service)
return output.returncode
def check(args):
returncode = 0
utils.configure_logging(args.verbose)
if args.service == 'all':
for service in ['family', 'activity', 'invoice', 'ape', 'site']:
result = check_one(args, service)
returncode = returncode or result
else:
returncode = check_one(args, args.service)
sys.exit(returncode)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--verbose', '-v', type=int, default=2, help='display errors')
parser.add_argument('--env', '-e', default='integ', help='dev, test, integ, prod')
parser.add_argument(
'service', help='family, activity, invoice, ape, site or all', nargs='?', default='all'
)
args = parser.parse_args()
check(args)