From a41f6335bc73d26b1f1a705ded342d539560bb57 Mon Sep 17 00:00:00 2001 From: nineven Date: Sat, 30 Jan 2021 18:20:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B6=85=E7=BA=A7=E7=AD=BE?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/FirSuperSignBase.vue | 6 +- fir_ser/api/utils/app/iossignapi.py | 69 +++++-- fir_ser/api/utils/app/supersignutils.py | 186 +++++++++--------- 3 files changed, 145 insertions(+), 116 deletions(-) diff --git a/fir_client/src/components/FirSuperSignBase.vue b/fir_client/src/components/FirSuperSignBase.vue index f207613..18f91cb 100644 --- a/fir_client/src/components/FirSuperSignBase.vue +++ b/fir_client/src/components/FirSuperSignBase.vue @@ -500,9 +500,13 @@ }) }, syncdevices() { + let data={"email": this.editdeveloperinfo.email, "act": "syncdevice"}; + if(this.editdeveloperinfo.issuer_id){ + data={"issuer_id": this.editdeveloperinfo.issuer_id, "act": "syncdevice"}; + } this.iosdeveloperFun({ "methods": "PUT", - "data": {"email": this.editdeveloperinfo.email, "act": "syncdevice"} + "data": data }); }, isocertcert() { diff --git a/fir_ser/api/utils/app/iossignapi.py b/fir_ser/api/utils/app/iossignapi.py index c68d160..143498d 100644 --- a/fir_ser/api/utils/app/iossignapi.py +++ b/fir_ser/api/utils/app/iossignapi.py @@ -169,33 +169,64 @@ class AppDeveloperApiV2(object): f.write(n) return True, profile_obj.profileContent except Exception as e: - logger.error("ios developer active Failed Exception:%s" % e) + logger.error("ios developer make profile Failed Exception:%s" % e) result['return_info'] = "%s" % e return False, result def del_profile(self, bundleId, app_id): - self.cmd = self.cmd + " profile del '%s' '%s'" % (bundleId, app_id) - result = exec_shell(self.cmd) + result = {} + try: + apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key) + profile_obj = apple_obj.list_profile_by_profile_name(app_id) + if profile_obj: + if apple_obj.delete_profile_by_id(profile_obj.id): + return True, profile_obj + except Exception as e: + logger.error("ios developer delete profile Failed Exception:%s" % e) + result['return_info'] = "%s" % e + return False, result def set_device_status(self, status, device_udid): - if status == "enable": - self.cmd = self.cmd + " device enable '%s'" % (device_udid) - else: - self.cmd = self.cmd + " device disable '%s'" % (device_udid) - result = exec_shell(self.cmd) + apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key) + result = {} + try: + if status == "enable": + device_obj = apple_obj.enabled_device(device_udid) + else: + device_obj = apple_obj.disabled_device(device_udid) + logger.info("device_obj %s result:%s" %(device_obj,status)) + if device_obj and device_obj.id: + return True, result + except Exception as e: + logger.error("ios developer set devices status Failed Exception:%s" % e) + result['return_info'] = "%s" %e + return False, result - def add_device(self, device_udid, device_name): - self.cmd = self.cmd + " device add '%s' '%s'" % (device_udid, device_name) - result = exec_shell(self.cmd) def get_device(self, user_obj): - self.cmd = self.cmd + " device get '%s' " % (self.file_format_path_name(user_obj)) - return exec_shell(self.cmd) - - def add_app(self, bundleId, app_id): - self.cmd = self.cmd + " app add '%s' '%s'" % (bundleId, app_id) - result = exec_shell(self.cmd) + result = {} + try: + apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key) + devices_obj_list = apple_obj.get_all_devices() + if devices_obj_list: + return True,devices_obj_list + except Exception as e: + logger.error("ios developer delete profile Failed Exception:%s" % e) + result['return_info'] = "%s" % e + return False, result def del_app(self, bundleId, app_id): - self.cmd = self.cmd + " app del '%s' '%s'" % (bundleId, app_id) - result = exec_shell(self.cmd) + result = {} + try: + apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key) + profile_obj = apple_obj.list_profile_by_profile_name(app_id) + if profile_obj: + if apple_obj.delete_profile_by_id(profile_obj.id): + pass + if apple_obj.delete_bundle_by_identifier(bundleId+app_id): + return True, profile_obj + + except Exception as e: + logger.error("ios developer delete profile Failed Exception:%s" % e) + result['return_info'] = "%s" % e + return False, result diff --git a/fir_ser/api/utils/app/supersignutils.py b/fir_ser/api/utils/app/supersignutils.py index d58c855..6c875cf 100644 --- a/fir_ser/api/utils/app/supersignutils.py +++ b/fir_ser/api/utils/app/supersignutils.py @@ -124,6 +124,41 @@ def get_post_udid_url(request, short): return udid_url +def get_auth_form_developer(developer_obj): + if developer_obj.email: + auth = { + "username": developer_obj.email, + "password": developer_obj.password, + "certid": developer_obj.certid + } + + elif developer_obj.issuer_id: + auth = { + "issuer_id": developer_obj.issuer_id, + "private_key_id": developer_obj.private_key_id, + "p8key": developer_obj.p8key, + "certid": developer_obj.certid + } + else: + auth = {} + return auth + + +def get_api_obj(auth): + if auth.get("username"): + app_api_obj = AppDeveloperApi(**auth) + elif auth.get("issuer_id"): + app_api_obj = AppDeveloperApiV2(**auth) + else: + app_api_obj = None + return app_api_obj + +def get_apple_udid_key(auth): + mpkey = auth.get("username") + if auth.get("issuer_id"): + mpkey = auth.get("issuer_id") + return mpkey + def get_http_server_doamin(request): server_domain = SERVER_DOMAIN.get('POST_UDID_DOMAIN', None) if not server_domain or not server_domain.startswith("http"): @@ -170,24 +205,8 @@ class IosUtils(object): def get_developer_auth(self): developer_obj = self.get_developer_user_by_app_udid() - if developer_obj.email: - auth = { - "username": developer_obj.email, - "password": developer_obj.password, - "certid": developer_obj.certid - } - - elif developer_obj.issuer_id: - auth = { - "issuer_id": developer_obj.issuer_id, - "private_key_id": developer_obj.private_key_id, - "p8key": developer_obj.p8key, - "certid": developer_obj.certid - } - else: - auth={} self.developer_obj = developer_obj - self.auth = auth + self.auth = get_auth_form_developer(developer_obj) def get_developer_user_by_app_udid(self): usedeviceobj = APPSuperSignUsedInfo.objects.filter(udid__udid=self.udid_info.get('udid'), @@ -214,22 +233,15 @@ class IosUtils(object): return developer_obj def download_profile(self): - if self.auth.get("username",None): - app_api_obj = AppDeveloperApi(**self.auth) - else: - app_api_obj = AppDeveloperApiV2(**self.auth) - bundleId = self.app_obj.bundle_id app_id = self.app_obj.app_id device_udid = self.udid_info.get('udid') device_name = self.udid_info.get('product') - return app_api_obj.get_profile(bundleId, app_id, device_udid, device_name, self.get_profile_full_path(),self.auth) + return get_api_obj(self.auth).get_profile(bundleId, app_id, device_udid, device_name, self.get_profile_full_path(), + self.auth) def get_profile_full_path(self): - mpkey = self.auth.get("username") - if self.auth.get("issuer_id"): - mpkey = self.auth.get("issuer_id") - cert_dir_name = make_app_uuid(self.user_obj, mpkey) + cert_dir_name = make_app_uuid(self.user_obj, get_apple_udid_key(self.auth)) cert_dir_path = os.path.join(SUPER_SIGN_ROOT, cert_dir_name, "profile") if not os.path.isdir(cert_dir_path): os.makedirs(cert_dir_path) @@ -331,16 +343,12 @@ class IosUtils(object): usedeviceobj = APPSuperSignUsedInfo.objects.filter(udid=udid_obj, app_id_id=app_id) if usedeviceobj: developer_obj = usedeviceobj.first().developerid - auth = { - "username": developer_obj.email, - "password": developer_obj.password, - "certid": developer_obj.certid - } + auth = get_auth_form_developer(developer_obj) # 需要判断该设备在同一个账户下 的多个应用,若存在,则不操作 udid_lists = list(APPSuperSignUsedInfo.objects.values_list("udid__udid").filter(developerid=developer_obj)) if udid_lists.count((udid_obj.udid,)) == 1: - app_api_obj = AppDeveloperApi(**auth) + app_api_obj = get_api_obj(auth) app_api_obj.set_device_status("disable", udid_obj.udid) if developer_obj.use_number > 0: @@ -351,10 +359,10 @@ class IosUtils(object): # 通过开发者id判断 app_id 是否多个,否则删除profile 文件 if APPSuperSignUsedInfo.objects.filter(developerid=developer_obj, app_id_id=app_id).count() == 0: - app_api_obj = AppDeveloperApi(**auth) + app_api_obj = get_api_obj(auth) app_obj = Apps.objects.filter(pk=app_id).first() app_api_obj.del_profile(app_obj.bundle_id, app_obj.app_id) - app_api_obj2 = AppDeveloperApi(**auth) + app_api_obj2 = get_api_obj(auth) app_api_obj2.del_app(app_obj.bundle_id, app_obj.app_id) delete_app_to_dev_and_file(developer_obj, app_id) delete_app_profile_file(developer_obj, app_obj) @@ -362,11 +370,7 @@ class IosUtils(object): @staticmethod def clean_udid_by_app_obj(app_obj, developer_obj): - auth = { - "username": developer_obj.email, - "password": developer_obj.password, - "certid": developer_obj.certid - } + auth = get_auth_form_developer(developer_obj) # 需要判断该设备在同一个账户下 的多个应用,若存在,则不操作 udid_lists = list(APPSuperSignUsedInfo.objects.values_list("udid__udid").filter(developerid=developer_obj)) @@ -375,7 +379,7 @@ class IosUtils(object): udid_obj = SuperSignUsed_obj.udid if udid_lists.count((udid_obj.udid,)) == 1: - app_api_obj = AppDeveloperApi(**auth) + app_api_obj = get_api_obj(auth) app_api_obj.set_device_status("disable", udid_obj.udid) if developer_obj.use_number > 0: @@ -406,14 +410,11 @@ class IosUtils(object): @staticmethod def clean_app_by_developer_obj(app_obj, developer_obj): - auth = { - "username": developer_obj.email, - "password": developer_obj.password, - "certid": developer_obj.certid - } - app_api_obj = AppDeveloperApi(**auth) + auth = get_auth_form_developer(developer_obj) + + app_api_obj = get_api_obj(auth) app_api_obj.del_profile(app_obj.bundle_id, app_obj.app_id) - app_api_obj2 = AppDeveloperApi(**auth) + app_api_obj2 = get_api_obj(auth) app_api_obj2.del_app(app_obj.bundle_id, app_obj.app_id) @staticmethod @@ -448,24 +449,8 @@ class IosUtils(object): :param code: :return: ''' - if developer_obj.email: - auth = { - "username": developer_obj.email, - "password": developer_obj.password, - "certid": developer_obj.certid - } - app_api_obj = AppDeveloperApi(**auth) - - elif developer_obj.issuer_id: - auth = { - "issuer_id": developer_obj.issuer_id, - "private_key_id": developer_obj.private_key_id, - "p8key": developer_obj.p8key, - "certid": developer_obj.certid - } - app_api_obj = AppDeveloperApiV2(**auth) - else: - return False, {} + auth = get_auth_form_developer(developer_obj) + app_api_obj = get_api_obj(auth) status, result = app_api_obj.active(user_obj) if status: developer_obj.is_actived = True @@ -474,12 +459,8 @@ class IosUtils(object): @staticmethod def create_developer_cert(developer_obj, user_obj): - auth = { - "username": developer_obj.email, - "password": developer_obj.password, - "certid": developer_obj.certid - } - app_api_obj = AppDeveloperApi(**auth) + auth = get_auth_form_developer(developer_obj) + app_api_obj = get_api_obj(auth) status, result = app_api_obj.create_cert(user_obj) if status: file_format_path_name = file_format_path(user_obj, auth) @@ -498,33 +479,18 @@ class IosUtils(object): @staticmethod def get_device_from_developer(developer_obj, user_obj): - auth = { - "username": developer_obj.email, - "password": developer_obj.password, - "certid": developer_obj.certid - } - app_api_obj = AppDeveloperApi(**auth) + auth = get_auth_form_developer(developer_obj) + app_api_obj = get_api_obj(auth) status, result = app_api_obj.get_device(user_obj) if status: - file_format_path_name = file_format_path(user_obj, auth) - devices_info = "" - try: - with open(file_format_path_name + ".devices.info", "r") as f: - devices_info = f.read().replace("\n\t", "").replace("[", "").replace("]", "") - except Exception as e: - logger.error( - "get_device_from_developer developer_obj:%s user_obj:%s delete file failed Exception:%s" % ( - developer_obj, user_obj, e)) - - UDIDsyncDeveloper.objects.filter(developerid=developer_obj, platform=1).delete() - for devicestr in devices_info.split(">"): - formatdevice = re.findall(r'.*Device id="(.*)",.*name="(.*)",.*udid="(.*?)",.*model=(.*),.*', devicestr) - if formatdevice: + if auth.get("issuer_id"): + UDIDsyncDeveloper.objects.filter(developerid=developer_obj, platform=1).delete() + for device_obj in result: device = { - "serial": formatdevice[0][0], - "product": formatdevice[0][1], - "udid": formatdevice[0][2], - "version": formatdevice[0][3], + "serial": device_obj.id, + "product": device_obj.name, + "udid": device_obj.udid, + "version": device_obj.model, "platform": 1 } app_udid_obj = UDIDsyncDeveloper.objects.filter(developerid=developer_obj, udid=device.get("udid")) @@ -532,4 +498,32 @@ class IosUtils(object): pass else: UDIDsyncDeveloper.objects.create(developerid=developer_obj, **device) + else: + + file_format_path_name = file_format_path(user_obj, auth) + devices_info = "" + try: + with open(file_format_path_name + ".devices.info", "r") as f: + devices_info = f.read().replace("\n\t", "").replace("[", "").replace("]", "") + except Exception as e: + logger.error( + "get_device_from_developer developer_obj:%s user_obj:%s delete file failed Exception:%s" % ( + developer_obj, user_obj, e)) + + UDIDsyncDeveloper.objects.filter(developerid=developer_obj, platform=1).delete() + for devicestr in devices_info.split(">"): + formatdevice = re.findall(r'.*Device id="(.*)",.*name="(.*)",.*udid="(.*?)",.*model=(.*),.*', devicestr) + if formatdevice: + device = { + "serial": formatdevice[0][0], + "product": formatdevice[0][1], + "udid": formatdevice[0][2], + "version": formatdevice[0][3], + "platform": 1 + } + app_udid_obj = UDIDsyncDeveloper.objects.filter(developerid=developer_obj, udid=device.get("udid")) + if app_udid_obj: + pass + else: + UDIDsyncDeveloper.objects.create(developerid=developer_obj, **device) return status, result