Change to oidc and new foreign id format
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful
This commit is contained in:
49
inventory-app/api.py
Normal file
49
inventory-app/api.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import const
|
||||
from pymongo import MongoClient
|
||||
from flask import Blueprint, abort, g, make_response, redirect, render_template, request, jsonify
|
||||
from common import CustomForm, build_query, flatten, format_name, spam
|
||||
from kubernetes import client, config
|
||||
|
||||
page_api = Blueprint("api", __name__)
|
||||
db = MongoClient(const.MONGO_URI).get_default_database()
|
||||
|
||||
def get_users():
|
||||
config.load_incluster_config()
|
||||
api_instance = client.CustomObjectsApi()
|
||||
ret = api_instance.list_namespaced_custom_object("codemowers.io", "v1alpha1", "default", "oidcgatewayusers")
|
||||
resp = []
|
||||
for item in ret["items"]:
|
||||
resp.append(item)
|
||||
return resp
|
||||
|
||||
@page_api.route("/users")
|
||||
def view_users():
|
||||
resp = get_users()
|
||||
print(resp)
|
||||
return jsonify(resp)
|
||||
|
||||
@page_api.route("/cards")
|
||||
def get_group_cards():
|
||||
group = request.args.get("group", False)
|
||||
if not group:
|
||||
return "must specify group in parameter", 400
|
||||
print(group)
|
||||
gu = list(filter(lambda u: any(g["name"] == group for g in u["status"]["groups"]), get_users()))
|
||||
keys = list(map(lambda u: u["metadata"]["name"], gu))
|
||||
print(keys)
|
||||
flt = {
|
||||
"token.uid_hash": {"$exists": True},
|
||||
"inventory.owner.foreign_id": {"$in": keys}
|
||||
}
|
||||
prj = {
|
||||
"inventory.owner": True,
|
||||
"token.uid_hash": True
|
||||
}
|
||||
found = []
|
||||
for obj in db.inventory.find(flt, prj):
|
||||
del obj["_id"]
|
||||
if obj["inventory"] and obj["inventory"]["owner"] and type(obj["inventory"]["owner"]["foreign_id"]) != str:
|
||||
del obj["inventory"]
|
||||
found.append(obj)
|
||||
return jsonify(list(found))
|
||||
|
Reference in New Issue
Block a user