访问控制
更新时间:2023-05-16
下列代码中对函数入参c即是CdnClient对象,详情参见CdnClient。
设置访问ua控制
whiteList和blackList不能同时设置也不能都没有
case1:设置ua白名单
def test_set_ua_acl_white_list(c):
"""
test_set_ua_acl_white_list
"""
ua_acl = {
"whiteList": [
"Mozilla/5.0 (Windows NT 6.1",
"Mozilla/5.0 (Linux; Android 7.0"
],
}
response = c.set_domain_ua_acl('example.test.com', ua_acl)
print(response)
case2:设置ua黑名单
def test_set_ua_acl_black_list(c):
"""
test_set_ua_acl_black_list
"""
ua_acl = {
"blackList": [
"Mozilla/5.0 (Windows NT 6.1",
"Mozilla/5.0 (Linux; Android 7.0"
],
}
response = c.set_domain_ua_acl('example.test.com', ua_acl)
print(response)
case3:删除ua白名单
def test_delete_ua_acl_white_list(c):
"""
test_delete_ua_acl_white_list
"""
ua_acl = {
"whiteList": [],
}
response = c.set_domain_ua_acl('example.test.com', ua_acl)
print(response)
case4:删除ua黑名单
def test_delete_ua_acl_black_list(c):
"""
test_delete_ua_acl_black_list
"""
ua_acl = {
"blackList": [],
}
response = c.set_domain_ua_acl('example.test.com', ua_acl)
print(response)
查询访问ua控制配置
def test_get_ua_acl(c):
"""
test_get_ua_acl
"""
response = c.get_domain_ua_acl('example.test.com')
print(response)
设置域名限速
def test_set_traffic_limit(c):
"""
test_set_traffic_limit
"""
traffic_limit = {
"enable": True,
"limitRate": 1024,
"limitStartHour": 1,
"limitEndHour": 10,
"limitRateAfter": 2048,
"trafficLimitArg": "a",
"trafficLimitUnit": "k"
}
response = c.set_domain_traffic_limit('example.test.com', traffic_limit)
print(response)
查询域名限速配置
def test_get_traffic_limit(c):
"""
test_get_traffic_limit
"""
response = c.get_domain_traffic_limit('example.test.com')
print(response)
设置访问 ip 控制
def test_set_domain_ip_acl(c):
"""
test_set_domain_ip_acl
"""
blackList = ['1.1.1.2', '1.1.1.3']
response = c.set_domain_ip_acl(
domain = 'example.test.com',
blackList = blackList)
print(response)
查询访问 ip 控制
def test_get_domain_ip_acl(c):
"""
test get domain ip acl
"""
response = c.get_domain_ip_acl('test-sdk.sys-qa.com')
print(response)
设置访问鉴权
def test_set_request_auth(c):
"""
test_set_request_auth
"""
request_auth = {
"type": "c",
"key1": "secretekey1",
"key2": "secretekey2",
"timeout": 300,
"whiteList": ["/crossdomain.xml"],
"signArg": "sign",
"timeArg": "t"
}
response = c.set_request_auth('test.example.com', request_auth)
print(response)
设置 cors 跨域
def test_set_domain_cors(c):
"""
test set domain cors
"""
cors = {
"allow": "on",
"originList": ["http://www.baidu.com", "http://*.bce.com"]
}
domain = 'test-sdk.sys-qa.com'
response = c.set_domain_cors(domain, cors);
print(response)
查询 cors 跨域
def test_get_domain_cors(c):
"""
test get domain cors
"""
response = c.get_domain_cors('test-sdk.sys-qa.com')
print(response)
设置 ip 访问限频
def test_set_domain_access_limit(c):
"""
test set domain access limit
"""
access_limit = {
"enabled": True,
"limit": 2000
}
domain = 'test-sdk.sys-qa.com'
response = c.set_domain_access_limit(domain, access_limit);
print(response)
下列代码中对函数入参c即是CdnClient对象,详情参见CdnClient。
查询 ip 访问限频
def test_get_domain_access_limit(c):
"""
test get domain access limit
"""
response = c.get_domain_access_limit('test-sdk.sys-qa.com')
print(response)
设置获取用户真实 ip
def test_set_domain_client_ip(c):
"""
test set domain client ip
"""
client_ip = {
"enabled": True,
"name": "True-Client-Ip"
}
domain = 'test-sdk.sys-qa.com'
response = c.set_domain_client_ip(domain, client_ip);
print(response)
查询获取用户真实ip
def test_get_domain_client_ip(c):
"""
test get domain client_ip
"""
response = c.get_domain_client_ip('test-sdk.sys-qa.com')
print(response)
查询访问 Referer 控制
def test_set_domain_referer_acl(c):
"""
test_set_domain_referer_acl
"""
blackList = ["http://a/b/c/", "http://c/d/e/"]
response = c.set_domain_referer_acl(
domain = 'www.example.com',
blackList = blackList,
allowEmpty = True)
print(response)