@@ -301,23 +301,24 @@ def present(
301301 )
302302 return ret
303303
304- # Get only the path to the file without env referrences to check if exists
305304 if source != "" :
305+ # Get only the path to the file without env references to check if exists
306306 source_path = __salt__ ["cp.get_url" ](source , None , saltenv = __env__ )
307307
308- if source != "" and not source_path :
309- data = "no key"
310- elif source != "" and source_path :
311- # ssh.set_auth_key_from_file already reads and add/replace all keys
312- # from source file.
313- data = __salt__ ["ssh.set_auth_key_from_file" ](
314- user ,
315- source ,
316- config = config ,
317- saltenv = __env__ ,
318- fingerprint_hash_type = fingerprint_hash_type ,
319- options = options ,
320- )
308+ # Extract Key from file if source is present
309+ if not source_path :
310+ data = "no key"
311+ else :
312+ # ssh.set_auth_key_from_file already reads and add/replace all keys
313+ # from source file.
314+ data = __salt__ ["ssh.set_auth_key_from_file" ](
315+ user ,
316+ source ,
317+ config = config ,
318+ saltenv = __env__ ,
319+ fingerprint_hash_type = fingerprint_hash_type ,
320+ options = options ,
321+ )
321322 else :
322323 data = __salt__ ["ssh.set_auth_key" ](
323324 user ,
@@ -435,23 +436,23 @@ def absent(
435436 )
436437 return ret
437438
438- # Get only the path to the file without env referrences to check if exists
439439 if source != "" :
440+ # Get only the path to the file without env references to check if exists
440441 source_path = __salt__ ["cp.get_url" ](source , None , saltenv = __env__ )
441442
442- # Extract Key from file if source is present
443- if source != "" and not source_path :
444- data = "no key"
445- elif source != "" and source_path :
446- # ssh.rm_auth_key_from_file already reads and delete all keys
447- # from source file.
448- ret ["comment" ] = __salt__ ["ssh.rm_auth_key_from_file" ](
449- user ,
450- source ,
451- config ,
452- saltenv = __env__ ,
453- fingerprint_hash_type = fingerprint_hash_type ,
454- )
443+ # Extract Key from file if source is present
444+ if not source_path :
445+ data = "no key"
446+ else :
447+ # ssh.rm_auth_key_from_file already reads and delete all keys
448+ # from source file.
449+ ret ["comment" ] = __salt__ ["ssh.rm_auth_key_from_file" ](
450+ user ,
451+ source ,
452+ config ,
453+ saltenv = __env__ ,
454+ fingerprint_hash_type = fingerprint_hash_type ,
455+ )
455456 else :
456457 # Get just the key
457458 sshre = re .
compile (
r"^(.*?)\s?((?:sk-)?(?:ssh\-|ecds)[\[email protected] ]+\s.+)$" )
0 commit comments