#-----------------------------------------------------------------------------# Copyright (c) Anaconda, Inc., and Bokeh Contributors.# All rights reserved.## The full license is in the file LICENSE.txt, distributed with this software.#-----------------------------------------------------------------------------''' Generate new secret keys that can be used by the Bokeh server tocryptographically sign session IDs.To generate a new secret key for use with Bokeh server, execute.. code-block:: sh bokeh secreton the command line. The key will be printed to standard output.The secret key can be provided to the ``bokeh serve`` command withthe ``BOKEH_SECRET_KEY`` environment variable... warning:: You must keep the secret secret! Protect it like a root password.'''#-----------------------------------------------------------------------------# Boilerplate#-----------------------------------------------------------------------------from__future__importannotationsimportlogging# isort:skiplog=logging.getLogger(__name__)#-----------------------------------------------------------------------------# Imports#-----------------------------------------------------------------------------# Standard library importsfromargparseimportNamespace# Bokeh importsfrombokeh.util.tokenimportgenerate_secret_key# Bokeh importsfrom..subcommandimportSubcommand#-----------------------------------------------------------------------------# Globals and constants#-----------------------------------------------------------------------------__all__=('Secret',)#-----------------------------------------------------------------------------# General API#-----------------------------------------------------------------------------
[docs]classSecret(Subcommand):''' Subcommand to generate a new secret key. '''#: name for this subcommandname="secret"help="Create a Bokeh secret key for use with Bokeh server"
[docs]definvoke(self,args:Namespace)->None:''' '''key=generate_secret_key()# suppress LGTM, since the intent is precisesly to output a secretprint(key)# lgtm [py/clear-text-logging-sensitive-data]
#-----------------------------------------------------------------------------# Dev API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Private API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Code#-----------------------------------------------------------------------------