openssl_privatekey: Standardize implementaton of the module

The OpenSSLObject class has been merged[1]. This commit makes the
openssl_privatekey rely on this class and standardize the way openssl
module should be written.

Co-Authored-By: Christian Pointner <cpointner@mgit.at>

[1] https://github.com/ansible/ansible/pull/26945
This commit is contained in:
Yanis Guenane 2017-07-24 10:49:22 +02:00 committed by Michael Scherer
commit d72ac0b391
3 changed files with 74 additions and 50 deletions

View file

@ -95,11 +95,20 @@ class OpenSSLObject(object):
self.changed = False
self.check_mode = check_mode
@abc.abstractmethod
def check(self):
def check(self, module, perms_required=True):
"""Ensure the resource is in its desired state."""
pass
def _check_state():
return os.path.exists(self.path)
def _check_perms(module):
file_args = module.load_file_common_arguments(module.params)
return not module.set_fs_attributes_if_different(file_args, False)
if not perms_required:
return _check_state()
return _check_state() and _check_perms(module)
@abc.abstractmethod
def dump(self):