-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathservice_credential_bindings.py
More file actions
51 lines (46 loc) · 2.08 KB
/
service_credential_bindings.py
File metadata and controls
51 lines (46 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from typing import TYPE_CHECKING
from cloudfoundry_client.v3.entities import EntityManager, Entity, ToOneRelationship
if TYPE_CHECKING:
from cloudfoundry_client.client import CloudFoundryClient
class ServiceCredentialBindingManager(EntityManager):
def __init__(self, target_endpoint: str, client: "CloudFoundryClient"):
super(ServiceCredentialBindingManager, self).__init__(target_endpoint, client,
"/v3/service_credential_bindings")
def create(
self,
name: str,
service_credential_binding_type: str,
service_instance_guid: str,
application_guid: str | None,
parameters: dict | None,
meta_labels: dict | None,
meta_annotations: dict | None,
asynchronous: bool = True,
) -> str | Entity | None:
data = {
"name": name,
"type": service_credential_binding_type,
"relationships": {"service_instance": ToOneRelationship(service_instance_guid)},
}
if application_guid:
data["relationships"]["app"] = ToOneRelationship(application_guid)
if parameters:
data["parameters"] = parameters
if meta_labels or meta_annotations:
metadata = dict()
if meta_labels:
metadata["labels"] = meta_labels
if meta_annotations:
metadata["annotations"] = meta_annotations
data["metadata"] = metadata
url = "%s%s" % (self.target_endpoint, self.entity_uri)
response = self.client.post(url, json=data)
location = super(ServiceCredentialBindingManager, self)._location(response)
if location:
job_guid = super(ServiceCredentialBindingManager, self)._extract_job_guid(location)
if asynchronous:
return job_guid
else:
self.client.v3.jobs.wait_for_job_completion(job_guid)
return None
return super(ServiceCredentialBindingManager, self)._read_response(response, None)