Updated udsacotr config tool

This commit is contained in:
Adolfo Gómez García 2019-11-22 09:36:16 +01:00
parent 07d337364d
commit bef9776a6b
5 changed files with 35 additions and 34 deletions

View File

@ -55,15 +55,20 @@ class UDSConfigDialog(QDialog):
QDialog.__init__(self, None)
# Get local config config
config: udsactor.types.ActorConfigurationType = udsactor.store.readConfig()
self.ui = Ui_UdsActorSetupDialog()
self.ui.setupUi(self)
self.ui.host.setText(config.host)
self.ui.validateCertificate.setCurrentIndex(1 if config.validateCertificate else 0)
self.ui.postConfigCommand.setText(config.post_command or '')
self.ui.preCommand.setText(config.pre_command or '')
self.ui.runonceCommand.setText(config.runonce_command or '')
self.ui.logLevelComboBox.setCurrentIndex(config.log_level)
if config.host:
self.updateAuthenticators()
self.ui.username.setText('')
self.ui.password.setText('')
self.ui.postConfigCommand.setText('')
self.ui.preCommand.setText('')
self.ui.runonceCommand.setText(r'c:\windows\runonce.bat')
@property
def api(self) -> udsactor.rest.REST:
@ -115,14 +120,18 @@ class UDSConfigDialog(QDialog):
self.ui.preCommand.text(),
self.ui.runonceCommand.text(),
self.ui.postConfigCommand.text(),
(self.ui.logLevelComboBox.currentIndex() + 1) * 10000 # Loglevel
self.ui.logLevelComboBox.currentIndex() # Loglevel
)
# Store parameters on register for later use, notify user of registration
udsactor.store.writeConfig(
udsactor.types.ActorConfigurationType(
host=self.ui.host.text(),
validateCertificate=self.ui.validateCertificate.currentIndex() == 1,
master_token=token
master_token=token,
pre_command=self.ui.preCommand.text(),
post_command=self.ui.postConfigCommand.text(),
runonce_command=self.ui.runonceCommand.text(),
log_level=self.ui.logLevelComboBox.currentIndex()
)
)
# Inform the user

View File

@ -55,6 +55,10 @@ def readConfig() -> types.ActorConfigurationType:
validateCertificate=uds.getboolean('validate', fallback=False),
master_token=uds.get('master_token', None),
own_token=uds.get('own_token', None),
pre_command=uds.get('pre_command', None),
runonce_command=uds.get('runonce_command', None),
post_command=uds.get('post_command', None),
log_level=int(uds.get('log_level', '1')),
data=data
)
except Exception:
@ -67,11 +71,16 @@ def writeConfig(config: types.ActorConfigurationType) -> None:
uds: configparser.SectionProxy = cfg['uds']
uds['host'] = config.host
uds['validate'] = 'yes' if config.validateCertificate else 'no'
if config.master_token:
uds['master_token'] = config.master_token
if config.own_token:
uds['own_token'] = config.own_token
if config.data:
def writeIfValue(val, name):
if val:
uds[name] = val
writeIfValue(config.master_token, 'master_token')
writeIfValue(config.own_token, 'own_token')
writeIfValue(config.pre_command, 'pre_command')
writeIfValue(config.post_command, 'post_command')
writeIfValue(config.runonce_command, 'runonce_command')
uds['log_level'] = str(config.log_level)
if config.data: # Special case, encoded & dumped
uds['data'] = base64.b64encode(pickle.dumps(config.data)).decode()
# Ensures exists destination folder

View File

@ -175,24 +175,3 @@ class REST:
pass
raise RESTError(result.content)
def readConfig(
self,
auth: str,
username: str,
password: str,
mac: str,
config: typing.Optional[types.ActorConfigurationType] = None
) -> typing.Optional[typing.MutableMapping[str, typing.Any]]:
try:
res = None
headers = self._login(auth, username, password)
result = requests.post(self.url + 'actor/v2/config', data=json.dumps(mac), headers=headers, verify=self.validateCert)
if result.ok:
res = result.json()['result']
except Exception:
pass
if config:
config
return None

View File

@ -18,7 +18,11 @@ class ActorConfigurationType(typing.NamedTuple):
validateCertificate: bool
master_token: typing.Optional[str] = None
own_token: typing.Optional[str] = None
pre_command: typing.Optional[str] = None
run_once_command: typing.Optional[str] = None
runonce_command: typing.Optional[str] = None
post_command: typing.Optional[str] = None
log_level: int = 0
data: typing.Optional[typing.Dict[str, str]] = None

View File

@ -37,7 +37,7 @@ import typing
from uds.models import getSqlDatetimeAsUnix, getSqlDatetime, ActorToken
from uds.core import VERSION
from ..handlers import Handler
from ..handlers import Handler, NotFound
logger = logging.getLogger(__name__)