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

@ -144,7 +144,7 @@ def config_reports(_config, _factory):
return report_server
# Start API server
def config_API(_config, _apiqueu, _bridges):
def config_API(_config, _bridges):
application = Application([FD_API],
@ -154,7 +154,7 @@ def config_API(_config, _apiqueu, _bridges):
)
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)
@ -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]
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']:
try:
@ -2642,7 +2636,6 @@ if __name__ == '__main__':
import signal
global CONFIG
global APIQUEUE
# Higheset peer ID permitted by HBP
PEER_MAX = 4294967295
@ -2886,9 +2879,8 @@ if __name__ == '__main__':
#Initialize API
APIQUEUE = []
if CONFIG['GLOBAL']['ENABLE_API']:
api = config_API(CONFIG,APIQUEUE,BRIDGES)
api = config_API(CONFIG,BRIDGES)
else:
api = False
if api:

Loading…
Cancel
Save

Powered by TurnKey Linux.