Skip to main content

DCG DOT Compliance Group

Project description

The module contains several features that provide functionality for various aspects of your application. Here is a breakdown of each feature:

  1. Activity Events:

    • SqlAlchemy events are used to log user activity logs to Elasticsearch.
    • The dcg_service.core.events.py file contains more details about these events.
    • It includes SqlAlchemy model events such as before_create, after_create, before_update, and after_update.
    • The module includes an ActivityEvent class and registers the event class in the __init__.py file.
    • You can exclude specific model names from activity events by adding them to the EXCLUDE_MODEL_EVENTS list in the settings.py file.
    • You can add events to log activity by specifying them in the EVENTS list in the settings.py file.
    • The model file path can be specified using the APP_MODELS variable in the settings.py file.
  2. Authentication/Permission:

    • User authentication is handled using JWT tokens.
    • You need to set the signing key and JWT algorithms in your settings file.
    • The is_authenticated function from dcg_service.core.permissions can be used as a decorator to enforce authentication on API views.
  3. Service Cache:

    • The module includes a ServicePrice class that fetches service fee structure from an Elasticsearch index.
    • To retrieve service fee details, you can call ServicePrice(service_id, units).get_fee_details().
    • The get_fee_details function has an optional include_tax parameter to include/exclude tax details.
    • Additionally, you can use get_coupon_details to retrieve the total discount and coupon code.
  4. Filters:

    • The module provides a Flask filter class that can be inherited to apply filters on querysets.
    • You can create a custom filter class by inheriting from Filter and implementing the add_filter method.
    • In your API views or functions, you can use the filter class by setting the filter_class attribute and calling apply() on an instance of the filter class.
  5. Custom Response Handler:

    • You can change the default API response format by overriding the CustomResponse class from dcg_service.core.response.
    • The overridden class should provide a response JSON with the following structure: {"data": data, "message": message, "title": self.response.status, "code": self.response.status_code}.
  6. Logger:

    • The module provides an overridden logger for better app debugging.
  7. Encryption:

    • The module includes functions for encrypting and decrypting data.
    • You need to set the CIPHER_PRIVATE_KEY environment variable with a 16-character key for AES128 encryption.
  8. Elastic-search DSL:

    • The module utilizes Elastic-search DSL for connecting and querying Elastic search indexes.
    • You need to set the ELASTICSEARCH_URL environment variable in your settings file.
    • The ACTIVITY_INDEX and SERVICE_CACHE_INDEX variables can be set to specify the indexes to be used for activity logs and service caching, respectively.

Elastic-search DSL

Elastic-search DSL is used to connect/query on elastic search indexes.

Must add following in your settings.py file:

ELASTICSEARCH_URL = os.environ.get('ELASTICSEARCH_URL')
ACTIVITY_INDEX = os.environ.get('ACTIVITY_INDEX', '').lower() # must be lower
SERVICE_CACHE_INDEX = os.environ.get('SERVICE_CACHE_INDEX')

Activity Events

SqlAlchemy events are used to log user activity logs to 'Elasticsearch'.

You can check dcg_service.core.events.py file for details.

Contains: SqlAlchemy model events before_create, after_create, before_update, after_update.

Activity event class,
registerd event class in __init__.py file

e.g.
def register_events():
    from . import events
    activity_events = events.ActivityEvent()
    activity_events.initialise_events()

register_events()

Add models names of your apps in settings.py to exclude from activity events.

e.g.  EXCLUDE_MODEL_EVENTS = ['Cart']

Add events to log activity.

e.g.  EVENTS = ['after_insert', 'before_update']

Add model file path.

e.g APP_MODELS = 'order_app.models'

Authentication/Permission

User authentication JWT token, set following details in your settings file.

    SIGNING_KEY = os.environ.get('SIGNING_KEY')
    JWT_ALGORITHMS = ['HS256']

Start using:

from dcg_service.core.permissions import is_authenticated

class ExampleView(views.MethodView):
"""
APIs Methods
-----------
GET: Get list.
"""
decorators = [is_authenticated]

def get(self):

Service cache

    Service price class to fetch service fee structure from `Elasticsearch` index.
    service_id: Respective service id,
    units: Units/quantity of service
    -----------------------------------------------------------------------------
    Call `ServicePrice(service_id, units).get_fee_details()` to get service fee details.
    
    For more information check file function docs.

Start using:

from dcg_service.core.services import ServicePrice
service = ServicePrice(service_id, units)
price_details = service.get_fee_details(include_tax=False)
total_discount, coupon_code = service.get_coupon_details()

Filters

Flask filter class, Inherit this class to apply filters on queryset.

e.g.

class ModelFilter(Filter):
    model = model_name
    def add_filter(self, *args, **kwargs):
        queryset = self.get_queryset()
        queryset = queryset.filter_by(**self.request_params)
        return queryset

use this filter class in your API view or function.

class APIView():
    filter_class = ModelFilter
    def get():
        queryset = self.filter_class(queryset).apply()

Custom Response handler

Change default API response, override dcg_service.core.response.CustomResponse class according to your need.

returns:

response_json = {
            "data": data,
            "message": message,
            "title": self.response.status,
            "code": self.response.status_code
        }

Logger

Logger override for maintain app debugging.

Encryption

Contain encrypt, decrypt functions for encryption.

Must add "CIPHER_PRIVATE_KEY" in your env:

key = os.environ['CIPHER_PRIVATE_KEY']  # Must Be 16 char for AES128

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

dcg_service-1.9.2.tar.gz (36.7 kB view details)

Uploaded Source

Built Distribution

dcg_service-1.9.2-py3-none-any.whl (44.5 kB view details)

Uploaded Python 3

File details

Details for the file dcg_service-1.9.2.tar.gz.

File metadata

  • Download URL: dcg_service-1.9.2.tar.gz
  • Upload date:
  • Size: 36.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.6

File hashes

Hashes for dcg_service-1.9.2.tar.gz
Algorithm Hash digest
SHA256 ffeb72439892a2b47bc1d0e10fe60c0051ed0235e38fb2985b91e873fceee8fc
MD5 0f71fa60bec9dea839fccd515a1e3017
BLAKE2b-256 8ad2a648a54a97f0ab1a245aceeabd0ca67e885e18f9e7972b9cdc3c22de1256

See more details on using hashes here.

File details

Details for the file dcg_service-1.9.2-py3-none-any.whl.

File metadata

  • Download URL: dcg_service-1.9.2-py3-none-any.whl
  • Upload date:
  • Size: 44.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.6

File hashes

Hashes for dcg_service-1.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5463599cdc3270d5727bca91dbc003a0da29183c9c0e000c80502961d8a81511
MD5 8f21d6746ceaa59298179ab6e84f9346
BLAKE2b-256 622610655546a4d087d482d3614624d0086c479fc8de225c96d13e41fe5f1430

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