#NEWLINE# def present( name , keys = None , user = None , keyserver = None , gnupghome = None , trust = None , **kwargs ) : #NEWLINE# #INDENT# "\n    Ensure GPG public key is present in keychain\n\n    name\n        The unique name or keyid for the GPG public key.\n\n    keys\n        The keyId or keyIds to add to the GPG keychain.\n\n    user\n        Add GPG keys to the user's keychain\n\n    keyserver\n        The keyserver to retrieve the keys from.\n\n    gnupghome\n        Override GNUPG Home directory\n\n    trust\n        Trust level for the key in the keychain,\n        ignored by default.  Valid trust levels:\n        expired, unknown, not_trusted, marginally,\n        fully, ultimately\n\n\n    " #NEWLINE# ret = { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'result' : True , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'comment' : [ ] , #NEWLINE# #UNINDENT# } #NEWLINE# _current_keys = __salt__ [ 'gpg.list_keys' ] ( ) #NEWLINE# current_keys = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for key in _current_keys : #NEWLINE# #INDENT# keyid = key [ 'keyid' ] #NEWLINE# current_keys [ keyid ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# current_keys [ keyid ] [ 'trust' ] = key [ 'trust' ] #NEWLINE# #UNINDENT# if ( not keys ) : #NEWLINE# #INDENT# keys = name #NEWLINE# #UNINDENT# if isinstance ( keys , string_types ) : #NEWLINE# #INDENT# keys = [ keys ] #NEWLINE# #UNINDENT# for key in keys : #NEWLINE# #INDENT# if ( key in current_keys . keys ( ) ) : #NEWLINE# #INDENT# if trust : #NEWLINE# #INDENT# if ( trust in _VALID_TRUST_VALUES ) : #NEWLINE# #INDENT# if ( current_keys [ key ] [ 'trust' ] != TRUST_MAP [ trust ] ) : #NEWLINE# #INDENT# result = __salt__ [ 'gpg.trust_key' ] ( keyid = key , trust_level = trust , user = user ) #NEWLINE# if ( ( 'result' in result ) and ( not result [ 'result' ] ) ) : #NEWLINE# #INDENT# ret [ 'result' ] = result [ 'result' ] #NEWLINE# ret [ 'comment' ] . append ( result [ 'comment' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'comment' ] . append ( 'Set trust level for {0} to {1}' . format ( key , trust ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'comment' ] . append ( 'GPG Public Key {0} already in correct trust state' . format ( gnupghome ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'comment' ] . append ( 'Invalid trust level {0}' . format ( trust ) ) #NEWLINE# #UNINDENT# #UNINDENT# ret [ 'comment' ] . append ( 'GPG Public Key {0} already in keychain ' . format ( key ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# result = __salt__ [ 'gpg.receive_keys' ] ( keyserver , key , user , gnupghome ) #NEWLINE# if ( ( 'result' in result ) and ( not result [ 'result' ] ) ) : #NEWLINE# #INDENT# ret [ 'result' ] = result [ 'result' ] #NEWLINE# ret [ 'comment' ] . append ( result [ 'comment' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'comment' ] . append ( 'Adding {0} to GPG keychain' . format ( name ) ) #NEWLINE# #UNINDENT# if trust : #NEWLINE# #INDENT# if ( trust in _VALID_TRUST_VALUES ) : #NEWLINE# #INDENT# result = __salt__ [ 'gpg.trust_key' ] ( keyid = key , trust_level = trust , user = user ) #NEWLINE# if ( ( 'result' in result ) and ( not result [ 'result' ] ) ) : #NEWLINE# #INDENT# ret [ 'result' ] = result [ 'result' ] #NEWLINE# ret [ 'comment' ] . append ( result [ 'comment' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'comment' ] . append ( 'Set trust level for {0} to {1}' . format ( key , trust ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'comment' ] . append ( 'Invalid trust level {0}' . format ( trust ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# ret [ 'comment' ] = '\n' . join ( ret [ 'comment' ] ) #NEWLINE# #UNINDENT# return ret