Exemplo n.º 1
0
    def set(self, ctx: dict) -> str:
        ctx = copy.deepcopy(ctx)

        # 获取web-console context信息
        session_id = uuid.uuid4().hex

        ctx['session_id'] = session_id

        key = self.CACHE_KEY.format(project_id=self.project_id, cluster_id=self.cluster_id, session_id=session_id)

        rd_client.set(key, json.dumps(ctx, cls=JSONEncoder), ex=self.EXPIRE)

        return session_id
Exemplo n.º 2
0
    def get_client(self, ctx):
        # 每次保存最新的user_token, 12小时过期
        source_cluster_id = ctx['source_cluster_id'].lower()
        data = {'admin_user_token': ctx['admin_user_token'],
                'admin_cluster_identifier': ctx['admin_cluster_identifier'],
                'cluster_id': source_cluster_id,
                'admin_server_address': ctx['admin_server_address'],
                'mode': ctx['mode']}

        if ctx.get('should_cache_ctx') is True:
            name = f"{source_cluster_id}-u{ctx['username_slug']}"
            CACHE_KEY = f"{self.CACHE_KEY_PREFIX}:{name}"
            rd_client.set(CACHE_KEY, json.dumps(data), ex=constants.USER_CTX_EXPIRE_TIME)
        k8s_client = self.get_api_client(
            ctx['admin_server_address'], ctx['admin_cluster_identifier'], ctx['admin_user_token'], ctx)
        return k8s_client
Exemplo n.º 3
0
def handler_redis():
    from backend.utils.cache import rd_client

    if rd_client.set("__healthz__", 1) is False:
        raise HealthzError("redis set command failed")
    if rd_client.get("__healthz__") != b'1':
        raise HealthzError("redis get command failed")
Exemplo n.º 4
0
    def get_client(self, ctx):
        # 每次保存最新的user_token, 12小时过期
        source_cluster_id = ctx["source_cluster_id"].lower()
        data = {
            "admin_user_token": ctx["admin_user_token"],
            "admin_cluster_identifier": ctx["admin_cluster_identifier"],
            "cluster_id": source_cluster_id,
            "admin_server_address": ctx["admin_server_address"],
            "mode": ctx["mode"],
        }

        if ctx.get("should_cache_ctx") is True:
            name = f"{source_cluster_id}-u{ctx['username_slug']}"
            CACHE_KEY = f"{self.CACHE_KEY_PREFIX}:{name}"
            rd_client.set(CACHE_KEY, json.dumps(data), ex=constants.USER_CTX_EXPIRE_TIME)
        k8s_client = self.get_api_client(
            ctx["admin_server_address"], ctx["admin_cluster_identifier"], ctx["admin_user_token"], ctx
        )
        return k8s_client