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, 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 username: str = Field(default="", alias="Username", description="Username for the basic authentication.")
43 _password: str = PrivateAttr(default="")
44
45 def is_active(self) -> bool:
46 """Check if the basic authentication is active.
47
48 :return: True if the username is not empty, False otherwise.
49 """
50 return bool(self.username and self._password_password)
51
52 def set_password(self, password: str) -> None:
53 """Set the password for the basic authentication.
54
55 :param password: Password for the basic authentication.
56 """
57 self._password_password = password
58
59 def get_password(self) -> str:
60 """Get the password for the basic authentication.
61
62 :return: The password.
63 """
64 return self._password_password
65
66
67class OAuth(BaseModel):
68 """Open Authentication Configuration.
69
70 :param BaseModel: Pydantic BaseModel for data validation.
71 """
72
73 token_url: str = Field(default="", alias="TokenUrl", description="Endpoint URL for the token request.")
74 client_id: str = Field(default="", alias="ClientId", description="Client identifier for authentication.")
75 grant_type: str = Field(default="client_credentials", alias="GrantType", description="Grant type for the authentication.")
76 header_name: str = Field(default="Authorization", alias="HeaderName", description="Header name for the authentication.")
77 _client_secret: str = PrivateAttr(default="")
78
79 def is_active(self) -> bool:
80 """Check if the service provider authentication is active.
81
82 :return: True if the client ID is not empty, False otherwise.
83 """
84 return bool(self.client_id and self._client_secret_client_secret and self.token_urltoken_url)
85
86 def set_client_secret(self, client_secret: str) -> None:
87 """Set the client secret for the authentication.
88
89 :param client_secret: Client secret for the authentication.
90 """
91 self._client_secret_client_secret = client_secret
92
93 def get_client_secret(self) -> str:
94 """Get the client secret for the authentication.
95
96 :return: The client secret.
97 """
98 if self._client_secret_client_secret is None:
99 return ""
100
102
103
104class AuthenticationConfig(BaseModel):
105 """Authentication Configuration.
106
107 param BaseModel: Pydantic BaseModel for data validation.
108 """
109
110 basic_auth: BasicAuth = Field(default_factory=BasicAuth, alias="BasicAuth", description="Basic authentication configuration.")
111 o_auth: OAuth = Field(
112 default_factory=OAuth,
113 alias="OAuth",
114 description="Service provider authentication configuration.",
115 )
116 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.