Socket
Socket
Sign inDemoInstall

directory-components

Package Overview
Dependencies
42
Maintainers
2
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    directory-components

Shared components library for Great services.


Maintainers
2

Readme

directory-components

code-climate-image circle-ci-image codecov-image pypi-image semver-image

Reusable components used across the GREAT platform for the Department for Business and Trade.


Installation

pip install directory-components

Development

$ git clone https://github.com/uktrade/directory-components
$ cd directory-components
$ [create virtual environment and activate]
$ make install_requirements

To test cookies locally add this to your /etc/hosts:

127.0.0.1       components.trade.great

Then visit the demo at components.trade.great:9013

Commands

CommandDescription
make cleanDelete pyc files
make pytestRun all tests. Run pip install .[test] first
make pytest test_foo.pyRun all tests in file called test_foo.py
make pytest -- --last-failed`Run the last tests to fail
make pytest -- -k fooRun the test called foo
make pytest -- Run arbitrary pytest command
make flake8Run linting
make manage Run arbitrary management command
make webserverRun the demo development web server. Run pip install .[demo] first
make requirementsCompile the requirements file
make install_requirementsInstalled the compile requirements file
make cssCompile scss to css
make publishPublish the package to PyPI

Features

Environment variables

Environment variableNotes
FEATURE_MAINTENANCE_MODE_ENABLEDControls MaintenanceModeMiddleware.
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.

Middleware

Middleware can be found in directory_components.middleware.FooBar.

MiddlewareNotes
MaintenanceModeMiddlewareRedirects to http://sorry.great.gov.uk if FEATURE_MAINTENANCE_MODE_ENABLED is true.
NoCacheMiddlwarePrevents any page in the service from caching pages of logged in users.
PrefixUrlMiddlewareRedirects use from unprefixed url to prefixed url.

Context processors

Middleware can be found in directory_components.context_processors.foo_bar.

ProcessorContext variable nameNotes
sso_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 handlers

Add the following to your urls.py for directory components templates to be used on 404 and 500

handler404 = '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 processors

Settings janitor

Management commands are provided to assist in the maintenance of settings. Install by pip install directory-components[janitor] and then add the following to settings.py:

if some_predicate_is_met:  # feature flagged so it's not used in prod
    INSTALLED_APPS.append('directory_components.janitor')

Diff vaults

You 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 the DIRECTORY_COMPONENTS_VAULT_DOMAIN, DIRECTORY_COMPONENTS_VAULT_PROJECT, and DIRECTORY_COMPONENTS_VAULT_ROOT_PATH that simplifies to

manage.py environment_diff \
    --token=<token> \
    --environment_a=<environment_a> \
    --environment_b=<environment_b>

Update vaults

You can batch update the vaults of all your environments by running the following

manage.py vault_update -- \
    --token=<token> \
    --domain=<domain> \
    --root=<root> \
    --mutator='path.to.function'

mutator is the path to a function relative to the project root. The call signature is secrets=dict, path=str. The return dict will be uploaded to vault.

For simplicity once you set the DIRECTORY_COMPONENTS_VAULT_DOMAIN, and DIRECTORY_COMPONENTS_VAULT_ROOT_PATH that simplifies to:

manage.py vault_update \
    --token=<token> \
    --mutator='path.to.function'

Detect settings orphans

You 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 the DIRECTORY_COMPONENTS_VAULT_DOMAIN, DIRECTORY_COMPONENTS_VAULT_PROJECT, and DIRECTORY_COMPONENTS_VAULT_ROOT_PATH that simplifies to

manage.py settings_shake \
    --token=<token> \
    --environment=<environment>

Publish to PyPI

The 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:

Setting
DIRECTORY_PYPI_USERNAME
DIRECTORY_PYPI_PASSWORD

Then run the following command:

make publish

FAQs


Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc