def get_cert_file(name, cert_format=_DEFAULT_FORMAT):
 ret = dict()
 cmd = list()
 blacklist_keys = ['DnsNameList']
 cert_format = cert_format.lower()
 _validate_cert_format(name=cert_format)
 if ((not name) or (not os.path.isfile(name))):
  _LOG.error('Path is not present: %s', name)
  return ret
 if (cert_format == 'pfx'):
  cmd.append("Get-PfxCertificate -FilePath '{0}'".format(name))
  cmd.append(' | Select-Object DnsNameList, SerialNumber, Subject, Thumbprint, Version')
 else:
  cmd.append('$CertObject = New-Object')
  cmd.append(' System.Security.Cryptography.X509Certificates.X509Certificate2;')
  cmd.append(" $CertObject.Import('{0}'); $CertObject".format(name))
  cmd.append(' | Select-Object DnsNameList, SerialNumber, Subject, Thumbprint, Version')
 items = _cmd_run(cmd=str().join(cmd), as_json=True)
 for item in items:
  for key in item:
   if (key not in blacklist_keys):
    ret[key.lower()] = item[key]
  ret['dnsnames'] = [name['Unicode'] for name in item['DnsNameList']]
 if ret:
  _LOG.debug('Certificate thumbprint obtained successfully: %s', name)
 else:
  _LOG.error('Unable to obtain certificate thumbprint: %s', name)
 return ret

def get_cert_file ( name , cert_format = _DEFAULT_FORMAT ) : ret = dict ( ) cmd = list ( ) blacklist_keys = [ 'DnsNameList' ] cert_format = cert_format . lower ( ) _validate_cert_format ( name = cert_format ) if ( ( not name ) or ( not os . path . isfile ( name ) ) ) : _LOG . error ( 'Path is not present: %s' , name ) return ret if ( cert_format == 'pfx' ) : cmd . append ( "Get-PfxCertificate -FilePath '{0}'" . format ( name ) ) cmd . append ( ' | Select-Object DnsNameList, SerialNumber, Subject, Thumbprint, Version' ) else : cmd . append ( '$CertObject = New-Object' ) cmd . append ( ' System.Security.Cryptography.X509Certificates.X509Certificate2;' ) cmd . append ( " $CertObject.Import('{0}'); $CertObject" . format ( name ) ) cmd . append ( ' | Select-Object DnsNameList, SerialNumber, Subject, Thumbprint, Version' ) items = _cmd_run ( cmd = str ( ) . join ( cmd ) , as_json = True ) for item in items : for key in item : if ( key not in blacklist_keys ) : ret [ key . lower ( ) ] = item [ key ] ret [ 'dnsnames' ] = [ name [ 'Unicode' ] for name in item [ 'DnsNameList' ] ] if ret : _LOG . debug ( 'Certificate thumbprint obtained successfully: %s' , name ) else : _LOG . error ( 'Unable to obtain certificate thumbprint: %s' , name ) return ret
get the cert file location or bail .