Refactor get_resource_urls() to return a dict
Anirudh Oppiliappan x@icyphox.sh
Sun, 07 Mar 2021 22:07:56 +0530
3 files changed,
13 insertions(+),
10 deletions(-)
M
janny/auth.py
→
janny/auth.py
@@ -20,4 +20,5 @@ logging.info("Not in-cluster, continuing as is")
return session + SESSION = kube_auth()
M
janny/main.py
→
janny/main.py
@@ -1,20 +1,21 @@
from janny.utils import get -def get_resources(): + +def get_resource_urls(): apis = get("/apis/") apiv1 = get("/api/v1") - resource_objs = list() - resource_objs.append(apiv1.resources) + resource_urls = dict() + resource_urls["/api/v1"] = apiv1.resources for g in apis.groups: - resource_objs.append(get("/apis/" + g.preferredVersion.groupVersion).resources) + version = g.preferredVersion.groupVersion + resource_urls["/apis/" + version] = get( + "/apis/" + g.preferredVersion.groupVersion + ).resources - for resources in resource_objs: - for r in resources: - if "/" not in r.name and r.namespaced: - yield r.name + return resource_urls + def main(): - for r in get_resources(): - print(r) + get_resource_urls()
M
janny/utils.py
→
janny/utils.py
@@ -5,6 +5,7 @@
from janny.config import API_HOST from janny.auth import SESSION + def get(path): """Convert a JSON response into a Python object""" s = SESSION