def make_app(name, debug, serverName, version, requestIdHolder, sessionIdHolder):
    serviceJwtHolder = SettableValueHolder(value=None)
    requester = Requester(requestIdHolder=requestIdHolder, requestJwtHolder=serviceJwtHolder)
    guardianClient = GuardianClient(requester=requester)
    serviceJwt = guardianClient.login_with_password(userId=constants.SERVICE_ID, password=constants.SERVICE_PASSWORD, maxTokenAge=60 * 60)
    serviceJwtHolder.set_value(value=serviceJwt)

    requestJwtHolder = SettableValueHolder(value=None)
    jwtAuthorizer = JwtAuthorizer(jwtRefreshingClient=GuardianRefreshingClient(requester=Requester(requestIdHolder=requestIdHolder)))
    databaseConnection = connections.get_database()
    userClient = RegisterClient(requester=requester)
    serviceRetriever = ServiceRetriever()
    serviceSaver = ServiceSaver()
    serviceManager = ServiceManager(databaseConnection=databaseConnection, serviceRetriever=serviceRetriever, serviceSaver=serviceSaver, userClient=userClient)
    serviceServletSaver = ServiceServletSaver()
    serviceServletRetriever = ServiceServletRetriever()
    serviceServletManager = ServiceServletManager(databaseConnection=databaseConnection, serviceRetriever=serviceRetriever, serviceServletRetriever=serviceServletRetriever, serviceServletSaver=serviceServletSaver)
    serviceServletEnvironmentSaver = ServiceServletEnvironmentSaver()
    serviceServletEnvironmentRetriever = ServiceServletEnvironmentRetriever() # pylint: disable=invalid-name
    serviceServletEnvironmentManager = ServiceServletEnvironmentManager(databaseConnection=databaseConnection, serviceServletEnvironmentSaver=serviceServletEnvironmentSaver, serviceServletEnvironmentRetriever=serviceServletEnvironmentRetriever)   # pylint: disable=invalid-name
    inceptionApiV0 = InceptionApiV0(requestIdHolder=requestIdHolder, sessionIdHolder=sessionIdHolder, requestJwtHolder=requestJwtHolder, jwtAuthorizer=jwtAuthorizer, serviceManager=serviceManager, serviceServletManager=serviceServletManager, serviceServletEnvironmentManager=serviceServletEnvironmentManager)
    inceptionApiV1 = InceptionApiV1(requestIdHolder=requestIdHolder, sessionIdHolder=sessionIdHolder, requestJwtHolder=requestJwtHolder, jwtAuthorizer=jwtAuthorizer, serviceManager=serviceManager, serviceServletManager=serviceServletManager, serviceServletEnvironmentManager=serviceServletEnvironmentManager)
    healthApiProvider = JwtRefreshingHealthApiProvider(requestIdHolder=requestIdHolder, sessionIdHolder=sessionIdHolder, serverName=serverName, serverVersion=version, jwtAuthorizer=jwtAuthorizer, jwtToRefreshHolder=serviceJwtHolder)
    swaggerApiProvider = SwaggerApiProvider(requestIdHolder=requestIdHolder, sessionIdHolder=sessionIdHolder)
    application = CarbonFlask(importName=name, debug=debug, serverName=serverName, version=version)

    application.register_providers(carbonApiProviders=[inceptionApiV0, inceptionApiV1, healthApiProvider, swaggerApiProvider], disableTimeLimits=debug)
    return application
