Skip to content
This repository was archived by the owner on Nov 13, 2023. It is now read-only.

Commit 1a095a1

Browse files
committed
AKSK认证时候支持客户自定义auth url
1 parent c11c18b commit 1a095a1

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 1.1
22
Name: huaweicloud-sdk-python
3-
Version: 1.0.20
3+
Version: 1.0.21
44
Summary: An SDK for building applications to work with OpenStack
55
Home-page: https://github.com/huaweicloud/huaweicloud-sdk-python
66
Author: huawei

openstack/aksksession.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
from openstack.exceptions import EndpointNotFound, SDKException
2727
from openstack.session import DEFAULT_USER_AGENT
2828
from openstack import session as osession
29-
from keystoneauth1 import _utils as utils
29+
from keystoneauth1 import _utils as log_utils
30+
from openstack import utils
3031
from openstack.session import map_exceptions
3132
from openstack.service_endpoint import endpoint as _endpoint
3233
from keystoneauth1 import exceptions
@@ -38,9 +39,10 @@
3839
ALGORITHM = "SDK-HMAC-SHA256"
3940
PYTHON2 = "2"
4041
UTF8 = "utf-8"
41-
IAMURL = "https://iam.%s/v3/%s"
42+
PROJECTIAMURL = "https://iam.%s.%s/v3/"
43+
GLOBALIAMURL = "https://iam.%s/v3/"
4244

43-
_logger = utils.get_logger(__name__)
45+
_logger = log_utils.get_logger(__name__)
4446

4547

4648
def construct_session(session_obj=None):
@@ -152,7 +154,7 @@ def _make_canonical_request(self, method=None, url=None, headers=None, params=No
152154
canonical_header = '\n'.join(canonical_header)
153155
canonical_header += '\n'
154156
signed_header = ';'.join([k.lower() for k in self.headtosign])
155-
body = body if body else ""
157+
body = body if body else ""
156158
request_payload = hashlib.sha256(get_utf8_bytes(body)).hexdigest()
157159
return '\n'.join(
158160
[canonical_method, canonical_uri, canonical_querystring, canonical_header, signed_header, request_payload])
@@ -254,6 +256,7 @@ def __init__(self, profile,
254256
**kwargs
255257
):
256258
self.project_id = kwargs.get("project_id")
259+
self.auth_url = kwargs.get('auth_url', None)
257260
self.domain_id = kwargs.get("domain_id", None)
258261
self.domain = kwargs.get("domain")
259262
self.region = kwargs.get("region")
@@ -491,10 +494,14 @@ def _get_endpoint_from_configdata(self, service_type, interface):
491494

492495
def __fetch_all_endpoint_service_project_level(self):
493496
kvendpoints = {}
494-
resp = self.request(IAMURL % (self.domain, "endpoints"), "GET",
497+
if self.auth_url:
498+
auth_url = self.auth_url
499+
else:
500+
auth_url = PROJECTIAMURL % (self.region, self.domain)
501+
resp = self.request(utils.urljoin(auth_url, "endpoints"), "GET",
495502
endpoint_filter=identity_service.AdminService())
496503
endpoints = resp.json().get("endpoints", [])
497-
resp = self.request(IAMURL % (self.domain, "services"), "GET",
504+
resp = self.request(utils.urljoin(auth_url, "services"), "GET",
498505
endpoint_filter=identity_service.AdminService())
499506
services = resp.json().get("services", [])
500507
id_endpoint_map, servicetype_id_map = {}, {}
@@ -520,10 +527,14 @@ def __fetch_all_endpoint_service_project_level(self):
520527

521528
def __fetch_all_endpoint_service_global_level(self):
522529
kvendpoints = {}
523-
resp = self.request(IAMURL % (self.domain, "endpoints"), "GET",
530+
if self.auth_url:
531+
auth_url = self.auth_url
532+
else:
533+
auth_url = GLOBALIAMURL % self.domain
534+
resp = self.request(utils.urljoin(auth_url, "endpoints"), "GET",
524535
endpoint_filter=identity_service.AdminService())
525536
endpoints = resp.json().get("endpoints", [])
526-
resp = self.request(IAMURL % (self.domain, "services"), "GET",
537+
resp = self.request(utils.urljoin(auth_url, "services"), "GET",
527538
endpoint_filter=identity_service.AdminService())
528539
services = resp.json().get("services", [])
529540
id_endpoint_map, servicetype_id_map = {}, {}

openstack/connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ def __init__(self, session=None, authenticator=None, profile=None,
267267
region=auth_args.get("region", None),
268268
domain=auth_args.get('domain', None),
269269
securitytoken=auth_args.get("securitytoken", None),
270+
auth_url=auth_args.get('auth_url', None),
270271
domain_id=auth_args.get("domain_id", None)
271272
)
272273
elif auth_args.get('auth_token', None):

0 commit comments

Comments
 (0)