5252class Info :
5353 def __init__ (
5454 self ,
55- api_v2_version : str ,
55+ api_v2_url : str ,
56+ api_v3_url : str ,
5657 authorization_endpoint : str ,
5758 api_endpoint : str ,
5859 doppler_endpoint : Optional [str ],
5960 log_stream_endpoint : Optional [str ],
6061 ):
61- self .api_v2_version = api_v2_version
62+ self ._api_v2_url = api_v2_url
63+ self ._api_v3_url = api_v3_url
6264 self .authorization_endpoint = authorization_endpoint
6365 self .api_endpoint = api_endpoint
6466 self .doppler_endpoint = doppler_endpoint
6567 self .log_stream_endpoint = log_stream_endpoint
6668
69+ @property
70+ def api_v2_url (self ) -> Optional [str ]:
71+ return self ._api_v2_url
72+
73+ @property
74+ def api_v3_url (self ) -> Optional [str ]:
75+ return self ._api_v3_url
6776
6877class NetworkingV1External (object ):
6978 def __init__ (self , target_endpoint : str , credential_manager : "CloudFoundryClient" ):
@@ -83,18 +92,18 @@ def __init__(self, target_endpoint: str, credential_manager: "CloudFoundryClient
8392 self .service_plans = ServicePlanManagerV2 (target_endpoint , credential_manager )
8493 # Default implementations
8594 self .event = EventManager (target_endpoint , credential_manager )
86- self .organizations = EntityManagerV2 (target_endpoint , credential_manager , "/v2/ organizations" )
87- self .private_domains = EntityManagerV2 (target_endpoint , credential_manager , "/v2/ private_domains" )
95+ self .organizations = EntityManagerV2 (target_endpoint , credential_manager , "/organizations" )
96+ self .private_domains = EntityManagerV2 (target_endpoint , credential_manager , "/private_domains" )
8897 self .routes = RouteManager (target_endpoint , credential_manager )
89- self .services = EntityManagerV2 (target_endpoint , credential_manager , "/v2/ services" )
90- self .shared_domains = EntityManagerV2 (target_endpoint , credential_manager , "/v2/ shared_domains" )
98+ self .services = EntityManagerV2 (target_endpoint , credential_manager , "/services" )
99+ self .shared_domains = EntityManagerV2 (target_endpoint , credential_manager , "/shared_domains" )
91100 self .spaces = SpaceManagerV2 (target_endpoint , credential_manager )
92- self .stacks = EntityManagerV2 (target_endpoint , credential_manager , "/v2/ stacks" )
101+ self .stacks = EntityManagerV2 (target_endpoint , credential_manager , "/stacks" )
93102 self .user_provided_service_instances = EntityManagerV2 (
94- target_endpoint , credential_manager , "/v2/ user_provided_service_instances"
103+ target_endpoint , credential_manager , "/user_provided_service_instances"
95104 )
96- self .security_groups = EntityManagerV2 (target_endpoint , credential_manager , "/v2/ security_groups" )
97- self .users = EntityManagerV2 (target_endpoint , credential_manager , "/v2/ users" )
105+ self .security_groups = EntityManagerV2 (target_endpoint , credential_manager , "/security_groups" )
106+ self .users = EntityManagerV2 (target_endpoint , credential_manager , "/users" )
98107 # Resources implementation used by push operation
99108 self .resources = ResourceManager (target_endpoint , credential_manager )
100109
@@ -146,8 +155,6 @@ def __init__(self, target_endpoint: str, client_id: str = "cf", client_secret: s
146155 self .login_hint = kwargs .get ("login_hint" )
147156 target_endpoint_trimmed = target_endpoint .rstrip ("/" )
148157 info = self ._get_info (target_endpoint_trimmed , proxy , verify = verify )
149- if not info .api_v2_version .startswith ("2." ):
150- raise AssertionError ("Only version 2 is supported for now. Found %s" % info .api_v2_version )
151158 service_information = ServiceInformation (
152159 None , "%s/oauth/token" % info .authorization_endpoint , client_id , client_secret , [], verify
153160 )
@@ -156,8 +163,16 @@ def __init__(self, target_endpoint: str, client_id: str = "cf", client_secret: s
156163 proxies = proxy ,
157164 user_agent = kwargs .get ("user_agent" , "cf-python-client" )
158165 )
159- self .v2 = V2 (target_endpoint_trimmed , self )
160- self .v3 = V3 (target_endpoint_trimmed , self )
166+ self ._v2 = (
167+ V2 (info .api_v2_url , self )
168+ if info .api_v2_url is not None
169+ else None
170+ )
171+ self ._v3 = (
172+ V3 (info .api_v3_url , self )
173+ if info .api_v3_url is not None
174+ else None
175+ )
161176 self ._doppler = (
162177 DopplerClient (
163178 info .doppler_endpoint ,
@@ -181,6 +196,18 @@ def __init__(self, target_endpoint: str, client_id: str = "cf", client_secret: s
181196 self .networking_v1_external = NetworkingV1External (target_endpoint_trimmed , self )
182197 self .info = info
183198
199+ @property
200+ def v2 (self ) -> V2 :
201+ if self ._v2 is None :
202+ raise NotImplementedError ("No V2 endpoint for this instance" )
203+ return self ._v2
204+
205+ @property
206+ def v3 (self ) -> V3 :
207+ if self ._v3 is None :
208+ raise NotImplementedError ("No V3 endpoint for this instance" )
209+ return self ._v3
210+
184211 @property
185212 def doppler (self ) -> DopplerClient :
186213 if self ._doppler is None :
@@ -194,7 +221,6 @@ def rlpgateway(self):
194221 if self ._rlpgateway is None :
195222 raise NotImplementedError ("No RLP gateway endpoint for this instance" )
196223 else :
197-
198224 return self ._rlpgateway
199225
200226 def _get_info (self , target_endpoint : str , proxy : Optional [dict ] = None , verify : bool = True ) -> Info :
@@ -206,8 +232,11 @@ def _get_info(self, target_endpoint: str, proxy: Optional[dict] = None, verify:
206232 root_links = root_info ["links" ]
207233 logging = root_links .get ("logging" )
208234 log_stream = root_links .get ("log_stream" )
235+ cloud_controller_v2 = root_links .get ("cloud_controller_v2" )
236+ cloud_controller_v3 = root_links .get ("cloud_controller_v3" )
209237 return Info (
210- root_links ["cloud_controller_v2" ]["meta" ]["version" ],
238+ cloud_controller_v2 ["href" ] if cloud_controller_v2 is not None else None ,
239+ cloud_controller_v3 ["href" ] if cloud_controller_v3 is not None else None ,
211240 self ._resolve_login_endpoint (root_links ),
212241 target_endpoint ,
213242 logging .get ("href" ) if logging is not None else None ,
0 commit comments