-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathservice_plans.py
More file actions
54 lines (43 loc) · 2.51 KB
/
service_plans.py
File metadata and controls
54 lines (43 loc) · 2.51 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
52
53
54
from typing import TYPE_CHECKING
from cloudfoundry_client.v3.entities import EntityManager, Entity
if TYPE_CHECKING:
from cloudfoundry_client.client import CloudFoundryClient
class ServicePlanManager(EntityManager):
def __init__(self, target_endpoint: str, client: "CloudFoundryClient"):
super(ServicePlanManager, self).__init__(target_endpoint, client, "/v3/service_plans")
def update(
self,
guid: str,
meta_labels: dict | None = None,
meta_annotations: dict | None = None,
) -> Entity:
payload = {"metadata": {}}
if meta_labels:
payload["metadata"]["labels"] = meta_labels
if meta_annotations:
payload["metadata"]["annotations"] = meta_annotations
return super(ServicePlanManager, self)._update(guid, payload)
def remove(self, guid: str):
super(ServicePlanManager, self)._remove(guid)
def get_visibility(self, service_plan_guid: str) -> dict:
return super(ServicePlanManager, self)._get(f"{self.target_endpoint}{self.entity_uri}/{service_plan_guid}/visibility")
# Updates a service plan visibility. It behaves similar to the POST service plan visibility endpoint but
# this endpoint will REPLACE the existing list of organizations when the service plan is organization visible.
def update_visibility(self, service_plan_guid: str, type: str, organizations: list[dict] | None = None) -> dict:
payload = {"type": type}
if organizations:
payload["organizations"] = organizations
return super(ServicePlanManager, self)._patch(
url=f"{self.target_endpoint}{self.entity_uri}/{service_plan_guid}/visibility", data=payload
)
# Applies a service plan visibility. It behaves similar to the PATCH service plan visibility endpoint but
# this endpoint will APPEND to the existing list of organizations when the service plan is organization visible.
def apply_visibility_to_extra_orgs(self, service_plan_guid: str, organizations: list[dict]) -> dict:
payload = {"type": "organization", "organizations": organizations}
return super(ServicePlanManager, self)._post(
url=f"{self.target_endpoint}{self.entity_uri}/{service_plan_guid}/visibility", data=payload, files=None
)
def remove_org_from_service_plan_visibility(self, service_plan_guid: str, org_guid: str):
super(ServicePlanManager, self)._delete(
url=f"{self.target_endpoint}{self.entity_uri}/{service_plan_guid}/visibility/{org_guid}"
)