Skip to main content

Initial configuration layer for microservices

Project description

# Initial configuration layer for Microservices

![](http://www.italiamappe.it/mappa/ImmaginiVetrine/0000106274/Immagine1lrg.jpg)


```json
_ _ _ _
| (_) | | (_)
__| |_ ___ ___| | __ _ _ _ __ ___ ___ _ __
/ _` | / __|/ __| |/ _` | | '_ ` _ \ / _ \ '__|
| (_| | \__ \ (__| | (_| | | | | | | | __/ |
\__,_|_|___/\___|_|\__,_|_|_| |_| |_|\___|_|


```

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.


# How to add it to your microservice

```python
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)
)
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()

```

# 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\"}]}"
}
```
```json
{
"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
```json

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

# Example of the message service sends to request the configuration

```json

{
"topic": "tcgetconf",
"value": {
"cmd": "get_conf",
"auth": "ASC",
"service_name": "myservicename"
}
}
```
# Example of a response

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

```


License
-------
MIT License


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

configuration_layer-1.0.9.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

configuration_layer-1.0.9-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file configuration_layer-1.0.9.tar.gz.

File metadata

File hashes

Hashes for configuration_layer-1.0.9.tar.gz
Algorithm Hash digest
SHA256 8207a4f79f46c41cd121ea8d8a4c47406b71d05096a7745bebd3fb3d8299f42f
MD5 5c09c59fbb800cda37f52a26b336fbcd
BLAKE2b-256 7a180579f17d22c439fc3114383241500412d2665ca3759729807268b1018c6f

See more details on using hashes here.

File details

Details for the file configuration_layer-1.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for configuration_layer-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 8f0b062993c493cd561ebbfaa2725da1fc4c90cc14c66e4cc42af23fc0d9b676
MD5 59c65353895cc21b87e1ee6feacd1649
BLAKE2b-256 9effadc0de5f4eeb3497d66c6e5d679cfaeffa0d9be412a1178f9cf399a03b4e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page