代码之家  ›  专栏  ›  技术社区  ›  Peter Smit

在google appengine(python)中存储配置的好地方是什么?

  •  14
  • Peter Smit  · 技术社区  · 14 年前

    我正在开发一个Google Appengine应用程序,我怀疑我是否应该存储(敏感)配置数据,比如凭证。

    我应该为配置创建一个大表实体,还是有其他建议的方法来存储它?

    3 回复  |  直到 8 年前
        1
  •  18
  •   Nick Johnson    14 年前

    class Configuration(db.Model):
      _INSTANCE = None
    
      @classmethod
      def get_instance(cls):
        if not cls._INSTANCE:
          cls._INSTANCE = cls.get_or_insert('config')
        return cls._INSTANCE
    

    class Configuration(db.Model):
      CACHE_TIME = datetime.timedelta(minutes=5)
    
      _INSTANCE = None
      _INSTANCE_AGE = None
    
      @classmethod
      def get_instance(cls):
        now = datetime.datetime.now()
        if not cls._INSTANCE or cls._INSTANCE_AGE + cls.CACHE_TIME < now:
          cls._INSTANCE = cls.get_or_insert('config')
          cls._INSTANCE_AGE = now
        return cls._INSTANCE
    
        2
  •  10
  •   moraes    14 年前

    config.py

    AMAZON_KEY = 'XXXX'
    

    import config
    service = my_amazon_service(config.AMAZON_KEY)
    

        3
  •  4
  •   Martin Omander    8 年前

    from google.appengine.ext import ndb
    
    class Settings(ndb.Model):
      name = ndb.StringProperty()
      value = ndb.StringProperty()
    
      @staticmethod
      def get(name):
        NOT_SET_VALUE = "NOT SET"
        retval = Settings.query(Settings.name == name).get()
        if not retval:
          retval = Settings()
          retval.name = name
          retval.value = NOT_SET_VALUE
          retval.put()
        if retval.value == NOT_SET_VALUE:
          raise Exception(('Setting %s not found in the database. A placeholder ' +
            'record has been created. Go to the Developers Console for your app ' +
            'in App Engine, look up the Settings record with name=%s and enter ' +
            'its value in that record\'s value field.') % (name, name))
        return retval.value
    

    AMAZON_KEY = Settings.get('AMAZON_KEY')