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
56eeac5e
Commit
56eeac5e
authored
Dec 02, 2024
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_json_rpc_api: WIP 2 actions
parent
81215fb0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
23 deletions
+37
-23
master/bt5/erp5_json_rpc_api/DocumentTemplateItem/portal_components/document.erp5.JsonRpcAPIService.py
...Item/portal_components/document.erp5.JsonRpcAPIService.py
+19
-22
master/bt5/erp5_json_rpc_api/TestTemplateItem/portal_components/test.erp5.testJsonRpcAPIService.py
...Item/portal_components/test.erp5.testJsonRpcAPIService.py
+18
-1
No files found.
master/bt5/erp5_json_rpc_api/DocumentTemplateItem/portal_components/document.erp5.JsonRpcAPIService.py
View file @
56eeac5e
...
...
@@ -26,11 +26,11 @@
##############################################################################
import
base64
import
binascii
#
import base64
#
import binascii
import
json
import
typing
import
six
#
import six
from
six.moves.urllib.parse
import
unquote
if
typing
.
TYPE_CHECKING
:
...
...
@@ -40,7 +40,7 @@ if typing.TYPE_CHECKING:
_
=
(
OpenAPIOperation
,
OpenAPIParameter
,
HTTPRequest
,
Any
,
Callable
,
Optional
)
import
jsonschema
#
import jsonschema
from
AccessControl
import
ClassSecurityInfo
from
zExceptions
import
NotFound
from
zope.publisher.browser
import
BrowserView
...
...
@@ -51,9 +51,6 @@ import zope.interface
from
Products.ERP5Type
import
Permissions
,
PropertySheet
from
erp5.component.document.JsonRpcAPITypeInformation
import
(
NoMethodForOperationError
,
ParameterValidationError
,
SchemaDefinitionError
,
byteify
)
from
erp5.component.document.OpenAPIService
import
OpenAPIService
...
...
@@ -119,6 +116,15 @@ class JsonRpcAPIService(OpenAPIService):
request_method
=
request
.
method
.
lower
()
matched_operation
=
None
if
(
request_method
==
'post'
)
and
(
len
(
request_path_parts
)
==
1
):
matched_operation
=
None
if
request_path_parts
[
0
]
==
'WIP.create.installation'
:
matched_operation
=
'jIOWebSection_createSoftwareInstallationFromJSON'
elif
request_path_parts
[
0
]
==
'WIP.request'
:
matched_operation
=
'jIOWebSection_requestSoftwareInstanceFromJSON'
self
.
log
(
'ROMAIN %s'
%
str
(
request_path_parts
))
"""
for operation in self.getTypeInfo().getOpenAPIOperationIterator():
if operation.request_method != request_method:
continue
...
...
@@ -149,9 +155,11 @@ class JsonRpcAPIService(OpenAPIService):
# > their templated counterparts
matched_operation = operation
continue
"""
request
.
other
[
'traverse_subpath'
]
=
request_path_parts
return
matched_operation
'''
def getMethodForOperation(self, operation):
# type: (OpenAPIOperation) -> Optional[Callable]
operation_id = operation.get('operationId')
...
...
@@ -242,26 +250,15 @@ class JsonRpcAPIService(OpenAPIService):
{},
schema,
)
'''
def
executeMethod
(
self
,
request
):
self
.
log
(
'XXX ROMAIN execute method'
)
if
1
:
# jIOWebSection_requestSoftwareInstanceFromJSON
json_data
=
byteify
(
request
.
get
(
'BODY'
))
self
.
log
(
json_data
)
return
self
.
jIOWebSection_requestSoftwareInstanceFromJSON
(
json_data
=
byteify
(
json
.
loads
(
request
.
get
(
'BODY'
))))
#return 'nope'
#return self._asjIOStyle(mode="post", text_content=self.REQUEST.get('BODY'))
#raise NotImplementedError('plop')
# type: (HTTPRequest) -> Any
operation
=
self
.
getMatchingOperation
(
request
)
if
operation
is
None
:
raise
NotFound
()
method
=
self
.
getMethodForOperation
(
operation
)
parameters
=
self
.
extractParametersFromRequest
(
operation
,
request
)
result
=
method
(
**
parameters
)
method
=
getattr
(
self
,
operation
)
#
self.getMethodForOperation(operation)
#
parameters = self.extractParametersFromRequest(operation, request)
result
=
method
(
json_data
=
byteify
(
json
.
loads
(
request
.
get
(
'BODY'
))))
#
**parameters)
response
=
request
.
RESPONSE
if
response
.
getHeader
(
'Content-Type'
):
return
result
...
...
master/bt5/erp5_json_rpc_api/TestTemplateItem/portal_components/test.erp5.testJsonRpcAPIService.py
View file @
56eeac5e
...
...
@@ -165,9 +165,26 @@ class TestJsonRpcAPIConnectorView(JsonRpcAPITestCase):
class
TestJsonRpcAPIDemoDemoDemoXXXTOMoveTODO
(
JsonRpcAPITestCase
):
def
test_21_createSoftwareInstallation
(
self
):
response
=
self
.
publish
(
self
.
connector
.
getPath
()
+
'/WIP.create.installation'
,
user
=
'ERP5TypeTestCase'
,
request_method
=
'POST'
,
stdin
=
io
.
BytesIO
(
json
.
dumps
(
{
"software_release_uri"
:
"https://example.org/foobar"
,
"reference"
:
"XXX"
,
"portal_type"
:
"Software Instance"
,
"title"
:
"new_name"
}).
encode
()),
env
=
{
'CONTENT_TYPE'
:
'application/json'
})
self
.
assertEqual
(
response
.
getBody
(),
b'"ok"'
)
self
.
assertEqual
(
response
.
getStatus
(),
200
)
def
test_21_request
(
self
):
response
=
self
.
publish
(
self
.
connector
.
getPath
()
+
'/
XXXcallAPIEndpointXXX
'
,
self
.
connector
.
getPath
()
+
'/
WIP.request
'
,
user
=
'ERP5TypeTestCase'
,
request_method
=
'POST'
,
stdin
=
io
.
BytesIO
(
...
...
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