Skip to content

Commit

Permalink
Merge pull request #42 from Venafi/update_vcert_dependency
Browse files Browse the repository at this point in the history
Update vcert dependency
  • Loading branch information
rvelaVenafi authored Nov 9, 2023
2 parents f20c4ed + fc86c63 commit 4ee9549
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,10 @@ ansible-molecule:

unit-test:
PYTHONPATH=./:$PYTHONPATH pytest ./tests/certificate/test_venafi_certificate.py

install:
ansible-galaxy collection build --force
ansible-galaxy collection install venafi-machine_identity-1.0.1.tar.gz --force

uninstall:
rm -rf ~/.ansible/collections/ansible_collections/venafi
33 changes: 21 additions & 12 deletions plugins/modules/venafi_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ def enroll(self):
self.module.fail_json(msg="Missing parameter for Service Generated CSR: %s" % F_PK_PASSPHRASE)
request.include_private_key = True
self.serialize_private_key = True
if self.privatekey_type is not None:
request.key_type = self._get_key_type()

elif self.csr_origin == CSR_ORIGIN_PROVIDED:
if not self.csr_path:
Expand All @@ -465,17 +467,7 @@ def enroll(self):
private_key = to_text(open(self.privatekey_filename, "rb").read())
request.private_key = private_key
elif self.privatekey_type:
key_type = {"RSA": "rsa", "ECDSA": "ec", "EC": "ec"}.get(self.privatekey_type)
if not key_type:
self.module.fail_json(msg=("Failed to determine key type: %s. Must be RSA or ECDSA"
% self.privatekey_type))
if key_type == "rsa":
request.key_type = KeyType(KeyType.RSA, self.privatekey_size)
elif key_type == "ecdsa" or key_type == "ec":
request.key_type = KeyType(KeyType.ECDSA, self.privatekey_curve)
else:
self.module.fail_json(msg=("Failed to determine key type: %s. Must be RSA or ECDSA"
% self.privatekey_type))
request.key_type = self._get_key_type()
self.serialize_private_key = True
else:
self.module.fail_json(msg="Failed to determine %s: %s" % (F_CSR_ORIGIN, self.csr_origin))
Expand Down Expand Up @@ -506,6 +498,23 @@ def enroll(self):
if self.serialize_private_key and cert.key is not None:
self._atomic_write(self.privatekey_filename, cert.key)

def _get_key_type(self):
"""
:rtype: KeyType
"""
key_type = {"RSA": "rsa", "ECDSA": "ec", "EC": "ec"}.get(self.privatekey_type)
if not key_type:
self.module.fail_json(msg=("Failed to determine key type: %s. Must be RSA or ECDSA"
% self.privatekey_type))
if key_type == "rsa":
return KeyType(KeyType.RSA, self.privatekey_size)
elif key_type == "ecdsa" or key_type == "ec":
return KeyType(KeyType.ECDSA, self.privatekey_curve)
else:
self.module.fail_json(msg=("Failed to determine key type: %s. Must be RSA or ECDSA"
% self.privatekey_type))

def _get_pkcs12_cert_path(self):
"""
Expand Down Expand Up @@ -783,7 +792,7 @@ def main():
module.exit_json(**change_dump)

if not vcert.check_dirs_existed():
module.fail_json(msg="Dirs not existed")
module.fail_json(msg="directories do not exist")
if change_dump['changed']:
# TODO: Cover it by tests
"""
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
vcert==0.16.0
vcert==0.16.2
ansible==8.0.0
cryptography==40.0.2

0 comments on commit 4ee9549

Please sign in to comment.