netcmd: add domain models and basic model layer
authorRob van der Linde <rob@catalyst.net.nz>
Tue, 16 May 2023 00:09:39 +0000 (12:09 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 25 Jun 2023 23:29:32 +0000 (23:29 +0000)
commit3a0160ae94301c9931ee25eb7a87cf77cd588f33
treeb0a49db3f6c36fda127b7488184d06699e25b3fe
parentd01cd64da23bb092c63ef7a2ff57d83c6b4e76e8
netcmd: add domain models and basic model layer

The ORM is somewhat inspired by Django, but it has some key
differences that make it work better with the Ldb database.

A field can be a singular value or a list, so a BooleanField can
either be True, or [True, False, True], or None.

The only thing that many=True does is say that the field "prefers" to
be a list, but really any field can be a list. For example when
creating a new object, it initialises the field as an empty list
rather than None if many=True.

When saving an object, if it is an update operation, only write the
fields that have actually changed.

When updating an object, any fields that are unset (set to None, or an
empty list) will be treated as a REMOVE operation.

Note that silo members should not be saved this way, writing the whole
list can lead to data loss if multiple admins are saving the silo at
the same time. Silo members will need to be handled differently, just
removing one member but not writing the whole list.

Unlike Django, there is no .objects class, instead there are a bunch
of static methods for querying:

  * Model.get
  * Model.query
  * Model.create
  * Model.get_or_create

Signed-off-by: Rob van der Linde <rob@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
python/samba/netcmd/domain/models/__init__.py [new file with mode: 0644]
python/samba/netcmd/domain/models/auth_policy.py [new file with mode: 0644]
python/samba/netcmd/domain/models/auth_silo.py [new file with mode: 0644]
python/samba/netcmd/domain/models/claim_type.py [new file with mode: 0644]
python/samba/netcmd/domain/models/exceptions.py [new file with mode: 0644]
python/samba/netcmd/domain/models/fields.py [new file with mode: 0644]
python/samba/netcmd/domain/models/model.py [new file with mode: 0644]
python/samba/netcmd/domain/models/user.py [new file with mode: 0644]
python/samba/netcmd/domain/models/value_type.py [new file with mode: 0644]