Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
minirc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Dano Mathis
minirc
Commits
1a32ff2a
Commit
1a32ff2a
authored
5 years ago
by
Olivier Levillain
Browse files
Options
Downloads
Patches
Plain Diff
Add first support for user database.
parent
7228a0cd
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
config.py
+26
-1
26 additions, 1 deletion
config.py
test_config.py
+14
-1
14 additions, 1 deletion
test_config.py
with
40 additions
and
2 deletions
config.py
+
26
−
1
View file @
1a32ff2a
...
...
@@ -25,7 +25,7 @@ class Config:
return
self
.
params
[
name
]
def
from_content
(
content
):
def
load_config_
from_content
(
content
):
config
=
Config
()
for
line
in
content
.
split
(
'
\n
'
):
if
line
==
""
:
...
...
@@ -33,3 +33,28 @@ def from_content(content):
elts
=
line
.
split
(
"
=
"
)
config
.
add_param
(
elts
[
0
].
strip
(),
elts
[
1
].
strip
())
return
config
class
UserDB
:
def
__init__
(
self
):
self
.
users
=
dict
()
self
.
users
[
"
admin
"
]
=
{
"
admin
"
:
True
,
"
password
"
:
"
admin
"
}
self
.
users
[
"
guest
"
]
=
{
"
admin
"
:
False
,
"
password
"
:
"
guest
"
}
def
add_user
(
self
,
login
,
password
,
admin
):
self
.
users
[
login
]
=
{
"
admin
"
:
bool
(
admin
),
"
password
"
:
password
}
def
get
(
self
,
login
):
try
:
return
self
.
users
[
login
]
except
Exception
:
return
None
def
load_userdb_from_content
(
content
):
userdb
=
UserDB
()
for
line
in
content
.
split
(
'
\n
'
):
login
,
password
,
admin
=
line
.
split
(
2
)
userdb
.
add_user
(
login
,
password
,
admin
)
This diff is collapsed.
Click to expand it.
test_config.py
+
14
−
1
View file @
1a32ff2a
...
...
@@ -2,7 +2,7 @@ import config
def
test_address_port_params
():
config_content
=
"
address = 10.0.0.1
\n
port = 123
\n
"
c
=
config
.
from_content
(
config_content
)
c
=
config
.
load_config_
from_content
(
config_content
)
assert
c
[
'
address
'
]
==
"
10.0.0.1
"
assert
c
[
'
port
'
]
==
123
...
...
@@ -10,3 +10,16 @@ def test_default_address_port():
c
=
config
.
Config
()
assert
c
[
'
address
'
]
==
"
0.0.0.0
"
assert
c
[
'
port
'
]
==
12345
def
test_user_database
():
users
=
config
.
UserDB
()
admin_user
=
users
.
get
(
"
admin
"
)
assert
admin_user
is
not
None
assert
admin_user
[
"
admin
"
]
==
True
assert
admin_user
[
"
password
"
]
==
"
admin
"
users
.
add_user
(
"
toto
"
,
"
tititoto
"
,
False
)
toto_user
=
users
.
get
(
"
toto
"
)
assert
toto_user
is
not
None
assert
toto_user
[
"
admin
"
]
==
False
assert
toto_user
[
"
password
"
]
==
"
tititoto
"
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