def make_app(name, debug, serverName, version, requestIdHolder,
             sessionIdHolder):
    serviceJwtHolder = SettableValueHolder(value=None)
    requester = Requester(requestIdHolder=requestIdHolder,
                          requestJwtHolder=serviceJwtHolder)
    authorizationClient = GuardianClient(requester=requester)
    serviceJwt = authorizationClient.login_with_password(
        userId=constants.SERVICE_ID,
        password=constants.SERVICE_PASSWORD,
        maxTokenAge=60 * 60)
    serviceJwtHolder.set_value(value=serviceJwt)
    broomClient = BroomClient(requester=requester)
    webpageProcessor = WebpageProcessor(
        requester=requester,
        htmlTidyClient=broomClient,
        dateParserLanguages=DATA_PARSER_LANGUAGES)

    jwtAuthorizer = JwtAuthorizer(jwtRefreshingClient=GuardianRefreshingClient(
        requester=Requester(requestIdHolder=requestIdHolder)))
    requestJwtHolder = SettableValueHolder(value=None)
    chadApiV0 = ChadApiV0(requestIdHolder=requestIdHolder,
                          requestJwtHolder=requestJwtHolder,
                          jwtAuthorizer=jwtAuthorizer,
                          sessionIdHolder=sessionIdHolder,
                          webpageProcessor=webpageProcessor)

    application = CarbonFlask(importName=name,
                              debug=debug,
                              serverName=serverName,
                              version=version)
    healthApiProvider = JwtRefreshingHealthApiProvider(
        requestIdHolder=requestIdHolder,
        sessionIdHolder=sessionIdHolder,
        serverName=serverName,
        serverVersion=version,
        jwtToRefreshHolder=serviceJwtHolder,
        jwtAuthorizer=jwtAuthorizer)
    swaggerApiProvider = SwaggerApiProvider(requestIdHolder=requestIdHolder,
                                            sessionIdHolder=sessionIdHolder)
    carbonApiProviders = [healthApiProvider, swaggerApiProvider, chadApiV0]
    application.register_providers(carbonApiProviders=carbonApiProviders)
    return application
                              version=version)
    healthApiProvider = JwtRefreshingHealthApiProvider(
        requestIdHolder=requestIdHolder,
        sessionIdHolder=sessionIdHolder,
        serverName=serverName,
        serverVersion=version,
        jwtToRefreshHolder=serviceJwtHolder,
        jwtAuthorizer=jwtAuthorizer)
    swaggerApiProvider = SwaggerApiProvider(requestIdHolder=requestIdHolder,
                                            sessionIdHolder=sessionIdHolder)
    carbonApiProviders = [healthApiProvider, swaggerApiProvider, chadApiV0]
    application.register_providers(carbonApiProviders=carbonApiProviders)
    return application


REQUEST_ID_HOLDER = SettableValueHolder(value=None)
SESSION_ID_HOLDER = SettableValueHolder(value=None)
logging_formatter.init_logging(serverName=constants.SERVER_NAME,
                               environment=constants.ENVIRONMENT,
                               version=constants.VERSION,
                               requestIdHolder=REQUEST_ID_HOLDER,
                               sessionIdHolder=SESSION_ID_HOLDER)

app = make_app(name=__name__,
               debug=constants.DEBUG,
               serverName=constants.SERVER_NAME,
               version=constants.VERSION,
               requestIdHolder=REQUEST_ID_HOLDER,
               sessionIdHolder=SESSION_ID_HOLDER)  # pylint: disable=invalid-name

