anancarv / python-artifactory

Typed interactions with the Jfrog Artifactory REST API
MIT License
55 stars 50 forks source link

Failing validation of SimpleUser #163

Closed dakky closed 2 months ago

dakky commented 2 months ago

Describe the bug The User response object does not match the real world/documentation

To Reproduce Steps to reproduce the behavior:

 art = Artifactory(url="ARTIFACTORY_URL", auth=('USERNAME','PASSWORD_OR_API_KEY'), api_version=1)
art.users.list()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/dakky/Library/Caches/pypoetry/virtualenvs/artifactory-config-Xr84_Zh7-py3.12/lib/python3.12/site-packages/pyartifactory/objects/user.py", line 63, in list
    return [SimpleUser(**user) for user in response.json()]
            ^^^^^^^^^^^^^^^^^^
  File "/Users/dakky/Library/Caches/pypoetry/virtualenvs/artifactory-config-Xr84_Zh7-py3.12/lib/python3.12/site-packages/pydantic/main.py", line 192, in __init__
    self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for SimpleUser
status
  Field required [type=missing, input_value={'name': 'admin', 'uri': ...n', 'realm': 'internal'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.8/v/missing

Expected behavior List of Users is returned

Environment:

Additional context There is something quite fucked up concerning the states/doc of the object

Response from the api:

[ {
  "name" : "admin",
  "uri" : "https://artifactory.mydomain.de/artifactory/api/security/users/admin",
  "realm" : "internal"
}]

Official doc as of today:

{
  - "name": "davids",
  + "email" : "davids@jfrog.com",
  + "password": "***" (write-only, never returned),
  - "admin": false (default),
  - "profileUpdatable": true (default),
  - "disableUIAccess" : true,
  - "internalPasswordDisabled": false (default),
  ! "lastLoggedIn": ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ),
  ! "realm": "Realm name (e.g. internal, saml, oauth, ldap, crowd, scim)",
  - "groups" : [ "deployers", "users" ],
  - "watchManager": false(default),
  - "policyManager": false(default)
}

Code in pyartifactory:

class SimpleUser(BaseModel):
    """Models a simple user."""

    name: str
    uri: str
    status: str
    realm: Optional[str] = None

These 3 "states" does not match 😢

dakky commented 2 months ago

I guess it's basically one wrong field:

    status: str

is not in the reponse. I'll prepare a PR for this