优化超级签逻辑

super_sign_new
nineven 4 years ago
parent 5b7e6a3869
commit a41f6335bc
  1. 6
      fir_client/src/components/FirSuperSignBase.vue
  2. 65
      fir_ser/api/utils/app/iossignapi.py
  3. 150
      fir_ser/api/utils/app/supersignutils.py

@ -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() {

@ -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):
apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key)
result = {}
try:
if status == "enable":
self.cmd = self.cmd + " device enable '%s'" % (device_udid)
device_obj = apple_obj.enabled_device(device_udid)
else:
self.cmd = self.cmd + " device disable '%s'" % (device_udid)
result = exec_shell(self.cmd)
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

@ -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,14 +479,27 @@ 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:
if auth.get("issuer_id"):
UDIDsyncDeveloper.objects.filter(developerid=developer_obj, platform=1).delete()
for device_obj in result:
device = {
"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"))
if app_udid_obj:
pass
else:
UDIDsyncDeveloper.objects.create(developerid=developer_obj, **device)
else:
file_format_path_name = file_format_path(user_obj, auth)
devices_info = ""
try:

Loading…
Cancel
Save