Skip to content

Commit f97a9ac

Browse files
committed
Update expiry threshold and field names
1 parent 96d5a31 commit f97a9ac

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

src/confluent_kafka/schema_registry/schema_registry_client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ def __init__(self, client_id: str, client_secret: str, scope: str, token_endpoin
7171
self.max_retries = max_retries
7272
self.retries_wait_ms = retries_wait_ms
7373
self.retries_max_wait_ms = retries_max_wait_ms
74+
self.token_expiry_threshold = 0.8
7475

7576
def token_expired(self):
76-
expiry_window = self.token['expires_in'] * 0.7
77+
expiry_window = self.token['expires_in'] * self.token_expiry_threshold
7778

7879
return self.token['expires_at'] < time.time() + expiry_window
7980

@@ -206,25 +207,24 @@ def __init__(self, conf: dict):
206207
self.retries_max_wait_ms = retries_max_wait_ms
207208

208209
self.oauth_client = None
209-
self.bearer_auth_credentials_source = None
210-
if 'bearer.auth.credentials.source' in conf_copy:
210+
self.bearer_auth_credentials_source = conf_copy.pop('bearer.auth.credentials.source', None)
211+
if self.bearer_auth_credentials_source is not None:
211212
self.auth = None
212-
headers = ['logical.cluster', 'identity.pool.id']
213+
headers = ['bearer.auth.logical.cluster', 'bearer.auth.identity.pool.id']
213214
missing_headers = [header for header in headers if header not in conf_copy]
214215
if missing_headers:
215216
raise ValueError("Missing required bearer configuration properties: {}"
216217
.format(", ".join(missing_headers)))
217218

218-
self.logical_cluster = conf_copy.pop('logical.cluster')
219+
self.logical_cluster = conf_copy.pop('bearer.auth.logical.cluster')
219220
if not isinstance(self.logical_cluster, str):
220221
raise TypeError("logical cluster must be a str, not " + str(type(self.logical_cluster)))
221222

222-
self.identity_pool_id = conf_copy.pop('identity.pool.id')
223+
self.identity_pool_id = conf_copy.pop('bearer.auth.identity.pool.id')
223224
if not isinstance(self.identity_pool_id, str):
224225
raise TypeError("identity pool id must be a str, not " + str(type(self.identity_pool_id)))
225226

226-
if conf_copy['bearer.auth.credentials.source'] == 'OAUTHBEARER':
227-
self.bearer_auth_credentials_source = conf_copy.pop('bearer.auth.credentials.source')
227+
if self.bearer_auth_credentials_source == 'OAUTHBEARER':
228228
properties_list = ['bearer.auth.client.id', 'bearer.auth.client.secret', 'bearer.auth.client.scope',
229229
'bearer.auth.issuer.endpoint.url']
230230
missing_properties = [prop for prop in properties_list if prop not in conf_copy]
@@ -252,7 +252,7 @@ def __init__(self, conf: dict):
252252
self.oauth_client = _OAuthClient(self.client_id, self.client_secret, self.scope, self.token_endpoint,
253253
self.max_retries, self.retries_wait_ms, self.retries_max_wait_ms)
254254

255-
elif conf_copy['bearer.auth.credentials.source'] == 'STATIC_TOKEN':
255+
elif self.bearer_auth_credentials_source == 'STATIC_TOKEN':
256256
if 'bearer.auth.token' not in conf_copy:
257257
raise ValueError("Missing bearer.auth.token")
258258
self.bearer_token = conf_copy.pop('bearer.auth.token')

tests/schema_registry/test_config.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ def test_bearer_config():
127127
def test_oauth_bearer_config_missing():
128128
conf = {'url': TEST_URL,
129129
'bearer.auth.credentials.source': "OAUTHBEARER",
130-
'logical.cluster': TEST_CLUSTER,
131-
'identity.pool.id': TEST_POOL}
130+
'bearer.auth.logical.cluster': TEST_CLUSTER,
131+
'bearer.auth.identity.pool.id': TEST_POOL}
132132

133133
with pytest.raises(ValueError, match=r"Missing required OAuth configuration properties: (.*)"):
134134
SchemaRegistryClient(conf)
@@ -137,24 +137,24 @@ def test_oauth_bearer_config_missing():
137137
def test_oauth_bearer_config_invalid():
138138
conf = {'url': TEST_URL,
139139
'bearer.auth.credentials.source': "OAUTHBEARER",
140-
'logical.cluster': TEST_CLUSTER,
141-
'identity.pool.id': 1}
140+
'bearer.auth.logical.cluster': TEST_CLUSTER,
141+
'bearer.auth.identity.pool.id': 1}
142142

