AAS HTTP Client Documentation
Loading...
Searching...
No Matches
config_classes.py
Go to the documentation of this file.
1"""Basic Authentication Configuration."""
2
3from pydantic import BaseModel, ConfigDict, Field, PrivateAttr
4
5
6class BearerAuth(BaseModel):
7 """Bearer Authentication Configuration.
8
9 :param BaseModel: Pydantic BaseModel for data validation.
10 """
11
12 _token: str = PrivateAttr(default="")
13
14 def set_token(self, token: str) -> None:
15 """Set the bearer token for the authentication.
16
17 :param token: Bearer token for the authentication.
18 """
19 self._token_token = token
20
21 def get_token(self) -> str:
22 """Get the bearer token for the authentication.
23
24 :return: The bearer token.
25 """
26 return self._token_token
27
28 def is_active(self) -> bool:
29 """Check if the bearer authentication is active.
30
31 :return: True if the token is not empty, False otherwise.
32 """
33 return bool(self._token_token)
34
35
36class BasicAuth(BaseModel):
37 """Basic Authentication Configuration.
38
39 :param BaseModel: Pydantic BaseModel for data validation.
40 """
41
42 model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
43
44 username: str = Field(default="", alias="Username", description="Username for the basic authentication.")
45 _password: str = PrivateAttr(default="")
46
47 def is_active(self) -> bool:
48 """Check if the basic authentication is active.
49
50 :return: True if the username is not empty, False otherwise.
51 """
52 return bool(self.username and self._password_password)
53
54 def set_password(self, password: str) -> None:
55 """Set the password for the basic authentication.
56
57 :param password: Password for the basic authentication.
58 """
59 self._password_password = password
60
61 def get_password(self) -> str:
62 """Get the password for the basic authentication.
63
64 :return: The password.
65 """
66 return self._password_password
67
68
69class OAuth(BaseModel):
70 """Open Authentication Configuration.
71
72 :param BaseModel: Pydantic BaseModel for data validation.
73 """
74
75 model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
76
77 token_url: str = Field(default="", alias="TokenUrl", description="Endpoint URL for the token request.")
78 client_id: str = Field(default="", alias="ClientId", description="Client identifier for authentication.")
79 grant_type: str = Field(default="client_credentials", alias="GrantType", description="Grant type for the authentication.")
80 header_name: str = Field(default="Authorization", alias="HeaderName", description="Header name for the authentication.")
81 _client_secret: str = PrivateAttr(default="")
82
83 def is_active(self) -> bool:
84 """Check if the service provider authentication is active.
85
86 :return: True if the client ID is not empty, False otherwise.
87 """
88 return bool(self.client_id and self._client_secret_client_secret and self.token_urltoken_url)
89
90 def set_client_secret(self, client_secret: str) -> None:
91 """Set the client secret for the authentication.
92
93 :param client_secret: Client secret for the authentication.
94 """
95 self._client_secret_client_secret = client_secret
96
97 def get_client_secret(self) -> str:
98 """Get the client secret for the authentication.
99
100 :return: The client secret.
101 """
102 if self._client_secret_client_secret is None:
103 return ""
104
106
107
108class AuthenticationConfig(BaseModel):
109 """Authentication Configuration.
110
111 param BaseModel: Pydantic BaseModel for data validation.
112 """
113
114 model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
115
116 basic_auth: BasicAuth = Field(default_factory=BasicAuth, alias="BasicAuth", description="Basic authentication configuration.")
117 o_auth: OAuth = Field(
118 default_factory=OAuth,
119 alias="OAuth",
120 description="Service provider authentication configuration.",
121 )
122 bearer_auth: BearerAuth = Field(default_factory=BearerAuth, alias="BearerAuth", description="Bearer authentication configuration.")
Authentication Configuration.
Basic Authentication Configuration.
None set_password(self, str password)
Set the password for the basic authentication.
str get_password(self)
Get the password for the basic authentication.
bool is_active(self)
Check if the basic authentication is active.
Bearer Authentication Configuration.
None set_token(self, str token)
Set the bearer token for the authentication.
bool is_active(self)
Check if the bearer authentication is active.
Open Authentication Configuration.
bool is_active(self)
Check if the service provider authentication is active.
str get_client_secret(self)
Get the client secret for the authentication.
None set_client_secret(self, str client_secret)
Set the client secret for the authentication.