forked from canonical/charm-relation-interfaces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.py
61 lines (43 loc) · 1.54 KB
/
schema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Copyright 2023 Canonical
# See LICENSE file for licensing details.
"""This file defines the schemas for the provider and requirer sides of the ingress interface.
It exposes two interfaces.schema_base.DataBagSchema subclasses called:
- ProviderSchema
- RequirerSchema
Examples:
ProviderSchema:
unit: <empty>
app: {"ingress":
{"url": "http://foo.bar:80/model_name-app_name"}
}
RequirerSchema:
unit: {
"name": "app-name",
"host": "hostname"
}
app: {
"port": 4242,
"model": "model-name"
}
"""
import json
import yaml
from pydantic import BaseModel, AnyHttpUrl, validator, Field, Json
from interface_tester.schema_base import DataBagSchema
class Url(BaseModel):
url: AnyHttpUrl
class MyProviderData(BaseModel):
ingress: Json[Url]
class ProviderSchema(DataBagSchema):
"""Provider schema for Ingress."""
app: MyProviderData
class IngressRequirerAppData(BaseModel):
model: Json[str] = Field(description="The model the application is in.")
port: Json[int] = Field(description="The port the unit wishes to be exposed. Stringified int.")
name: Json[str] = Field(description="The name of the application requesting ingress.")
class IngressRequirerUnitData(BaseModel):
host: Json[str] = Field(description="Unit hostname to be exposed.")
class RequirerSchema(DataBagSchema):
"""Requirer schema for Ingress."""
app: IngressRequirerAppData
unit: IngressRequirerUnitData