优化代码

xsign
MMXX 3 years ago
parent 75c7d365a3
commit 378912944f
  1. 4
      fir_ser/common/core/sysconfig.py
  2. 3
      fir_ser/config.py
  3. 74
      fir_ser/xsign/utils/iossignapi.py
  4. 59
      fir_ser/xsign/utils/supersignutils.py

@ -319,6 +319,10 @@ class AppleDeveloperConfCache(ConfigCacheBase):
def DEVELOPER_USE_STATUS(self):
return super().get_value('DEVELOPER_USE_STATUS', APPLEDEVELOPERCONF.DEVELOPER_USE_STATUS)
@property
def DEVELOPER_SIGN_STATUS(self):
return super().get_value('DEVELOPER_SIGN_STATUS', APPLEDEVELOPERCONF.DEVELOPER_SIGN_STATUS)
@property
def DEVELOPER_AUTO_CHECK_STATUS(self):
return super().get_value('DEVELOPER_AUTO_CHECK_STATUS', APPLEDEVELOPERCONF.DEVELOPER_AUTO_CHECK_STATUS)

@ -355,8 +355,9 @@ class DOWNLOADTIMESCONF(object):
class APPLEDEVELOPERCONF(object):
# (-1, '疑似被封'), (0, '未激活'), (1, '已激活'), (2, '协议待同意'), (3, '维护中'), (4, '证书过期'), (5, '状态异常')
DEVELOPER_SIGN_STATUS = [1] # 开发者可用于签名的查询
DEVELOPER_USE_STATUS = [1, 2, 3, 4, 5] # 开发者可用状态,详情查看 model.AppIOSDeveloperInfo
DEVELOPER_AUTO_CHECK_STATUS = [1, 2] # 定时认证自动检测
DEVELOPER_AUTO_CHECK_STATUS = [1, 2, 5] # 定时认证自动检测
DEVELOPER_WRITE_STATUS = [1, 3, 4] # 开发者api写操作查询
DEVELOPER_DISABLED_STATUS = [2, 4, 5] # 开发者不可 修改为状态,用户前端控制
DEVELOPER_UID_KEY = "T:" # 开发者共享给其他第三方用户, 中间必须包含 : 前端需要根据 : 进行分割

