@@ -22,6 +22,13 @@ class AuthenticationError(Exception):
22
22
def __init__ (self , user ):
23
23
super ().__init__ (f"failed to authenticate as user: { user } " )
24
24
25
+ class CatalogError (Exception ):
26
+ """
27
+ Raised when an unknown catalog service type is requested.
28
+ """
29
+ def __init__ (self , name ):
30
+ super ().__init__ (f"service type { name } not found in OpenStack service catalog" )
31
+
25
32
26
33
class Auth (httpx .Auth ):
27
34
"""
@@ -128,13 +135,17 @@ class Client(rest.AsyncClient):
128
135
Client for OpenStack APIs.
129
136
"""
130
137
def __init__ (self , / , base_url , prefix = None , ** kwargs ):
131
- # Extract the path part of the base_url
138
+ # Extract the path part of the base_url
132
139
url = urllib .parse .urlsplit (base_url )
133
140
# Initialise the client with the scheme/host
134
141
super ().__init__ (base_url = f"{ url .scheme } ://{ url .netloc } " , ** kwargs )
135
- # If another prefix is not given, use the path from the base URL as the prefix
142
+ # If another prefix is not given, use the path from the base URL as the prefix,
143
+ # otherwise combine the prefixes and remove duplicates path sections.
136
144
# This ensures things like pagination work nicely without duplicating the prefix
137
- self ._prefix = prefix or url .path
145
+ if prefix :
146
+ self ._prefix = "/" .join ([url .path .rstrip ("/" ), prefix .lstrip ("/" ).lstrip (url .path )])
147
+ else :
148
+ self ._prefix = url .path
138
149
139
150
def __aenter__ (self ):
140
151
# Prevent individual clients from being used in a context manager
0 commit comments