Skip to main content

Initial configuration layer for Microservices

#DISCLAMER

This service is in his early age. DO NOT USE in production or if you want to, please be aware you are going to use a piece of code which probably will be changed or improved ( and not necessarily in this order) soon and very often. You have been warned! This service requires at least another service listening to a few KAFKA topics.

Service description

This service has been developed to be used as part of a multilayer microservice based infrastructure. It provides services with a layer of functionalities to be used in order to request the needed configuration settings to start a service. It uses KAFKA as messaging platform in order to exchange messages among services. In order to be used it needs a service which acts as a service-registry that receive a request and send back a response. An addition function can be executed when the configuration is received in the not breakable mode. This is comes handy when we want to add a reactive behaviour as a result of a given services' configuration update

How to add it to your microservice

from configuration_layer.service_setup.configuration_request import ConfigurationSeeker
from configuration_layer.utils.configuration_validation import validate_service_configuration
import configuration_layer.helpers.producer_messages as message
import sys, os
import datetime
from messaging_middleware.utils.logger import Logger



def check_configuration_directory():
    service_configuration_directory = os.environ.get('service_configuration_directory', 'configuration')
    if os.path.isdir(service_configuration_directory):
        return os.getcwd() + service_configuration_directory
    else:
        return False


def seeker_request(**kwargs):
    seeker = ConfigurationSeeker(consumer_topic='tcsetconf',
                                 producer_topic='tcgetconf',
                                 bootstrap_servers="your broker here",
                                 schema_registry='your schema registry here',
                                 message={"cmd": "get_conf", "auth": "ASC", "service_name": "myservicename"},
                                 key_schema={"service_name": "myservicename"},
                                 service_name='myservicename',
                                 service_configuration_directory= os.environ.get('service_configuration_directory', 'configuration'),
                                 breakable=kwargs.get('breakable', 1),
                                 set=kwargs.get('set', 0),
                                function_to_run=kwargs.get('function_to_run',None)


                                 )
    seeker.start()
    seeker.join()


if __name__ == "__main__":
    if not check_configuration_directory():
        sys.exit()

    logger = Logger()
    seeker_request()
    if validate_service_configuration():
        logger.logmsg('info', "==Configuration Completed==")
    else:
        message_to_produce = message.operation_result(service_name="myservicename",
                                                      last_operation='setconf',
                                                      timestamp=datetime.datetime.now(
                                                          datetime.timezone.utc).strftime(
                                                          '%Y-%m-%dT%H:%M:%S%z'),
                                                      operation_result=message.const_values()[
                                                          'CONFIGURATION_FILE_VALIDATION_ERROR'],
                                                      error_description='')

        logger.produce_msg(message_to_produce)
        logger.logmsg('error', "==CONFIGURATION_FILE_VALIDATION_ERROR==")
        sys.exit()

SSL Configuration

If you want to use a security protocol such as SSL, these are the changes you have to apply

from configuration_layer.service_setup.configuration_request import ConfigurationSeeker
from configuration_layer.utils.configuration_validation import validate_service_configuration
import configuration_layer.helpers.producer_messages as message
import sys, os
import datetime
from messaging_middleware.utils.logger import Logger



def check_configuration_directory():
    service_configuration_directory = os.environ.get('service_configuration_directory', 'configuration')
    if os.path.isdir(service_configuration_directory):
        return os.getcwd() + service_configuration_directory
    else:
        return False


def seeker_request(**kwargs):
    seeker = ConfigurationSeeker(consumer_topic='tcsetconf',
                                 producer_topic='tcgetconf',
                                 bootstrap_servers="your broker here",
                                 schema_registry='your schema registry here',
                                 message={"cmd": "get_conf", "auth": "ASC", "service_name": "myservicename"},
                                 key_schema={"service_name": "myservicename"},
                                 service_name='myservicename',
                                 service_configuration_directory= os.environ.get('service_configuration_directory', 'configuration'),
                                 breakable=kwargs.get('breakable', 1),
                                 set=kwargs.get('set', 0),
                                 security_protocol='ssl',
                                 function_to_run=kwargs.get('function_to_run',None)

                                 )
    seeker.start()
    seeker.join()


