Skip to content

Commit

Permalink
adding vcap_services class from frontend (#89)
Browse files Browse the repository at this point in the history
* adding vcap_services class from frontend
  • Loading branch information
srh-sloan authored Jul 20, 2023
1 parent 3fceb38 commit 65afdf5
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions fsd_utils/toggles/vcap_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import json
from dataclasses import dataclass


@dataclass
class VcapServices(object):

services: dict

@staticmethod
def from_env_json(json_string: str):
json_dict = dict(json.loads(json_string))
vcap_services = VcapServices(services=json_dict)
return vcap_services

def does_service_exist(self, service_key: str) -> bool:
return service_key in self.services.keys()

def get_service_by_name(self, group_key: str, name: str) -> dict:
service_group = self.services.get(group_key)
if service_group:
for service in service_group:
if service.get("name") == name:
return service
raise Exception(f"Service name '{name}' not found")
raise Exception(f"Service group '{group_key}' not found")

def get_service_credentials_value(self, group_key: str, name: str, key: str):
service = self.get_service_by_name(group_key, name)
return service.get("credentials").get(key)

0 comments on commit 65afdf5

Please sign in to comment.