Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Warden
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pavel Valach
Warden
Commits
bbb948e7
Commit
bbb948e7
authored
9 years ago
by
Pavel Kácha
Browse files
Options
Downloads
Patches
Plain Diff
Reduced client attribute names redundancy in code
parent
c1a9b13b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
warden3/warden_server/warden_server.py
+33
-39
33 additions, 39 deletions
warden3/warden_server/warden_server.py
with
33 additions
and
39 deletions
warden3/warden_server/warden_server.py
+
33
−
39
View file @
bbb948e7
...
...
@@ -208,9 +208,8 @@ def SysLogger(req, socket="/dev/log", facility=logging.handlers.SysLogHandler.LO
Client
=
namedtuple
(
"
Client
"
,
[
"
id
"
,
"
registered
"
,
"
requestor
"
,
"
hostname
"
,
"
name
"
,
"
note
"
,
"
valid
"
,
"
secret
"
,
"
read
"
,
"
debug
"
,
"
write
"
,
"
test
"
])
[
"
id
"
,
"
registered
"
,
"
requestor
"
,
"
hostname
"
,
"
name
"
,
"
secret
"
,
"
valid
"
,
"
read
"
,
"
debug
"
,
"
write
"
,
"
test
"
,
"
note
"
])
class
Object
(
object
):
...
...
@@ -522,7 +521,7 @@ class MySQL(ObjectReq):
def
get_client_by_name
(
self
,
cert_names
,
name
=
None
,
secret
=
None
):
query
=
[
"
SELECT
id, registered, requestor, hostname, note, valid, name, secret, `read`, debug, `write`, test
FROM clients WHERE valid = 1
"
]
query
=
[
"
SELECT
*
FROM clients WHERE valid = 1
"
]
params
=
[]
if
name
:
query
.
append
(
"
AND name = %s
"
)
...
...
@@ -543,7 +542,7 @@ class MySQL(ObjectReq):
def
get_clients
(
self
,
id
=
None
):
query
=
[
"
SELECT
id, registered, requestor, hostname, note, valid, name, secret, `read`, debug, `write`, test
FROM clients
"
]
query
=
[
"
SELECT
*
FROM clients
"
]
params
=
[]
if
id
:
query
.
append
(
"
WHERE id = %s
"
)
...
...
@@ -562,12 +561,9 @@ class MySQL(ObjectReq):
uquery
.
append
(
"
registered = now()
"
)
else
:
query
.
append
(
"
UPDATE clients SET
"
)
for
attr
in
[
"
name
"
,
"
hostname
"
,
"
requestor
"
,
"
secret
"
,
"
note
"
,
"
valid
"
,
"
read
"
,
"
write
"
,
"
debug
"
,
"
test
"
]:
for
attr
in
set
(
Client
.
_fields
)
-
set
([
"
id
"
,
"
registered
"
]):
val
=
kwargs
.
get
(
attr
,
None
)
if
val
is
not
None
:
if
attr
in
[
"
name
"
,
"
hostname
"
]:
val
=
val
.
lower
()
uquery
.
append
(
"
`%s` = %%s
"
%
attr
)
params
.
append
(
val
)
if
not
uquery
:
...
...
@@ -1307,28 +1303,24 @@ def check_config():
def
list_clients
(
id
=
None
):
clients
=
server
.
handler
.
db
.
get_clients
(
id
)
order
=
[
"
id
"
,
"
registered
"
,
"
requestor
"
,
"
hostname
"
,
"
name
"
,
"
secret
"
,
"
valid
"
,
"
read
"
,
"
debug
"
,
"
write
"
,
"
test
"
,
"
note
"
]
lines
=
[[
str
(
getattr
(
client
,
col
))
for
col
in
order
]
for
client
in
clients
]
col_width
=
[
max
(
len
(
val
)
for
val
in
col
)
for
col
in
zip
(
*
(
lines
+
[
order
]))]
lines
=
[[
str
(
getattr
(
client
,
col
))
for
col
in
Client
.
_fields
]
for
client
in
clients
]
col_width
=
[
max
(
len
(
val
)
for
val
in
col
)
for
col
in
zip
(
*
(
lines
+
[
Client
.
_fields
]))]
divider
=
[
"
-
"
*
l
for
l
in
col_width
]
for
line
in
[
order
,
divider
]
+
lines
:
for
line
in
[
Client
.
_fields
,
divider
]
+
lines
:
print
"
"
.
join
([
val
.
ljust
(
width
)
for
val
,
width
in
zip
(
line
,
col_width
)])
def
register_client
(
name
,
hostname
,
requestor
,
secret
,
note
,
valid
,
read
,
write
,
debug
,
test
):
def
register_client
(
**
kwargs
):
# argparse does _always_ return something, so we cannot rely on missing arguments
if
valid
is
None
:
valid
=
1
if
read
is
None
:
read
=
1
if
write
is
None
:
write
=
0
if
debug
is
None
:
debug
=
0
if
test
is
None
:
test
=
1
modify_client
(
id
=
None
,
name
=
name
,
hostname
=
hostname
,
requestor
=
requestor
,
secret
=
secret
,
note
=
note
,
valid
=
valid
,
read
=
read
,
write
=
write
,
debug
=
debug
,
test
=
test
)
if
kwargs
[
"
valid
"
]
is
None
:
kwargs
[
"
valid
"
]
=
1
if
kwargs
[
"
read
"
]
is
None
:
kwargs
[
"
read
"
]
=
1
if
kwargs
[
"
write
"
]
is
None
:
kwargs
[
"
write
"
]
=
0
if
kwargs
[
"
debug
"
]
is
None
:
kwargs
[
"
debug
"
]
=
0
if
kwargs
[
"
test
"
]
is
None
:
kwargs
[
"
test
"
]
=
1
modify_client
(
id
=
None
,
**
kwargs
)
def
modify_client
(
id
,
name
,
hostname
,
requestor
,
secret
,
note
,
valid
,
read
,
write
,
debug
,
test
):
def
modify_client
(
**
kwargs
):
def
isValidHostname
(
hostname
):
if
len
(
hostname
)
>
255
:
...
...
@@ -1356,33 +1348,35 @@ def modify_client(id, name, hostname, requestor, secret, note, valid, read, writ
return
client
and
True
or
False
if
name
is
not
None
and
not
isValidNSID
(
name
):
print
>>
sys
.
stderr
,
"
Invalid client name
\"
%s
\"
.
"
%
name
if
kwargs
[
"
name
"
]
is
not
None
:
kwargs
[
"
name
"
]
=
kwargs
[
"
name
"
].
lower
()
if
not
isValidNSID
(
kwargs
[
"
name
"
]):
print
>>
sys
.
stderr
,
"
Invalid client name
\"
%s
\"
.
"
%
kwargs
[
"
name
"
]
return
254
if
hostname
is
not
None
and
not
isValidHostname
(
hostname
):
print
>>
sys
.
stderr
,
"
Invalid hostname
\"
%s
\"
.
"
%
hostname
return
254
if
kwargs
[
"
hostname
"
]
is
not
None
:
kwargs
[
"
hostname
"
]
=
kwargs
[
"
hostname
"
].
lower
()
if
not
isValidHostname
(
kwargs
[
"
hostname
"
]):
print
>>
sys
.
stderr
,
"
Invalid hostname
\"
%s
\"
.
"
%
kwargs
[
"
hostname
"
]
return
254
if
requestor
is
not
None
and
not
isValidEmail
(
requestor
):
print
>>
sys
.
stderr
,
"
Invalid requestor email
\"
%s
\"
.
"
%
requestor
if
kwargs
[
"
requestor
"
]
is
not
None
and
not
isValidEmail
(
kwargs
[
"
requestor
"
]
):
print
>>
sys
.
stderr
,
"
Invalid requestor email
\"
%s
\"
.
"
%
kwargs
[
"
requestor
"
]
return
254
if
id
is
not
None
and
not
isValidID
(
id
):
print
>>
sys
.
stderr
,
"
Invalid id
\"
%s
\"
.
"
%
id
if
kwargs
[
"
id
"
]
is
not
None
and
not
isValidID
(
kwargs
[
"
id
"
]
):
print
>>
sys
.
stderr
,
"
Invalid id
\"
%s
\"
.
"
%
kwargs
[
"
id
"
]
return
254
for
c
in
server
.
handler
.
db
.
get_clients
():
if
name
is
not
None
and
name
.
lower
()
==
c
.
name
:
if
kwargs
[
"
name
"
]
is
not
None
and
kwargs
[
"
name
"
]
.
lower
()
==
c
.
name
:
print
>>
sys
.
stderr
,
"
Clash with existing name: %s
"
%
str
(
c
)
return
254
if
secret
is
not
None
and
secret
==
c
.
secret
:
if
kwargs
[
"
secret
"
]
is
not
None
and
kwargs
[
"
secret
"
]
==
c
.
secret
:
print
>>
sys
.
stderr
,
"
Clash with existing secret: %s
"
%
str
(
c
)
return
254
newid
=
server
.
handler
.
db
.
add_modify_client
(
id
=
id
,
name
=
name
,
hostname
=
hostname
,
requestor
=
requestor
,
secret
=
secret
,
note
=
note
,
valid
=
valid
,
read
=
read
,
write
=
write
,
debug
=
debug
,
test
=
test
)
newid
=
server
.
handler
.
db
.
add_modify_client
(
**
kwargs
)
list_clients
(
id
=
newid
)
...
...
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