From 7ebc5cd4ce031395e9dd88211d7b7c7c7c9b717e Mon Sep 17 00:00:00 2001 From: Abhisek Padhi Date: Mon, 25 Mar 2019 17:37:29 +0530 Subject: [PATCH 1/3] Added token to params while creating sessions. --- consul/base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/consul/base.py b/consul/base.py index ee6ab254..42803c33 100755 --- a/consul/base.py +++ b/consul/base.py @@ -1769,6 +1769,9 @@ def create( if ttl: assert 10 <= ttl <= 86400 data['ttl'] = '%ss' % ttl + token = self.agent.token + if token: + params.append(('token', token)) if data: data = json.dumps(data) else: From 500946b57ceb9fd0d231593bb6d3e038b7ab30ee Mon Sep 17 00:00:00 2001 From: Abhisek Padhi Date: Mon, 25 Mar 2019 18:29:18 +0530 Subject: [PATCH 2/3] Added token for all consul.Session endpoints. --- consul/base.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/consul/base.py b/consul/base.py index 42803c33..527a8f8c 100755 --- a/consul/base.py +++ b/consul/base.py @@ -1793,6 +1793,9 @@ def destroy(self, session_id, dc=None): dc = dc or self.agent.dc if dc: params.append(('dc', dc)) + token = self.agent.token + if token: + params.append(('token', token)) return self.agent.http.put( CB.bool(), '/v1/session/destroy/%s' % session_id, @@ -1841,6 +1844,9 @@ def list(self, index=None, wait=None, consistency=None, dc=None): consistency = consistency or self.agent.consistency if consistency in ('consistent', 'stale'): params.append((consistency, '1')) + token = self.agent.token + if token: + params.append(('token', token)) return self.agent.http.get( CB.json(index=True), '/v1/session/list', params=params) @@ -1871,6 +1877,9 @@ def node(self, node, index=None, wait=None, consistency=None, dc=None): consistency = consistency or self.agent.consistency if consistency in ('consistent', 'stale'): params.append((consistency, '1')) + token = self.agent.token + if token: + params.append(('token', token)) return self.agent.http.get( CB.json(index=True), '/v1/session/node/%s' % node, params=params) @@ -1908,6 +1917,9 @@ def info(self, consistency = consistency or self.agent.consistency if consistency in ('consistent', 'stale'): params.append((consistency, '1')) + token = self.agent.token + if token: + params.append(('token', token)) return self.agent.http.get( CB.json(index=True, one=True), '/v1/session/info/%s' % session_id, @@ -1927,6 +1939,9 @@ def renew(self, session_id, dc=None): dc = dc or self.agent.dc if dc: params.append(('dc', dc)) + token = self.agent.token + if token: + params.append(('token', token)) return self.agent.http.put( CB.json(one=True, allow_404=False), '/v1/session/renew/%s' % session_id, @@ -2437,3 +2452,4 @@ def raft_config(self): """ return self.agent.http.get( CB.json(), '/v1/operator/raft/configuration') + From b86a75265129294037b01b016aa4bdaf525bf690 Mon Sep 17 00:00:00 2001 From: Abhisek Padhi Date: Mon, 25 Mar 2019 23:52:31 +0530 Subject: [PATCH 3/3] Added token for txn --- consul/base.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/consul/base.py b/consul/base.py index 527a8f8c..91e8ef08 100755 --- a/consul/base.py +++ b/consul/base.py @@ -687,8 +687,16 @@ def put(self, payload): } } """ - return self.agent.http.put(CB.json(), "/v1/txn", - data=json.dumps(payload)) + params = [] + token = self.agent.token + if token: + params.append(('token', tokenn)) + return self.agent.http.put( + CB.json(), + "/v1/txn", + params=params, + data=json.dumps(payload) + ) class Agent(object): """