Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
synnefo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
itminedu
synnefo
Commits
4b6ef8d6
Commit
4b6ef8d6
authored
Apr 15, 2013
by
Ilias Tsitsimpis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
astakosclient: Create function check_input to simplify code
parent
d0226124
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
42 deletions
+23
-42
astakosclient/astakosclient/__init__.py
astakosclient/astakosclient/__init__.py
+14
-42
astakosclient/astakosclient/utils.py
astakosclient/astakosclient/utils.py
+9
-0
No files found.
astakosclient/astakosclient/__init__.py
View file @
4b6ef8d6
...
...
@@ -38,7 +38,8 @@ import hashlib
from
copy
import
copy
import
simplejson
from
astakosclient.utils
import
retry
,
scheme_to_class
,
parse_request
from
astakosclient.utils
import
\
retry
,
scheme_to_class
,
parse_request
,
check_input
from
astakosclient.errors
import
\
AstakosClientException
,
Unauthorized
,
BadRequest
,
NotFound
,
Forbidden
,
\
NoUserName
,
NoUUID
,
BadValue
,
QuotaLimit
,
InvalidResponse
...
...
@@ -86,10 +87,7 @@ class AstakosClient():
logger
.
debug
(
"Intialize AstakosClient: astakos_url = %s, "
"use_pool = %s"
%
(
astakos_url
,
use_pool
))
if
not
astakos_url
:
m
=
"Astakos url not given"
logger
.
error
(
m
)
raise
BadValue
(
m
)
check_input
(
"__init__"
,
logger
,
astakos_url
=
astakos_url
)
# Check for supported scheme
p
=
urlparse
.
urlparse
(
astakos_url
)
...
...
@@ -168,7 +166,7 @@ class AstakosClient():
if
data
:
return
simplejson
.
loads
(
unicode
(
data
))
else
:
return
""
return
None
except
Exception
as
err
:
self
.
logger
.
error
(
"Cannot parse response
\"
%s
\"
with simplejson: %s"
%
(
data
,
str
(
err
)))
...
...
@@ -225,10 +223,7 @@ class AstakosClient():
def
get_username
(
self
,
token
,
uuid
):
"""Return the user name of a uuid (see get_usernames)"""
if
not
uuid
:
m
=
"No uuid was given"
self
.
logger
.
error
(
m
)
raise
BadValue
(
m
)
check_input
(
"get_username"
,
self
.
logger
,
uuid
=
uuid
)
uuid_dict
=
self
.
get_usernames
(
token
,
[
uuid
])
if
uuid
in
uuid_dict
:
return
uuid_dict
.
get
(
uuid
)
...
...
@@ -242,10 +237,7 @@ class AstakosClient():
def
service_get_username
(
self
,
token
,
uuid
):
"""Return the displayName of a uuid using a service's token"""
if
not
uuid
:
m
=
"No uuid was given"
self
.
logger
.
error
(
m
)
raise
BadValue
(
m
)
check_input
(
"service_get_username"
,
self
.
logger
,
uuid
=
uuid
)
uuid_dict
=
self
.
service_get_usernames
(
token
,
[
uuid
])
if
uuid
in
uuid_dict
:
return
uuid_dict
.
get
(
uuid
)
...
...
@@ -284,10 +276,7 @@ class AstakosClient():
def
get_uuid
(
self
,
token
,
display_name
):
"""Return the uuid of a name (see getUUIDs)"""
if
not
display_name
:
m
=
"No display_name was given"
self
.
logger
.
error
(
m
)
raise
BadValue
(
m
)
check_input
(
"get_uuid"
,
self
.
logger
,
display_name
=
display_name
)
name_dict
=
self
.
get_uuids
(
token
,
[
display_name
])
if
display_name
in
name_dict
:
return
name_dict
.
get
(
display_name
)
...
...
@@ -301,10 +290,7 @@ class AstakosClient():
def
service_get_uuid
(
self
,
token
,
display_name
):
"""Return the uuid of a name using a service's token"""
if
not
display_name
:
m
=
"No display_name was given"
self
.
logger
.
error
(
m
)
raise
BadValue
(
m
)
check_input
(
"service_get_uuid"
,
self
.
logger
,
display_name
=
display_name
)
name_dict
=
self
.
service_get_uuids
(
token
,
[
display_name
])
if
display_name
in
name_dict
:
return
name_dict
.
get
(
display_name
)
...
...
@@ -396,10 +382,7 @@ class AstakosClient():
informations (details) about the requests commission
"""
if
not
serial
:
m
=
"Commissions serial not given"
self
.
logger
.
error
(
m
)
raise
BadValue
(
m
)
check_input
(
"get_commission_info"
,
self
.
logger
,
serial
=
serial
)
path
=
"/astakos/api/commissions/"
+
str
(
serial
)
return
self
.
_call_astakos
(
token
,
path
)
...
...
@@ -417,14 +400,8 @@ class AstakosClient():
In case of success return nothing.
"""
if
not
serial
:
m
=
"Commission's serial not given"
self
.
logger
.
error
(
m
)
raise
BadValue
(
m
)
if
not
action
:
m
=
"Action not given"
self
.
logger
.
error
(
m
)
raise
BadValue
(
m
)
check_input
(
"commission_action"
,
self
.
logger
,
serial
=
serial
,
action
=
action
)
path
=
"/astakos/api/commissions/"
+
str
(
serial
)
+
"/action"
req_headers
=
{
'content-type'
:
'application/json'
}
...
...
@@ -454,14 +431,9 @@ class AstakosClient():
resolved.
"""
if
not
accept_serials
:
m
=
"accept_serials parameter not given"
self
.
logger
.
error
(
m
)
raise
BadValue
(
m
)
if
not
reject_serials
:
m
=
"reject_serials parameter not given"
self
.
logger
.
error
(
m
)
raise
BadValue
(
m
)
check_input
(
"resolve_commissions"
,
self
.
logger
,
accept_serials
=
accept_serials
,
reject_serials
=
reject_serials
)
path
=
"/astakos/api/commissions/action"
req_headers
=
{
'content-type'
:
'application/json'
}
...
...
astakosclient/astakosclient/utils.py
View file @
4b6ef8d6
...
...
@@ -93,3 +93,12 @@ def parse_request(request, logger):
%
(
request
,
str
(
err
))
logger
.
error
(
m
)
raise
BadValue
(
m
)
def
check_input
(
function_name
,
logger
,
**
kwargs
):
"""Check if given arguments are not None"""
for
i
in
kwargs
:
if
not
kwargs
[
i
]:
m
=
"in "
+
function_name
+
": "
+
str
(
i
)
+
" parameter not given"
logger
.
error
(
m
)
raise
BadValue
(
m
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment