Ver código fonte

Added http auth

Added auth to the api-calls. If it is working, maybe a switch would be nice.
tags/v1.2.0
lowEagle 6 anos atrás
pai
commit
93216528c2
Nenhuma conta vinculada ao e-mail do autor do commit
1 arquivos alterados com 17 adições e 5 exclusões
  1. 17
    5
      certbot_pdns/pdnsapi.py

+ 17
- 5
certbot_pdns/pdnsapi.py Ver arquivo

@@ -4,7 +4,10 @@ import requests
4 4
 
5 5
 
6 6
 class PdnsApi:
7
+    http_auth_user = None
8
+    http_auth_pass = None
7 9
     api_key = None
10
+    api_pass = None
8 11
     base_url = None
9 12
 
10 13
     def set_api_key(self, api_key):
@@ -13,6 +16,15 @@ class PdnsApi:
13 16
     def set_base_url(self, base_url):
14 17
         self.base_url = base_url
15 18
 
19
+    def set_api_pass(self, api_pass):
20
+        self.api_pass = api_pass
21
+        
22
+    def set_http_auth_user(self, http_auth_user):
23
+        self.http_auth_user = http_auth_user
24
+        
25
+    def set_http_auth_pass(self, http_auth_pass):
26
+        self.http_auth_pass = http_auth_pass
27
+        
16 28
     def _query(self, uri, method, kwargs=None):
17 29
         headers = {
18 30
             'X-API-Key': self.api_key,
@@ -23,15 +35,15 @@ class PdnsApi:
23 35
         data = json.dumps(kwargs)
24 36
 
25 37
         if method == "GET":
26
-            request = requests.get(self.base_url + uri, headers=headers)
38
+            request = requests.get(self.base_url + uri, headers=headers, auth=(self.http_auth_user, self.http_auth_pass))
27 39
         elif method == "POST":
28
-            request = requests.post(self.base_url + uri, headers=headers, data=data)
40
+            request = requests.post(self.base_url + uri, headers=headers, auth=(self.http_auth_user, self.http_auth_pass), data=data)
29 41
         elif method == "PUT":
30
-            request = requests.put(self.base_url + uri, headers=headers, data=data)
42
+            request = requests.put(self.base_url + uri, headers=headers, auth=(self.http_auth_user, self.http_auth_pass), data=data)
31 43
         elif method == "PATCH":
32
-            request = requests.patch(self.base_url + uri, headers=headers, data=data)
44
+            request = requests.patch(self.base_url + uri, headers=headers, auth=(self.http_auth_user, self.http_auth_pass), data=data)
33 45
         elif method == "DELETE":
34
-            request = requests.delete(self.base_url + uri, headers=headers)
46
+            request = requests.delete(self.base_url + uri, headers=headers, auth=(self.http_auth_user, self.http_auth_pass))
35 47
         else:
36 48
             raise ValueError("Invalid method '%s'" % method)
37 49
 

Carregando…
Cancelar
Salvar