Introduce ability to attach users to devices

This commit is contained in:
clerie 2022-06-16 23:01:04 +02:00
parent ac9ae74a0b
commit 8849b8488c
5 changed files with 72 additions and 1 deletions

View File

@ -53,6 +53,32 @@ class OMMClient2:
r = self.connection.request(m)
r.raise_on_error()
def attach_user_device(self, uid, ppn):
"""
Attach user to device
:param uid: User id
:param ppn: Device id
Requires ommsync=True
"""
t_u = types.PPUserType()
t_u.uid = uid
t_u.ppn = ppn
t_u.relType = types.PPRelTypeType("Dynamic")
t_d = types.PPDevType()
t_d.ppn = ppn
t_d.uid = uid
t_d.relType = types.PPRelTypeType("Dynamic")
m = messages.SetPP()
m.childs.user = [t_u]
m.childs.pp = [t_d]
r = self.connection.request(m)
r.raise_on_error()
if r.childs.user is None:
return None
return r.childs.user[0], r.childs.pp[0]
def create_user(self, num):
"""
Create PP user

View File

@ -141,6 +141,7 @@ from .getppuser import GetPPUser, GetPPUserResp
from .getpublickey import GetPublicKey, GetPublicKeyResp
from .open import Open, OpenResp
from .ping import Ping, PingResp
from .setpp import SetPP, SetPPResp
from .setppuser import SetPPUser, SetPPUserResp
def construct(request):

View File

@ -0,0 +1,20 @@
#!/usr/bin/env python3
from . import Request, Response, request_type, response_type
from ..types import PPDevType, PPUserType
@request_type
class SetPP(Request):
CHILDS = {
"pp": PPDevType,
"user": PPUserType,
}
@response_type
class SetPPResp(Response):
CHILDS = {
"pp": PPDevType,
"user": PPUserType,
}

View File

@ -96,7 +96,11 @@ class MonitoringStateType(EnumType):
class PPRelTypeType(EnumType):
VALUES = None
VALUES = [
"Fixed",
"Dynamic",
"Unbound",
]
class AccountType(ChildType):
@ -134,6 +138,18 @@ class PPDevType(ChildType):
"ppDefaultProfileLoaded": bool,
"subscribeToPARIOnly": bool,
# undocumented
"ommId": str,
"ommIdAck": str,
"timeStampAdmin": int,
"timeStampRelation": int,
"timeStampRoaming": int,
"timeStampSubscription": int,
"autoCreate": bool,
"roaming": None, # value: 'RoamingComplete'
"modicType": str, # value: '01'
"locationData": str, # value: '000001000000'
"dectIeFixedId": str,
"subscriptionId": str,
"ppnSec": int,
}
@ -213,4 +229,7 @@ class PPUserType(ChildType):
"keyLockEnable": None,
"keyLockPin": None,
"keyLockTime": None,
"ppnOld": int,
"timeStampAdmin": int,
"timeStampRelation": int,
}

5
ommcli
View File

@ -70,6 +70,11 @@ if __name__ == "__main__":
parser_exit = subparsers.add_parser("exit")
parser_exit.set_defaults(func=exit)
parser_get_account = subparsers.add_parser("attach_user_device")
parser_get_account.add_argument("uid", type=int)
parser_get_account.add_argument("ppn", type=int)
parser_get_account.set_defaults(func=c.attach_user_device, format=format_list)
parser_get_account = subparsers.add_parser("create_user")
parser_get_account.add_argument("num")
parser_get_account.set_defaults(func=c.create_user, format=format_child_type)