Skip to content

Commit 8b7b9a2

Browse files
author
DanielePalaia
committed
refresh_token
1 parent c3a35ea commit 8b7b9a2

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

rabbitmq_amqp_python_client/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class CommonValues(enum.Enum):
1818
key = "key"
1919
queue = "queues"
2020
bindings = "bindings"
21+
path_tokens = "/auth/tokens"
2122

2223

2324
class ExchangeType(enum.Enum):

rabbitmq_amqp_python_client/connection.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,8 @@ def active_producers(self) -> int:
383383
def active_consumers(self) -> int:
384384
"""Returns the number of active consumers"""
385385
return len(self._consumers)
386+
387+
def refresh_token(self, token: str) -> None:
388+
389+
management = self.management()
390+
management.refresh_token(token)

rabbitmq_amqp_python_client/management.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,14 @@ def queue_info(self, name: str) -> QueueInfo:
573573
message_count=queue_info["message_count"],
574574
consumer_count=queue_info["consumer_count"],
575575
)
576+
577+
def refresh_token(self, token: str) -> None:
578+
579+
self.request(
580+
token.encode(),
581+
CommonValues.path_tokens.value,
582+
CommonValues.command_put.value,
583+
[
584+
CommonValues.response_code_204.value,
585+
],
586+
)

tests/test_connection.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_connection_ssl(ssl_context) -> None:
4444
environment.close()
4545

4646

47-
def test_connection_auth(environment_auth: Environment) -> None:
47+
def test_connection_oauth(environment_auth: Environment) -> None:
4848

4949
connection = environment_auth.connection()
5050
connection.dial()
@@ -54,7 +54,7 @@ def test_connection_auth(environment_auth: Environment) -> None:
5454
connection.close()
5555

5656

57-
def test_connection_auth_with_timeout(environment_auth: Environment) -> None:
57+
def test_connection_oauth_with_timeout(environment_auth: Environment) -> None:
5858

5959
connection = environment_auth.connection()
6060
connection.dial()
@@ -65,10 +65,32 @@ def test_connection_auth_with_timeout(environment_auth: Environment) -> None:
6565
try:
6666
management = connection.management()
6767
management.declare_queue(QuorumQueueSpecification(name="test-queue"))
68+
management.close()
6869
except Exception:
6970
raised = True
7071

7172
assert raised is True
73+
74+
connection.close()
75+
76+
77+
def test_connection_oauth_refresh_token(environment_auth: Environment) -> None:
78+
79+
connection = environment_auth.connection()
80+
connection.dial()
81+
# let the token expire
82+
time.sleep(3)
83+
raised = False
84+
# token expired, refresh
85+
connection.refresh_token("abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGH")
86+
87+
try:
88+
management = connection.management()
89+
management.declare_queue(QuorumQueueSpecification(name="test-queue"))
90+
except Exception:
91+
raised = True
92+
93+
assert raised is False
7294
connection.close()
7395

7496

0 commit comments

Comments
 (0)