@@ -22,6 +22,13 @@ class AuthenticationError(Exception):
2222 def __init__ (self , user ):
2323 super ().__init__ (f"failed to authenticate as user: { user } " )
2424
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+
2532
2633class Auth (httpx .Auth ):
2734 """
@@ -128,13 +135,17 @@ class Client(rest.AsyncClient):
128135 Client for OpenStack APIs.
129136 """
130137 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
132139 url = urllib .parse .urlsplit (base_url )
133140 # Initialise the client with the scheme/host
134141 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.
136144 # 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
138149
139150 def __aenter__ (self ):
140151 # Prevent individual clients from being used in a context manager
0 commit comments