blob: f4fecf8495d0b407701dfab98486f2fb2f6ede90 (
plain)
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
|
import dataclasses
from typing import Optional
@dataclasses.dataclass
class PasswordCredentials:
"""
Resource owner password credentials modelled according to
https://docs.gitlab.com/ee/api/oauth2.html#resource-owner-password-credentials-flow
https://datatracker.ietf.org/doc/html/rfc6749#section-4-3.
If the GitLab server has disabled the ROPC flow without client credentials,
client_id and client_secret must be provided.
"""
username: str
password: str
grant_type: str = "password"
scope: str = "api"
client_id: Optional[str] = None
client_secret: Optional[str] = None
def __post_init__(self) -> None:
basic_auth = (self.client_id, self.client_secret)
if not any(basic_auth):
self.basic_auth = None
return
if not all(basic_auth):
raise TypeError("Both client_id and client_secret must be defined")
self.basic_auth = basic_auth
|