Giter Club home page Giter Club logo

Comments (3)

Dreamsorcerer avatar Dreamsorcerer commented on June 20, 2024 1

@aiocache.cached(
aiocache.SimpleMemoryCache(serializer=MsgPackSerializer()),
key_builder=custom_key_builder,
)

As I suspected, you're passing a SimpleMemoryCache as the ttl argument. The examples/documentation all say to use kwargs to configure the decorator. This will likely be tightened up to disallow positional arguments in v1.

from aiocache.

Dreamsorcerer avatar Dreamsorcerer commented on June 20, 2024

Some code to reproduce would help. With no context, it looks like you've managed to set ttl to a SimpleMemoryCache.

from aiocache.

ludsrill avatar ludsrill commented on June 20, 2024
# this would work like asyncio.gather for execute all the methods
# each method call will make requests using run_boto3_fun
for finding, finding_methods in CHECKS:
      if finding not in finding_checks:
          continue
      log_blocking("info", "Executing %s methods", finding.name)
      vulnerabilities = [method(credentials) for method in finding_methods]

      # this would work like asyncio.gather for execute all the methods
      # each method call will make requests using run_boto3_fun
      results += list(
          collapse(
              await collect(vulnerabilities, workers=CPU_CORES),
              base_type=Vulnerability,
          )
      )
# here is the method that going to use the decorator

def custom_key_builder(_func: Any, *args: Any, **kwargs: Any) -> str:
    input_data = (args, kwargs)
    input_json = json.dumps(input_data, sort_keys=True)
    hash_generator = hashlib.sha256()
    hash_generator.update(input_json.encode("utf-8"))
    hash_value = hash_generator.hexdigest()
    custom_key = f"{hash_value}"
    return custom_key


@aiocache.cached(
    aiocache.SimpleMemoryCache(serializer=MsgPackSerializer()),
    key_builder=custom_key_builder,
)
async def run_boto3_fun(
    credentials: AwsCredentials,
    service: str,
    function: str,
    parameters: dict[str, object] | None = None,
    accepted_error_codes: set[str] | None = None,
) -> dict[str, dict | list]:
    try:
        session = aioboto3.Session(
            aws_access_key_id=credentials.access_key_id,
            aws_secret_access_key=credentials.secret_access_key,
            aws_session_token=credentials.session_token,
        )
        async with session.client(service) as client:
            return await getattr(client, function)(**(parameters or {}))
    except botocore.exceptions.ClientError as error:
            return {}

from aiocache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.