if __name__ == "__main__":
    if not check_configuration_directory():
        sys.exit()

    logger = Logger()
    seeker_request()
    if validate_service_configuration(ssl=1):
        logger.logmsg('info', "==Configuration Completed==")
    else:
        message_to_produce = message.operation_result(service_name="myservicename",
                                                      last_operation='setconf',
                                                      timestamp=datetime.datetime.now(
                                                          datetime.timezone.utc).strftime(
                                                          '%Y-%m-%dT%H:%M:%S%z'),
                                                      operation_result=message.const_values()[
                                                          'CONFIGURATION_FILE_VALIDATION_ERROR'],
                                                      error_description='')

        logger.produce_msg(message_to_produce)
        logger.logmsg('error', "==CONFIGURATION_FILE_VALIDATION_ERROR==")
        sys.exit()

CONFLUENT KAFKA TOPIC:

The service send message to a predefined (hardcoded atm) topic, which has the following schema registry

tcservicesmonitor-value schema message

{
    "schema": "{\"type\":\"record\",\"name\":\"key\",\"namespace\":\"example.avro\",\"fields\":[{\"name\": \"service_name\", \"type\": \"string\",\"default\": \"empty\"},{\"name\": \"last_operation\", \"type\": \"string\",\"default\": \"empty\"},{\"name\": \"timestamp\", \"type\": \"string\",\"default\": \"empty\"},{\"name\": \"operation_result\", \"type\":\"string\" },{\"name\": \"operation_description\", \"type\":\"string\" ,\"default\": \"empty\"},{\"name\": \"error_description\", \"type\":\"string\" ,\"default\": \"empty\"}]}"
}
{
  "type": "record",
  "name": "key",
  "namespace": "example.avro",
  "fields": [
    {
      "name": "service_name",
      "type": "string",
      "default": "empty"
    },
    {
      "name": "last_operation",
      "type": "string",
      "default": "empty"
    },
    {
      "name": "timestamp",
      "type": "string",
      "default": "empty"
    },
    {
      "name": "operation_result",
      "type": "string"
    },
    {
      "name": "operation_description",
      "type": "string"
    }
  ]
}

tcservicesmonitor-key schema message

{
  "type": "record",
  "name": "key",
  "namespace": "example.avro",
  "fields": [
    {
      "name": "service_name",
      "type": "string",
      "default": "empty"
    }
  ]
}

Example of how the messages payload configuration look like

request

{
  "topic": "tcgetconf", 
  "value": {
      "cmd": "get_conf", 
      "auth": "ASC", 
      "service_name": "myservicename"
      }
}

reply

{ 
    "service_name": "myservicename", 
    "start_environment": "staging",
    "datacentre": "", 
    "external_rest_services": {}, 
    "persistence_conf": {}, 
    "credentials": {}
 }

#Change Log

  • 1.0.14 Improved the incoming/outcoming messages processing. Added events handler

Metadata

Release files for configuration-layer 1.0.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for configuration-layer 1.0.17
File Size Uploaded Provenance Actions
configuration_layer-1.0.17.tar.gz 8.8 kB Without provenance Details for configuration_layer-1.0.17.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for configuration-layer 1.0.17
File Interpreter ABI Platform Actions
configuration_layer-1.0.17-py3-none-any.whl Python 3 none any Details for configuration_layer-1.0.17-py3-none-any.whl

Total release size: 19.6 kB

Release files / configuration_layer-1.0.17.tar.gz

Download URL configuration_layer-1.0.17.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
04840619b7ce934664d600275783a7449fb59e78fe111d6ba53405e91634cdff
BLAKE2b-256 checksum
How to use checksums
e86a9f3a91acf84d794f7e37d30102df4fd21a78b2ac84bd295dabe15c219842
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.13.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2

Release files / configuration_layer-1.0.17-py3-none-any.whl

Download URL configuration_layer-1.0.17-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
862313b52b08a9fa2a941deca36308f4dfa176976ae3bc7cf83458e063983b09
BLAKE2b-256 checksum
How to use checksums
c99c913bbb4d7709f1a6a5e8c348a8689ca7ce435b97d5166b1d8f1a407e9c5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.13.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2

Security for configuration-layer 1.0.17

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page