Skip to content

Commit d2f8590

Browse files
committed
1) Fixed a problem where the HTTP host header was not being added in request(on-premise only)
2) Add a lock to the internal cache that caches request signature 3) Fix some document and test issues
1 parent a97c1b7 commit d2f8590

File tree

6 files changed

+12
-10
lines changed

6 files changed

+12
-10
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ _____
5555
start time if both of them are specified, throw IAE if end time is smaller
5656
than start time.
5757
* Changed min/max implementation to make them deterministic.
58+
* On-premise only. Fixed a problem where the HTTP Host header was not being
59+
adding in all request cases. This prevented use of an intermediate proxy such
60+
as Nginx, which validates headers.
5861

5962
Removed
6063
_______

examples/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def generate_authorization_provider(tenant_id):
5151
region = endpoint
5252
provider = SignatureProvider.create_with_instance_principal(
5353
region=region)
54-
elif principal == 'resource principals':
54+
elif principal == 'resource principal':
5555
provider = SignatureProvider.create_with_resource_principal()
5656
else:
5757
raise IllegalArgumentException('Must specify the principal.')

src/borneo/common.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,13 @@ class Memoize(object):
539539
def __init__(self, duration=60):
540540
self._cache = {}
541541
self._duration = duration
542+
self.lock = Lock()
542543

544+
@synchronized
543545
def set(self, key, value):
544546
self._cache[key] = {'value': value, 'time': time()}
545547

548+
@synchronized
546549
def get(self, key):
547550
if key in self._cache and not self._is_obsolete(self._cache[key]):
548551
return self._cache[key]['value']
@@ -1203,14 +1206,14 @@ class ResourcePrincipalClaimKeys(object):
12031206
"""
12041207
The claim name that the RPST holds for the resource compartment. This can be
12051208
passed to
1206-
:py:method:`borneo.iam.SignatureProvider.get_resource_principal_claim` to
1209+
:py:meth:`borneo.iam.SignatureProvider.get_resource_principal_claim` to
12071210
retrieve the resource's compartment OCID.
12081211
"""
12091212
TENANT_ID_CLAIM_KEY = 'res_tenant'
12101213
"""
12111214
The claim name that the RPST holds for the resource tenancy. This can be
12121215
passed to
1213-
:py:method:`borneo.iam.SignatureProvider.get_resource_principal_claim` to
1216+
:py:meth:`borneo.iam.SignatureProvider.get_resource_principal_claim` to
12141217
retrieve the resource's tenancy OCID.
12151218
"""
12161219

src/borneo/iam/iam.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77

88
from os import path
9-
from requests import Request, Session
9+
from requests import Request
1010
from threading import Timer
1111
try:
1212
import oci
@@ -17,7 +17,6 @@
1717
from borneo.common import CheckValue, HttpConstants, LogUtils, Memoize
1818
from borneo.config import Region, Regions
1919
from borneo.exception import IllegalArgumentException
20-
from borneo.http import RequestUtils
2120

2221

2322
class SignatureProvider(AuthorizationProvider):
@@ -209,8 +208,6 @@ def __init__(self, provider=None, config_file=None, profile_name=None,
209208
self._service_url = None
210209
self._logger = None
211210
self._logutils = LogUtils()
212-
self._sess = Session()
213-
self._request_utils = RequestUtils(self._sess, self._logutils)
214211

215212
def close(self):
216213
"""
@@ -257,7 +254,6 @@ def set_logger(self, logger):
257254
CheckValue.check_logger(logger, 'logger')
258255
self._logger = logger
259256
self._logutils = LogUtils(logger)
260-
self._request_utils = RequestUtils(self._sess, self._logutils)
261257
return self
262258

263259
def set_required_headers(self, request, auth_string, headers):

src/borneo/kv/kv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def _schedule_refresh(self):
330330
def _send_request(self, auth_header, service_name):
331331
# Send HTTPS request to login/renew/logout service location with proper
332332
# authentication information.
333-
headers = {'Authorization': auth_header}
333+
headers = {'Host': self._url.hostname, 'Authorization': auth_header}
334334
return self._request_utils.do_get_request(
335335
self._url.geturl() + self._base_path + service_name, headers,
336336
StoreAccessTokenProvider._HTTP_TIMEOUT_MS)

test/testutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def generate_authorization_provider(tenant_id):
157157
region = endpoint
158158
authorization_provider = (
159159
SignatureProvider.create_with_instance_principal(region=region))
160-
elif iam_principal() == 'resource principals':
160+
elif iam_principal() == 'resource principal':
161161
authorization_provider = (
162162
SignatureProvider.create_with_resource_principal())
163163
else:

0 commit comments

Comments
 (0)