143143
with pytest.raises(TypeError, match=r"identity pool id must be a str, not (.*)"):
144144
SchemaRegistryClient(conf)
145145

146146
conf = {'url': TEST_URL,
147147
'bearer.auth.credentials.source': "OAUTHBEARER",
148-
'logical.cluster': 1,
149-
'identity.pool.id': TEST_POOL}
148+
'bearer.auth.logical.cluster': 1,
149+
'bearer.auth.identity.pool.id': TEST_POOL}
150150

151151
with pytest.raises(TypeError, match=r"logical cluster must be a str, not (.*)"):
152152
SchemaRegistryClient(conf)
153153

154154
conf = {'url': TEST_URL,
155155
'bearer.auth.credentials.source': "OAUTHBEARER",
156-
'logical.cluster': TEST_CLUSTER,
157-
'identity.pool.id': TEST_POOL,
156+
'bearer.auth.logical.cluster': TEST_CLUSTER,
157+
'bearer.auth.identity.pool.id': TEST_POOL,
158158
'bearer.auth.client.id': 1,
159159
'bearer.auth.client.secret': TEST_USER_PASSWORD,
160160
'bearer.auth.client.scope': TEST_SCOPE,
@@ -165,8 +165,8 @@ def test_oauth_bearer_config_invalid():
165165

166166
conf = {'url': TEST_URL,
167167
'bearer.auth.credentials.source': "OAUTHBEARER",
168-
'logical.cluster': TEST_CLUSTER,
169-
'identity.pool.id': TEST_POOL,
168+
'bearer.auth.logical.cluster': TEST_CLUSTER,
169+
'bearer.auth.identity.pool.id': TEST_POOL,
170170
'bearer.auth.client.id': TEST_USERNAME,
171171
'bearer.auth.client.secret': 1,
172172
'bearer.auth.client.scope': TEST_SCOPE,
@@ -177,8 +177,8 @@ def test_oauth_bearer_config_invalid():
177177

178178
conf = {'url': TEST_URL,
179179
'bearer.auth.credentials.source': "OAUTHBEARER",
180-
'logical.cluster': TEST_CLUSTER,
181-
'identity.pool.id': TEST_POOL,
180+
'bearer.auth.logical.cluster': TEST_CLUSTER,
181+
'bearer.auth.identity.pool.id': TEST_POOL,
182182
'bearer.auth.client.id': TEST_USERNAME,
183183
'bearer.auth.client.secret': TEST_USER_PASSWORD,
184184
'bearer.auth.client.scope': 1,
@@ -189,8 +189,8 @@ def test_oauth_bearer_config_invalid():
189189

190190
conf = {'url': TEST_URL,
191191
'bearer.auth.credentials.source': "OAUTHBEARER",
192-
'logical.cluster': TEST_CLUSTER,
193-
'identity.pool.id': TEST_POOL,
192+
'bearer.auth.logical.cluster': TEST_CLUSTER,
193+
'bearer.auth.identity.pool.id': TEST_POOL,
194194
'bearer.auth.client.id': TEST_USERNAME,
195195
'bearer.auth.client.secret': TEST_USER_PASSWORD,
196196
'bearer.auth.client.scope': TEST_SCOPE,
@@ -203,8 +203,8 @@ def test_oauth_bearer_config_invalid():
203203
def test_oauth_bearer_config_valid():
204204
conf = {'url': TEST_URL,
205205
'bearer.auth.credentials.source': "OAUTHBEARER",
206-
'logical.cluster': TEST_CLUSTER,
207-
'identity.pool.id': TEST_POOL,
206+
'bearer.auth.logical.cluster': TEST_CLUSTER,
207+
'bearer.auth.identity.pool.id': TEST_POOL,
208208
'bearer.auth.client.id': TEST_USERNAME,
209209
'bearer.auth.client.secret': TEST_USER_PASSWORD,
210210
'bearer.auth.client.scope': TEST_SCOPE,
@@ -223,8 +223,8 @@ def test_oauth_bearer_config_valid():
223223
def test_static_bearer_config():
224224
conf = {'url': TEST_URL,
225225
'bearer.auth.credentials.source': 'STATIC_TOKEN',
226-
'logical.cluster': 'lsrc',
227-
'identity.pool.id': 'pool_id'}
226+
'bearer.auth.logical.cluster': 'lsrc',
227+
'bearer.auth.identity.pool.id': 'pool_id'}
228228

229229
with pytest.raises(ValueError, match='Missing bearer.auth.token'):
230230
SchemaRegistryClient(conf)

0 commit comments

Comments
 (0)