Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Romain Courteaud
slapos.core
Commits
424fdb0b
Commit
424fdb0b
authored
Jan 22, 2025
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
libslap: add callJsonRpcAPI method
Drop GET/POST methods
parent
3a98bda4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
13 deletions
+43
-13
slapos/slap/hateoas.py
slapos/slap/hateoas.py
+43
-13
No files found.
slapos/slap/hateoas.py
View file @
424fdb0b
...
...
@@ -60,6 +60,42 @@ ALLOWED_JIO_FIELD_LIST = [
"FloatField"
,
"TextAreaField"
]
# https://stackoverflow.com/a/33571117
def
_byteify
(
data
,
ignore_dicts
=
False
):
if
isinstance
(
data
,
str
):
return
data
# if this is a list of values, return list of byteified values
if
isinstance
(
data
,
list
):
return
[
_byteify
(
item
,
ignore_dicts
=
True
)
for
item
in
data
]
# if this is a dictionary, return dictionary of byteified keys and values
# but only if we haven't already byteified it
if
isinstance
(
data
,
dict
)
and
not
ignore_dicts
:
return
{
_byteify
(
key
,
ignore_dicts
=
True
):
_byteify
(
value
,
ignore_dicts
=
True
)
for
key
,
value
in
data
.
items
()
# changed to .items() for python 2.7/3
}
# python 3 compatible duck-typing
# if this is a unicode string, return its string representation
if
str
(
type
(
data
))
==
"<type 'unicode'>"
:
return
data
.
encode
(
'utf-8'
)
# if it's anything else, return it in its original form
return
data
def
json_loads_byteified
(
json_text
):
"""
Encode string when loading JSON
"""
return
_byteify
(
json
.
loads
(
json_text
,
object_hook
=
_byteify
),
ignore_dicts
=
True
)
class
TempDocument
(
object
):
def
__init__
(
self
,
**
kw
):
"""
...
...
@@ -156,21 +192,15 @@ class ConnectionHelper:
return
req
def
GET
(
self
,
path
,
params
=
None
,
headers
=
None
):
req
=
self
.
do_request
(
self
.
session
.
get
,
path
=
path
,
params
=
params
,
headers
=
headers
)
return
req
.
text
.
encode
(
'utf-8'
)
def
POST
(
self
,
path
,
params
=
None
,
data
=
None
,
content_type
=
'application/x-www-form-urlencoded'
):
def
callJsonRpcAPI
(
self
,
path
,
data
,
cert_key
=
None
):
req
=
self
.
do_request
(
requests
.
post
,
path
=
path
,
params
=
params
,
data
=
data
,
headers
=
{
'Content-type'
:
content_type
})
return
req
.
text
.
encode
(
'utf-8'
)
data
=
json
.
dumps
(
data
),
headers
=
{
'Content-type'
:
'application/json'
},
expect_json_error
=
True
,
cert_key
=
cert_key
)
return
json_loads_byteified
(
req
.
text
)
class
HateoasNavigator
(
object
):
"""
...
...
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