Skip to content

Commit fc4d9d1

Browse files
committed
added new api method; fix minor codacy issues
1 parent 0365115 commit fc4d9d1

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ file of `<service>` unit. You can specify the number of lines by this way.
117117
In the example defined above all valid enpoins are.
118118

119119
```
120+
http://127.0.0.1:10080/api/v1/services
120121
http://127.0.0.1:10080/api/v1/ngx/start
121122
http://127.0.0.1:10080/api/v1/ngx/stop
122123
http://127.0.0.1:10080/api/v1/ngx/restart

sysdweb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Distributed under terms of the GNU GPLv3 license.
77

88
NAME = 'sysdweb'
9-
VERSION = '1.3.1'
9+
VERSION = '1.4.0'
1010
AUTHOR_NAME = 'Óscar García Amor'
1111
AUTHOR_EMAIL = 'ogarcia@connectical.com'
1212
DESCRIPTION = 'Control systemd services through Web or REST API'

sysdweb/server.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
#
77
# Distributed under terms of the GNU GPLv3 license.
88

9-
from bottle import abort, auth_basic, request, response, route, run, static_file, template, TEMPLATE_PATH, HTTPError
9+
import os
10+
from bottle import abort, request, response, route, run, static_file, template, TEMPLATE_PATH, HTTPError
1011
from pam import pam
1112
from socket import gethostname
13+
from datetime import datetime
1214
from sysdweb.config import checkConfig
1315
from sysdweb.systemd import systemdBus, Journal
14-
from datetime import datetime
15-
16-
import os
1716

1817
# Search for template path
1918
template_paths = [ os.path.join(os.path.abspath(os.path.dirname(__file__)), 'templates'),
@@ -30,10 +29,10 @@ def login(user, password):
3029
auth = config.get('DEFAULT', 'auth', fallback=None)
3130

3231
if auth == 'basic':
33-
users = [tuple(user.strip().split(':')) for user in users.split(',')]
34-
return True if (user,password) in users else False
32+
userlist = [tuple(usr.strip().split(':')) for usr in users.split(',')]
33+
return True if (user,password) in userlist else False
3534
elif auth == 'pam':
36-
if users and not user in users.split(','): return False
35+
if users and user not in users.split(','): return False
3736
return pam().authenticate(user, password)
3837
elif auth == 'none':
3938
return True
@@ -63,6 +62,11 @@ def wrapper(*a, **ka):
6362

6463
return decorator
6564

65+
@route('/api/v1/services')
66+
@if_auth(login)
67+
def get_service_list():
68+
return {'services': [service for service in config.sections() if service != 'DEFAULT']}
69+
6670
@route('/api/v1/<service>/<action>')
6771
@if_auth(login)
6872
def get_service_action(service, action):

0 commit comments

Comments
 (0)