Configuration#

pyramid_blacksmith is configuring the clients using the settings of the pyramid configurator, usually loaded via a paste.ini file format.

The configuration here will use this format for clarity.

Include pyramid_blacksmith as a pyramid plugin#

If you read the Pyramid documentation, there are many way to initialize its Configurator, lets go straigth to the point, by loging the plugin using the pyramid depencency injection.

def includeme(config):
   # Load the blacksmith binding
   config.include('pyramid_blacksmith')

The line above will read the configuration bellow from the config.registry.settings.

Loading resources#

The first setting is used to fillout the blacksmith registry.

blacksmith.scan =
   my.resources
   maybe.another.resources

Note

The resources is a list of packages.

Service Discovery#

A service discovery method has to be configured, and blacksmith discover can be choosen following the example bellow.

Example using a static#

blacksmith.client.service_discovery = static
blacksmith.client.static_sd_config = 
    foo     http://foo:8000/
    bar/v1  http://bar:8000/v1

Example using a consul#

blacksmith.client.service_discovery = consul
blacksmith.client.consul_sd_config = 
    addr                            http://consul:8500/v1
    service_name_fmt                {service}-{version}
    service_url_fmt                 http://{address}:{port}/{version}
    unversioned_service_name_fmt    {service}
    unversioned_service_url_fmt     http://{address}:{port}

Example using the router#

blacksmith.client_router.service_discovery = router
blacksmith.client_router.router_sd_config = 
    service_url_fmt                 http://router/{service}-{version}/{version}
    unversioned_service_url_fmt     http://router/{service}

Note

This strategy is perfect for testing too. You can use the following section in your test.ini file.

blacksmith.client_router.service_discovery = router
blacksmith.client_router.router_sd_config =
    service_url_fmt                 http://{service}.{version}
    unversioned_service_url_fmt     http://{service}.NaN

Timeout#

blacksmith.client.read_timeout = 5
blacksmith.client.connect_timeout = 2

Proxies#

blacksmith.client.proxies =
   http://   https://letmeout.example.net:8443/
   https://  https://letmeout.example.net:8443/

Disable Certificate Verification#

blacksmith.client.verify_certificate = false

Important

This let your application vulnerable to man-in-the-middle.
Great power came with great responsabilities.

Updating the collection parser#

While consuming API that does not do bared collection, a collection parser has to be set in blacksmith to change the collection_get method that deserialize and build back the pyrantic model.

blacksmith.client.collection_parser = path.to.module:MyCollectionParser

Updating the error parser#

While consuming API, the unboxed error is by default a HTTPError, to add a generic parser for a whole client factory, the path to the error_parser can be provided as a setting.

blacksmith.client.error_parser = path.to.module:MyErrorParser

Middlewares#

The blacksmith middlewares can also be configured using the configurator, this is going to be documented in the next chapters.

In blacksmith, there are global middlewares per ClientFactory, and there are middlewares per Client. Global Middlewares are usefull for metrics, tracing, caching, but they are not usesull for authentication in a multi user application. Middleware Factories are usefull for that purpose.