52
52
class Info :
53
53
def __init__ (
54
54
self ,
55
- api_v2_version : str ,
55
+ api_v2_url : str ,
56
+ api_v3_url : str ,
56
57
authorization_endpoint : str ,
57
58
api_endpoint : str ,
58
59
doppler_endpoint : Optional [str ],
59
60
log_stream_endpoint : Optional [str ],
60
61
):
61
- self .api_v2_version = api_v2_version
62
+ self ._api_v2_url = api_v2_url
63
+ self ._api_v3_url = api_v3_url
62
64
self .authorization_endpoint = authorization_endpoint
63
65
self .api_endpoint = api_endpoint
64
66
self .doppler_endpoint = doppler_endpoint
65
67
self .log_stream_endpoint = log_stream_endpoint
66
68
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
67
76
68
77
class NetworkingV1External (object ):
69
78
def __init__ (self , target_endpoint : str , credential_manager : "CloudFoundryClient" ):
@@ -83,18 +92,18 @@ def __init__(self, target_endpoint: str, credential_manager: "CloudFoundryClient
83
92
self .service_plans = ServicePlanManagerV2 (target_endpoint , credential_manager )
84
93
# Default implementations
85
94
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" )
88
97
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" )
91
100
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" )
93
102
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"
95
104
)
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" )
98
107
# Resources implementation used by push operation
99
108
self .resources = ResourceManager (target_endpoint , credential_manager )
100
109
@@ -146,8 +155,6 @@ def __init__(self, target_endpoint: str, client_id: str = "cf", client_secret: s
146
155
self .login_hint = kwargs .get ("login_hint" )
147
156
target_endpoint_trimmed = target_endpoint .rstrip ("/" )
148
157
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 )
151
158
service_information = ServiceInformation (
152
159
None , "%s/oauth/token" % info .authorization_endpoint , client_id , client_secret , [], verify
153
160
)
@@ -156,8 +163,16 @@ def __init__(self, target_endpoint: str, client_id: str = "cf", client_secret: s
156
163
proxies = proxy ,
157
164
user_agent = kwargs .get ("user_agent" , "cf-python-client" )
158
165
)
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
+ )
161
176
self ._doppler = (
162
177
DopplerClient (
163
178
info .doppler_endpoint ,
@@ -181,6 +196,18 @@ def __init__(self, target_endpoint: str, client_id: str = "cf", client_secret: s
181
196
self .networking_v1_external = NetworkingV1External (target_endpoint_trimmed , self )
182
197
self .info = info
183
198
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
+
184
211
@property
185
212
def doppler (self ) -> DopplerClient :
186
213
if self ._doppler is None :
@@ -194,7 +221,6 @@ def rlpgateway(self):
194
221
if self ._rlpgateway is None :
195
222
raise NotImplementedError ("No RLP gateway endpoint for this instance" )
196
223
else :
197
-
198
224
return self ._rlpgateway
199
225
200
226
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:
206
232
root_links = root_info ["links" ]
207
233
logging = root_links .get ("logging" )
208
234
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" )
209
237
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 ,
211
240
self ._resolve_login_endpoint (root_links ),
212
241
target_endpoint ,
213
242
logging .get ("href" ) if logging is not None else None ,
0 commit comments