if __name__ == '__main__':
Ejemplo n.º 4
0
def make_worker(requestIdHolder):
    dictCache = DictCache()
    serviceJwtHolder = SettableValueHolder(value=None)
    requester = Requester(requestIdHolder=requestIdHolder,
                          requestJwtHolder=serviceJwtHolder,
                          caches=[dictCache])
    guardianClient = GuardianClient(requester=requester)
    serviceJwt = guardianClient.login_with_password(
        userId=constants.SERVICE_ID,
        password=constants.SERVICE_PASSWORD,
        maxTokenAge=60 * 60)
    serviceJwtHolder.set_value(value=serviceJwt)

    databaseConnection = connections.get_database()
    redisConnection = connections.get_redis_connection()
    storageClient = S3StorageClient()
    rawWebpageStore = RawArticleStore(storageClient=storageClient,
                                      mimetype=http_util.MIMETYPE_HTML)
    rawAqmStore = RawArticleStore(storageClient=storageClient,
                                  mimetype=http_util.MIMETYPE_JSON)
    redisCache = RedisCache(keyPrefix=constants.SERVER_BASE_NAME,
                            redisConnection=redisConnection)
    redisLockingClient = RedisLockingClient(
        keyPrefix=constants.SERVER_BASE_NAME, redisConnection=redisConnection)
    imageUrlStore = ImageUrlStore(keyPrefix=constants.SERVER_BASE_NAME)
    preCalculatedImageUrlStore = PreCalculatedImageUrlStore(
        keyPrefix=constants.SERVER_BASE_NAME)

    articleMetadataRetriever = ArticleMetadataRetriever()
    articleContentRetriever = ArticleContentRetriever()
    articleSourceRetriever = ArticleSourcesRetriever()
    articleSearchIndexClient = WormClient(requester=requester)
    babelClient = BabelClient(requester=requester)
    bapClient = BapClient(requester=requester)
    sweepClient = SweepClient(requester=requester)
    journoClient = JournoClient(requester=requester)
    monicaClient = MonicaClient(requester=requester)
    pamClient = PamClient(requester=requester)
    valveClient = ValveClient(requester=requester)
    stitchClient = StitchClient(requester=requester)
    frankClient = FrankClient(requester=requester)
    lingoClient = LingoClient(requester=requester)
    picassoClient = PicassoClient(requester=requester)
    articleSaver = ArticleSaver()

    imageUrlFilterer = ImageUrlFilterer(
        imageUrlStore=imageUrlStore,
        preCalculatedImageUrlStore=preCalculatedImageUrlStore)
    externalRequester = Requester(requestIdHolder=requestIdHolder)
    imageSizeRetriever = ImageSizeRetriever(requester=externalRequester)
    articleRetrievingClient = ArticleRetrievingClient(
        aqmArticleClient=pamClient, webArticleClient=journoClient)
    articleManager = ArticleManager(
        databaseConnection=databaseConnection,
        rawWebpageStore=rawWebpageStore,
        rawAqmStore=rawAqmStore,
        articleMetadataRetriever=articleMetadataRetriever,
        articleContentRetriever=articleContentRetriever,
        articleSaver=articleSaver,
        articleTaggingClient=stitchClient,
        imageUrlStore=imageUrlStore,
        preCalculatedImageUrlStore=preCalculatedImageUrlStore,
        frankClient=frankClient,
        articleSourceRetriever=articleSourceRetriever,
        redisConnection=redisConnection,
        articleSearchIndexClient=articleSearchIndexClient,
        languageClient=lingoClient)
    articleProcessor = ArticleProcessor(
        requester=externalRequester,
        redisConnection=redisConnection,
        cache=redisCache,
        imageSizeRetriever=imageSizeRetriever,
        imageUrlFilterer=imageUrlFilterer,
        imageClient=picassoClient,
        lockingClient=redisLockingClient,
        articleRetrievingClient=articleRetrievingClient,
        htmlCleaningClient=sweepClient,
        htmlProcessingClient=bapClient,
        switchClient=valveClient,
        articleManager=articleManager,
        languageClient=lingoClient,
        languageTranslatingClient=babelClient)

    jwtAuthorizer = JwtAuthorizer(jwtRefreshingClient=GuardianRefreshingClient(
        requester=Requester(requestIdHolder=requestIdHolder)))
    articleQueueMessageClient = ArticleQueueMessageClient(
        jwtAuthorizer=jwtAuthorizer,
        jwtToRefreshHolder=serviceJwtHolder,
        articleProcessor=articleProcessor,
        articleManager=articleManager,
        hostClient=monicaClient)
    messageQueue = SqsMessageQueue(
        name=constants.QUEUE_NAME_ARTICLE_PROCESSING,
        region=constants.QUEUE_REGION_ARTICLE_PROCESSING,
        requestIdHolder=requestIdHolder)
    return MessageQueueProcessor(requestIdHolder=requestIdHolder,
                                 messageQueue=messageQueue,
                                 messageClient=articleQueueMessageClient)
