Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
soctools-user-mgmt-ui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gn4-3-wp8-t3.1 SOC
soctools-user-mgmt-ui
Commits
0376f33b
Commit
0376f33b
authored
3 years ago
by
Václav Bartoš
Browse files
Options
Downloads
Patches
Plain Diff
compatibility with Py3.6, params to integrated devel server
parent
d58514ed
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.py
+19
-10
19 additions, 10 deletions
main.py
requirements.txt
+6
-5
6 additions, 5 deletions
requirements.txt
with
25 additions
and
15 deletions
main.py
+
19
−
10
View file @
0376f33b
# Example of minimal working WSGI script
#!/usr/bin/env python3
import
sys
from
datetime
import
datetime
import
os.path
import
re
import
subprocess
from
flask
import
Flask
,
render_template
,
request
,
make_response
,
redirect
,
flash
from
flask
import
Flask
,
render_template
,
request
,
make_response
,
redirect
,
flash
from
flask_wtf
import
FlaskForm
from
flask_wtf
import
FlaskForm
from
wtforms
import
StringField
from
wtforms
import
StringField
...
@@ -7,11 +13,6 @@ from wtforms.validators import DataRequired, Email
...
@@ -7,11 +13,6 @@ from wtforms.validators import DataRequired, Email
import
requests
import
requests
import
yaml
import
yaml
from
datetime
import
datetime
import
os.path
import
re
import
subprocess
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
app
.
secret_key
=
"
ASDF1234 - CHANGE ME!
"
app
.
secret_key
=
"
ASDF1234 - CHANGE ME!
"
...
@@ -26,14 +27,15 @@ def load_config():
...
@@ -26,14 +27,15 @@ def load_config():
"""
Load various variables, api keys, etc. and set configuration parameters
"""
"""
Load various variables, api keys, etc. and set configuration parameters
"""
global
SOCTOOLSPROXY
,
KEYCLOAK_BASE_URL
,
KEYCLOAK_ADMIN_PASSWORD
global
SOCTOOLSPROXY
,
KEYCLOAK_BASE_URL
,
KEYCLOAK_ADMIN_PASSWORD
variables
=
yaml
.
safe_load
(
open
(
VARIABLES_FILE
,
"
r
"
))
variables
=
yaml
.
safe_load
(
open
(
VARIABLES_FILE
,
"
r
"
))
print
(
variables
)
# Get FQDN of the main server
# Get FQDN of the main server
SOCTOOLSPROXY
=
variables
[
"
soctoolsproxy
"
]
SOCTOOLSPROXY
=
variables
[
"
soctoolsproxy
"
]
assert
re
.
match
(
'
[a-zA-Z0-9.-]+
'
,
SOCTOOLSPROXY
),
f
"
ERROR: The
'
soctoolsproxy
'
variable loaded from
'
{
VARIABLES_FILE
}
'
is not a valid domain name.
"
assert
re
.
match
(
'
[a-zA-Z0-9.-]+
'
,
SOCTOOLSPROXY
),
f
"
ERROR: The
'
soctoolsproxy
'
variable loaded from
'
{
VARIABLES_FILE
}
'
is not a valid domain name.
"
# Set base URL to Keycloak
# Set base URL to Keycloak
KEYCLOAK_BASE_URL
=
f
"
https://
{
SOCTOOLSPROXY
}
:12443
"
KEYCLOAK_BASE_URL
=
f
"
https://
{
SOCTOOLSPROXY
}
:12443
"
# Load API key for Keycloak
# Load API key for Keycloak
KEYCLOAK_ADMIN_PASSWORD
=
open
(
KEYCLOAK_ADMIN_PASSWORD_FILE
,
"
r
"
).
read
(
100
)
# read max 100 B, the key should never be so long
KEYCLOAK_ADMIN_PASSWORD
=
open
(
KEYCLOAK_ADMIN_PASSWORD_FILE
,
"
r
"
).
read
(
100
).
strip
()
# read max 100 B, the key should never be so long
print
(
f
"
Config loaded:
\n
SOCTOOLSPROXY=
{
SOCTOOLSPROXY
}
\n
KEYCLOAK_BASE_URL=
{
KEYCLOAK_BASE_URL
}
\n
"
f
"
KEYCLOAK_ADMIN_PASSWORD=
{
KEYCLOAK_ADMIN_PASSWORD
[
:
3
]
}
...
{
KEYCLOAK_ADMIN_PASSWORD
[
-
4
:
]
}
"
)
# *** Custom Jinja filters ***
# *** Custom Jinja filters ***
...
@@ -105,7 +107,7 @@ def main():
...
@@ -105,7 +107,7 @@ def main():
if
form_add_user
.
validate_on_submit
():
if
form_add_user
.
validate_on_submit
():
# TODO check that username doesn't exist, yet (and check validity, i.e. special characters etc.)
# TODO check that username doesn't exist, yet (and check validity, i.e. special characters etc.)
# TODO add user
# TODO add user
result
=
subprocess
.
run
([
"
echo
"
,
"
test
"
]
,
capture_output
=
True
)
result
=
subprocess
.
run
([
"
echo
"
,
"
test
"
])
if
result
.
returncode
==
0
:
if
result
.
returncode
==
0
:
flash
(
f
'
User
"
{
form_add_user
.
username
.
data
}
"
successfully created.
'
,
"
success
"
)
flash
(
f
'
User
"
{
form_add_user
.
username
.
data
}
"
successfully created.
'
,
"
success
"
)
else
:
else
:
...
@@ -122,5 +124,12 @@ def main():
...
@@ -122,5 +124,12 @@ def main():
# When the script is run directly, run the application on a local development server.
# When the script is run directly, run the application on a local development server.
# Optionally pass two parameters, 'host' (IP to listen on) and 'port',
# e.g.: ./main.py 0.0.0.0 8080
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
app
.
run
()
host
,
port
=
'
127.0.0.1
'
,
5000
# defaults
if
len
(
sys
.
argv
)
>
2
:
host
=
sys
.
argv
[
1
]
port
=
int
(
sys
.
argv
[
2
])
app
.
config
[
'
ENV
'
]
=
'
development
'
app
.
run
(
host
=
host
,
port
=
port
,
debug
=
True
)
This diff is collapsed.
Click to expand it.
requirements.txt
+
6
−
5
View file @
0376f33b
flask
~=2.
1.0
flask
~=2.
0.3
flask_wtf
~=1.0.
0
flask_wtf
~=1.0.
1
wtforms
~=3.0.
1
wtforms
~=3.0.
0
email-validator
~=1.1.3
email-validator
~=1.1.3
requests
~=2.27.1
requests
~=2.27.1
jinja2
~=3.1.1
jinja2
~=3.0.3
PyYAML
~=5.2
PyYAML
~=6.0
\ No newline at end of file
gunicorn
~=20.1.0
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment