async def set_console_roles_in_cache( self, user, roles, expiration=config.get("group_mapping_config.role_cache_expiration", 21600), ): """Set roles in cache with a nominal expiration""" stats.count("set_console_roles_in_cache") if not self.red: self.red = await RedisHandler().redis() expiration = int(time.time()) + expiration role_blob = json.dumps({ "user": user, "roles": roles, "expiration": expiration }) crypto = Crypto() sig = crypto.sign(role_blob) key = config.get("group_mapping_config.role_cache_redis_key", "ROLE_CACHE_{}").format(user) sig_key = config.get("group_mapping_config.role_cache_redis_sig_key", "ROLE_CACHE_SIG_{}").format(user) try: self.red.setex(key, expiration, role_blob) self.red.setex(sig_key, expiration, sig) except ConnectionError: log.error("Error connecting to Redis.", exc_info=True)
from furl import furl from pydantic import ValidationError from consoleme.config import config from consoleme.handlers.base import BaseAPIV2Handler, BaseMtlsHandler from consoleme.lib.auth import can_create_roles, can_delete_roles, can_delete_roles_app from consoleme.lib.aws import clone_iam_role, create_iam_role, delete_iam_role from consoleme.lib.crypto import Crypto from consoleme.lib.generic import str2bool from consoleme.lib.plugins import get_plugin_by_name from consoleme.lib.v2.roles import get_role_details from consoleme.models import CloneRoleRequestModel, RoleCreationRequestModel stats = get_plugin_by_name(config.get("plugins.metrics", "default_metrics"))() log = config.get_logger() crypto = Crypto() auth = get_plugin_by_name(config.get("plugins.auth", "default_auth"))() aws = get_plugin_by_name(config.get("plugins.aws", "default_aws"))() group_mapping = get_plugin_by_name( config.get("plugins.group_mapping", "default_group_mapping"))() internal_policies = get_plugin_by_name( config.get("plugins.internal_policies", "default_policies"))() class RoleConsoleLoginHandler(BaseAPIV2Handler): async def get(self, role=None): """ Attempt to retrieve credentials and redirect the user to the AWS Console --- description: Retrieves credentials and redirects user to AWS console. responses: