Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加遍历域名的接口 #317

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion qiniu/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

def __return_wrapper(resp):
if resp.status_code != 200 or resp.headers.get('X-Reqid') is None:
print(resp.text)
return None, ResponseInfo(resp)
resp.encoding = 'utf-8'
ret = resp.json(encoding='utf-8') if resp.text != '' else {}
ret = resp.json() if resp.text != '' else {}
return ret, ResponseInfo(resp)


Expand All @@ -37,6 +38,21 @@ def _init():
global _session
_session = session

def _delete(url, data, files, auth, headers=None):
if _session is None:
_init()
try:
post_headers = _headers.copy()
if headers is not None:
for k, v in headers.items():
post_headers.update({k: v})
r = _session.delete(
url, data=data, files=files, auth=auth, headers=post_headers,
timeout=config.get_default('connection_timeout'))
except Exception as e:
return None, ResponseInfo(None, e)
return __return_wrapper(r)


def _post(url, data, files, auth, headers=None):
if _session is None:
Expand Down Expand Up @@ -107,6 +123,9 @@ def _post_with_auth(url, data, auth):
def _post_with_auth_and_headers(url, data, auth, headers):
return _post(url, data, None, qiniu.auth.RequestsAuth(auth), headers)

def _delete_with_auth_and_headers(url, data, auth, headers):
return _delete(url, data, None, qiniu.auth.RequestsAuth(auth), headers)


def _put_with_auth(url, data, auth):
return _put(url, data, None, qiniu.auth.RequestsAuth(auth))
Expand Down
53 changes: 53 additions & 0 deletions qiniu/services/cdn/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,67 @@ def create_sslcert(self, name, common_name, pri, ca):
url = '{0}/sslcert'.format(self.server)
return self.__post(url, body)

def sslcert_iter(self):
marker = None
while 1:
r = self.sslcert_list(200, marker)
li = r['certs']
if li:
for i in li:
yield i
marker = r['marker']
else:
break

def sslcert_delete(self, certid):
url = '{0}/sslcert/{1}'.format(self.server, certid)
return self.__delete(url)

def sslcert_list(self, limit=10, marker=None):
p = dict(limit=limit)
if marker:
p['marker']=marker
return self.__get("sslcert", p)[0]

def domain_iter(self):
"""
遍历所有域名
"""
marker = None
while 1:
r = self.domain_list(200, marker)
li = r['domains']
if li:
for i in li:
yield i
marker = r['marker']
else:
break


def domain_list(self, limit=10, marker=None):
p = dict(limit=limit)
if marker:
p['marker']=marker
url = 'domain'
return self.__get(url, p)[0]


def __post(self, url, data=None):
headers = {'Content-Type': 'application/json'}
return http._post_with_auth_and_headers(url, data, self.auth, headers)

def __delete(self, url, data=None):
headers = {'Content-Type': 'application/json'}
return http._delete_with_auth_and_headers(url, data, self.auth, headers)

def __put(self, url, data=None):
headers = {'Content-Type': 'application/json'}
return http._put_with_auth_and_headers(url, data, self.auth, headers)

def __get(self, url, params=None):
return http._get(self.server+"/"+url, params, self.auth)


def create_timestamp_anti_leech_url(host, file_name, query_string, encrypt_key, deadline):
"""
Expand Down