Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jun 27, 2022
1 parent 6b3b71b commit 4a104f0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
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
28 changes: 27 additions & 1 deletion qiniu/services/cdn/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,27 @@ 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):
return self.__delete("sslcert/"+certid)

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):
"""
遍历所有域名
Expand All @@ -280,12 +301,17 @@ def domain_list(self, limit=10, marker=None):
p = dict(limit=limit)
if marker:
p['marker']=marker
return self.__get("domain", p)[0]
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'}
Expand Down

0 comments on commit 4a104f0

Please sign in to comment.