From ca9c13543de9711fc44021db3825d8069cc4552d Mon Sep 17 00:00:00 2001 From: Roman Mogilatov Date: Wed, 15 Mar 2017 17:26:59 +0200 Subject: [PATCH] Update services miniapp example --- README.rst | 24 +++++++++---------- examples/miniapps/services/containers.py | 16 ++++++------- .../miniapps/services/example/services.py | 2 +- examples/miniapps/services/run.py | 8 +++---- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/README.rst b/README.rst index 739c4231..f3d87daa 100644 --- a/README.rst +++ b/README.rst @@ -280,7 +280,7 @@ great opportunity to control & manage application's structure in one place. import logging import sqlite3 - import boto.s3.connection + import boto3 import example.main import example.services @@ -292,7 +292,7 @@ great opportunity to control & manage application's structure in one place. class Core(containers.DeclarativeContainer): """IoC container of core component providers.""" - configuration = providers.Configuration('config') + config = providers.Configuration('config') logger = providers.Singleton(logging.Logger, name='example') @@ -300,12 +300,12 @@ great opportunity to control & manage application's structure in one place. class Gateways(containers.DeclarativeContainer): """IoC container of gateway (API clients to remote services) providers.""" - database = providers.Singleton(sqlite3.connect, - Core.configuration.database.dsn) + database = providers.Singleton(sqlite3.connect, Core.config.database.dsn) - s3 = providers.Singleton(boto.s3.connection.S3Connection, - Core.configuration.aws.access_key_id, - Core.configuration.aws.secret_access_key) + s3 = providers.Singleton( + boto3.client, 's3', + aws_access_key_id=Core.config.aws.access_key_id, + aws_secret_access_key=Core.config.aws.secret_access_key) class Services(containers.DeclarativeContainer): @@ -318,7 +318,7 @@ great opportunity to control & manage application's structure in one place. auth = providers.Factory(example.services.AuthService, db=Gateways.database, logger=Core.logger, - token_ttl=Core.configuration.auth.token_ttl) + token_ttl=Core.config.auth.token_ttl) photos = providers.Factory(example.services.PhotosService, db=Gateways.database, @@ -348,10 +348,10 @@ Next example demonstrates run of example application defined above: if __name__ == '__main__': # Configure platform: - Core.configuration.update({'database': {'dsn': ':memory:'}, - 'aws': {'access_key_id': 'KEY', - 'secret_access_key': 'SECRET'}, - 'auth': {'token_ttl': 3600}}) + Core.config.update({'database': {'dsn': ':memory:'}, + 'aws': {'access_key_id': 'KEY', + 'secret_access_key': 'SECRET'}, + 'auth': {'token_ttl': 3600}}) Core.logger().addHandler(logging.StreamHandler(sys.stdout)) # Run application: diff --git a/examples/miniapps/services/containers.py b/examples/miniapps/services/containers.py index 6b841a4d..d1ae0a52 100644 --- a/examples/miniapps/services/containers.py +++ b/examples/miniapps/services/containers.py @@ -3,7 +3,7 @@ import logging import sqlite3 -import boto.s3.connection +import boto3 import example.main import example.services @@ -15,7 +15,7 @@ import dependency_injector.providers as providers class Core(containers.DeclarativeContainer): """IoC container of core component providers.""" - configuration = providers.Configuration('config') + config = providers.Configuration('config') logger = providers.Singleton(logging.Logger, name='example') @@ -23,12 +23,12 @@ class Core(containers.DeclarativeContainer): class Gateways(containers.DeclarativeContainer): """IoC container of gateway (API clients to remote services) providers.""" - database = providers.Singleton(sqlite3.connect, - Core.configuration.database.dsn) + database = providers.Singleton(sqlite3.connect, Core.config.database.dsn) - s3 = providers.Singleton(boto.s3.connection.S3Connection, - Core.configuration.aws.access_key_id, - Core.configuration.aws.secret_access_key) + s3 = providers.Singleton( + boto3.client, 's3', + aws_access_key_id=Core.config.aws.access_key_id, + aws_secret_access_key=Core.config.aws.secret_access_key) class Services(containers.DeclarativeContainer): @@ -41,7 +41,7 @@ class Services(containers.DeclarativeContainer): auth = providers.Factory(example.services.AuthService, db=Gateways.database, logger=Core.logger, - token_ttl=Core.configuration.auth.token_ttl) + token_ttl=Core.config.auth.token_ttl) photos = providers.Factory(example.services.PhotosService, db=Gateways.database, diff --git a/examples/miniapps/services/example/services.py b/examples/miniapps/services/example/services.py index 4344e003..77e1ae99 100644 --- a/examples/miniapps/services/example/services.py +++ b/examples/miniapps/services/example/services.py @@ -82,7 +82,7 @@ class PhotosService(BaseService): :type db: sqlite3.Connection :param s3: AWS S3 client. - :type s3: boto.s3.connection.S3Connection + :type s3: botocore.client.S3 """ self.logger = logger self.db = db diff --git a/examples/miniapps/services/run.py b/examples/miniapps/services/run.py index acd37ace..93ce99d1 100644 --- a/examples/miniapps/services/run.py +++ b/examples/miniapps/services/run.py @@ -8,10 +8,10 @@ from containers import Core, Application if __name__ == '__main__': # Configure platform: - Core.configuration.update({'database': {'dsn': ':memory:'}, - 'aws': {'access_key_id': 'KEY', - 'secret_access_key': 'SECRET'}, - 'auth': {'token_ttl': 3600}}) + Core.config.update({'database': {'dsn': ':memory:'}, + 'aws': {'access_key_id': 'KEY', + 'secret_access_key': 'SECRET'}, + 'auth': {'token_ttl': 3600}}) Core.logger().addHandler(logging.StreamHandler(sys.stdout)) # Run application: