diff --git a/automation/service/apigee_tls_keystore.py b/automation/service/apigee_tls_keystore.py index 44385e2..4b262a7 100755 --- a/automation/service/apigee_tls_keystore.py +++ b/automation/service/apigee_tls_keystore.py @@ -130,15 +130,19 @@ def create_keystore(session: Session, org_name: str, env_name: str, keystore_nam return Keystore(keystore_name) -def create_aliases(session: Session, org_name: str, env_name: str, keystore_name: str, alias_name: str, path_name: str) -> Alias: +def create_aliases(session: Session, org_name: str, env_name: str, keystore_name: str, alias_name: str, + cert_file: str, key_file: str) -> Alias: """Creates an alias in tls keystores Apigee with the given name""" url = (APIGEE_API_URL + '/keystores/{}/aliases?alias={}&format={}').format(org_name, env_name, keystore_name, - alias_name, "pkcs12") + alias_name, "keycertfile") - file_name = {"file": open(path_name, 'rb')} - header = {'Content-Type': 'multipart/form-data'} + files = { + 'certFile': ('fullchain.pem', open(cert_file, 'rb')), + 'keyFile': ('key.pem', open(key_file, 'rb')), + } - response = session.post(url, headers=header, files=file_name) + header = {'Content-Type': 'multipart/form-data'} + response = session.post(url, headers=header, files=files) if response.status_code != 201: raise Exception(print_error(response)) diff --git a/automation/upload_portal_documentation.py b/automation/upload_portal_documentation.py index 1dcc24f..ba9226e 100755 --- a/automation/upload_portal_documentation.py +++ b/automation/upload_portal_documentation.py @@ -43,13 +43,12 @@ def spec_exists(org_name: str, spec_name: str) -> bool: def documentation_exists( spec_name: str, - portal_name: str, - page_size: int) -> ApiDoc: + portal_name: str, pagesize) -> ApiDoc: """Retrieves a list of API Products exposed on a portal and checks if there is an existing one using the given spec name.""" response = REQUEST.get( - 'https://apigee.com/portals/api/sites/{}/apidocs?pageSize={}'.format(portal_name, page_size)) + 'https://apigee.com/portals/api/sites/{}/apidocs?pageSize={}'.format(portal_name, pagesize)) if response.status_code != 200: raise RestException(utils.print_error(response)) @@ -157,10 +156,6 @@ def parse_args(): '-rt', '--refresh_token', help='apigee refresh token') - req_grp.add_argument( - '-pgs', - '--page_size', - help='page size for API calls that use paging - default is 100') parsed = parser.parse_args() @@ -182,9 +177,6 @@ def main(): password = args.password refresh_token = args.refresh_token - # Some API calls make use of paging, if the page size is not defined, we default it to 100. - page_size = 100 if args.page_size is None else args.page_size - data = open(doc_path, 'r', encoding='utf8').read() doc = json.loads(data) @@ -218,7 +210,7 @@ def main(): # the spec ID dynamically. doc.update({'specContent': spec_id}) - api_doc = documentation_exists(spec_name, current_portal.id, page_size) + api_doc = documentation_exists(spec_name, current_portal.id) if api_doc: print("API Doc already exists.") try: diff --git a/automation/upload_tls.py b/automation/upload_tls.py index f7ca496..440ef74 100755 --- a/automation/upload_tls.py +++ b/automation/upload_tls.py @@ -50,9 +50,14 @@ def parse_args(): help='name of the alias', required=True) req_grp.add_argument( - '-f', - '--file', - help='local file path of the pck12 certificate', + '-cf', + '--cert_file', + help='local file path of the pem certificate file', + required=True) + req_grp.add_argument( + '-kf', + '--key_file', + help='local file path of the pem private key file', required=True) req_grp.add_argument( '-u', @@ -94,7 +99,8 @@ def main(): keystore_name = args.keystore + "-" + datetime.datetime.today().strftime('%Y%m%d') portal_keystore_name = env_name + "-" + datetime.datetime.today().strftime('%Y%m%d') alias_name = args.alias - cert_file = args.file + cert_file = args.cert_file + key_file = args.key_file username = args.username password = args.password refresh_token = args.refresh_token @@ -124,7 +130,8 @@ def main(): # Create a new alias for the keystore on Apigee if there isn't an existing one. if alias_name not in alias_list: print('Alias does not exist - creating it on Apigee.') - alias = apigee_tls_keystore.create_aliases(REQUEST, org_name, env_name, keystore_name, alias_name, cert_file) + alias = apigee_tls_keystore.create_aliases(REQUEST, org_name, env_name, keystore_name, alias_name, + cert_file, key_file) print(f'Alias is successfully created and certificate uploaded! {alias}') else: print('Certification can not be updated!') diff --git a/automation/upload_tls_alias.py b/automation/upload_tls_alias.py index 73bf665..809ecb2 100755 --- a/automation/upload_tls_alias.py +++ b/automation/upload_tls_alias.py @@ -35,9 +35,14 @@ def parse_args(): help='name of the alias', required=True) req_grp.add_argument( - '-f', - '--file', - help='local file path of the pck12 certificate', + '-cf', + '--cert_file', + help='local file path of the pem certificate file', + required=True) + req_grp.add_argument( + '-kf', + '--key_file', + help='local file path of the pem private key file', required=True) req_grp.add_argument( '-u', @@ -68,7 +73,8 @@ def main(): env_name = args.env keystore_name = args.keystore alias_name = args.alias - cert_file = args.file + cert_file = args.cert_file + key_file = args.key_file username = args.username password = args.password refresh_token = args.refresh_token @@ -95,7 +101,8 @@ def main(): # Create a new alias for the keystore on Apigee if there isn't an existing one. if alias_name not in alias_list: print('Alias does not exist - creating it on Apigee.') - alias = apigee_tls_keystore.create_aliases(REQUEST, org_name, env_name, keystore_name, alias_name, cert_file) + alias = apigee_tls_keystore.create_aliases(REQUEST, org_name, env_name, keystore_name, + alias_name, cert_file, key_file) print(f'Alias is successfully created and certificate uploaded! {alias}') else: print('Certificate updated!')