Package: directory-components
directory-componentsReusable components used across the GREAT platform for the Department for Business and Trade.Installationpip install directory-componentsDevelopment$ git clone https://github.com/uktrade/directory-components
$ cd directory-components
$ [create virtual environment and activate]
$ make install_requirementsTo test cookies locally add this to your /etc/hosts:127.0.0.1       components.trade.greatThen visit the demo atcomponents.trade.great:9013CommandsCommandDescriptionmake cleanDelete pyc filesmake pytestRun all tests. Runpip install .[test] firstmake pytest test_foo.pyRun all tests in file called test_foo.pymake pytest -- --last-failed`Run the last tests to failmake pytest -- -k fooRun the test called foomake pytest --Run arbitrary pytest commandmake flake8Run lintingmake manageRun arbitrary management commandmake webserverRun the demo development web server. Runpip install .[demo] firstmake requirementsCompile the requirements filemake install_requirementsInstalled the compile requirements filemake cssCompile scss to cssmake publishPublish the package to PyPIFeaturesEnvironment variablesEnvironment variableNotesFEATURE_MAINTENANCE_MODE_ENABLEDControlsMaintenanceModeMiddleware.FEATURE_FLAGSPlace to store the service's feature flags.DIRECTORY_COMPONENTS_VAULT_DOMAINHashicorp vault domain. For diffing vaults.DIRECTORY_COMPONENTS_VAULT_ROOT_PATHHashicorp vault root path. For diffing vaults.DIRECTORY_COMPONENTS_VAULT_PROJECTHashicorp vault project. For diffing vaults.DIRECTORY_COMPONENTS_VAULT_IGNORE_SETTINGS_REGEXSettings to ignore when diffing vaults.MiddlewareMiddleware can be found indirectory_components.middleware.FooBar.MiddlewareNotesMaintenanceModeMiddlewareRedirects tohttp://sorry.great.gov.ukifFEATURE_MAINTENANCE_MODE_ENABLEDistrue.NoCacheMiddlwarePrevents any page in the service from caching pages of logged in users.PrefixUrlMiddlewareRedirects use from unprefixed url to prefixed url.Context processorsMiddleware can be found indirectory_components.context_processors.foo_bar.ProcessorContext variable nameNotessso_processorExposes the state of the SSO user.analyticsdirectory_components_analyticsGA details. Used by base template.header_footer_processorheader_footer_urlsUrls used by base template's header and footer.urls_processordirectory_components_urlsMore urls used by base template's header and footer.feature_flagsfeature_flagsExposes the service's feature flags.Exception handlersAdd the following to your urls.py for directory components templates to be used on 404 and 500handler404 = 'directory_components.views.handler404'

handler500 = 'directory_components.views.handler500'Without doing this the 500 and 400 pages would not receive context data provided by context processorsSettings janitorManagement commands are provided to assist in the maintenance of settings. Install bypip install directory-components[janitor]and then add the following tosettings.py:if some_predicate_is_met:  # feature flagged so it's not used in prod
    INSTALLED_APPS.append('directory_components.janitor')Diff vaultsYou can diff the vaults of two environments by running the following.manage.py vault_diff \
    --token=<token> \
    --domain=<domain> \
    --root=<root> \
    --project=<project> \
    --environment_a=<environment_a> \
    --environment_b=<environment_b>For simplicity once you set theDIRECTORY_COMPONENTS_VAULT_DOMAIN,DIRECTORY_COMPONENTS_VAULT_PROJECT, andDIRECTORY_COMPONENTS_VAULT_ROOT_PATHthat simplifies tomanage.py environment_diff \
    --token=<token> \
    --environment_a=<environment_a> \
    --environment_b=<environment_b>Update vaultsYou can batch update the vaults of all your environments by running the followingmanage.py vault_update -- \
    --token=<token> \
    --domain=<domain> \
    --root=<root> \
    --mutator='path.to.function'mutatoris the path to a function relative to the project root. The call signature issecrets=dict, path=str. The return dict will be uploaded to vault.For simplicity once you set theDIRECTORY_COMPONENTS_VAULT_DOMAIN, andDIRECTORY_COMPONENTS_VAULT_ROOT_PATHthat simplifies to:manage.py vault_update \
    --token=<token> \
    --mutator='path.to.function'Detect settings orphansYou can detect settings that are either unused in the codebase, redundant because they're explicitly set to the default django value, or obsolete because they're set in the vault but not used anywhere:manage.py settings_shake \
    --token=<token> \
    --root=<root> \
    --domain=<domain> \
    --project=<project> \
    --environment=<environment>For simplicity once you set theDIRECTORY_COMPONENTS_VAULT_DOMAIN,DIRECTORY_COMPONENTS_VAULT_PROJECT, andDIRECTORY_COMPONENTS_VAULT_ROOT_PATHthat simplifies tomanage.py settings_shake \
    --token=<token> \
    --environment=<environment>Publish to PyPIThe package should be published to PyPI on merge to master. If you need to do it locally then get the credentials from rattic and add the environment variables to your host machine:SettingDIRECTORY_PYPI_USERNAMEDIRECTORY_PYPI_PASSWORDThen run the following command:make publish