mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Import public key
This commit is contained in:
parent
1931870f26
commit
506ff01f65
@ -3825,6 +3825,46 @@ def create_keypair(kwargs=None, call=None):
|
||||
sigver='4')
|
||||
return data
|
||||
|
||||
def import_keypair(kwargs=None, call=None):
|
||||
'''
|
||||
Import an SSH public key
|
||||
'''
|
||||
if call != 'function':
|
||||
log.error(
|
||||
'The import_keypair function must be called with -f or --function.'
|
||||
)
|
||||
return False
|
||||
|
||||
if not kwargs:
|
||||
kwargs = {}
|
||||
|
||||
if 'keyname' not in kwargs:
|
||||
log.error('A keyname is required.')
|
||||
return False
|
||||
|
||||
if 'file' not in kwargs:
|
||||
log.error('A public key file is required.')
|
||||
return False
|
||||
|
||||
params = {'Action': 'ImportKeyPair',
|
||||
'KeyName': kwargs['keyname']}
|
||||
|
||||
public_key_file = kwargs['file']
|
||||
|
||||
if os.path.exists(public_key_file):
|
||||
with salt.utils.fopen(public_key_file, 'r') as fh_:
|
||||
public_key = fh_.read()
|
||||
|
||||
if public_key is not None:
|
||||
params['PublicKeyMaterial'] = base64.b64encode(public_key)
|
||||
|
||||
data = aws.query(params,
|
||||
return_url=True,
|
||||
location=get_location(),
|
||||
provider=get_provider(),
|
||||
opts=__opts__,
|
||||
sigver='4')
|
||||
return data
|
||||
|
||||
def show_keypair(kwargs=None, call=None):
|
||||
'''
|
||||
|
Loading…
Reference in New Issue
Block a user