code: def sdb_get_or_set_hash(uri,
                          opts,
                          length=8,
                          chars='abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)',
                          utils=None):
      '''
      Check if value exists in sdb.  If it does, return, otherwise generate a
      random string and store it.  This can be used for storing secrets in a
      centralized place.
      '''
      if not isinstance(uri, string_types) or not uri.startswith('sdb://'):
          return False
  
      if utils is None:
          utils = salt.loader.utils(opts)
  
      ret = sdb_get(uri, opts, utils=utils)
  
      if ret is None:
          val = ''.join([random.SystemRandom().choice(chars) for _ in range(length)])
          sdb_set(uri, val, opts, utils)
  
      return ret or vaf sdb_get_or_set_hash(uri,
                          opts,
                          length=8,
                          chars='abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)',
                          utils=None):
      '''
      Check if value exists in sdb.  If it does, return, otherwise generate a
      random string and store it.  This can be used for storing secrets in a
      centralized place.
      '''
      if not isinstance(uri, string_types) or not uri.startswith('sdb://'):
          return False
  
      if utils is None:
          utils = salt.loader.utils(opts)
  
      ret = sdb_get(uri, opts, utils=utils)
  
      if ret is None:
          val = ''.join([random.SystemRandom().choice(chars) for _ in range(length)])
          sdb_set(uri, val, opts, utils)
  
      return ret or val
docs: Check if value exists in sdb.  If it does, return, otherwise generate a
      random string and store it.  This can be used for storing secrets in a
      centralized place.