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.
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".
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With