Skip to content

Commit 8a833a5

Browse files
authored
update docs (#53)
* update docs * proof read
1 parent f18990f commit 8a833a5

File tree

2 files changed

+85
-8
lines changed

2 files changed

+85
-8
lines changed

docs/guide/auth.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ The authentication function for this repo has been set using the predefined vali
66

77
You can either inherit the authenticator class and overwrite the validate function, or provide an entirely new function. In either case, it's worth noting that the return value for any provided authentication function currently needs to be of type User. If you want to additionally change the return type you may have to overwrite the endpoint entirely.
88

9-
client = OpenEOCore(
10-
...
11-
)
9+
client = OpenEOCore(
10+
...
11+
)
1212

13-
api = OpenEOApi(client=client, app=FastAPI())
13+
api = OpenEOApi(client=client, app=FastAPI())
1414

15-
def cool_new_auth():
16-
return User(user_id=specific_uuid, oidc_sub="the-only-user")
15+
def cool_new_auth():
16+
return User(user_id=specific_uuid, oidc_sub="the-only-user")
1717

18-
core_api.override_authentication(cool_new_auth)
18+
core_api.override_authentication(cool_new_auth)
1919

2020
Now any endpoints that originally used the Authenticator.validate function, will now use cool_new_auth instead.

docs/guide/orms.md

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,78 @@
1-
## To be defined
1+
## Extending the Object Relational models.
2+
3+
Currently it's possible to extend the object relational models that the api uses in order to support extra values a backend might want to includse in any EndpointRegisters.
4+
5+
## How to extend the models.
6+
7+
In order to effectively use the extended models, you need to update the models.py file found in the alembic directory. After updating the models.py file, you will need to manually update the endpoints where you would like the new model to be used. This is a current pain point, and it would be good to improve this in the future.
8+
9+
#### Original - models.py
10+
11+
from openeo_fastapi.client.psql.settings import BASE
12+
from openeo_fastapi.client.psql.models import *
13+
14+
metadata = BASE.metadata
15+
16+
#### Updated - models.py
17+
18+
19+
from typing import Optional
20+
from openeo_fastapi.client.jobs import Job
21+
from openeo_fastapi.client.psql.settings import BASE
22+
from openeo_fastapi.client.psql.models import *
23+
24+
class ExtendedJobORM(JobORM):
25+
26+
special_string = Column(VARCHAR, nullable=True)
27+
"""A very special string."""
28+
29+
30+
class ExtendedJob(Job):
31+
32+
special_string: Optional[str]
33+
"""A very special string."""
34+
35+
@classmethod
36+
def get_orm(cls):
37+
return ExtendedJobORM
38+
39+
40+
metadata = BASE.metadata
41+
42+
#### Using extended model
43+
44+
In order use the class ExtendedJob, we will need to extend the register. The example below extends the JobRegister and edits the create_job function to create the ExtendedJob and includes setting the value for the new parameter. You will need to version the database in order for the new model to work, and additionally add the NewJobsRegister to the app instance [See Registers](/docs/guide/registers.md).
45+
46+
...
47+
from openeo_fastapi.client.jobs import JobsRegister
48+
from openeo_argoworkflows_api.psql.models import ExtendedJob
49+
50+
class NewJobsRegister(JobsRegister):
51+
52+
def __init__(self, settings, links) -> None:
53+
super().__init__(settings, links)
54+
55+
56+
def create_job(
57+
self, body: JobsRequest
58+
):
59+
"""Create a new ExtendedJob.
60+
"""
61+
62+
# Create the job
63+
job = ExtendedJob(
64+
job_id=job_id,
65+
process=body.process,
66+
status=Status.created,
67+
title=body.title,
68+
description=body.description,
69+
user_id=user.user_id,
70+
created=datetime.datetime.now(),
71+
special_string="A new type of job."
72+
)
73+
74+
engine.create(create_object=job)
75+
76+
return Response(
77+
status_code=201,
78+
)

0 commit comments

Comments
 (0)