Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good place to store configuration in Google AppEngine (python)

I am making a Google AppEngine application and am doubting were I should store (sensitive) configuration data like credentials.

Should I make a single bigtable entity for configuration, or is there another advised way to store it.

like image 885
Peter Smit Avatar asked Sep 23 '10 10:09

Peter Smit


People also ask

What are the development technologies currently supported by App Engine?

Google App Engine primarily supports Go, PHP, Java, Python, Node. js, . NET, and Ruby applications, although it can also support other languages via "custom runtimes".

What are the different ways of storing application data in Google App Engine?

To store data and files on App Engine, you can use Google Cloud services or any other storage service that is supported by your language and is accessible from your App Engine instance. Third-party databases can be hosted on another cloud provider, hosted on premises, or managed by a third-party vendor.

What is App Engine standard environment?

The App Engine standard environment is based on container instances running on Google's infrastructure. Containers are preconfigured with one of several available runtimes. The standard environment makes it easy to build and deploy an application that runs reliably even under heavy load and with large amounts of data.


2 Answers

If you're okay with embedding them in your source, you can do that, but if you need it to be dynamically configurable, the datastore is the way to go. You can avoid fetching the settings on every request by caching them in local memory. Here's a helper class for that:

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

Simply subclass this with whatever configuration values you need (or modify the class itself). Because loaded code persists between requests, you'll only have to do a single fetch per app instance - though if you want to be able to update the configuration dynamically, you may want to build in a timeout.

If you want to cache stuff for a limited time, your best option is simply storing the timestamp when you fetched it:

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
like image 133
Nick Johnson Avatar answered Nov 01 '22 17:11

Nick Johnson


Store them in a module. You can go simple, like having a config.py module with, say:

AMAZON_KEY = 'XXXX'

Then use:

import config
service = my_amazon_service(config.AMAZON_KEY)

Or have a slightly more sophisticated config object that allows you to have sensible defaults for your app, namespaced config keys etc.

like image 31
moraes Avatar answered Nov 01 '22 18:11

moraes