def get(self, request, project_id): image_list = [] # 获取公共镜像 pub_query = {'access_token': self.request.user.token.access_token} pub_resp = api.get_public_image_list(pub_query) pub_image_data = pub_resp.get('data', {}) or {} pub_image_list = pub_image_data.get('imageList', []) for _pub in pub_image_list: _repo = _pub.get('repo') image_list.append({ 'name': _repo.split(settings.DEPOT_PREFIX)[-1] if settings.DEPOT_PREFIX else _repo, 'value': _repo, 'is_pub': True, }) # 获取项目镜像 access_token = self.request.user.token.access_token pro_query = { 'repoType': 'all', 'projectId': project_id, 'access_token': access_token } pro_query[ 'project_code'] = self.request.project.english_name if 'english_name' in self.request.project else '' pro_resp = api.get_project_image_list(pro_query) pro_image_data = pro_resp.get('data', {}) or {} pro_image_list = pro_image_data.get('imageList', []) pro_name = request.project.project_code if settings.DEPOT_PREFIX: repo_prefix = f"{settings.DEPOT_PREFIX}/{pro_name}/" else: repo_prefix = f'{pro_name}/' for _pub in pro_image_list: image_list.append({ 'name': _pub.get('repo').split(repo_prefix)[-1] if pro_name else _pub.get('repo'), 'value': _pub.get('repo'), 'is_pub': False, }) return response.Response({ "code": 0, "message": "success", "data": image_list })
def get_images(self, project_id, params): params['project_id'] = project_id query = convert_mappings(self.ResultMappings, params, reversed=True) query["access_token"] = self.request.user.token.access_token query['project_code'] = self.request.project.project_code return api.get_project_image_list(query)