api
Simon 2 years ago
parent 708599551e
commit c60d1a53aa

@ -1,33 +1,32 @@
from spyne import ServiceBase, rpc, Integer, Decimal, UnsignedInteger32, Unicode, Iterable, error from spyne import ServiceBase, rpc, Integer, Decimal, UnsignedInteger32, Unicode, Iterable, error
from dmr_utils3.utils import bytes_3 from dmr_utils3.utils import bytes_3, bytes_4
class FD_APIUserDefinedContext(object): class FD_APIUserDefinedContext(object):
def __init__(self,CONFIG,APIQUEUE,BRIDGES): def __init__(self,CONFIG,BRIDGES):
self.CONFIG = CONFIG self.CONFIG = CONFIG
self.APIQUEUE = APIQUEUE
self.BRIDGES = BRIDGES self.BRIDGES = BRIDGES
def getconfig(self): def getconfig(self):
return self.CONFIG return self.CONFIG
def getapiqueue(self):
return self.APIQUEUE
def getbridges(self): def getbridges(self):
return self.BRIDGES return self.BRIDGES
def validateKey(self,dmrid,key): def validateKey(self,dmrid,key):
systems = self.CONFIG['SYSTEMS'] systems = self.CONFIG['SYSTEMS']
dmrid = bytes_3(dmrid) dmrid = bytes_4(dmrid)
print(dmrid)
for system in systems: for system in systems:
for peerid in systems[system]['PEERS']: for peerid in systems[system]['PEERS']:
print(peerid)
if peerid == dmrid: if peerid == dmrid:
if key == _hash: if key == systems[system]['_opt_key']:
return(systems[system]['_opt_key']) return(system)
else: else:
return(False) return(False)
return(False)
def validateSystemKey(self,systemkey): def validateSystemKey(self,systemkey):
if systemkey == self.CONFIG['GLOBAL']['SYSTEM_API_KEY']: if systemkey == self.CONFIG['GLOBAL']['SYSTEM_API_KEY']:
@ -41,6 +40,9 @@ class FD_APIUserDefinedContext(object):
def queue(self,system,options): def queue(self,system,options):
self.APIQUEUE.append((system,options)) self.APIQUEUE.append((system,options))
def options(self,system,options):
self.CONFIG['SYSTEMS'][system]['OPTIONS'] = options
class FD_API(ServiceBase): class FD_API(ServiceBase):
_version = 0.1 _version = 0.1
@ -63,17 +65,17 @@ class FD_API(ServiceBase):
@rpc(Unicode,Unicode, _returns=Unicode()) @rpc(Unicode,Unicode, _returns=Unicode())
def reset(ctx,dmrid,key): def reset(ctx,dmrid,key):
system = ctx.udc.validateKey(dmrid,key) system = ctx.udc.validateKey(int(dmrid),key)
if system: if system:
ctx.udc.reset(system) ctx.udc.reset(system)
else: else:
raise error.InvalidCredentialsError() raise error.InvalidCredentialsError()
@rpc(UnsignedInteger32,UnsignedInteger32,Unicode,_returns=Unicode()) @rpc(UnsignedInteger32,Unicode,Unicode,_returns=Unicode())
def setoptions(ctx,dmrid,key,options): def setoptions(ctx,dmrid,key,options):
system = ctx.udc.validateKey(dmrid,key) system = ctx.udc.validateKey(int(dmrid),key)
if system: if system:
ctx.udc.queue(system,options) ctx.udc.options(system,options)
else: else:
raise error.InvalidCredentialsError() raise error.InvalidCredentialsError()

@ -144,7 +144,7 @@ def config_reports(_config, _factory):
return report_server return report_server
# Start API server # Start API server
def config_API(_config, _apiqueu, _bridges): def config_API(_config, _bridges):
application = Application([FD_API], application = Application([FD_API],
@ -154,7 +154,7 @@ def config_API(_config, _apiqueu, _bridges):
) )
def _on_method_call(ctx): def _on_method_call(ctx):
ctx.udc = FD_APIUserDefinedContext(CONFIG,APIQUEUE,_bridges) ctx.udc = FD_APIUserDefinedContext(CONFIG,_bridges)
application.event_manager.add_listener('method_call', _on_method_call) application.event_manager.add_listener('method_call', _on_method_call)
@ -841,12 +841,6 @@ def options_config():
prohibitedTGs = [0,1,2,3,4,5,9,9990,9991,9992,9993,9994,9995,9996,9997,9998,9999] prohibitedTGs = [0,1,2,3,4,5,9,9990,9991,9992,9993,9994,9995,9996,9997,9998,9999]
try:
for (system,options) in APIQUEUE.pop(1):
if not CONFIG['SYSTEMS'][_system]['_reset']:
CONFIG['SYSTEMS'][system][OPTIONS] = options
except IndexError:
pass
for _system in CONFIG['SYSTEMS']: for _system in CONFIG['SYSTEMS']:
try: try:
@ -2642,7 +2636,6 @@ if __name__ == '__main__':
import signal import signal
global CONFIG global CONFIG
global APIQUEUE
# Higheset peer ID permitted by HBP # Higheset peer ID permitted by HBP
PEER_MAX = 4294967295 PEER_MAX = 4294967295
@ -2886,9 +2879,8 @@ if __name__ == '__main__':
#Initialize API #Initialize API
APIQUEUE = []
if CONFIG['GLOBAL']['ENABLE_API']: if CONFIG['GLOBAL']['ENABLE_API']:
api = config_API(CONFIG,APIQUEUE,BRIDGES) api = config_API(CONFIG,BRIDGES)
else: else:
api = False api = False
if api: if api:

Loading…
Cancel
Save

Powered by TurnKey Linux.