Commit 6d80301081aac1509650ca2a778ae23d8a9f1047
1 parent
a64868f0
Exists in
master
and in
4 other branches
Connection without credentials configuration
Showing
3 changed files
with
16 additions
and
17 deletions
Show diff stats
core/PikaManager.py
@@ -18,19 +18,7 @@ import json | @@ -18,19 +18,7 @@ import json | ||
18 | 18 | ||
19 | class PikaManager: | 19 | class PikaManager: |
20 | 20 | ||
21 | - def __init__(self, ip): | ||
22 | - """ | ||
23 | - Initialize the class without credentials. | ||
24 | - | ||
25 | - Parameters | ||
26 | - ---------- | ||
27 | - ip : string | ||
28 | - The server IP. | ||
29 | - """ | ||
30 | - self.server_ip = ip | ||
31 | - self.MAX_ERR_ATTEMPT = 3 | ||
32 | - | ||
33 | - def __init__(self, ip, username, password): | 21 | + def __init__(self, ip, username=None, password=None): |
34 | """ | 22 | """ |
35 | Initialize the class with credentials. | 23 | Initialize the class with credentials. |
36 | 24 | ||
@@ -45,8 +33,12 @@ class PikaManager: | @@ -45,8 +33,12 @@ class PikaManager: | ||
45 | """ | 33 | """ |
46 | self.server_ip = ip | 34 | self.server_ip = ip |
47 | self.MAX_ERR_ATTEMPT = 3 | 35 | self.MAX_ERR_ATTEMPT = 3 |
48 | - self.add_credentials(username, password) | ||
49 | - self.add_blockConnection() | 36 | + |
37 | + if not all((username, password)): | ||
38 | + self.add_localBlockConnection() | ||
39 | + else: | ||
40 | + self.add_credentials(username, password) | ||
41 | + self.add_blockConnection() | ||
50 | 42 | ||
51 | def add_credentials(self, username, password): | 43 | def add_credentials(self, username, password): |
52 | """ | 44 | """ |
@@ -61,6 +53,13 @@ class PikaManager: | @@ -61,6 +53,13 @@ class PikaManager: | ||
61 | """ | 53 | """ |
62 | self.credentials = pika.PlainCredentials(username, password) | 54 | self.credentials = pika.PlainCredentials(username, password) |
63 | 55 | ||
56 | + def add_localBlockConnection(self): | ||
57 | + """ | ||
58 | + Create the blocking connection object. | ||
59 | + """ | ||
60 | + self.conn_send = pika.BlockingConnection(pika.ConnectionParameters(host = self.server_ip, heartbeat_interval = 0)) | ||
61 | + self.conn_receive = pika.BlockingConnection(pika.ConnectionParameters(host = self.server_ip, heartbeat_interval = 0)) | ||
62 | + | ||
64 | def add_blockConnection(self): | 63 | def add_blockConnection(self): |
65 | """ | 64 | """ |
66 | Create the blocking connection object. Credentials are used. | 65 | Create the blocking connection object. Credentials are used. |
core/logger.py
@@ -23,7 +23,7 @@ from time import sleep | @@ -23,7 +23,7 @@ from time import sleep | ||
23 | SERVER_URL = sys.argv[1] | 23 | SERVER_URL = sys.argv[1] |
24 | 24 | ||
25 | # Manager of queues connections. | 25 | # Manager of queues connections. |
26 | -manager = PikaManager.PikaManager("150.165.205.10", "test", "test") | 26 | +manager = PikaManager.PikaManager("localhost") |
27 | 27 | ||
28 | # Logging configuration. | 28 | # Logging configuration. |
29 | logger = logging.getLogger('text_container') | 29 | logger = logging.getLogger('text_container') |
core/translator.py
@@ -20,7 +20,7 @@ from PortGlosa import traduzir | @@ -20,7 +20,7 @@ from PortGlosa import traduzir | ||
20 | from time import sleep | 20 | from time import sleep |
21 | 21 | ||
22 | # Manager of queues connections. | 22 | # Manager of queues connections. |
23 | -manager = PikaManager.PikaManager("localhost", "test", "test") | 23 | +manager = PikaManager.PikaManager("localhost") |
24 | 24 | ||
25 | def run(ch, method, properties, body): | 25 | def run(ch, method, properties, body): |
26 | """ | 26 | """ |