cdn_client.py 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884
  1. # Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  4. # except in compliance with the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the
  9. # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  10. # either express or implied. See the License for the specific language governing permissions
  11. # and limitations under the License.
  12. """
  13. This module provides a client class for CDN.
  14. """
  15. import copy
  16. import json
  17. import logging
  18. import baidubce
  19. from baidubce import bce_base_client
  20. from baidubce.auth import bce_v1_signer
  21. from baidubce.http import bce_http_client
  22. from baidubce.http import handler
  23. from baidubce.http import http_content_types
  24. from baidubce.http import http_headers
  25. from baidubce.http import http_methods
  26. from baidubce.exception import BceClientError
  27. from baidubce.exception import BceServerError
  28. from baidubce.utils import required
  29. from baidubce import utils
  30. from baidubce.services.cdn.cdn_stats_param import CdnStatsParam
  31. _logger = logging.getLogger(__name__)
  32. class CdnClient(bce_base_client.BceBaseClient):
  33. """
  34. CdnClient
  35. """
  36. prefix = b"/v2"
  37. def __init__(self, config=None):
  38. bce_base_client.BceBaseClient.__init__(self, config)
  39. def list_domains(self, config=None):
  40. """
  41. get domain list
  42. :param config: None
  43. :type config: baidubce.BceClientConfiguration
  44. :return:
  45. :rtype: baidubce.bce_response.BceResponse
  46. """
  47. return self._send_request(
  48. http_methods.GET,
  49. '/domain',
  50. config=config)
  51. def list_user_domains(self, status, rule=None, config=None):
  52. """
  53. get user domain list
  54. :param status: Specify the domain whose return 'status' is status
  55. :type status: string
  56. :param rule: domain Fuzzy Matching
  57. :type rule: string
  58. :param config: None
  59. :type config: baidubce.BceClientConfiguration
  60. :return:
  61. :rtype: baidubce.bce_response.BceResponse
  62. """
  63. params = {}
  64. params['status'] = status
  65. if rule is not None:
  66. params['rule'] = rule
  67. return self._send_request(
  68. http_methods.GET, '/user/domains',
  69. params=params,
  70. config=config)
  71. def valid_domain(self, domain, config=None):
  72. """
  73. query if a domain can be create
  74. :param domain: the domain name
  75. :type domain: string
  76. :param config: None
  77. :type config: baidubce.BceClientConfiguration
  78. :return:
  79. :rtype: baidubce.bce_response.BceResponse
  80. """
  81. return self._send_request(
  82. http_methods.GET,
  83. '/domain/' + domain + '/valid',
  84. config=config)
  85. def get_domain_cache_full_url(self, domain, config=None):
  86. """
  87. get cache full url of a domain
  88. :param domain: the domain name
  89. :type domain: string
  90. :param config: None
  91. :type config: baidubce.BceClientConfiguration
  92. :return:
  93. :rtype: baidubce.bce_response.BceResponse
  94. """
  95. return self._send_request(
  96. http_methods.GET, '/domain/' + domain + '/config',
  97. params={'cacheFullUrl': ''},
  98. config=config)
  99. def set_domain_cache_share(self, domain, cache_share, config=None):
  100. """
  101. update cacheShare of the domain
  102. :param domain: the domain name
  103. :type domain: string
  104. :param cache_share: detailed configuration of cacheShare
  105. :type cache_share: dictionary
  106. :param config: None
  107. :type config: baidubce.BceClientConfiguration
  108. :return:
  109. :rtype: baidubce.bce_response.BceResponse
  110. """
  111. return self._send_request(
  112. http_methods.PUT,
  113. '/domain/' + domain + '/config',
  114. params={'cacheShare': ''},
  115. body=json.dumps({'cacheShare': cache_share}),
  116. config=config)
  117. def get_domain_cache_share(self, domain, config=None):
  118. """
  119. get cacheShare configuration of a domain
  120. :param domain: the domain name
  121. :type domain: string
  122. :param config: None
  123. :type config: baidubce.BceClientConfiguration
  124. :return:
  125. :rtype: baidubce.bce_response.BceResponse
  126. """
  127. return self._send_request(
  128. http_methods.GET, '/domain/' + domain + '/config',
  129. params={'cacheShare': ''},
  130. config=config)
  131. def set_domain_traffic_limit(self, domain, traffic_limit, config=None):
  132. """
  133. update trafficLimit of the domain
  134. :param domain: the domain name
  135. :type domain: string
  136. :param traffic_limit: detailed configuration of trafficLimit
  137. :type traffic_limit: dictionary
  138. :param config: None
  139. :type config: baidubce.BceClientConfiguration
  140. :return:
  141. :rtype: baidubce.bce_response.BceResponse
  142. """
  143. return self._send_request(
  144. http_methods.PUT,
  145. '/domain/' + domain + '/config',
  146. params={'trafficLimit': ''},
  147. body=json.dumps({'trafficLimit': traffic_limit}),
  148. config=config)
  149. def get_domain_traffic_limit(self, domain, config=None):
  150. """
  151. get trafficLimit configuration of a domain
  152. :param domain: the domain name
  153. :type domain: string
  154. :param config: None
  155. :type config: baidubce.BceClientConfiguration
  156. :return:
  157. :rtype: baidubce.bce_response.BceResponse
  158. """
  159. return self._send_request(
  160. http_methods.GET, '/domain/' + domain + '/config',
  161. params={'trafficLimit': ''},
  162. config=config)
  163. def set_domain_ua_acl(self, domain, ua_acl, config=None):
  164. """
  165. update uaAcl of the domain
  166. :param domain: the domain name
  167. :type domain: string
  168. :param ua_acl: detailed configuration of uaAcl
  169. :type ua_acl: dictionary
  170. :param config: None
  171. :type config: baidubce.BceClientConfiguration
  172. :return:
  173. :rtype: baidubce.bce_response.BceResponse
  174. """
  175. return self._send_request(
  176. http_methods.PUT,
  177. '/domain/' + domain + '/config',
  178. params={'uaAcl': ''},
  179. body=json.dumps({'uaAcl': ua_acl}),
  180. config=config)
  181. def get_domain_ua_acl(self, domain, config=None):
  182. """
  183. get uaAcl configuration of a domain
  184. :param domain: the domain name
  185. :type domain: string
  186. :param config: None
  187. :type config: baidubce.BceClientConfiguration
  188. :return:
  189. :rtype: baidubce.bce_response.BceResponse
  190. """
  191. return self._send_request(
  192. http_methods.GET, '/domain/' + domain + '/config',
  193. params={'uaAcl': ''},
  194. config=config)
  195. def set_domain_origin_protocol(self, domain, origin_protocol, config=None):
  196. """
  197. update originProtocol of the domain
  198. :param domain: the domain name
  199. :type domain: string
  200. :param origin_protocol: detailed configuration of originProtocol
  201. :type origin_protocol: dictionary
  202. :param config: None
  203. :type config: baidubce.BceClientConfiguration
  204. :return:
  205. :rtype: baidubce.bce_response.BceResponse
  206. """
  207. return self._send_request(
  208. http_methods.PUT,
  209. '/domain/' + domain + '/config',
  210. params={'originProtocol': ''},
  211. body=json.dumps({'originProtocol': origin_protocol}),
  212. config=config)
  213. def get_domain_origin_protocol(self, domain, config=None):
  214. """
  215. get originProtocol configuration of a domain
  216. :param domain: the domain name
  217. :type domain: string
  218. :param config: None
  219. :type config: baidubce.BceClientConfiguration
  220. :return:
  221. :rtype: baidubce.bce_response.BceResponse
  222. """
  223. return self._send_request(
  224. http_methods.GET, '/domain/' + domain + '/config',
  225. params={'originProtocol': ''},
  226. config=config)
  227. def set_domain_retry_origin(self, domain, retry_origin, config=None):
  228. """
  229. update retryOrigin of the domain
  230. :param domain: the domain name
  231. :type domain: string
  232. :param retry_origin: detailed configuration of retryOrigin
  233. :type retry_origin: dictionary
  234. :param config: None
  235. :type config: baidubce.BceClientConfiguration
  236. :return:
  237. :rtype: baidubce.bce_response.BceResponse
  238. """
  239. return self._send_request(
  240. http_methods.PUT,
  241. '/domain/' + domain + '/config',
  242. params={'retryOrigin': ''},
  243. body=json.dumps({'retryOrigin': retry_origin}),
  244. config=config)
  245. def get_domain_retry_origin(self, domain, config=None):
  246. """
  247. get retryOrigin configuration of a domain
  248. :param domain: the domain name
  249. :type domain: string
  250. :param config: None
  251. :type config: baidubce.BceClientConfiguration
  252. :return:
  253. :rtype: baidubce.bce_response.BceResponse
  254. """
  255. return self._send_request(
  256. http_methods.GET, '/domain/' + domain + '/config',
  257. params={'retryOrigin': ''},
  258. config=config)
  259. def set_domain_ipv6_dispatch(self, domain, ipv6_dispatch, config=None):
  260. """
  261. update ipv6Dispatch of the domain
  262. :param domain: the domain name
  263. :type domain: string
  264. :param ipv6_dispatch: detailed configuration of IPv6 access and IPv6 back to source
  265. :type ipv6_dispatch: IPv6Config
  266. :param config: None
  267. :type config: baidubce.BceClientConfiguration
  268. :return:
  269. :rtype: baidubce.bce_response.BceResponse
  270. """
  271. return self._send_request(
  272. http_methods.PUT,
  273. '/domain/' + domain + '/config',
  274. params={'ipv6Dispatch': ''},
  275. body=json.dumps({'ipv6Dispatch': ipv6_dispatch}),
  276. config=config)
  277. def get_domain_ipv6_dispatch(self, domain, config=None):
  278. """
  279. get ipv6Dispatch configuration of a domain
  280. :param domain: the domain name
  281. :type domain: string
  282. :param config: None
  283. :type config: baidubce.BceClientConfiguration
  284. :return:
  285. :rtype: baidubce.bce_response.BceResponse
  286. """
  287. return self._send_request(
  288. http_methods.GET, '/domain/' + domain + '/config',
  289. params={'ipv6Dispatch': ''},
  290. config=config)
  291. def set_domain_quic(self, domain, quic, config=None):
  292. """
  293. update QUIC of the domain
  294. :param domain: the domain name
  295. :type domain: string
  296. :param quic: detailed configuration of Quick UDP Internet Connection
  297. :type quic: bool
  298. :param config: None
  299. :type config: baidubce.BceClientConfiguration
  300. :return:
  301. :rtype: baidubce.bce_response.BceResponse
  302. """
  303. return self._send_request(
  304. http_methods.PUT,
  305. '/domain/' + domain + '/config',
  306. params={'quic': ''},
  307. body=json.dumps({'quic': quic}),
  308. config=config)
  309. def get_domain_quic(self, domain, config=None):
  310. """
  311. get quic configuration of a domain
  312. :param domain: the domain name
  313. :type domain: string
  314. :param config: None
  315. :type config: baidubce.BceClientConfiguration
  316. :return:
  317. :rtype: baidubce.bce_response.BceResponse
  318. """
  319. return self._send_request(
  320. http_methods.GET, '/domain/' + domain + '/config',
  321. params={'quic': ''},
  322. config=config)
  323. def set_domain_offline_mode(self, domain, offline_mode, config=None):
  324. """
  325. update offlineMode of the domain
  326. :param domain: the domain name
  327. :type domain: string
  328. :param offline_mode: detailed configuration of offlineMode
  329. :type offline_mode: bool
  330. :param config: None
  331. :type config: baidubce.BceClientConfiguration
  332. :return:
  333. :rtype: baidubce.bce_response.BceResponse
  334. """
  335. return self._send_request(
  336. http_methods.PUT,
  337. '/domain/' + domain + '/config',
  338. params={'offlineMode': ''},
  339. body=json.dumps({'offlineMode': offline_mode}),
  340. config=config)
  341. def get_domain_offline_mode(self, domain, config=None):
  342. """
  343. get offlineMode configuration of a domain
  344. :param domain: the domain name
  345. :type domain: string
  346. :param config: None
  347. :type config: baidubce.BceClientConfiguration
  348. :return:
  349. :rtype: baidubce.bce_response.BceResponse
  350. """
  351. return self._send_request(
  352. http_methods.GET, '/domain/' + domain + '/config',
  353. params={'offlineMode': ''},
  354. config=config)
  355. def set_domain_ocsp(self, domain, ocsp, config=None):
  356. """
  357. update OCSP configuration of the domain
  358. :param domain: the domain name
  359. :type domain: string
  360. :param ocsp: detailed configuration of Online Certificate Status Protocol
  361. :type ocsp: bool
  362. :param config: None
  363. :type config: baidubce.BceClientConfiguration
  364. :return:
  365. :rtype: baidubce.bce_response.BceResponse
  366. """
  367. return self._send_request(
  368. http_methods.PUT,
  369. '/domain/' + domain + '/config',
  370. params={'ocsp': ''},
  371. body=json.dumps({'ocsp': ocsp}),
  372. config=config)
  373. def get_domain_ocsp(self, domain, config=None):
  374. """
  375. get ocsp configuration of a domain
  376. :param domain: the domain name
  377. :type domain: string
  378. :param config: None
  379. :type config: baidubce.BceClientConfiguration
  380. :return:
  381. :rtype: baidubce.bce_response.BceResponse
  382. """
  383. return self._send_request(
  384. http_methods.GET, '/domain/' + domain + '/config',
  385. params={'ocsp': ''},
  386. config=config)
  387. def set_domain_error_page(self, domain, error_page, config=None):
  388. """
  389. update error_page of the domain
  390. :param domain: the domain name
  391. :type domain: string
  392. :param error_page: Detailed configuration of custom error jump pages
  393. :type error_page: list<ErrorPage>
  394. :param config: None
  395. :type config: baidubce.BceClientConfiguration
  396. :return:
  397. :rtype: baidubce.bce_response.BceResponse
  398. """
  399. return self._send_request(
  400. http_methods.PUT,
  401. '/domain/' + domain + '/config',
  402. params={'errorPage': ''},
  403. body=json.dumps({'errorPage': error_page}),
  404. config=config)
  405. def get_domain_error_page(self, domain, config=None):
  406. """
  407. get error page configuration of a domain
  408. :param domain: the domain name
  409. :type domain: string
  410. :param config: None
  411. :type config: baidubce.BceClientConfiguration
  412. :return:
  413. :rtype: baidubce.bce_response.BceResponse
  414. """
  415. return self._send_request(
  416. http_methods.GET, '/domain/' + domain + '/config',
  417. params={'errorPage': ''},
  418. config=config)
  419. def get_domain_referer_acl(self, domain, config=None):
  420. """
  421. get referer acl configuration of a domain
  422. :param domain: the domain name
  423. :type domain: string
  424. :param config: None
  425. :type config: baidubce.BceClientConfiguration
  426. :return:
  427. :rtype: baidubce.bce_response.BceResponse
  428. """
  429. return self._send_request(
  430. http_methods.GET, '/domain/' + domain + '/config',
  431. params={'refererACL': ''},
  432. config=config)
  433. def get_domain_ip_acl(self, domain, config=None):
  434. """
  435. get ip acl configuration of a domain
  436. :param domain: the domain name
  437. :type domain: string
  438. :param config: None
  439. :type config: baidubce.BceClientConfiguration
  440. :return:
  441. :rtype: baidubce.bce_response.BceResponse
  442. """
  443. return self._send_request(
  444. http_methods.GET, '/domain/' + domain + '/config',
  445. params={'ipACL': ''},
  446. config=config)
  447. def set_domain_cors(self, domain, cors, config=None):
  448. """
  449. update cors of the domain
  450. :param domain: the domain name
  451. :type domain: string
  452. :param cors: Accelerating Cross-domain Settings for Domain Names
  453. :type cors
  454. :param config: None
  455. :type config: baidubce.BceClientConfiguration
  456. :return:
  457. :rtype: baidubce.bce_response.BceResponse
  458. """
  459. return self._send_request(
  460. http_methods.PUT,
  461. '/domain/' + domain + '/config',
  462. params={'cors': ''},
  463. body=json.dumps({'cors': cors}),
  464. config=config)
  465. def get_domain_cors(self, domain, config=None):
  466. """
  467. get cors configuration of a domain
  468. :param domain: the domain name
  469. :type domain: string
  470. :param config: None
  471. :type config: baidubce.BceClientConfiguration
  472. :return:
  473. :rtype: baidubce.bce_response.BceResponse
  474. """
  475. return self._send_request(
  476. http_methods.GET, '/domain/' + domain + '/config',
  477. params={'cors': ''},
  478. config=config)
  479. def set_domain_access_limit(self, domain, access_limit, config=None):
  480. """
  481. update access limit of the domain
  482. :param domain: the domain name
  483. :type domain: string
  484. :param access_limit: Setting IP Access Limitation
  485. :type AccessLimit
  486. :param config: None
  487. :type config: baidubce.BceClientConfiguration
  488. :return:
  489. :rtype: baidubce.bce_response.BceResponse
  490. """
  491. return self._send_request(
  492. http_methods.PUT,
  493. '/domain/' + domain + '/config',
  494. params={'accessLimit': ''},
  495. body=json.dumps({'accessLimit': access_limit}),
  496. config=config)
  497. def get_domain_access_limit(self, domain, config=None):
  498. """
  499. get access limit configuration of a domain
  500. :param domain: the domain name
  501. :type domain: string
  502. :param config: None
  503. :type config: baidubce.BceClientConfiguration
  504. :return:
  505. :rtype: baidubce.bce_response.BceResponse
  506. """
  507. return self._send_request(
  508. http_methods.GET, '/domain/' + domain + '/config',
  509. params={'accessLimit': ''},
  510. config=config)
  511. def set_domain_client_ip(self, domain, client_ip, config=None):
  512. """
  513. update Getting Real User IP Settings
  514. :param domain: the domain name
  515. :type domain: string
  516. :param client_ip: Getting Real User IP Settings
  517. :type ClientIp
  518. :param config: None
  519. :type config: baidubce.BceClientConfiguration
  520. :return:
  521. :rtype: baidubce.bce_response.BceResponse
  522. """
  523. return self._send_request(
  524. http_methods.PUT,
  525. '/domain/' + domain + '/config',
  526. params={'clientIp': ''},
  527. body=json.dumps({'clientIp': client_ip}),
  528. config=config)
  529. def get_domain_client_ip(self, domain, config=None):
  530. """
  531. get client ip configuration of a domain
  532. :param domain: the domain name
  533. :type domain: string
  534. :param config: None
  535. :type config: baidubce.BceClientConfiguration
  536. :return:
  537. :rtype: baidubce.bce_response.BceResponse
  538. """
  539. return self._send_request(
  540. http_methods.GET, '/domain/' + domain + '/config',
  541. params={'clientIp': ''},
  542. config=config)
  543. def set_domain_range_switch(self, domain, range_switch, config=None):
  544. """
  545. update range backsource Settings
  546. :param domain: the domain name
  547. :type domain: string
  548. :param range_switch: rangre backsource settings
  549. :type bool
  550. :param config: None
  551. :type config: baidubce.BceClientConfiguration
  552. :return:
  553. :rtype: baidubce.bce_response.BceResponse
  554. """
  555. return self._send_request(
  556. http_methods.PUT,
  557. '/domain/' + domain + '/config',
  558. params={'rangeSwitch': ''},
  559. body=json.dumps({'rangeSwitch': range_switch}),
  560. config=config)
  561. def get_domain_range_switch(self, domain, config=None):
  562. """
  563. get range switch configuration of a domain
  564. :param domain: the domain name
  565. :type domain: string
  566. :param config: None
  567. :type config: baidubce.BceClientConfiguration
  568. :return:
  569. :rtype: baidubce.bce_response.BceResponse
  570. """
  571. return self._send_request(
  572. http_methods.GET, '/domain/' + domain + '/config',
  573. params={'rangeSwitch': ''},
  574. config=config)
  575. def set_domain_mobile_access(self, domain, mobile_access, config=None):
  576. """
  577. update mobile access Settings
  578. :param domain: the domain name
  579. :type domain: string
  580. :param mobile_access: mobile access settings
  581. :type MobileAccess
  582. :param config: None
  583. :type config: baidubce.BceClientConfiguration
  584. :return:
  585. :rtype: baidubce.bce_response.BceResponse
  586. """
  587. return self._send_request(
  588. http_methods.PUT,
  589. '/domain/' + domain + '/config',
  590. params={'mobileAccess': ''},
  591. body=json.dumps({'mobileAccess': mobile_access}),
  592. config=config)
  593. def get_domain_mobile_access(self, domain, config=None):
  594. """
  595. get mobile access configuration of a domain
  596. :param domain: the domain name
  597. :type domain: string
  598. :param config: None
  599. :type config: baidubce.BceClientConfiguration
  600. :return:
  601. :rtype: baidubce.bce_response.BceResponse
  602. """
  603. return self._send_request(
  604. http_methods.GET, '/domain/' + domain + '/config',
  605. params={'mobileAccess': ''},
  606. config=config)
  607. def set_domain_http_header(self, domain, http_header, config=None):
  608. """
  609. update http header Settings
  610. :param domain: the domain name
  611. :type domain: string
  612. :param http_header: http header settings
  613. :type HttpHeader
  614. :param config: None
  615. :type config: baidubce.BceClientConfiguration
  616. :return:
  617. :rtype: baidubce.bce_response.BceResponse
  618. """
  619. return self._send_request(
  620. http_methods.PUT,
  621. '/domain/' + domain + '/config',
  622. params={'httpHeader': ''},
  623. body=json.dumps({'httpHeader': http_header}),
  624. config=config)
  625. def get_domain_http_header(self, domain, config=None):
  626. """
  627. get http header configuration of a domain
  628. :param domain: the domain name
  629. :type domain: string
  630. :param config: None
  631. :type config: baidubce.BceClientConfiguration
  632. :return:
  633. :rtype: baidubce.bce_response.BceResponse
  634. """
  635. return self._send_request(
  636. http_methods.GET, '/domain/' + domain + '/config',
  637. params={'httpHeader': ''},
  638. config=config)
  639. def set_domain_file_trim(self, domain, file_trim, config=None):
  640. """
  641. update file trim Settings
  642. :param domain: the domain name
  643. :type domain: string
  644. :param file_trim: file trim settings
  645. :type bool
  646. :param config: None
  647. :type config: baidubce.BceClientConfiguration
  648. :return:
  649. :rtype: baidubce.bce_response.BceResponse
  650. """
  651. return self._send_request(
  652. http_methods.PUT,
  653. '/domain/' + domain + '/config',
  654. params={'fileTrim': ''},
  655. body=json.dumps({'fileTrim': file_trim}),
  656. config=config)
  657. def get_domain_file_trim(self, domain, config=None):
  658. """
  659. get file trim configuration of a domain
  660. :param domain: the domain name
  661. :type domain: string
  662. :param config: None
  663. :type config: baidubce.BceClientConfiguration
  664. :return:
  665. :rtype: baidubce.bce_response.BceResponse
  666. """
  667. return self._send_request(
  668. http_methods.GET, '/domain/' + domain + '/config',
  669. params={'fileTrim': ''},
  670. config=config)
  671. def set_domain_media_drag(self, domain, media_drag, config=None):
  672. """
  673. update media drag Settings
  674. :param domain: the domain name
  675. :type domain: string
  676. :param media_drag: media drag settings
  677. :type MediaDragConf
  678. :param config: None
  679. :type config: baidubce.BceClientConfiguration
  680. :return:
  681. :rtype: baidubce.bce_response.BceResponse
  682. """
  683. return self._send_request(
  684. http_methods.PUT,
  685. '/domain/' + domain + '/config',
  686. params={'mediaDrag': ''},
  687. body=json.dumps({'mediaDragConf': media_drag}),
  688. config=config)
  689. def get_domain_media_drag(self, domain, config=None):
  690. """
  691. get range switch configuration of a domain
  692. :param domain: the domain name
  693. :type domain: string
  694. :param config: None
  695. :type config: baidubce.BceClientConfiguration
  696. :return:
  697. :rtype: baidubce.bce_response.BceResponse
  698. """
  699. return self._send_request(
  700. http_methods.GET, '/domain/' + domain + '/config',
  701. params={'mediaDrag': ''},
  702. config=config)
  703. def set_domain_compress(self, domain, compress, config=None):
  704. """
  705. update compress Settings
  706. :param domain: the domain name
  707. :type domain: string
  708. :param compress: media drag settings
  709. :type compress
  710. :param config: None
  711. :type config: baidubce.BceClientConfiguration
  712. :return:
  713. :rtype: baidubce.bce_response.BceResponse
  714. """
  715. return self._send_request(
  716. http_methods.PUT,
  717. '/domain/' + domain + '/config',
  718. params={'compress': ''},
  719. body=json.dumps({'compress': compress}),
  720. config=config)
  721. def get_domain_compress(self, domain, config=None):
  722. """
  723. get compress configuration of a domain
  724. :param domain: the domain name
  725. :type domain: string
  726. :param config: None
  727. :type config: baidubce.BceClientConfiguration
  728. :return:
  729. :rtype: baidubce.bce_response.BceResponse
  730. """
  731. return self._send_request(
  732. http_methods.GET, '/domain/' + domain + '/config',
  733. params={'compress': ''},
  734. config=config)
  735. def get_domain_records(self, Type=None, start_time=None, end_time=None,
  736. url=None, marker=None, config=None):
  737. """
  738. Query refresh and preload records
  739. :param Type: None
  740. :type string
  741. :param start_time: None
  742. :type Timestamp
  743. :param end_time: None
  744. :type Timestamp
  745. :param url: None
  746. :type string
  747. :param marker: None
  748. :type string
  749. :param config: None
  750. :type config: baidubce.BceClientConfiguration
  751. :return:
  752. :rtype: baidubce.bce_response.BceResponse
  753. """
  754. params = {}
  755. if Type is not None:
  756. params['type'] = Type
  757. if start_time is not None:
  758. params['startTime'] = start_time
  759. if end_time is not None:
  760. params['endTime'] = end_time
  761. if url is not None:
  762. params['url'] = url
  763. if marker is not None:
  764. params['marker'] = marker
  765. if params is None:
  766. params = {}
  767. return self._send_request(
  768. http_methods.GET, '/cache/records',
  769. params = params,
  770. config=config)
  771. def set_dsa(self, action, config=None):
  772. """
  773. set das enable
  774. :param action: dsa enable
  775. :type string
  776. :param config: None
  777. :type config: baidubce.BceClientConfiguration
  778. :return:
  779. :rtype: baidubce.bce_response.BceResponse
  780. """
  781. return self._send_request(
  782. http_methods.PUT,
  783. '/dsa',
  784. body=json.dumps({'action': action}),
  785. config=config)
  786. def set_domain_dsa(self, domain, dsa, config=None):
  787. """
  788. update domain dsa Settings
  789. :param domain: the domain name
  790. :type domain: string
  791. :param dsa: domain dsa settings
  792. :type DSA
  793. :param config: None
  794. :type config: baidubce.BceClientConfiguration
  795. :return:
  796. :rtype: baidubce.bce_response.BceResponse
  797. """
  798. return self._send_request(
  799. http_methods.PUT,
  800. '/domain/' + domain + '/config',
  801. params={'dsa': ''},
  802. body=json.dumps({'dsa': dsa}),
  803. config=config)
  804. def get_dsa_domains(self, config=None):
  805. """
  806. get dsa domain list
  807. :param config: None
  808. :type config: baidubce.BceClientConfiguration
  809. :return:
  810. :rtype: baidubce.bce_response.BceResponse
  811. """
  812. return self._send_request(
  813. http_methods.GET,
  814. '/dsa/domain',
  815. config=config)
  816. def get_log_list(self, log, config=None):
  817. """
  818. get log list
  819. :param config: None
  820. :type config: baidubce.BceClientConfiguration
  821. :return:
  822. :rtype: baidubce.bce_response.BceResponse
  823. """
  824. return self._send_request(
  825. http_methods.POST,
  826. '/log/list',
  827. body=json.dumps(log),
  828. config=config)
  829. def create_domain(self, domain, origin, other=None, config=None):
  830. """
  831. create domain
  832. :param domain: the domain name
  833. :type domain: string
  834. :param origin: the origin address list
  835. :type origin: list<OriginPeer>
  836. :param other: the other config
  837. :type other: list<CONFIG>
  838. :param config: None
  839. :type config: baidubce.BceClientConfiguration
  840. :return:
  841. :rtype: baidubce.bce_response.BceResponse
  842. """
  843. body = {'origin': origin}
  844. if other is not None:
  845. body.update(other)
  846. return self._send_request(
  847. http_methods.PUT,
  848. '/domain/' + domain,
  849. body=json.dumps(body),
  850. config=config)
  851. def delete_domain(self, domain, config=None):
  852. """
  853. delete a domain
  854. :param domain: the domain name
  855. :type domain: string
  856. :param config: None
  857. :type config: baidubce.BceClientConfiguration
  858. :return:
  859. :rtype: baidubce.bce_response.BceResponse
  860. """
  861. return self._send_request(
  862. http_methods.DELETE,
  863. '/domain/' + domain,
  864. config=config)
  865. def enable_domain(self, domain, config=None):
  866. """
  867. enable a domain
  868. :param domain: the domain name
  869. :type domain: string
  870. :param config: None
  871. :type config: baidubce.BceClientConfiguration
  872. :return:
  873. :rtype: baidubce.bce_response.BceResponse
  874. """
  875. return self._send_request(
  876. http_methods.POST,
  877. '/domain/' + domain,
  878. params={'enable': ''},
  879. config=config)
  880. def disable_domain(self, domain, config=None):
  881. """
  882. disable a domain
  883. :param domain: the domain name
  884. :type domain: string
  885. :param config: None
  886. :type config: baidubce.BceClientConfiguration
  887. :return:
  888. :rtype: baidubce.bce_response.BceResponse
  889. """
  890. return self._send_request(
  891. http_methods.POST,
  892. '/domain/' + domain,
  893. params={'disable': ''},
  894. config=config)
  895. def get_domain_config(self, domain, config=None):
  896. """
  897. get configuration of the domain
  898. :param domain: the domain name
  899. :type domain: string
  900. :param config: None
  901. :type config: baidubce.BceClientConfiguration
  902. :return:
  903. :rtype: baidubce.bce_response.BceResponse
  904. """
  905. if domain[0] == '*':
  906. domain = '%2A' + domain[1:]
  907. return self._send_request(
  908. http_methods.GET,
  909. '/domain/' + domain + '/config',
  910. config=config)
  911. def set_domain_multi_configs(self, domain, multi_configs, config=None):
  912. """
  913. update multiConfigs of the domain
  914. :param domain: the domain name
  915. :type domain: string
  916. :param multi_configs: the domain config list
  917. :type multi_configs: list<config>
  918. :param config: None
  919. :type config: baidubce.BceClientConfiguration
  920. :return:
  921. :rtype: baidubce.bce_response.BceResponse
  922. """
  923. return self._send_request(
  924. http_methods.PUT,
  925. '/domain/' + domain + '/config',
  926. params={'multiConfigs': ''},
  927. body=json.dumps({'multiConfigs': multi_configs}),
  928. config=config)
  929. def set_domain_origin(self, domain, origin, other=None, config=None):
  930. """
  931. update origin address of the domain
  932. :param domain: the domain name
  933. :type domain: string
  934. :param origin: the origin address list
  935. :type origin: list<OriginPeer>
  936. :param other: origin extension configuration
  937. :type other: dictionary
  938. :param config: None
  939. :type config: baidubce.BceClientConfiguration
  940. :return:
  941. :rtype: baidubce.bce_response.BceResponse
  942. """
  943. body = {'origin': origin}
  944. if other is not None:
  945. body.update(other)
  946. return self._send_request(
  947. http_methods.PUT,
  948. '/domain/' + domain + '/config',
  949. params={'origin': ''},
  950. body=json.dumps(body),
  951. config=config)
  952. def get_domain_cache_ttl(self, domain, config=None):
  953. """
  954. get cache rules of a domain
  955. :param domain: the domain name
  956. :type domain: string
  957. :param config: None
  958. :type config: baidubce.BceClientConfiguration
  959. :return:
  960. :rtype: baidubce.bce_response.BceResponse
  961. """
  962. return self._send_request(
  963. http_methods.GET, '/domain/' + domain + '/config',
  964. params={'cacheTTL': ''},
  965. config=config)
  966. @required(domain=str, rules=list)
  967. def set_domain_cache_ttl(self, domain, rules, config=None):
  968. """
  969. set cache rules of a domain
  970. :param domain: the domain name
  971. :type domain: string
  972. :param rules: cache rules
  973. :type rules: list
  974. :param config: None
  975. :type config: baidubce.BceClientConfiguration
  976. :return:
  977. :rtype: baidubce.bce_response.BceResponse
  978. """
  979. return self._send_request(
  980. http_methods.PUT,
  981. '/domain/' + domain + '/config',
  982. params={'cacheTTL': ''},
  983. body=json.dumps({'cacheTTL': rules}),
  984. config=config)
  985. def set_domain_cache_full_url(self, domain, flag, config=None):
  986. """
  987. set if use the full url as cache key
  988. :param domain: the domain name
  989. :type domain: string
  990. :param flag:
  991. :type flag: bool
  992. :param config: None
  993. :type config: baidubce.BceClientConfiguration
  994. :return:
  995. :rtype: baidubce.bce_response.BceResponse
  996. """
  997. return self._send_request(
  998. http_methods.PUT,
  999. '/domain/' + domain + '/config',
  1000. params={'cacheFullUrl': ''},
  1001. body=json.dumps({'cacheFullUrl': flag}),
  1002. config=config)
  1003. @required(domain=str)
  1004. def set_domain_referer_acl(self, domain,
  1005. blackList=None, whiteList=None,
  1006. allowEmpty=True, config=None):
  1007. """
  1008. set request referer access control
  1009. :param domain: the domain name
  1010. :type domain: string
  1011. :param blackList: referer blackList
  1012. :type blackList: list
  1013. :param whitelist: referer whitelist
  1014. :type whitelist: list
  1015. :param allowempty: allow empty referer?
  1016. :type allowempty: bool
  1017. :param config: None
  1018. :type config: baidubce.BceClientConfiguration
  1019. :return:
  1020. :rtype: baidubce.bce_response.BceResponse
  1021. """
  1022. acl = {}
  1023. acl['allowEmpty'] = allowEmpty
  1024. if blackList is not None:
  1025. acl['blackList'] = blackList
  1026. if whiteList is not None:
  1027. acl['whiteList'] = whiteList
  1028. return self._send_request(
  1029. http_methods.PUT, '/domain/' + domain + '/config',
  1030. params={'refererACL': ''},
  1031. body=json.dumps({'refererACL': acl}),
  1032. config=config)
  1033. @required(domain=str)
  1034. def set_domain_ip_acl(self, domain, blackList=None, whiteList=None, config=None):
  1035. """
  1036. set request ip access control
  1037. :param domain: the domain name
  1038. :type domain: string
  1039. :param blackList: ip blackList
  1040. :type blackList: list
  1041. :param whitelist: ip whitelist
  1042. :type whitelist: list
  1043. :param config: None
  1044. :type config: baidubce.BceClientConfiguration
  1045. :return:
  1046. :rtype: baidubce.bce_response.BceResponse
  1047. """
  1048. acl = {}
  1049. if blackList is not None:
  1050. acl['blackList'] = blackList
  1051. if whiteList is not None:
  1052. acl['whiteList'] = whiteList
  1053. return self._send_request(
  1054. http_methods.PUT, '/domain/' + domain + '/config',
  1055. params={'ipACL': ''},
  1056. body=json.dumps({'ipACL': acl}),
  1057. config=config)
  1058. @required(domain=str, https=dict)
  1059. def set_domain_https(self, domain, https, config=None):
  1060. """
  1061. set request ip access control
  1062. :param domain: the domain name
  1063. :type domain: string
  1064. :param https: https config
  1065. :type https: dict
  1066. :param config: None
  1067. :type config: baidubce.BceClientConfiguration
  1068. :return:
  1069. :rtype: baidubce.bce_response.BceResponse
  1070. """
  1071. return self._send_request(
  1072. http_methods.PUT, '/domain/' + domain + '/config',
  1073. params={'https': ''},
  1074. body=json.dumps({'https': https}),
  1075. config=config)
  1076. @required(domain=str, limitRate=int)
  1077. def set_domain_limit_rate(self, domain, limitRate, config=None):
  1078. """
  1079. set limit rate
  1080. :param domain: the domain name
  1081. :type domain: string
  1082. :param limitRate: limit rate value (Byte/s)
  1083. :type limitRate: int
  1084. :param config: None
  1085. :type config: baidubce.BceClientConfiguration
  1086. :return:
  1087. :rtype: baidubce.bce_response.BceResponse
  1088. """
  1089. return self._send_request(
  1090. http_methods.PUT, '/domain/' + domain + '/config',
  1091. params={'limitRate': ''},
  1092. body=json.dumps({'limitRate': limitRate}),
  1093. config=config)
  1094. @required(domain=str, request_auth=dict)
  1095. def set_domain_request_auth(self, domain, requestAuth, config=None):
  1096. """
  1097. set request auth
  1098. :param domain: the domain
  1099. :type domain: string
  1100. :param requestAuth: request auth config
  1101. :type requestAuth: dict
  1102. :param config: None
  1103. :type config: baidubce.BceClientConfiguration
  1104. :return:
  1105. :rtype: baidubce.bce_response.BceResponse
  1106. """
  1107. return self._send_request(
  1108. http_methods.PUT, '/domain/' + domain + '/config',
  1109. params={'requestAuth': ''},
  1110. body=json.dumps({'requestAuth': requestAuth}),
  1111. config=config)
  1112. @required(param=CdnStatsParam)
  1113. def get_domain_stats(self, param, config=None):
  1114. """
  1115. query stats of the domain or uid or tagId, eg : flow pv
  1116. :param param: the stats query param
  1117. :type param: cdn_stats_param.CdnStatsParam
  1118. :param config: None
  1119. :type config: baidubce.BceClientConfiguration
  1120. :return:
  1121. :rtype: baidubce.bce_response.BceResponse
  1122. """
  1123. return self._send_request(
  1124. http_methods.POST,
  1125. '/stat/query',
  1126. body=json.dumps(param.__dict__),
  1127. config=config)
  1128. def get_domain_pv_stat(self, domain=None,
  1129. startTime=None, endTime=None,
  1130. period=300, withRegion=None, config=None):
  1131. """
  1132. query pv and qps of the domain
  1133. :param domain: the domain name
  1134. :type domain: string
  1135. :param startTime: query start time
  1136. :type startTime: Timestamp
  1137. :param endTime: query end time
  1138. :type endTime: Timestamp
  1139. :param period: time interval of query result
  1140. :type period: int
  1141. :param withRegion: if need client region distribution
  1142. :type withRegion: any
  1143. :param config: None
  1144. :type config: baidubce.BceClientConfiguration
  1145. :return:
  1146. :rtype: baidubce.bce_response.BceResponse
  1147. """
  1148. params = {}
  1149. params['domain'] = domain
  1150. if startTime is not None:
  1151. params['startTime'] = startTime
  1152. if endTime is not None:
  1153. params['endTime'] = endTime
  1154. params['period'] = period
  1155. params['withRegion'] = withRegion
  1156. return self._send_request(
  1157. http_methods.GET, '/stat/pv',
  1158. params=params,
  1159. config=config)
  1160. def get_domain_flow_stat(self, domain=None,
  1161. startTime=None, endTime=None,
  1162. period=300, withRegion=None, config=None):
  1163. """
  1164. query bandwidth of the domain
  1165. :param domain: the domain name
  1166. :type domain: string
  1167. :param startTime: query start time
  1168. :type startTime: Timestamp
  1169. :param endTime: query end time
  1170. :type endTime: Timestamp
  1171. :param period: time interval of query result
  1172. :type period: int
  1173. :param withRegion: if need client region distribution
  1174. :type withRegion: any
  1175. :param config: None
  1176. :type config: baidubce.BceClientConfiguration
  1177. :return:
  1178. :rtype: baidubce.bce_response.BceResponse
  1179. """
  1180. params = {}
  1181. params['domain'] = domain
  1182. if startTime is not None:
  1183. params['startTime'] = startTime
  1184. if endTime is not None:
  1185. params['endTime'] = endTime
  1186. params['period'] = period
  1187. params['withRegion'] = withRegion
  1188. return self._send_request(
  1189. http_methods.GET, '/stat/flow',
  1190. params=params,
  1191. config=config)
  1192. def get_domain_src_flow_stat(self, domain=None,
  1193. startTime=None, endTime=None,
  1194. period=300, config=None):
  1195. """
  1196. query origin bandwidth of the domain
  1197. :param domain: the domain name
  1198. :type domain: string
  1199. :param startTime: query start time
  1200. :type startTime: Timestamp
  1201. :param endTime: query end time
  1202. :type endTime: Timestamp
  1203. :param period: time interval of query result
  1204. :type period: int
  1205. :param config: None
  1206. :type config: baidubce.BceClientConfiguration
  1207. :return:
  1208. :rtype: baidubce.bce_response.BceResponse
  1209. """
  1210. params = {}
  1211. params['domain'] = domain
  1212. if startTime is not None:
  1213. params['startTime'] = startTime
  1214. if endTime is not None:
  1215. params['endTime'] = endTime
  1216. params['period'] = period
  1217. return self._send_request(
  1218. http_methods.GET, '/stat/srcflow',
  1219. params=params,
  1220. config=config)
  1221. def get_domain_hitrate_stat(self, domain=None,
  1222. startTime=None, endTime=None,
  1223. period=300, config=None):
  1224. """
  1225. query hit rate of the domain
  1226. :param domain: the domain name
  1227. :type domain: string
  1228. :param startTime: query start time
  1229. :type startTime: Timestamp
  1230. :param endTime: query end time
  1231. :type endTime: Timestamp
  1232. :param period: time interval of query result
  1233. :type period: int
  1234. :param config: None
  1235. :type config: baidubce.BceClientConfiguration
  1236. :return:
  1237. :rtype: baidubce.bce_response.BceResponse
  1238. """
  1239. params = {}
  1240. params['domain'] = domain
  1241. if startTime is not None:
  1242. params['startTime'] = startTime
  1243. if endTime is not None:
  1244. params['endTime'] = endTime
  1245. params['period'] = period
  1246. return self._send_request(
  1247. http_methods.GET, '/stat/hitrate',
  1248. params=params,
  1249. config=config)
  1250. def get_domain_httpcode_stat(self, domain=None,
  1251. startTime=None, endTime=None,
  1252. period=300, withRegion=None, config=None):
  1253. """
  1254. query http response code of a domain or all domains of the user
  1255. :param domain: the domain name
  1256. :type domain: string
  1257. :param startTime: query start time
  1258. :type startTime: Timestamp
  1259. :param endTime: query end time
  1260. :type endTime: Timestamp
  1261. :param period: time interval of query result
  1262. :type period: int
  1263. :param withRegion: if need client region distribution
  1264. :type withRegion: any
  1265. :param config: None
  1266. :type config: baidubce.BceClientConfiguration
  1267. :return:
  1268. :rtype: baidubce.bce_response.BceResponse
  1269. """
  1270. params = {}
  1271. params['domain'] = domain
  1272. if startTime is not None:
  1273. params['startTime'] = startTime
  1274. if endTime is not None:
  1275. params['endTime'] = endTime
  1276. params['period'] = period
  1277. params['withRegion'] = withRegion
  1278. return self._send_request(
  1279. http_methods.GET, '/stat/httpcode',
  1280. params=params,
  1281. config=config)
  1282. def get_domain_topn_url_stat(self, domain=None,
  1283. startTime=None, endTime=None,
  1284. period=300, config=None):
  1285. """
  1286. query top n url of the domain or all domains of the user
  1287. :param domain: the domain name
  1288. :type domain: string
  1289. :param startTime: query start time
  1290. :type startTime: Timestamp
  1291. :param endTime: query end time
  1292. :type endTime: Timestamp
  1293. :param period: time interval of query result
  1294. :type period: int
  1295. :param config: None
  1296. :type config: baidubce.BceClientConfiguration
  1297. :return:
  1298. :rtype: baidubce.bce_response.BceResponse
  1299. """
  1300. params = {}
  1301. params['domain'] = domain
  1302. if startTime is not None:
  1303. params['startTime'] = startTime
  1304. if endTime is not None:
  1305. params['endTime'] = endTime
  1306. params['period'] = period
  1307. return self._send_request(
  1308. http_methods.GET, '/stat/topn/url',
  1309. params=params,
  1310. config=config)
  1311. def get_domain_topn_referer_stat(self, domain=None,
  1312. startTime=None, endTime=None,
  1313. period=300, config=None):
  1314. """
  1315. query top n referer of the domain or all domains of the user
  1316. :param domain: the domain name
  1317. :type domain: string
  1318. :param startTime: query start time
  1319. :type startTime: Timestamp
  1320. :param endTime: query end time
  1321. :type endTime: Timestamp
  1322. :param period: time interval of query result
  1323. :type period: int
  1324. :param config: None
  1325. :type config: baidubce.BceClientConfiguration
  1326. :return:
  1327. :rtype: baidubce.bce_response.BceResponse
  1328. """
  1329. params = {}
  1330. params['domain'] = domain
  1331. if startTime is not None:
  1332. params['startTime'] = startTime
  1333. if endTime is not None:
  1334. params['endTime'] = endTime
  1335. params['period'] = period
  1336. return self._send_request(
  1337. http_methods.GET, '/stat/topn/referer',
  1338. params=params,
  1339. config=config)
  1340. def get_domain_uv_stat(self, domain=None,
  1341. startTime=None, endTime=None,
  1342. period=3600, config=None):
  1343. """
  1344. query the total number of client of a domain or all domains of the user
  1345. :param domain: the domain name
  1346. :type domain: string
  1347. :param startTime: query start time
  1348. :type startTime: Timestamp
  1349. :param endTime: query end time
  1350. :type endTime: Timestamp
  1351. :param period: time interval of query result
  1352. :type period: int
  1353. :param config: None
  1354. :type config: baidubce.BceClientConfiguration
  1355. :return:
  1356. :rtype: baidubce.bce_response.BceResponse
  1357. """
  1358. params = {}
  1359. params['domain'] = domain
  1360. if startTime is not None:
  1361. params['startTime'] = startTime
  1362. if endTime is not None:
  1363. params['endTime'] = endTime
  1364. params['period'] = period
  1365. return self._send_request(
  1366. http_methods.GET, '/stat/uv',
  1367. params=params,
  1368. config=config)
  1369. def get_domain_avg_speed_stat(self, domain=None,
  1370. startTime=None, endTime=None,
  1371. period=300, config=None):
  1372. """
  1373. query average of the domain or all domains of the user
  1374. :param domain: the domain name
  1375. :type domain: string
  1376. :param startTime: query start time
  1377. :type startTime: Timestamp
  1378. :param endTime: query end time
  1379. :type endTime: Timestamp
  1380. :param period: time interval of query result
  1381. :type period: int
  1382. :param config: None
  1383. :type config: baidubce.BceClientConfiguration
  1384. :return:
  1385. :rtype: baidubce.bce_response.BceResponse
  1386. """
  1387. params = {}
  1388. params['domain'] = domain
  1389. if startTime is not None:
  1390. params['startTime'] = startTime
  1391. if endTime is not None:
  1392. params['endTime'] = endTime
  1393. params['period'] = period
  1394. return self._send_request(
  1395. http_methods.GET, '/stat/avgspeed',
  1396. params=params,
  1397. config=config)
  1398. @required(tasks=list)
  1399. def purge(self, tasks, config=None):
  1400. """
  1401. purge the cache of specified url or directory
  1402. :param tasks: url or directory list to purge
  1403. :type tasks: list
  1404. :param config: None
  1405. :type config: baidubce.BceClientConfiguration
  1406. :return:
  1407. :rtype: baidubce.bce_response.BceResponse
  1408. """
  1409. body = {}
  1410. body['tasks'] = tasks
  1411. return self._send_request(
  1412. http_methods.POST, '/cache/purge',
  1413. config=config, body=json.dumps(body))
  1414. def list_purge_tasks(self, id=None, url=None,
  1415. startTime=None, endTime=None,
  1416. marker=None, config=None):
  1417. """
  1418. query the status of purge tasks
  1419. :param id: purge task id to query
  1420. :type id: string
  1421. :param url: purge url to query
  1422. :type url: string
  1423. :param startTime: query start time
  1424. :type startTime: Timestamp
  1425. :param endTime: query end time
  1426. :type endTime: Timestamp
  1427. :param marker: 'nextMarker' get from last query
  1428. :type marker: int
  1429. :param config: None
  1430. :type config: baidubce.BceClientConfiguration
  1431. :return:
  1432. :rtype: baidubce.bce_response.BceResponse
  1433. """
  1434. params = {}
  1435. params['id'] = id
  1436. params['url'] = url
  1437. if startTime is not None:
  1438. params['startTime'] = startTime
  1439. if endTime is not None:
  1440. params['endTime'] = endTime
  1441. params['marker'] = marker
  1442. return self._send_request(
  1443. http_methods.GET, '/cache/purge',
  1444. params=params,
  1445. config=config)
  1446. @required(tasks=list)
  1447. def prefetch(self, tasks, config=None):
  1448. """
  1449. prefetch the source of specified url from origin
  1450. :param tasks: url or directory list need prefetch
  1451. :type tasks: list
  1452. :param config: None
  1453. :type config: baidubce.BceClientConfiguration
  1454. :return:
  1455. :rtype: baidubce.bce_response.BceResponse
  1456. """
  1457. body = {}
  1458. body['tasks'] = tasks
  1459. return self._send_request(
  1460. http_methods.POST,
  1461. '/cache/prefetch',
  1462. config=config, body=json.dumps(body))
  1463. def list_prefetch_tasks(self, id=None, url=None,
  1464. startTime=None, endTime=None,
  1465. marker=None, config=None):
  1466. """
  1467. query the status of prefetch tasks
  1468. :param id: prefetch task id to query
  1469. :type id: string
  1470. :param url: prefetch url to query
  1471. :type url: string
  1472. :param startTime: query start time
  1473. :type startTime: Timestamp
  1474. :param endTime: query end time
  1475. :type endTime: Timestamp
  1476. :param marker: 'nextMarker' get from last query
  1477. :type marker: int
  1478. :param config: None
  1479. :type config: baidubce.BceClientConfiguration
  1480. :return:
  1481. :rtype: baidubce.bce_response.BceResponse
  1482. """
  1483. params = {}
  1484. params['id'] = id
  1485. params['url'] = url
  1486. if startTime is not None:
  1487. params['startTime'] = startTime
  1488. if endTime is not None:
  1489. params['endTime'] = endTime
  1490. params['marker'] = marker
  1491. return self._send_request(
  1492. http_methods.GET, '/cache/prefetch',
  1493. params=params,
  1494. config=config)
  1495. def list_quota(self, config=None):
  1496. """
  1497. query purge quota of the user
  1498. :param config: None
  1499. :type config: baidubce.BceClientConfiguration
  1500. :return:
  1501. :rtype: baidubce.bce_response.BceResponse
  1502. """
  1503. return self._send_request(http_methods.GET,
  1504. '/cache/quota',
  1505. config=config)
  1506. def get_domain_log(self, domain, startTime, endTime, config=None):
  1507. """
  1508. get log of the domain in specified period of time
  1509. :param domain: the domain name
  1510. :type domain: string
  1511. :param startTime: query start time
  1512. :type startTime: Timestamp
  1513. :param endTime: query end time
  1514. :type endTime: Timestamp
  1515. :param config: None
  1516. :type config: baidubce.BceClientConfiguration
  1517. :return:
  1518. :rtype: baidubce.bce_response.BceResponse
  1519. """
  1520. params = {}
  1521. if startTime is not None:
  1522. params['startTime'] = startTime
  1523. if endTime is not None:
  1524. params['endTime'] = endTime
  1525. return self._send_request(
  1526. http_methods.GET,
  1527. '/log/' + domain + '/log',
  1528. params=params,
  1529. config=config)
  1530. def ip_query(self, action, ip, config=None):
  1531. """
  1532. check specified ip whether belongs to Baidu CDN
  1533. :param action: 'describeIp'
  1534. :type action: string
  1535. :param ip: specified ip
  1536. :type ip: string
  1537. """
  1538. params = {}
  1539. params['action'] = action
  1540. params['ip'] = ip
  1541. if params is None:
  1542. params = {}
  1543. return self._send_request(
  1544. http_methods.GET, '/utils',
  1545. params=params,
  1546. config=config)
  1547. def list_nodes(self, config=None):
  1548. """
  1549. Baidu back source IP address segment query
  1550. :return:
  1551. :rtype: baidubce.bce_response.BceResponse
  1552. """
  1553. return self._send_request(
  1554. http_methods.GET, '/nodes/list',
  1555. params={},
  1556. config=config)
  1557. @required(domain=str)
  1558. def set_seo(self, domain, push_record=False, directory_origin=False, config=None):
  1559. """
  1560. set seo
  1561. :param domain: the domain name
  1562. :type domain: string
  1563. :param push_record: push record to baidu or not
  1564. :type param: boolean
  1565. :param directory_origin: directory access origin or not
  1566. :param config: None
  1567. :type config: baidubce.BceClientConfiguration
  1568. :return:
  1569. :rtype: baidubce.bce_response.BceResponse
  1570. """
  1571. body = dict()
  1572. body['pushRecord'] = "ON" if push_record else "OFF"
  1573. body['diretlyOrigin'] = "ON" if directory_origin else "OFF"
  1574. return self._send_request(
  1575. http_methods.PUT,
  1576. '/domain/' + domain + '/config',
  1577. params={'seoSwitch': ''},
  1578. body=json.dumps({'seoSwitch': body}),
  1579. config=config)
  1580. @required(domain=str)
  1581. def get_seo(self, domain, config=None):
  1582. """
  1583. get seo configuration.
  1584. :param domain: the domain name
  1585. :type domain: string
  1586. :return:
  1587. :rtype: baidubce.bce_response.BceResponse
  1588. """
  1589. return self._send_request(
  1590. http_methods.GET,
  1591. '/domain/' + domain + '/config',
  1592. params={'seoSwitch': ''},
  1593. config=config)
  1594. @required(domain=str)
  1595. def set_follow_protocol(self, domain, follow, config=None):
  1596. """
  1597. set follow protocol.
  1598. :param domain: the domain name
  1599. :type domain: string
  1600. :param follow: follow protocol or not
  1601. :type follow: boolean
  1602. :return:
  1603. :rtype: baidubce.bce_response.BceResponse
  1604. """
  1605. return self._send_request(
  1606. http_methods.PUT,
  1607. '/domain/' + domain + '/config',
  1608. params={'followProtocol': ''},
  1609. body=json.dumps({'followProtocol': follow}),
  1610. config=config)
  1611. @staticmethod
  1612. def _merge_config(self, config):
  1613. if config is None:
  1614. return self.config
  1615. else:
  1616. new_config = copy.copy(self.config)
  1617. new_config.merge_non_none_values(config)
  1618. return new_config
  1619. def _send_request(
  1620. self, http_method, path,
  1621. body=None, headers=None, params=None,
  1622. config=None,
  1623. body_parser=None):
  1624. config = self._merge_config(self, config)
  1625. if body_parser is None:
  1626. body_parser = handler.parse_json
  1627. return bce_http_client.send_request(
  1628. config, bce_v1_signer.sign, [handler.parse_error, body_parser],
  1629. http_method, utils.append_uri(CdnClient.prefix, path), body, headers, params)