Initial upload of source.

This commit is contained in:
Mikael Frykholm 2024-07-24 15:57:11 +02:00
parent 0ba89f3c21
commit dd7f0aa4ac
Signed by: mifr
GPG key ID: 1467F9D69135C236
2 changed files with 63 additions and 0 deletions

42
main.py Normal file
View file

@ -0,0 +1,42 @@
from typing import Union
import uuid
from fastapi import FastAPI
import json
from datetime import datetime, timezone
from dulwich import porcelain
from dulwich.objects import Blob
from dulwich.repo import MemoryRepo
#Clone repo into memory
local_repo = MemoryRepo()
local_repo.refs.set_symbolic_ref(b"HEAD", b"refs/heads/main")
fetch_result = porcelain.fetch(local_repo, "ssh://git@platform.sunet.se:22022/mifr/scim-source.git")
local_repo.refs[b"refs/heads/main"] = fetch_result.refs[b"refs/heads/main"]
last_tree = local_repo[local_repo[b"HEAD"].tree]
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/v2/Users/{item_id}")
def read_user(item_id: uuid.UUID):
try:
path = f"Users/{item_id}.json"
blob = porcelain.get_object_by_path(local_repo, path, None)
user = json.loads(blob.data)
commits = [w.commit for w in local_repo.get_walker(paths=[path.encode()])]
#import pdb;pdb.set_trace()
last_mod = commits[0].author_time
created = commits[-1].author_time
user['meta'] = {}
user['meta']['resourceType'] = 'User'
user['meta']['version'] = commits[0].sha().hexdigest()
user['meta']['created'] = datetime.fromtimestamp(created , tz=timezone.utc).isoformat()
user['meta']['lastModified'] = datetime.fromtimestamp(last_mod, tz=timezone.utc).isoformat()
user['meta']['location'] = "https://example.com/v2/Users/b181c1ec-46a9-40e1-965d-c6c78de47cb9"
return user
except KeyError:
return("Panic, no file found. ")

21
pyproject.toml Normal file
View file

@ -0,0 +1,21 @@
[project]
name = "tinyscim"
version = "0.1"
description = "Small SCIM v2 implementation"
classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3"
]
authors = [
{name = "Mikael Frykholm", email = "mikael@frykholm.com"},
]
dependencies = [
"fastapi",
"xattr",
"dulwich"
]