@ -254,7 +254,7 @@ class AppDeveloperApiV2(object):
attr = object.__getattribute__(self, name)
if hasattr(attr, '__call__'):
def func(*args, **kwargs):
if attr.__name__ in ['active', 'get_device', '__result_format']:
if attr.__name__ in ['active', 'get_device', '__result_format', '__callback_run']:
return attr(*args, **kwargs)
else:
if AppIOSDeveloperInfo.objects.filter(pk=self.developer_pk,
@ -298,6 +298,21 @@ class AppDeveloperApiV2(object):
return True, result
raise Exception(f'{result} is not {is_instance}')
def __callback_run(self, err_msg, failed_call_prefix, callback_info=None):
if callback_info is None:
callback_info = []
for callback in callback_info:
for match_msg in callback.get('err_match_msg', []):
if match_msg in err_msg:
with CleanErrorBundleIdSignDataState(failed_call_prefix) as state:
if state:
for func in callback.get('func_list', []):
logger.info(f'issuer_id:{self.issuer_id} run callback func {func}')
func()
else:
logger.warning(
f'issuer_id:{self.issuer_id} {callback_info}-{failed_call_prefix} is running')
def active(self):
"""
:return: 结果为空列表或者是 object 或者是 [object,object] 其他为 false
@ -417,15 +432,11 @@ class AppDeveloperApiV2(object):
return True, result
raise Exception(str(device_obj))
except Exception as e:
err_msg = str(e)
logger.error(f"issuer_id:{self.issuer_id} ios developer set devices status Failed Exception:{e}")
result['return_info'] = check_error_call_back(str(e), self.developer_pk)
if device_err_callback and ("There are no current ios devices" in str(e) or "Device obj is None" in str(e)):
with CleanErrorBundleIdSignDataState(failed_call_prefix) as state:
if state:
device_err_callback()
else:
logger.warning(
f'issuer_id:{self.issuer_id} {device_err_callback}-{failed_call_prefix} is running')
result['return_info'] = check_error_call_back(err_msg, self.developer_pk)
self.__callback_run(err_msg, failed_call_prefix, device_err_callback)
return False, result
def get_device(self):
@ -451,9 +462,7 @@ class AppDeveloperApiV2(object):
result['return_info'] = check_error_call_back(str(e), self.developer_pk)
return False, result
def create_app(self, bundle_id, app_id, s_type, app_id_err_callback=None):
if app_id_err_callback is None:
app_id_err_callback = []
def create_app(self, bundle_id, app_id, s_type, failed_call_prefix, app_id_err_callback=None):
result = {}
try:
result = {}
@ -469,11 +478,10 @@ class AppDeveloperApiV2(object):
return True, result
raise Exception(str(bundle_obj))
except Exception as e:
err_msg = str(e)
logger.error(f"issuer_id:{self.issuer_id} ios developer create app Failed Exception:{e}")
result['return_info'] = check_error_call_back(str(e), self.developer_pk)
if app_id_err_callback and "There is no App ID with ID" in str(e):
for call_fun in app_id_err_callback:
call_fun()
result['return_info'] = check_error_call_back(err_msg, self.developer_pk)
self.__callback_run(err_msg, failed_call_prefix, app_id_err_callback)
return False, result
def register_device(self, device_udid, device_name, failed_call_prefix, device_err_callback=None):
@ -485,28 +493,14 @@ class AppDeveloperApiV2(object):
return True, device_obj
raise Exception(str(device_obj))
except Exception as e:
err_msg = str(e)
logger.error(f"issuer_id:{self.issuer_id} ios developer register device Failed Exception:{e}")
result['return_info'] = check_error_call_back(str(e), self.developer_pk)
err_msg_list = [
"There are no current ios devices",
"Your development team has reached the maximum number of registered iPhone devices"
]
if device_err_callback:
for err_msg in err_msg_list:
if err_msg in str(e):
with CleanErrorBundleIdSignDataState(failed_call_prefix) as state:
if state:
device_err_callback()
else:
logger.warning(
f'issuer_id:{self.issuer_id} {device_err_callback}-{failed_call_prefix} is running')
break
result['return_info'] = check_error_call_back(err_msg, self.developer_pk)
self.__callback_run(err_msg, failed_call_prefix, device_err_callback)
return False, result
def make_and_download_profile(self, app_obj, provision_name, auth, developer_app_id, device_id_list, profile_id,
failed_call_prefix, app_id_err_callback=None):
if app_id_err_callback is None:
app_id_err_callback = []
failed_call_prefix, callback_info=None):
result = {}
try:
apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key)
@ -523,17 +517,11 @@ class AppDeveloperApiV2(object):
return True, result
raise Exception(str(profile_obj))
except Exception as e:
err_msg = str(e)
logger.error(f"issuer_id:{self.issuer_id} app_id {app_obj.app_id} ios developer make profile Failed "
f"Exception:{e}")
result['return_info'] = check_error_call_back(str(e), self.developer_pk)
if app_id_err_callback and "There is no App ID with ID" in str(e):
with CleanErrorBundleIdSignDataState(failed_call_prefix) as state:
if state:
for call_fun in app_id_err_callback:
call_fun()
else:
logger.warning(
f'issuer_id:{self.issuer_id} {app_id_err_callback}-{failed_call_prefix} is running')
result['return_info'] = check_error_call_back(err_msg, self.developer_pk)
self.__callback_run(err_msg, failed_call_prefix, callback_info)
return False, result
def modify_capability(self, app_obj, developer_app_id):

@ -297,7 +297,7 @@ def get_developer_user_by_app_udid(user_objs, udid, app_obj, private_first=True,
if read_only:
status_choice = Config.DEVELOPER_USE_STATUS
else:
status_choice = [1]
status_choice = Config.DEVELOPER_SIGN_STATUS
status_filter = {'developerid__certid__isnull': False, 'developerid__status__in': status_choice}
developer_udid_queryset = UDIDsyncDeveloper.objects.filter(developerid__user_id__in=user_objs,
@ -576,6 +576,26 @@ class IosUtils(object):
if not device_udid:
logger.error("device udid is not exists. so return and exit")
return True, 'continue'
register_failed_callback = [
{
'func_list': [err_callback(IosUtils.get_device_from_developer, developer_obj)],
'err_match_msg': [
"There are no current ios devices",
"Your development team has reached the maximum number of registered iPhone devices"
]
}
]
set_failed_callback = [
{
'func_list': [err_callback(IosUtils.get_device_from_developer, developer_obj)],
'err_match_msg': [
"There are no current ios devices",
"Device obj is None"
]
}
]
sync_device_obj = UDIDsyncDeveloper.objects.filter(udid=device_udid,
developerid=developer_obj).first()
# auth = get_auth_form_developer(developer_obj)
@ -588,9 +608,7 @@ class IosUtils(object):
sync_device_obj.product,
sync_device_obj.udid,
failed_call_prefix,
err_callback(
IosUtils.get_device_from_developer,
developer_obj))
set_failed_callback)
if not status: # 已经包含异常操作,暂定
return status, result
sync_device_obj.status = True
@ -599,9 +617,7 @@ class IosUtils(object):
# 库里面不存在,注册设备,新设备注册默认就是启用状态
status, device_obj = get_api_obj(developer_obj).register_device(device_udid, device_name,
failed_call_prefix,
err_callback(
IosUtils.get_device_from_developer,
developer_obj))
register_failed_callback)
if not status:
return status, device_obj
@ -641,18 +657,23 @@ class IosUtils(object):
@staticmethod
@call_function_try_attempts()
def check_or_add_new_bundles(app_obj, developer_obj, failed_callback=None):
def check_or_add_new_bundles(app_obj, developer_obj, add_new_bundles_prefix, failed_callback=None):
if failed_callback is None:
failed_callback = []
failed_callback.append(err_callback(IosUtils.clean_super_sign_things_by_app_obj,
app_obj, developer_obj))
failed_callback.extend([
{
'func_list': [err_callback(IosUtils.clean_super_sign_things_by_app_obj, app_obj, developer_obj)],
'err_match_msg': ["There is no App ID with ID"]
}
])
developer_app_id_obj = DeveloperAppID.objects.filter(developerid=developer_obj,
app_id=app_obj).first()
if not developer_app_id_obj:
bundle_id = app_obj.bundle_id
app_id = app_obj.app_id
s_type = app_obj.supersign_type
status, result = get_api_obj(developer_obj).create_app(bundle_id, app_id, s_type, failed_callback)
status, result = get_api_obj(developer_obj).create_app(bundle_id, app_id, s_type, add_new_bundles_prefix,
failed_callback)
if status and result.get('aid'):
developer_app_id_obj = DeveloperAppID.objects.create(aid=result.get('aid'), developerid=developer_obj,
app_id=app_obj)
@ -671,8 +692,17 @@ class IosUtils(object):
if failed_callback is None:
failed_callback = []
failed_callback.append(err_callback(IosUtils.clean_super_sign_things_by_app_obj,
app_obj, developer_obj))
failed_callback.extend([
{
'func_list': [err_callback(IosUtils.clean_super_sign_things_by_app_obj, app_obj, developer_obj)],
'err_match_msg': ["There is no App ID with ID"]
},
{
'func_list': [err_callback(IosUtils.active_developer, developer_obj)],
'err_match_msg': ["There are no current certificates on this team matching the provided certificate"]
}
])
device_id_list = DeveloperDevicesID.objects.filter(app_id=app_obj,
developerid=developer_obj).values_list('did')
device_id_lists = [did[0] for did in device_id_list]
@ -764,7 +794,8 @@ class IosUtils(object):
if status and 'continue' in [str(did_udid_result)]:
return True, True
with cache.lock(add_new_bundles_prefix, timeout=360):
status, bundle_result = IosUtils.check_or_add_new_bundles(self.app_obj, self.developer_obj)
status, bundle_result = IosUtils.check_or_add_new_bundles(self.app_obj, self.developer_obj,
add_new_bundles_prefix)
if not status:
if 'UNEXPECTED_ERROR' in str(bundle_result):
return False, {}

Loading…
Cancel
Save