fixed syntax errors

This commit is contained in:
Austin Lucas Lake 2024-05-01 11:03:10 -07:00 committed by Austin Lucas Lake
parent 6760591c54
commit 90a8906d3e
No known key found for this signature in database
GPG key ID: 6A37FA54CFCFA4DB
2 changed files with 15 additions and 14 deletions

View file

@ -13,9 +13,9 @@ __metaclass__ = type
DOCUMENTATION = ''' DOCUMENTATION = '''
module: github_gpg_key module: github_gpg_key
short_description: Manage GitHub access keys short_description: Manage GitHub GPG keys
description: description:
- Creates, removes, or updates GitHub GPG keys. - Creates, removes, or list GitHub GPG keys.
extends_documentation_fragment: extends_documentation_fragment:
- community.general.attributes - community.general.attributes
attributes: attributes:
@ -224,7 +224,7 @@ class GitHubSession(object):
headers = { headers = {
'Authorization': 'token %s' % self.token, 'Authorization': 'token %s' % self.token,
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Accept': 'application/vnd.github.v3+json', 'Accept': 'application/vnd.github.v3+json'
} }
response, info = fetch_url( response, info = fetch_url(
self.module, url, method=method, data=data, headers=headers) self.module, url, method=method, data=data, headers=headers)
@ -268,7 +268,7 @@ def create_key(session, name, armored_public_key, check_mode):
"can_encrypt_comms": True, "can_encrypt_comms": True,
"can_encrypt_storage": True, "can_encrypt_storage": True,
"can_certify": False, "can_certify": False,
"created_at": datetime.strftime(now_t, "%Y-%m-%dT%H:%M:%SZ"), "created_at": now_t.strftime("%Y-%m-%dT%H:%M:%SZ"),
"expires_at": None, "expires_at": None,
"revoked": False "revoked": False
}], }],
@ -276,7 +276,7 @@ def create_key(session, name, armored_public_key, check_mode):
"can_encrypt_comms": False, "can_encrypt_comms": False,
"can_encrypt_storage": False, "can_encrypt_storage": False,
"can_certify": True, "can_certify": True,
"created_at": datetime.strftime(now_t, "%Y-%m-%dT%H:%M:%SZ"), "created_at": now_t.strftime("%Y-%m-%dT%H:%M:%SZ"),
"expires_at": None, "expires_at": None,
"revoked": False, "revoked": False,
"raw_key": armored_public_key "raw_key": armored_public_key
@ -334,7 +334,7 @@ def ensure_key_present(module, session, name, armored_public_key, force, check_m
} }
def run_module(module, token, name, armored_public_key, state, force, check_mode) def run_module(module, token, name, armored_public_key, state, force, check_mode):
session = GitHubSession(module, token) session = GitHubSession(module, token)
if state == 'present': if state == 'present':
ensure_key_present(module, session, name, armored_public_key, force=force, ensure_key_present(module, session, name, armored_public_key, force=force,
@ -355,7 +355,7 @@ def main():
} }
module = AnsibleModule( module = AnsibleModule(
argument_spec=argument_spec, argument_spec=argument_spec,
supports_check_mode=True, supports_check_mode=True
) )
armored_public_key = module.params.get('armored_public_key') armored_public_key = module.params.get('armored_public_key')
@ -381,5 +381,6 @@ def main():
) )
module.exit_json(**result) module.exit_json(**result)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View file

@ -91,7 +91,7 @@ def create_gpg_key_mock(url, request):
"can_encrypt_comms": True, "can_encrypt_comms": True,
"can_encrypt_storage": True, "can_encrypt_storage": True,
"can_certify": False, "can_certify": False,
"created_at": datetime.strftime(now_t, "%Y-%m-%dT%H:%M:%SZ"), "created_at": now_t.strftime("%Y-%m-%dT%H:%M:%SZ"),
"expires_at": None, "expires_at": None,
"revoked": False "revoked": False
}], }],
@ -99,7 +99,7 @@ def create_gpg_key_mock(url, request):
"can_encrypt_comms": False, "can_encrypt_comms": False,
"can_encrypt_storage": False, "can_encrypt_storage": False,
"can_certify": True, "can_certify": True,
"created_at": datetime.strftime(now_t, "%Y-%m-%dT%H:%M:%SZ"), "created_at": now_T.strftime("%Y-%m-%dT%H:%M:%SZ"),
"expires_at": None, "expires_at": None,
"revoked": False, "revoked": False,
"raw_key": gpg_key.get("armored_public_key") "raw_key": gpg_key.get("armored_public_key")
@ -127,7 +127,7 @@ class TestGithubRepo(unittest.TestCase):
'name': {'required': True}, 'name': {'required': True},
'armored_public_key': {}, 'armored_public_key': {},
'state': {'choices': ['present', 'absent'], 'default': 'present'}, 'state': {'choices': ['present', 'absent'], 'default': 'present'},
'force': {'default': True, 'type': 'bool'}, 'force': {'default': True, 'type': 'bool'}
} }
self.module = AnsibleModule( self.module = AnsibleModule(
argument_spec=argument_spec, argument_spec=argument_spec,
@ -138,7 +138,7 @@ class TestGithubRepo(unittest.TestCase):
@with_httmock(create_gpg_key_mock) @with_httmock(create_gpg_key_mock)
def test_create_gpg_key_repo(self): def test_create_gpg_key_repo(self):
result = github_gpg_key.run_module( result = github_gpg_key.run_module(
module=self.module module=self.module,
token="github_access_token", token="github_access_token",
name="GPG public key", name="GPG public key",
armored_public_key="-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n\n\nMy ASCII-armored GPG public key\r\n-----END PGP PUBLIC KEY BLOCK-----", armored_public_key="-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n\n\nMy ASCII-armored GPG public key\r\n-----END PGP PUBLIC KEY BLOCK-----",