Ejemplo n.º 5
0
def make_app(name, debug, serverName, version, requestIdHolder,
             sessionIdHolder):
    dictCache = DictCache()
    serviceJwtHolder = SettableValueHolder(value=None)
    requester = Requester(requestIdHolder=requestIdHolder,
                          requestJwtHolder=serviceJwtHolder,
                          caches=[dictCache])
    guardianClient = GuardianClient(requester=requester)
    serviceJwt = guardianClient.login_with_password(
        userId=constants.SERVICE_ID,
        password=constants.SERVICE_PASSWORD,
        maxTokenAge=60 * 60)
    serviceJwtHolder.set_value(value=serviceJwt)

    databaseConnection = connections.get_database()
    redisConnection = connections.get_redis_connection()
    storageClient = S3StorageClient()
    imageUrlStore = ImageUrlStore(keyPrefix=constants.SERVER_BASE_NAME)
    preCalculatedImageUrlStore = PreCalculatedImageUrlStore(
        keyPrefix=constants.SERVER_BASE_NAME)

    rawWebpageStore = RawArticleStore(storageClient=storageClient,
                                      mimetype=http_util.MIMETYPE_HTML)
    rawAqmStore = RawArticleStore(storageClient=storageClient,
                                  mimetype=http_util.MIMETYPE_JSON)
    articleContentRetriever = ArticleContentRetriever()
    articleMetadataRetriever = ArticleMetadataRetriever()
    articleSourceRetriever = ArticleSourcesRetriever()
    wormClient = WormClient(requester=requester)
    stitchClient = StitchClient(requester=requester)
    frankClient = FrankClient(requester=requester)
    lingoClient = LingoClient(requester=requester)
    articleSaver = ArticleSaver()
    articleManager = ArticleManager(
        databaseConnection=databaseConnection,
        rawWebpageStore=rawWebpageStore,
        rawAqmStore=rawAqmStore,
        articleMetadataRetriever=articleMetadataRetriever,
        articleContentRetriever=articleContentRetriever,
        articleSaver=articleSaver,
        articleTaggingClient=stitchClient,
        imageUrlStore=imageUrlStore,
        preCalculatedImageUrlStore=preCalculatedImageUrlStore,
        frankClient=frankClient,
        articleSourceRetriever=articleSourceRetriever,
        redisConnection=redisConnection,
        articleSearchIndexClient=wormClient,
        languageClient=lingoClient)

    penguinQueue = SqsMessageQueue(
        requestIdHolder=requestIdHolder,
        region=constants.QUEUE_REGION_ARTICLE_PROCESSING,
        name=constants.QUEUE_NAME_ARTICLE_PROCESSING,
        messageDelay=constants.MAX_REPLICA_LAG)

    requestJwtHolder = SettableValueHolder(value=None)
    jwtAuthorizer = JwtAuthorizer(jwtRefreshingClient=GuardianRefreshingClient(
        requester=Requester(requestIdHolder=requestIdHolder)))
    penguinApiV0 = PenguinApiV0(requestIdHolder=requestIdHolder,
                                requestJwtHolder=requestJwtHolder,
                                jwtAuthorizer=jwtAuthorizer,
                                sessionIdHolder=sessionIdHolder,
                                penguinQueue=penguinQueue,
                                articleManager=articleManager)
    penguinApiV1 = PenguinApiV1(requestIdHolder=requestIdHolder,
                                requestJwtHolder=requestJwtHolder,
                                jwtAuthorizer=jwtAuthorizer,
                                sessionIdHolder=sessionIdHolder,
                                penguinQueue=penguinQueue,
                                articleManager=articleManager)
    penguinApiV2 = PenguinApiV2(requestIdHolder=requestIdHolder,
                                requestJwtHolder=requestJwtHolder,
                                jwtAuthorizer=jwtAuthorizer,
                                sessionIdHolder=sessionIdHolder,
                                penguinQueue=penguinQueue,
                                articleManager=articleManager)
    penguinApiV3 = PenguinApiV3(requestIdHolder=requestIdHolder,
                                requestJwtHolder=requestJwtHolder,
                                jwtAuthorizer=jwtAuthorizer,
                                sessionIdHolder=sessionIdHolder,
                                penguinQueue=penguinQueue,
                                articleManager=articleManager)
    penguinApiV4 = PenguinApiV4(requestIdHolder=requestIdHolder,
                                requestJwtHolder=requestJwtHolder,
                                jwtAuthorizer=jwtAuthorizer,
                                sessionIdHolder=sessionIdHolder,
                                penguinQueue=penguinQueue,
                                articleManager=articleManager)

    healthApiProvider = JwtRefreshingHealthApiProvider(
        requestIdHolder=requestIdHolder,
        sessionIdHolder=sessionIdHolder,
        serverName=serverName,
        serverVersion=version,
        jwtAuthorizer=jwtAuthorizer,
        jwtToRefreshHolder=serviceJwtHolder)
    swaggerApiProvider = SwaggerApiProvider(requestIdHolder=requestIdHolder,
                                            sessionIdHolder=sessionIdHolder)
    application = CarbonFlask(importName=name,
                              debug=debug,
                              serverName=serverName,
                              version=version)
    carbonApiProviders = [
        healthApiProvider, swaggerApiProvider, penguinApiV0, penguinApiV1,
        penguinApiV2, penguinApiV3, penguinApiV4
    ]
    application.register_providers(carbonApiProviders=carbonApiProviders)

    return application