def create_project_path_by_api(access_token, project_id, project_code): """调用仓库API创建项目仓库路径 { "result": true, "message": "success", "data": { "project_id": 6, "name": "test", "creation_time": "2018-12-25 16:13:10", "update_time": "2018-12-25 16:13:10", "repo_count": 2 }, "code": 0 } """ client = HarborClient(access_token, project_id, project_code) resp = client.create_project_path() # api调用失败 if resp.get("code") != 0: error_message = "%s, %s" % ( error_codes.DepotError.f(_("创建项目仓库路径失败"), replace=True), resp.get("message", ""), ) logger.error(error_message) raise error_codes.ComponentError(error_message) return True
def get_image_tags(access_token, project_id, project_code, offset, limit, **query_params): """获取镜像信息和tag列表""" client = HarborClient(access_token, project_id, project_code) resp = client.get_image_tags(**query_params) # 处理返回数据(harbor 的tag列表没有做分页) data = resp.get("data") or {} data["has_previous"] = False data["has_next"] = False tags = data.get("tags") or [] for tag in tags: # 外部版本只有一套仓库 tag["artifactorys"] = ["PROD"] return resp
def get_jfrog_account(access_token, project_code, project_id, is_bk=False): """ 获取项目的镜像账号 """ client = HarborClient(access_token, project_id, project_code) resp = client.create_account() # api调用失败 if resp.get('code') != 0: error_message = ('%s, %s' % (bk_error_codes.DepotError("创建项目仓库账号失败"), resp.get('message', ''))) logger.error(error_message) raise error_codes.ComponentError(error_message) return resp.get('data')
def get_jfrog_account(access_token, project_code, project_id, is_bk=False): """ 获取项目的镜像账号 """ client = HarborClient(access_token, project_id, project_code) resp = client.create_account() # api调用失败 if resp.get('code') != 0: message = bk_error_codes.DepotError(_("创建项目仓库账号失败")) error_message = f'{message}, {resp.get("message", "")}' logger.error(error_message) raise error_codes.ComponentError(error_message) return resp.get('data')
def get_harbor_client(query): """镜像相关第一批API统一方法 该方法只在本文件内调用 """ project_id = query.get('projectId') project_code = query.get('project_code', '') access_token = query.pop('access_token') client = HarborClient(access_token, project_id, project_code) return client
def get_harbor_client(query): """镜像相关第一批API统一方法 该方法只在本文件内调用 """ project_id = query.get("projectId") project_code = query.get("project_code", "") access_token = query.pop("access_token") client = HarborClient(access_token, project_id, project_code) return client