1
1
#!/usr/bin/python
2
2
# -*- coding: utf-8 -*-
3
3
4
- # Copyright 2024, Austin Lucas Lake <[email protected] .com>
4
+ # Copyright (c) 2024-2025 , Austin Lucas Lake <git@austinlucaslake .com>
5
5
# Based on community.general.github_key module by Ansible Project
6
6
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
7
7
# SPDX-License-Identifier: GPL-3.0-or-later
14
14
module: github_gpg_key
15
15
author: Austin Lucas Lake (@austinlucaslake)
16
16
short_description: Manage GitHub GPG keys
17
- version_added: 9.0 .0
17
+ version_added: 10.5 .0
18
18
description:
19
19
- Creates or removes GitHub GPG keys for an authenticated user.
20
20
extends_documentation_fragment:
48
48
force:
49
49
description:
50
50
- The default is V(true), which will replace the existing remote key
51
- if it is different than O(pubkey ). If V(false), the key will only be
51
+ if it is different than O(armored_public_key ). If V(false), the key will only be
52
52
set if no key with the given O(name) exists.
53
53
type: bool
54
54
default: true
62
62
returned: When O(state=absent)
63
63
sample: [{
64
64
'id': 3,
65
- 'name': ' Octocat's GPG Key' ,
65
+ 'name': " Octocat's GPG Key" ,
66
66
'primary_key_id': 2,
67
67
'key_id': '3262EFF25BA0D270',
68
68
'public_key': 'xsBNBFayYZ...',
100
100
returned: When O(state=present)
101
101
sample: [{
102
102
'id': 3,
103
- 'name': ' Octocat's GPG Key' ,
103
+ 'name': " Octocat's GPG Key" ,
104
104
'primary_key_id': 2,
105
105
'key_id': '3262EFF25BA0D270',
106
106
'public_key': 'xsBNBFayYZ...',
137
137
returned: When O(state=present)
138
138
sample: {
139
139
'id': 3,
140
- 'name': ' Octocat's GPG Key' ,
140
+ 'name': " Octocat's GPG Key" ,
141
141
'primary_key_id': 2,
142
142
'key_id': '3262EFF25BA0D270',
143
143
'public_key': 'xsBNBFayYZ...',
@@ -239,39 +239,7 @@ def get_all_keys(session):
239
239
def create_key (session , name , armored_public_key , check_mode ):
240
240
if check_mode :
241
241
now_t = now ()
242
- return {
243
- 'id' : 3 ,
244
- 'name' : name ,
245
- 'primary_key_id' : 2 ,
246
- 'key_id' : '3262EFF25BA0D270' ,
247
- 'public_key' : 'xsBNBFayYZ...' ,
248
- 'emails' : [{
249
-
250
- 'verified' : True
251
- }],
252
- 'subkeys' : [{
253
- 'id' : 4 ,
254
- 'primary_key_id' : 3 ,
255
- 'key_id' : '4A595D4C72EE49C7' ,
256
- 'public_key' : 'zsBNBFayYZ...' ,
257
- 'emails' : [],
258
- 'can_sign' : False ,
259
- 'can_encrypt_comms' : True ,
260
- 'can_encrypt_storage' : True ,
261
- 'can_certify' : False ,
262
- 'created_at' : now_t .strftime ('%Y-%m-%dT%H:%M:%SZ' ),
263
- 'expires_at' : None ,
264
- 'revoked' : False
265
- }],
266
- 'can_sign' : True ,
267
- 'can_encrypt_comms' : False ,
268
- 'can_encrypt_storage' : False ,
269
- 'can_certify' : True ,
270
- 'created_at' : now_t .strftime ('%Y-%m-%dT%H:%M:%SZ' ),
271
- 'expires_at' : None ,
272
- 'revoked' : False ,
273
- 'raw_key' : armored_public_key
274
- }
242
+ return {}
275
243
else :
276
244
return session .request (
277
245
'POST' ,
@@ -342,7 +310,7 @@ def run_module(module, params, check_mode):
342
310
def main ():
343
311
module = AnsibleModule (
344
312
argument_spec = dict (
345
- state = dict (type = 'str' , default = 'present' , choice = ['present' , 'absent' ]),
313
+ state = dict (type = 'str' , default = 'present' , choices = ['present' , 'absent' ]),
346
314
token = dict (type = 'str' , required = True , no_log = True ),
347
315
name = dict (type = 'str' , required = True ),
348
316
armored_public_key = dict (type = 'str' , no_log = True ),
@@ -362,7 +330,7 @@ def main():
362
330
)
363
331
module .exit_json (** result )
364
332
except Exception as e :
365
- module .fail_json (str (e ))
333
+ module .fail_json (msg = str (e ))
366
334
367
335
368
336
if __name__ == '__main__' :
0 commit comments