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
76
+
67
77
68
78
class NetworkingV1External (object ):
69
79
def __init__ (self , target_endpoint : str , credential_manager : "CloudFoundryClient" ):
@@ -83,18 +93,18 @@ def __init__(self, target_endpoint: str, credential_manager: "CloudFoundryClient
83
93
self .service_plans = ServicePlanManagerV2 (target_endpoint , credential_manager )
84
94
# Default implementations
85
95
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" )
96
+ self .organizations = EntityManagerV2 (target_endpoint , credential_manager , "/organizations" )
97
+ self .private_domains = EntityManagerV2 (target_endpoint , credential_manager , "/private_domains" )
88
98
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" )
99
+ self .services = EntityManagerV2 (target_endpoint , credential_manager , "/services" )
100
+ self .shared_domains = EntityManagerV2 (target_endpoint , credential_manager , "/shared_domains" )
91
101
self .spaces = SpaceManagerV2 (target_endpoint , credential_manager )
92
- self .stacks = EntityManagerV2 (target_endpoint , credential_manager , "/v2/ stacks" )
102
+ self .stacks = EntityManagerV2 (target_endpoint , credential_manager , "/stacks" )
93
103
self .user_provided_service_instances = EntityManagerV2 (
94
- target_endpoint , credential_manager , "/v2/ user_provided_service_instances"
104
+ target_endpoint , credential_manager , "/user_provided_service_instances"
95
105
)
96
- self .security_groups = EntityManagerV2 (target_endpoint , credential_manager , "/v2/ security_groups" )
97
- self .users = EntityManagerV2 (target_endpoint , credential_manager , "/v2/ users" )
106
+ self .security_groups = EntityManagerV2 (target_endpoint , credential_manager , "/security_groups" )
107
+ self .users = EntityManagerV2 (target_endpoint , credential_manager , "/users" )
98
108
# Resources implementation used by push operation
99
109
self .resources = ResourceManager (target_endpoint , credential_manager )
100
110
@@ -146,8 +156,6 @@ def __init__(self, target_endpoint: str, client_id: str = "cf", client_secret: s
146
156
self .login_hint = kwargs .get ("login_hint" )
147
157
target_endpoint_trimmed = target_endpoint .rstrip ("/" )
148
158
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
159
service_information = ServiceInformation (
152
160
None , "%s/oauth/token" % info .authorization_endpoint , client_id , client_secret , [], verify
153
161
)
@@ -156,8 +164,16 @@ def __init__(self, target_endpoint: str, client_id: str = "cf", client_secret: s
156
164
proxies = proxy ,
157
165
user_agent = kwargs .get ("user_agent" , "cf-python-client" )
158
166
)
159
- self .v2 = V2 (target_endpoint_trimmed , self )
160
- self .v3 = V3 (target_endpoint_trimmed , self )
167
+ self ._v2 = (
168
+ V2 (info .api_v2_url , self )
169
+ if info .api_v2_url is not None
170
+ else None
171
+ )
172
+ self ._v3 = (
173
+ V3 (info .api_v3_url , self )
174
+ if info .api_v3_url is not None
175
+ else None
176
+ )
161
177
self ._doppler = (
162
178
DopplerClient (
163
179
info .doppler_endpoint ,
@@ -181,6 +197,18 @@ def __init__(self, target_endpoint: str, client_id: str = "cf", client_secret: s
181
197
self .networking_v1_external = NetworkingV1External (target_endpoint_trimmed , self )
182
198
self .info = info
183
199
200
+ @property
201
+ def v2 (self ) -> V2 :
202
+ if self ._v2 is None :
203
+ raise NotImplementedError ("No V2 endpoint for this instance" )
204
+ return self ._v2
205
+
206
+ @property
207
+ def v3 (self ) -> V3 :
208
+ if self ._v3 is None :
209
+ raise NotImplementedError ("No V3 endpoint for this instance" )
210
+ return self ._v3
211
+
184
212
@property
185
213
def doppler (self ) -> DopplerClient :
186
214
if self ._doppler is None :
@@ -194,7 +222,6 @@ def rlpgateway(self):
194
222
if self ._rlpgateway is None :
195
223
raise NotImplementedError ("No RLP gateway endpoint for this instance" )
196
224
else :
197
-
198
225
return self ._rlpgateway
199
226
200
227
def _get_info (self , target_endpoint : str , proxy : Optional [dict ] = None , verify : bool = True ) -> Info :
@@ -206,8 +233,11 @@ def _get_info(self, target_endpoint: str, proxy: Optional[dict] = None, verify:
206
233
root_links = root_info ["links" ]
207
234
logging = root_links .get ("logging" )
208
235
log_stream = root_links .get ("log_stream" )
236
+ cloud_controller_v2 = root_links .get ("cloud_controller_v2" )
237
+ cloud_controller_v3 = root_links .get ("cloud_controller_v3" )
209
238
return Info (
210
- root_links ["cloud_controller_v2" ]["meta" ]["version" ],
239
+ cloud_controller_v2 ["href" ] if cloud_controller_v2 is not None else None ,
240
+ cloud_controller_v3 ["href" ] if cloud_controller_v3 is not None else None ,
211
241
self ._resolve_login_endpoint (root_links ),
212
242
target_endpoint ,
213
243
logging .get ("href" ) if logging is not None else None ,
0 commit comments