mirror of https://git.48k.eu/ogcp
Retreive scopes from several ogServers
Update the configuration file format to support several ogServers and retrieve scopes from those ogServers. The old config file format is still supported.async-tree
parent
c4aa1f2f54
commit
2cbe6b774c
|
@ -1,7 +1,4 @@
|
|||
{
|
||||
"IP": "127.0.0.1",
|
||||
"PORT": 8888,
|
||||
"API_TOKEN": "c3fe7bb0395747ec42a25df027585871",
|
||||
"LANG": "en",
|
||||
"USERS": [
|
||||
{
|
||||
|
@ -18,5 +15,19 @@
|
|||
"Unidad Organizativa (Default)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"SERVERS": [
|
||||
{
|
||||
"NAME": "Server 1",
|
||||
"IP": "127.0.0.1",
|
||||
"PORT": 8888,
|
||||
"API_TOKEN": "a0e9ab768cbe93dab5b1998e952bcdb7"
|
||||
},
|
||||
{
|
||||
"NAME": "Server 2",
|
||||
"IP": "127.0.0.1",
|
||||
"PORT": 18888,
|
||||
"API_TOKEN": "e4c8gh913dph32nxm6q2768c427jrsj1"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -11,9 +11,8 @@ import requests
|
|||
import json
|
||||
|
||||
class OGServer:
|
||||
def __init__(self, ip=app.config['IP'],
|
||||
port=app.config['PORT'],
|
||||
api_token=app.config['API_TOKEN']):
|
||||
def __init__(self, name, ip, port, api_token):
|
||||
self.name = name
|
||||
self.ip = ip
|
||||
self.port = port
|
||||
self.api_token = api_token
|
||||
|
@ -34,3 +33,19 @@ class OGServer:
|
|||
headers=self.HEADERS,
|
||||
json=payload)
|
||||
return r
|
||||
|
||||
|
||||
servers = []
|
||||
if {'IP', 'PORT', 'API_TOKEN'} <= app.config.keys():
|
||||
# Config file backward compatibility
|
||||
servers.append(OGServer(app.config['IP'],
|
||||
app.config['IP'],
|
||||
app.config['PORT'],
|
||||
app.config['API_TOKEN']))
|
||||
else:
|
||||
for server in app.config['SERVERS']:
|
||||
ogserver = OGServer(server['NAME'],
|
||||
server['IP'],
|
||||
server['PORT'],
|
||||
server['API_TOKEN'])
|
||||
servers.append(ogserver)
|
||||
|
|
|
@ -25,7 +25,7 @@ from pathlib import Path
|
|||
|
||||
from ogcp.models import User
|
||||
from ogcp.forms.auth import LoginForm, UserForm, DeleteUserForm
|
||||
from ogcp.og_server import OGServer
|
||||
from ogcp.og_server import servers
|
||||
from flask_babel import lazy_gettext as _l
|
||||
from flask_babel import _
|
||||
from ogcp import app
|
||||
|
@ -177,17 +177,24 @@ def get_allowed_scopes(scopes, allowed_scopes):
|
|||
get_allowed_scopes(scope, allowed_scopes)
|
||||
|
||||
def get_scopes(ips=set()):
|
||||
r = g.server.get('/scopes')
|
||||
scopes = r.json()
|
||||
list_scopes = []
|
||||
for server in servers:
|
||||
r = server.get('/scopes')
|
||||
scopes = r.json()
|
||||
server_scope = {}
|
||||
server_scope['name'] = server.name
|
||||
server_scope.update(scopes)
|
||||
list_scopes.append(server_scope)
|
||||
all_scopes = {'scope': list_scopes}
|
||||
if current_user.scopes:
|
||||
allowed_scopes = []
|
||||
get_allowed_scopes(scopes, allowed_scopes)
|
||||
scopes = {'scope': allowed_scopes}
|
||||
get_allowed_scopes(all_scopes, allowed_scopes)
|
||||
all_scopes = {'scope': allowed_scopes}
|
||||
r = g.server.get('/clients')
|
||||
clients = r.json()
|
||||
add_state_and_ips(scopes, clients['clients'], ips)
|
||||
add_state_and_ips(all_scopes, clients['clients'], ips)
|
||||
|
||||
return scopes, clients
|
||||
return all_scopes, clients
|
||||
|
||||
|
||||
def hash_password(pwd):
|
||||
|
@ -245,7 +252,7 @@ def load_user(username):
|
|||
|
||||
@app.before_request
|
||||
def load_config():
|
||||
g.server = OGServer()
|
||||
g.server = servers[0]
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(error):
|
||||
|
|
Loading…
Reference in New Issue