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
0
Merge Requests
0
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
Titouan Soulard
slapos.core
Commits
2586f844
Commit
2586f844
authored
Oct 05, 2023
by
Titouan Soulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos: use Software Instance certificate/key pair for request
parent
9f79a6dd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
18 deletions
+29
-18
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+10
-1
slapos/slap/hateoas.py
slapos/slap/hateoas.py
+4
-6
slapos/slap/slap.py
slapos/slap/slap.py
+15
-11
No files found.
slapos/grid/slapgrid.py
View file @
2586f844
...
@@ -1629,6 +1629,15 @@ stderr_logfile_backups=1
...
@@ -1629,6 +1629,15 @@ stderr_logfile_backups=1
# even if something is terribly wrong while processing an instance, it
# even if something is terribly wrong while processing an instance, it
# won't prevent processing other ones.
# won't prevent processing other ones.
if
not
self
.
api_backward_compatibility
:
if
not
self
.
api_backward_compatibility
:
# Try to use partition certificate
# TODO: find a clean way to request the certificate
partition_certificate_file
=
os
.
path
.
join
(
self
.
certificate_repository_path
,
computer_partition
[
"compute_partition_id"
]
+
".crt"
)
partition_key_file
=
os
.
path
.
join
(
self
.
certificate_repository_path
,
computer_partition
[
"compute_partition_id"
]
+
".key"
)
if
os
.
path
.
exists
(
partition_certificate_file
)
and
os
.
path
.
exists
(
partition_key_file
):
computer_partition
=
self
.
slap
.
jio_api_connector
.
get
(
computer_partition
[
"get_parameters"
],
cert_key
=
(
partition_certificate_file
,
partition_key_file
))
else
:
computer_partition
=
self
.
slap
.
jio_api_connector
.
get
(
computer_partition
[
"get_parameters"
])
computer_partition
=
self
.
slap
.
jio_api_connector
.
get
(
computer_partition
[
"get_parameters"
])
try
:
try
:
# Process the partition itself
# Process the partition itself
...
...
slapos/slap/hateoas.py
View file @
2586f844
...
@@ -87,7 +87,7 @@ class ConnectionHelper:
...
@@ -87,7 +87,7 @@ class ConnectionHelper:
cache
=
FileCache
(
os
.
path
.
expanduser
(
"~/.slapos_cached_get"
)))
cache
=
FileCache
(
os
.
path
.
expanduser
(
"~/.slapos_cached_get"
)))
def
do_request
(
self
,
method
,
path
,
params
=
None
,
data
=
None
,
headers
=
None
,
def
do_request
(
self
,
method
,
path
,
params
=
None
,
data
=
None
,
headers
=
None
,
expect_json_error
=
False
):
expect_json_error
=
False
,
cert_key
=
None
):
url
=
parse
.
urljoin
(
self
.
slapgrid_uri
,
path
)
url
=
parse
.
urljoin
(
self
.
slapgrid_uri
,
path
)
if
headers
is
None
:
if
headers
is
None
:
headers
=
{}
headers
=
{}
...
@@ -97,10 +97,8 @@ class ConnectionHelper:
...
@@ -97,10 +97,8 @@ class ConnectionHelper:
# raise ValueError('method path should be relative: %s' % path)
# raise ValueError('method path should be relative: %s' % path)
try
:
try
:
if
url
.
startswith
(
'https'
):
if
url
.
startswith
(
'https'
)
and
cert_key
is
None
:
cert
=
(
self
.
cert_file
,
self
.
key_file
)
cert_key
=
(
self
.
cert_file
,
self
.
key_file
)
else
:
cert
=
None
# XXX TODO: handle host cert verify
# XXX TODO: handle host cert verify
...
@@ -114,7 +112,7 @@ class ConnectionHelper:
...
@@ -114,7 +112,7 @@ class ConnectionHelper:
req
=
method
(
url
=
url
,
req
=
method
(
url
=
url
,
params
=
params
,
params
=
params
,
cert
=
cert
,
cert
=
cert
_key
,
verify
=
False
,
verify
=
False
,
data
=
data
,
data
=
data
,
headers
=
headers
,
headers
=
headers
,
...
...
slapos/slap/slap.py
View file @
2586f844
...
@@ -796,30 +796,34 @@ def json_loads_byteified(json_text):
...
@@ -796,30 +796,34 @@ def json_loads_byteified(json_text):
)
)
class
JioAPIConnectionHelper
(
ConnectionHelper
):
class
JioAPIConnectionHelper
(
ConnectionHelper
):
def
apiCall
(
self
,
path
,
data
,
cert_key
=
None
):
def
apiCall
(
self
,
path
,
data
):
req
=
self
.
do_request
(
requests
.
post
,
req
=
self
.
do_request
(
requests
.
post
,
path
=
path
,
path
=
path
,
data
=
json
.
dumps
(
data
),
data
=
json
.
dumps
(
data
),
headers
=
{
'Content-type'
:
'application/json'
},
headers
=
{
'Content-type'
:
'application/json'
},
expect_json_error
=
True
)
expect_json_error
=
True
,
cert_key
=
cert_key
)
return
json_loads_byteified
(
req
.
text
)
return
json_loads_byteified
(
req
.
text
)
def
get
(
self
,
data
):
def
get
(
self
,
data
,
cert_key
=
None
):
return
self
.
apiCall
(
path
=
"get/"
,
return
self
.
apiCall
(
path
=
"get/"
,
data
=
data
)
data
=
data
,
cert_key
=
cert_key
)
def
post
(
self
,
data
):
def
post
(
self
,
data
,
cert_key
=
None
):
return
self
.
apiCall
(
path
=
"post/"
,
return
self
.
apiCall
(
path
=
"post/"
,
data
=
data
)
data
=
data
,
cert_key
=
cert_key
)
def
put
(
self
,
data
):
def
put
(
self
,
data
,
cert_key
=
None
):
return
self
.
apiCall
(
path
=
"put/"
,
return
self
.
apiCall
(
path
=
"put/"
,
data
=
data
)
data
=
data
,
cert_key
=
cert_key
)
def
allDocs
(
self
,
data
):
def
allDocs
(
self
,
data
,
cert_key
=
None
):
return
self
.
apiCall
(
path
=
"allDocs/"
,
return
self
.
apiCall
(
path
=
"allDocs/"
,
data
=
data
)
data
=
data
,
cert_key
=
cert_key
)
getHateoasUrl_cache
=
{}
getHateoasUrl_cache
=
{}
getjIOAPI_cache
=
{}
getjIOAPI_cache
=
{}
...
...
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