def test_CDN_246182(self): console_host = self.base_info['ctyunHost'] workspace_id = self.base_info['ctyun_workspaceid'] email = self.base_info['email'] createCert_url = console_host + self.cert_info['createCert'] select_cert_url = console_host + self.cert_info['viewCert'] cert_name = 'Auto_Cert_' + random_string(4) createCert_data = { "data": { "workspaceId": workspace_id, "name": cert_name, "certs": 'test_certs', "key": 'test_key', "email": email } } cert_response = self.session.post(url=createCert_url, data=json.dumps(createCert_data), headers=headers_json, verify=False, timeout=10) print("-------------------创建证书-------------------") print('请求url: ' + str(createCert_url)) print("请求data: " + str(createCert_data)) print("返回: " + str(cert_response.text)) print("重点验证:" + cert_name + " expect: 创建证书异常:证书已过期") assert cert_response.status_code == 200 assert cert_response.elapsed.total_seconds() < 3 assert '创建证书异常' in cert_response.text assert 'core.e' in cert_response.text
def test_CDN_241172(self): createcert_url = self.v1_info["createCert"] cert_name = "V1_Test_" + random_string(3) data = { "ctyunAcctId": self.ctyunacctid, "name": cert_name, "certs": self.public_key, "key": self.pravate_key, "email": self.email } response = post_form_head(self.host, createcert_url, data) print("请求url:" + str(createcert_url)) print("返回:" + str(response.text)) assert "服务调用成功" in response.text samename_data = { "ctyunAcctId": self.ctyunacctid, "name": cert_name, "certs": self.public_key, "key": self.pravate_key, "email": self.email } same_response = post_form_head(self.host, createcert_url, samename_data) print("请求url:" + str(createcert_url)) print("请求数据:" + str(samename_data)) print("返回:" + str(same_response.text)) assert "新增证书异常:已存在重名的证书" in same_response.text
def generate_live_video_pull(self): domain = 'Auto-pull-' + random_string(4) + '.ctyun.cn' live_video_data = { "data": { "workspaceId": self.workspace_id, "action": 1, "domain": domain, "recordNum": "京ICP备12022551号", "productCode": "005", "liveConf": { "mode": 1, "multiProtocol": 0, "protocolType": 2, "domainType": 2, "publishPoint": "live,app" }, "originProtocol": "http", "origin": [{ "origin": "", "port": 1935, "role": "master", "weight": 1 }] } } return live_video_data
def test_CDN_241174(self): createcert_url = self.v1_info["createCert"] cert_name = "V1_Test_" + random_string(3) data = { "ctyunAcctId": self.ctyunacctid, "name": cert_name, "certs": "abc", "key": "abc", "email": self.email } response = post_form_head(self.host, createcert_url, data) print("请求url:" + str(createcert_url)) print("返回:" + str(response.text)) assert "新增证书异常:tls: failed to find any PEM data in certificate input" in response.text
def test_CDN_241175(self): createcert_url = self.v1_info["createCert"] cert_name = "V1_Test_" + random_string(3) data = { "ctyunAcctId": self.ctyunacctid, "name": cert_name, "certs": self.public_key, "key": self.expire_private_key, "email": self.email } response = post_form_head(self.host, createcert_url, data) print("请求url:" + str(createcert_url)) print("返回:" + str(response.text)) assert "新增证书异常:tls: private key does not match public key" in response.text
def generate_cert(workspaceid): public_key = read('/params/cdn/server.crt') private_key = read('/params/cdn/server_private.key') certName = 'Auto_Cert_' + random_string(6) certinfo = { "data": { "workspaceId": workspaceid, "name": certName, "certs": public_key, "key": private_key, "email": "*****@*****.**" } } return certinfo
def create_live_domain(self): """ 创建视频直播加速域名 :return: """ url = "/cdn/gw/domain/CreateDomain" name = "Domain_Test_" + random_string(4) + ".zhihu.com" data = { "data": { "workspaceId": self.workspaceid, "action": 1, "userName": "******", "domain": name, "recordNum": "京ICP备13052560号", "productCode": "005", "liveConf": { "mode": 1, "multiProtocol": 0, "protocolType": 2, "domainType": 2, "publishPoint": "app" }, "originProtocol": "http", "origin": [{ "origin": "", "port": 1935, "role": "master", "weight": 1 }], "httpsBasic": { "originProtocol": "http" } } } print("域名name:{},产品类型product为:{}".format(name, data["data"]["productCode"])) response = self.session.post(self.host + url, json=data, verify=False) print(response.text) return response
def test_CDN_246183(self): console_host = self.base_info['ctyunHost'] workspace_id = self.base_info['ctyun_workspaceid'] email = self.base_info['email'] createCert_url = console_host + self.cert_info['createCert'] select_cert_url = console_host + self.cert_info['viewCert'] cert_name = 'Auto_Cert_' + random_string(4) createCert_data = { "data": { "workspaceId": workspace_id, "name": cert_name, "certs": public_key_expire, "key": private_key_expire, "email": email } } cert_response = self.session.post(url=createCert_url, data=json.dumps(createCert_data), headers=headers_json, verify=False, timeout=10) print("-------------------创建证书-------------------") print('请求url: ' + str(createCert_url)) print("请求data: " + str(createCert_data)) print("返回: " + str(cert_response.text)) print("重点验证:" + cert_name + " expect: 创建证书异常:证书已过期") assert '创建证书异常:证书已过期' in cert_response.text assert cert_response.status_code == 200 assert cert_response.elapsed.total_seconds() < 3 select_data = 'workspaceId=' + workspace_id + '&name=' + cert_name + '' select_cert_response = self.session.get(url=select_cert_url, params=select_data, headers=headers_form, verify=False, timeout=10) body1 = eval(select_cert_response.text) result = body1['data']['result'] print("-------------------控制台查询证书是否创建-------------------") print('请求url: ' + str(select_cert_url)) print("请求data: " + str(select_data)) print("返回: " + str(select_cert_response.text)) # print(result) assert '服务调用成功' in select_cert_response.text assert result == '[]'
def test_CDN_246180(self): console_host = self.base_info['ctyunHost'] workspace_id = self.base_info['ctyun_workspaceid'] email = self.base_info['email'] createCert_url = console_host + self.cert_info['createCert'] select_cert_url = console_host + self.cert_info['viewCert'] cert_name = 'Auto_Cert_' + random_string(4) createCert_data = { "data": { "workspaceId": workspace_id, "name": cert_name, "certs": public_key_365, "key": private_key_365, "email": email } } cert_response = self.session.post(url=createCert_url, data=json.dumps(createCert_data), headers=headers_json, verify=False, timeout=10) print("-------------------创建证书-------------------") print('请求url: ' + str(createCert_url)) print("请求data: " + str(createCert_data)) print("返回: " + str(cert_response.text)) print("重点验证:" + cert_name + " expect: 返回里面有证书名") assert cert_name in cert_response.text assert '服务调用成功' in cert_response.text select_data = 'workspaceId=' + workspace_id + '&name=' + cert_name + '' select_cert_response = self.session.get(url=select_cert_url, params=select_data, headers=headers_form, verify=False, timeout=10) assert '服务调用成功' in select_cert_response.text print("-------------------控制台查询证书是否创建成功-------------------") print('请求url: ' + str(select_cert_url)) print("请求data: " + str(select_data)) print("返回: " + str(select_cert_response.text)) print("重点验证:" + cert_name + " expect: 返回里面有证书名")
def generate_live_video_push(self): domain = 'Auto-push-' + random_string(4) + '.ctyun.cn' live_video_data = { "data": { "workspaceId": self.workspace_id, "action": 1, "domain": domain, "recordNum": "京ICP备12022551号", "productCode": "005", "liveConf": { "mode": 1, "multiProtocol": 1, "protocolType": 2, "domainType": 1, "publishPoint": "live,pull", "relatedDomain": "Auto-random-0f6C.ctyun.cn" }, "httpsPublicContent": public_key, "httpsPrivateKey": private_key, "certName": "CTYUN_TEST", "pathTtl": [{ "path": "/test/4", "ttl": 80, "cacheType": 3, "cacheWithArgs": 0 }], "filetypeTtl": [{ "fileType": "m3u8", "ttl": 0, "cacheType": 3, "cacheWithArgs": 0 }, { "fileType": "ts", "ttl": 86400, "cacheType": 3, "cacheWithArgs": 0 }], "ipWhiteList": "127.0.0.3", "userAgent": { "type": 0, "ua": ["curl*", "*IE"] }, "whiteReferer": { "allowList": ["*.demo.com"], "allowEmpty": "on" }, "originProtocol": "http", "origin": [{ "origin": "", "port": 1935, "role": "master", "weight": 1 }] } } return live_video_data
def create_commin_domin(self): """ 创建通用域名:静态加速域名,下载加速域名,视频点播加速域名 :return: """ url = "/cdn/gw/domain/CreateDomain" name = "Domain_Test_" + random_string(4) + ".zhihu.com" data = { "data": { "workspaceId": self.workspaceid, "action": 1, "userName": "******", "domain": name, "recordNum": "京ICP备13052560号", "productCode": random.choice(productcode), "origin": [{ "role": "master", "origin": "1.1.1.1", "port": "80", "weight": 1, "protocol": "http" }], "originProtocol": "http", "basicConf": { "follow302": 0 }, "reqHost": "cc.ctyun.com", "filetypeTtl": [{ "fileType": "php,ashx,aspx,asp,jsp,do", "ttl": 0, "cacheType": 3, "cacheWithArgs": 0 }, { "fileType": "js,css,xml,htm,html", "ttl": 1800, "cacheType": 3, "cacheWithArgs": 0 }, { "fileType": "swf,jpg,gif,png,bmp,ico,ts", "ttl": 86400, "cacheType": 3, "cacheWithArgs": 0 }, { "fileType": "wmv,mp3,wma,ogg,flv,mp4,avi,mpg,mpeg,f4v,hlv,rmvb,rm,3gp,img,bin,zip,rar,ipa,apk,jar,sis,xap,msi,exe,cab,7z,pdf,doc,docx,xls,xlsx,ppt,pptx,txt", "ttl": 31536000, "cacheType": 3, "cacheWithArgs": 0 }], "ipWhiteList": "127.0.0.1", "whiteReferer": { "allowList": ["ab.ctyun.com"], "allowEmpty": "on" }, "httpsBasic": { "originProtocol": "http" } } } print("域名name:{},产品类型product为:{}".format(name, data["data"]["productCode"])) response = self.session.post(self.host + url, json=data, verify=False) print(response.text) return response
def test_CDN_246181(self): console_host = self.base_info['ctyunHost'] workspace_id = self.base_info['ctyun_workspaceid'] email = self.base_info['email'] createCert_url = console_host + self.cert_info['createCert'] select_cert_url = console_host + self.cert_info['viewCert'] del_cert_url = console_host + self.cert_info['delCert'] certList_url = console_host + self.cert_info['listCert'] cert_name = 'Auto_Cert_' + random_string(4) createCert_data = { "data": { "workspaceId": workspace_id, "name": cert_name, "certs": public_key_365, "key": private_key_365, "email": email } } cert_response = self.session.post(url=createCert_url, data=json.dumps(createCert_data), headers=headers_json, verify=False, timeout=10) print("-------------------创建证书-------------------") print('请求url: ' + str(createCert_url)) print("请求data: " + str(createCert_data)) print("返回: " + str(cert_response.text)) print("重点验证:" + cert_name + " expect: 返回里面有证书名") assert cert_name in cert_response.text assert '服务调用成功' in cert_response.text assert cert_response.status_code == 200 assert cert_response.elapsed.total_seconds() < 3 select_data = 'workspaceId=' + workspace_id + '&name=' + cert_name + '' select_cert_response = self.session.get(url=select_cert_url, params=select_data, headers=headers_form, verify=False, timeout=10) assert '服务调用成功' in select_cert_response.text assert cert_response.status_code == 200 assert cert_response.elapsed.total_seconds() < 3 print("-------------------控制台查询证书是否创建成功-------------------") print('请求url: ' + str(select_cert_url)) print("请求data: " + str(select_data)) print("返回: " + str(select_cert_response.text)) print("重点验证:" + cert_name + " expect: 返回里面有证书名") # sql = 'select * from ecfSecret.certificate_metadata where name= \'%s\'' % cert_name # r = self.db.select(sql) # print("-------------------数据库查询证书是否入库-------------------") # print("数据库查询结果:", r) # assert cert_name in r[0]['name'] # self.db.close() # python 查询数据库有缓存,存储在内存中 # 删除证书 del_response = self.session.get(url=del_cert_url, params=select_data, headers=headers_form, verify=False, timeout=10) print("-------------------删除证书-------------------") print('请求url: ' + str(del_cert_url)) print("请求data: " + str(select_data)) print("返回: " + str(del_response.text)) assert del_response.status_code == 200 assert del_response.elapsed.total_seconds() < 3 # 去数据库查询是否删除成功 time.sleep(2) list_data = 'workspaceId=' + workspace_id + '&page=1&perPage=50' list_respones = self.session.get(url=certList_url, params=list_data, headers=headers_form, verify=False, timeout=10) assert cert_name not in list_respones.text print("-------------------控制台查询证书是否消失-------------------") print('请求url: ' + str(certList_url)) print("请求data: " + str(list_data)) print("返回: " + str(list_respones.text))
def generate_randomDomain(self): domain = 'Auto-' + random_string(6) + '.ctyun.cn' flag = random_int('1, 2') if flag == '1': public = public_key private = private_key certName = "CTYUN_TEST" else: public = '' private = '' certName = '' random_data = { "data": { "workspaceId": self.workspace_id, "action": 1, "domain": domain, "recordNum": "京ICP备12022551号", "productCode": random.choice(productCode), # 测试非法的productCode # "productCode": "006", "origin": [{ "role": "master", "origin": "192.255.0.5", "port": 80, "weight": 1 }, { "role": "slave", "origin": "gg.ctyun.cn", "port": 80, "weight": 1 }], "originProtocol": "http", "basicConf": { "follow302": 0 }, "reqHost": "ss.ctyun.cn", "httpsPublicContent": public, "httpsPrivateKey": private, "certName": certName, "pathTtl": [{ "path": "/test/a", "ttl": 80, "cacheType": 3, "cacheWithArgs": 0 }], "filetypeTtl": [{ "fileType": "php,ashx,aspx,asp,jsp,do", "ttl": 0, "cacheType": 3, "cacheWithArgs": 0 }, { "fileType": "js,css,xml,htm,html", "ttl": 1800, "cacheType": 3, "cacheWithArgs": 0 }, { "fileType": "jpg,gif,png,bmp,ico,swf,ts,test1,test2", "ttl": 86400, "cacheType": 3, "cacheWithArgs": 0 }, { "fileType": "wmv,mp3,wma,ogg,flv,mp4,avi,mpg,mpeg,f4v,hlv,rmvb,rm,3gp,img,bin,zip,rar,ipa,apk,jar,sis,xap,msi,exe,cab,7z,pdf,doc,docx,xls,xlsx,ppt,pptx,txt", "ttl": 31536000, "cacheType": 3, "cacheWithArgs": 0 }], "ipWhiteList": "199.231.0.5", "userAgent": { "type": 0, "ua": ["gg.ctyun.cn"] }, "whiteReferer": { "allowList": ["gg.ctyun.cn"], "allowEmpty": "on" } } } hit = random_int('1,10') if hit == '10': data = self.generate_live_video_push() elif hit == '9': data = self.generate_live_video_pull() else: data = random_data return data
def test_CDN_241170(self): createcert_url = self.v1_info["createCert"] getcert_url = self.v1_info["getCert"] deletecert_url = self.v1_info["deleteCert"] certlist_url = self.v1_info["certList"] cert_name = "V1_Test_" + random_string(3) print("证书名称:" + cert_name) data = { "ctyunAcctId": self.ctyunacctid, "name": cert_name, "certs": self.public_key, "key": self.pravate_key, "email": self.email } response = post_form_head(self.host, createcert_url, data) print("请求url:" + str(createcert_url)) print("返回:" + str(response.text)) assert "服务调用成功" in response.text # 数据库验证,新增证书是否落库 # 环境分隔,不再校验 # sql = "SELECT * FROM `ecfSecret`.`certificate_metadata` where name = \"%s\"" % cert_name # r = self.db.select(sql) # print("查询结果:",sql) # assert cert_name in r[0]["name"] # 查询证书 get_cert_data = { "ctyunAcctId": self.ctyunacctid, "secretName": cert_name } get_cert_response = post_form_head(self.host, getcert_url, get_cert_data) print(get_cert_response.text) print("请求url:" + str(getcert_url)) print("返回:" + str(get_cert_response.text)) print("重点校验:" + cert_name + "except:返回里有证书名") assert "服务调用成功" in response.text assert cert_name in get_cert_response.text # 删除证书 delete_cert_data = {"ctyunAcctId": self.ctyunacctid, "name": cert_name} delete_cert_response = post_form_head(self.host, deletecert_url, delete_cert_data) print(delete_cert_response.text) print("请求url:" + str(deletecert_url)) print("返回:" + str(delete_cert_response.text)) assert "服务调用成功" in response.text # # 数据库验证 # del_r = self.db.select(sql) # print("删除证书后查询结果:",del_r) # assert del_r == () # 证书列表 cert_list_response = get_form_head(self.host, self.ctyunacctid, certlist_url) print(cert_list_response.text) print("请求url:" + str(certlist_url)) print("返回:" + str(cert_list_response.text)) print("重点校验:" + cert_name + "except:返回里有无证书名") assert cert_name not in cert_list_response.text
def generate_v1Domain(self): """ 获取V1格式的域名信息,用于新增V1域名 :return: """ productcode = ["003", "004", "000", "006"] name = "V1_Test_" + random_string(6) + ".ctyun.cn" public = read('/params/cdn/server365.crt') private = read('/params/cdn/server_private365.key') customerName = ['', '陈孟琪_v1'] domain_data_list = [] # self.ctyunacctid = "2364d5f2c3f541e8925de5c866341c7a" print('self.ctyunacctid: ', self.ctyunacctid) domain_data = { "data": { "ctyunAcctId": self.ctyunacctid, "action": 1, "domain": name, "recordNum": "京ICP备13052560号", "recordStatus": 2, "productCode": "005", "customerName": random.choice(customerName), "liveConf": { "mode": 1, "multiProtocol": 0, "protocolType": 2, "domainType": 2, "publishPoint": "app" + random_string(3) }, "originProtocol": "http", "origin": [{ "origin": "", "port": 1935, "role": "master", "weight": 1 }], "httpsBasic": { "originProtocol": "http" } } } common_domain_data2 = { "data": { "ctyunAcctId": self.ctyunacctid, "action": 1, "domain": name, "recordNum": "京ICP备13052560号", "recordStatus": 2, "productCode": "001", "customerName": random.choice(customerName), "origin": [{ "role": "master", "origin": "1.1.1.1", "port": "443", "weight": 1, "protocol": "https" }], "originProtocol": "https", "basicConf": { "follow302": 0 }, "reqHost": "cc.ctyun.com", "filetypeTtl": [{ "fileType": "php,ashx,aspx,asp,jsp,do", "ttl": 0, "cacheType": 3, "cacheWithArgs": 0 }, { "fileType": "js,css,xml,htm,html", "ttl": 1800, "cacheType": 3, "cacheWithArgs": 0 }, { "fileType": "swf,jpg,gif,png,bmp,ico,ts", "ttl": 86400, "cacheType": 3, "cacheWithArgs": 0 }, { "fileType": "wmv,mp3,wma,ogg,flv,mp4,avi,mpg,mpeg,f4v,hlv,rmvb,rm,3gp,img,bin,zip,rar,ipa,apk,jar,sis,xap,msi,exe,cab,7z,pdf,doc,docx,xls,xlsx,ppt,pptx,txt", "ttl": 31536000, "cacheType": 3, "cacheWithArgs": 0 }], "httpsPublicContent": public, "httpsPrivateKey": private, "certName": "CTYUN_TEST", "ipWhiteList": "127.0.0.1", "whiteReferer": { "allowList": ["ab.ctyun.com"], "allowEmpty": "on" }, "httpsBasic": { "originProtocol": "https" } } } live_domain_data = { "data": { "ctyunAcctId": self.ctyunacctid, "action": 1, "domain": name, "recordNum": "京ICP备13052560号", "recordStatus": 2, "productCode": "005", "customerName": random.choice(customerName), "liveConf": { "mode": 1, "multiProtocol": 0, "protocolType": 2, "domainType": 2, "publishPoint": "app" }, "originProtocol": "http", "origin": [{ "origin": "", "port": 1935, "role": "master", "weight": 1 }], "httpsBasic": { "originProtocol": "http" } } } common_domain_data = { "data": { "ctyunAcctId": self.ctyunacctid, "action": 1, "domain": name, "recordNum": "京ICP备13052560号", "recordStatus": 2, "productCode": random.choice(productcode), "customerName": random.choice(customerName), "origin": [{ "role": "master", "origin": "1.1.1.1", "port": "80", "weight": 1, "protocol": "http" }], "originProtocol": "http", "basicConf": { "follow302": 0 }, "reqHost": "cc.ctyun.com", "filetypeTtl": [{ "fileType": "php,ashx,aspx,asp,jsp,do", "ttl": 0, "cacheType": 3, "cacheWithArgs": 0 }, { "fileType": "js,css,xml,htm,html", "ttl": 1800, "cacheType": 3, "cacheWithArgs": 0 }, { "fileType": "swf,jpg,gif,png,bmp,ico,ts", "ttl": 86400, "cacheType": 3, "cacheWithArgs": 0 }, { "fileType": "wmv,mp3,wma,ogg,flv,mp4,avi,mpg,mpeg,f4v,hlv,rmvb,rm,3gp,img,bin,zip,rar,ipa,apk,jar,sis,xap,msi,exe,cab,7z,pdf,doc,docx,xls,xlsx,ppt,pptx,txt", "ttl": 31536000, "cacheType": 3, "cacheWithArgs": 0 }], "httpsPublicContent": public, "httpsPrivateKey": private, "certName": "CTYUN_TEST", "ipWhiteList": "127.0.0.1", "whiteReferer": { "allowList": ["ab.ctyun.com"], "allowEmpty": "on" }, "httpsBasic": { "originProtocol": "http" } } } domain_data_list.append(common_domain_data) domain_data_list.append(live_domain_data) domain_data_list.append(common_domain_data2) domain_data_list.append(domain_data) return domain_data_list
def full_field_domain(self, ctyunAcctId): """ 创建随机域名,全量字段 :param ctyunAcctId: 天翼云id :return: """ name = "V1_Test_" + random_string(4) + ".ctyun.cn" data = { "data": { "ctyunAcctId": ctyunAcctId, "action": 1, "domain": name, "recordNum": "京ICP备13052560号", "recordStatus": 2, "productCode": random.choice(productCode), "customerName": "陈孟琪", "specialRequirement": "无", "testUrl": "www.ctyun.com", "areaScope": 1, "sharedHost": "www.ctyun.com", "ignoreHeaders": "abc", "origin": [ { "role": "master", "origin": "1.1.1.1", "port": "80", "weight": 1, "protocol": "http" } ], "originProtocol": "http", "basicConf": { "follow302": 0, "https_return": "off", "httpServerPort": "80", "httpsServerPort": "443", "httpOriginPort": 80, "httpsOriginPort": 443, "xff": 0, "corsOrigin": 0, "buffer": "off", "defaultCacheRule": "off" }, "errorPage": { "code": "404", "url": "http://www.ctyun.com/iam/cdn/v1/domainlist/" }, "uploadConf": { "maxBodySize": "1m", "maxBuffSize": "1k" }, "gzip": { "minLength": "1k", "fileType": "zip", }, # 额外配置(真实),非真实走自助会失败 # "expandConf": [{ # "content": "cssabcd", # "level": "1", # "priority": 10, # "message": "test" # } # ], "reqHost": "cc.ctyun.com", "filetypeTtl": [ {"fileType": "php,ashx,aspx,asp,jsp,do", "ttl": 0, "cacheType": 3, "cacheWithArgs": 0, "split": 0, "mode": 0, "priority": 10 }, {"fileType": "js,css,xml,htm,html", "ttl": 1800, "cacheType": 3, "cacheWithArgs": 0, "split": 0, "mode": 0, "priority": 10 }, {"fileType": "swf,jpg,gif,png,bmp,ico,ts", "ttl": 86400, "cacheType": 3, "cacheWithArgs": 0, "split": 0, "mode": 0, "priority": 10 }, { "fileType": "wmv,mp3,wma,ogg,flv,mp4,avi,mpg,mpeg,f4v,hlv,rmvb," "rm,3gp,img,bin,zip,rar,ipa,apk,jar,sis,xap,msi,exe," "cab,7z,pdf,doc,docx,xls,xlsx,ppt,pptx,txt", "ttl": 31536000, "cacheType": 3, "cacheWithArgs": 0, "split": 0, "mode": 0, "priority": 10 } ], "urlRewrite": [{ "uri": "/cdn/iam/domain", "targetUri": "/cdn/iam/domainlist", "weight": 1 }], "cacheArgs": { "args":"abc", "disables":"on" }, "pathTtl": [ {"path": "/a", "ttl": 1800, "cacheType": 3, "cacheWithArgs": 0 }, {"path": "/b", "ttl": 1800, "cacheType": 3, "cacheWithArgs": 0 } ], "httpsPublicContent": self.public_key, "httpsPrivateKey": self.private_key, "certName": "CTYUN_TEST", "ipWhiteList": "127.0.0.1", "whiteReferer": { "allowList": ["ab.ctyun.com"], "allowEmpty": "on" }, "blackReferer": { "allowList": ["ac.ctyun.com"], "allowEmpty": "on" }, "httpsBasic": { "originProtocol": "http", "httpsForce":"on", "httpForce":"off", "forceStatus":"302" }, "ipBlackList": "1.1.1.1,1.1.1.2", "reqHeaders": [ {"key": "abc", "value": "测试" }], "respHeaders": [ { "key": "Content-Type", "value": "测试2" } ], "errorCode": [ { "code": ["404"], "ttl": 10 }, { "code": ["500"], "ttl": 60 } ], "userAgent": { "type": 0, "ua": ["t", "e", "s", "t"] } } } return data
def create_domain(self, ctyunAcctId, productcode): """ 创建域名 :param ctyunAcctId: 天翼云id :param productcode: 产品类型 :return: """ name = "V1_Test_" + random_string(4) + ".zhihu.com" if productcode == "005": data = { "data": { "ctyunAcctId": ctyunAcctId, "action": 1, "domain": name, "recordNum": "京ICP备13052560号", "recordStatus": 2, "productCode": productcode, "customerName": "陈孟琪", "liveConf": { "mode": 1, "multiProtocol": 0, "protocolType": 2, "domainType": 2, "publishPoint": "app" }, "originProtocol": "http", "origin": [ { "origin": "", "port": 1935, "role": "master", "weight": 1 } ], "httpsBasic": { "originProtocol": "http" } } } else: data = { "data": { "ctyunAcctId": ctyunAcctId, "action": 1, "domain": name, "recordNum": "京ICP备13052560号", "recordStatus": 2, "productCode": productcode, "customerName": "陈孟琪", "origin": [ { "role": "master", "origin": "1.1.1.1", "port": "80", "weight": 1, "protocol": "http" } ], "originProtocol": "http", "basicConf": { "follow302": 0 }, "reqHost": "cc.ctyun.com", "filetypeTtl": [ {"fileType": "php,ashx,aspx,asp,jsp,do", "ttl": 0, "cacheType": 3, "cacheWithArgs": 0, "split": 0, }, {"fileType": "js,css,xml,htm,html", "ttl": 1800, "cacheType": 3, "cacheWithArgs": 0, "split": 0, }, {"fileType": "swf,jpg,gif,png,bmp,ico,ts", "ttl": 86400, "cacheType": 3, "cacheWithArgs": 0, "split": 0, }, { "fileType": "wmv,mp3,wma,ogg,flv,mp4,avi,mpg,mpeg,f4v,hlv,rmvb," "rm,3gp,img,bin,zip,rar,ipa,apk,jar,sis,xap,msi,exe," "cab,7z,pdf,doc,docx,xls,xlsx,ppt,pptx,txt", "ttl": 31536000, "cacheType": 3, "cacheWithArgs": 0, "split": 0, } ], "pathTtl": [ {"path": "/a", "ttl": 1800, "cacheType": 3, "cacheWithArgs": 0 }, {"path": "/b", "ttl": 1800, "cacheType": 3, "cacheWithArgs": 0 } ], "ipWhiteList": "127.0.0.1", "whiteReferer": { "allowList": ["ab.ctyun.com"], "allowEmpty": "on" }, "blackReferer": { "allowList": ["ac.ctyun.com"], "allowEmpty": "on" }, "httpsPublicContent": self.public_key, "httpsPrivateKey": self.private_key, "certName": "CTYUN_TEST", "httpsBasic": { "originProtocol": "http", "httpsForce":"on", "httpForce":"off", "forceStatus":"302" }, "ipBlackList": "1.1.1.1,1.1.1.2", "reqHeaders": [ {"key": "abc", "value": "测试" }], "respHeaders": [ { "key": "Content-Type", "value": "测试2" } ], "errorCode": [ { "code": ["404"], "ttl": 10 }, { "code": ["500"], "ttl": 60 } ], "userAgent": { "type": 0, "ua": ["test"] }, } } return data
def edit_domain(self, name, product): # eidt_domain("xxx.zhihu.com","001") """ 编辑域名 :param name: :param product: :return: """ url = "/cdn/gw/domain/CreateDomain" if product == "005": data = { "data": { "workspaceId": self.workspaceid, "action": 2, "userName": "******", "domain": name, "recordNum": "京ICP备13052560号", "productCode": product, "liveConf": { "mode": 1, "multiProtocol": 0, "protocolType": 2, "domainType": 2, "publishPoint": "app" + random_string(4) }, "originProtocol": "http", "origin": [{ "origin": "", "port": 1935, "role": "master", "weight": 1 }], "httpsBasic": { "originProtocol": "http" } } } elif product == "001" or product == "003" or product == "004": data = { "data": { "workspaceId": self.workspaceid, "action": 2, "userName": "******", "domain": name, "recordNum": "京ICP备13052560号", "productCode": product, "origin": [{ "role": "master", "origin": "1.1.1.1", "port": "443", "weight": 1, "protocol": "https" }], "originProtocol": "https", "basicConf": { "follow302": 0 }, "reqHost": "cc.ctyun.com", "filetypeTtl": [{ "fileType": "php,ashx,aspx,asp,jsp,do", "ttl": 0, "cacheType": 3, "cacheWithArgs": 0 }, { "fileType": "js,css,xml,htm,html", "ttl": 1800, "cacheType": 3, "cacheWithArgs": 0 }, { "fileType": "swf,jpg,gif,png,bmp,ico,ts", "ttl": 86400, "cacheType": 3, "cacheWithArgs": 0 }, { "fileType": "wmv,mp3,wma,ogg,flv,mp4,avi,mpg,mpeg,f4v,hlv,rmvb,rm,3gp,img,bin,zip,rar,ipa,apk,jar,sis,xap,msi,exe,cab,7z,pdf,doc,docx,xls,xlsx,ppt,pptx,txt", "ttl": 31536000, "cacheType": 3, "cacheWithArgs": 0 }], "ipWhiteList": "127.0.0.1", "whiteReferer": { "allowList": ["ab.ctyun.com"], "allowEmpty": "on" }, "httpsBasic": { "originProtocol": "https" } } } else: print("参数错误,请检查product!!!") data = "" response = self.session.post(self.host + url, json=data, verify=False) print(response.text) return response