Esempio n. 1
0
    def _get_project_id(self, access_token, project_id_or_code: str) -> str:
        cache_key = f'BK_DEVOPS_BCS:PROJECT_ID:{project_id_or_code}'
        project_id = region.get(cache_key, expiration_time=EXPIRATION_TIME)

        if not project_id:
            paas_cc = PaaSCCClient(auth=ComponentAuth(access_token))
            project_data = paas_cc.get_project(project_id_or_code)
            project_id = project_data['project_id']
            region.set(cache_key, project_id)

        return project_id
Esempio n. 2
0
    def _get_enabled_project(self, access_token,
                             project_id_or_code: str) -> Optional[FancyDict]:
        cache_key = f"BK_DEVOPS_BCS:ENABLED_BCS_PROJECT:{project_id_or_code}"
        project = region.get(cache_key, expiration_time=EXPIRATION_TIME)
        if project and isinstance(project, FancyDict):
            return project

        paas_cc = PaaSCCClient(auth=ComponentAuth(access_token))
        project_data = paas_cc.get_project(project_id_or_code)
        project = FancyDict(**project_data)

        self._refine_project(project)

        # 用户绑定了项目, 并且选择了编排类型
        if project.cc_app_id != 0 and project.kind in ClusterType:
            region.set(cache_key, project)
            return project

        return None
Esempio n. 3
0
    def _get_enabled_project(self, access_token,
                             project_id_or_code: str) -> Optional[FancyDict]:
        cache_key = bcs_project_cache_key.format(
            project_id_or_code=project_id_or_code)
        project = region.get(cache_key, expiration_time=EXPIRATION_TIME)
        if project and isinstance(project, FancyDict):
            return project

        paas_cc = PaaSCCClient(auth=ComponentAuth(access_token))
        project_data = paas_cc.get_project(project_id_or_code)
        project = FancyDict(**project_data)

        self._refine_project(project)

        # 项目绑定了业务,即开启容器服务
        if project.cc_app_id != 0:
            region.set(cache_key, project)
            return project

        return None