def get_client_instance(id, key, product):
    '''获取指定endpoint的实例,用于后面对其的各种操作
    '''
    try:
        # 实例化一个认证对象,入参需要传入腾讯云账户 secretId,secretKey, 此处还需注意密钥对的保密
        cred = credential.Credential(id, key)

        # 实例化一个 http 选项,可选
        httpProfile = HttpProfile()
        # post 请求 (默认为 post 请求)
        httpProfile.reqMethod = "POST"
        # 请求超时时间,单位为秒 (默认60秒)
        httpProfile.reqTimeout = 30
        # 不指定接入地域域名 (默认就近接入)
        httpProfile.endpoint = "{}.tencentcloudapi.com".format(product)

        # 实例化一个 client 选项,可选
        clientProfile = ClientProfile()
        clientProfile.httpProfile = httpProfile
        # 实例化要请求产品的 client 对象,clientProfile 是可选的
        if product == "ssl":
            client = ssl_client.SslClient(cred, "", clientProfile)
            print("实例化一个ssl_client成功")
        elif product == "cdn":
            client = cdn_client.CdnClient(cred, "", clientProfile)
            print("实例化cdn client成功")
        elif product == "ecdn":
            client = ecdn_client.EcdnClient(cred, "", clientProfile)
            print("实例化ecdn client成功")
        else:
            exit("本程序仅支持ssl、cdn、ecdn")
        return client
    except TencentCloudSDKException as err:
        print(err)
        exit(-1)
Example #2
0
def dcdn():
    from tencentcloud.ecdn.v20191012 import ecdn_client, models
    DCDN_list = args.url.split(',')
    httpProfile = HttpProfile()
    httpProfile.endpoint = "ecdn.tencentcloudapi.com"

    clientProfile = ClientProfile()
    clientProfile.httpProfile = httpProfile
    client = ecdn_client.EcdnClient(cred, "", clientProfile)

    req = models.PurgePathCacheRequest()
    params = {"Paths": DCDN_list, "FlushType": args.fresh}
    req.from_json_string(json.dumps(params))

    resp = client.PurgePathCache(req)
    print(resp.to_json_string())
Example #3
0
def TENCENTECDNConfig(domain, ak, sk):
    try:
        cred = credential.Credential(ak, sk)
        httpProfile = HttpProfile()
        httpProfile.endpoint = "ecdn.tencentcloudapi.com"

        clientProfile = ClientProfile()
        clientProfile.httpProfile = httpProfile
        client = ecdn_client.EcdnClient(cred, "", clientProfile)

        req = models.DescribeDomainsConfigRequest()
        params = {"Filters": [{"Name": "domain", "Value": [domain]}]}
        req.from_json_string(json.dumps(params))

        resp = client.DescribeDomainsConfig(req)
        resp = resp.to_json_string()
        resp = json.loads(resp)
        return {"msg": resp['Domains'][0], "code": 200}
    except TencentCloudSDKException as err:
        return {"msg": str(err), "code": 5001}
Example #4
0
def TENCENTECDNRefresh(domain, ak, sk):

    try:
        cred = credential.Credential(
            ak,
            sk,
        )
        httpProfile = HttpProfile()
        httpProfile.endpoint = "ecdn.tencentcloudapi.com"

        clientProfile = ClientProfile()
        clientProfile.httpProfile = httpProfile
        client = ecdn_client.EcdnClient(cred, "", clientProfile)

        req = models.PurgePathCacheRequest()
        params = {"Paths": [domain], "FlushType": "flush"}
        req.from_json_string(json.dumps(params))
        resp = client.PurgePathCache(req)
        return {"msg": "刷新完成", "refresh_url": domain, "code": 200}
    except TencentCloudSDKException as err:
        return {"msg": "刷新失败", "refresh_url": str(err), "code": 5001}
Example #5
0
from my_models.config import cred, args
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception \
    import TencentCloudSDKException
from tencentcloud.ecdn.v20191012 import ecdn_client, models  # noqa
import json

httpProfile = HttpProfile()
httpProfile.endpoint = "ecdn.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = ecdn_client.EcdnClient(cred, "", clientProfile)


def example(params):
    try:
        req = eval('models.' + args.m + 'EcdnDomainRequest()')
        req.from_json_string(json.dumps(params))
        resp = eval('client.' + args.m + 'EcdnDomain' + '(req)')
        print(resp.to_json_string())
    except TencentCloudSDKException as err:
        print(err)


class Ecdn_base():
    def addEcdn(self, port, ssl, pri, pub):
        """ Qcloud SDK生成後加入自訂變數"""
        params = {
            "Domain": self,
            "Origin": {