Skip to content

Commit

Permalink
Feature/changing the way certificates are uploaded (#56)
Browse files Browse the repository at this point in the history
* changed the way certificates are uploaded.  We are now uploading the certificate and private key as PEM files

* changed the way certificates are uploaded.  We are now uploading the certificate and private key as PEM files

* changed the way certificates are uploaded.  We are now uploading the certificate and private key as PEM files

* changed the way certificates are uploaded.  We are now uploading the certificate and private key as PEM files

* changed the way certificates are uploaded.  We are now uploading the certificate and private key as PEM files

---------

Co-authored-by: ryana-ccbill <[email protected]>
  • Loading branch information
ryanskandal and ryana-ccbill authored Jul 19, 2024
1 parent 85f227e commit ae0a563
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
lint:
runs-on: ubuntu-22.04
container: python:3.7.4-alpine3.10
env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
steps:
- name: Check out the repo
uses: actions/checkout@v2
Expand Down
14 changes: 9 additions & 5 deletions automation/service/apigee_tls_keystore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
21 changes: 14 additions & 7 deletions automation/upload_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!')
Expand All @@ -145,8 +152,8 @@ def main():
print('Keystore already exist!')
sys.exit(0)

portal_alias = apigee_tls_keystore.create_aliases(REQUEST, org_name, 'portal', portal_keystore_name, alias_name,
cert_file)
portal_alias = apigee_tls_keystore.create_aliases(REQUEST, org_name, 'portal', portal_keystore_name,
alias_name, cert_file, key_file)

settings = {"domain": domain, "force": "false", "id": None, "siteId": portal.id, "subdomain": None,
"tlsAlias": portal_alias.name, "tlsKeystore": portal_keystore_name}
Expand Down
17 changes: 12 additions & 5 deletions automation/upload_tls_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand All @@ -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!')
Expand Down

0 comments on commit ae0a563

Please sign in to comment.