Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pulsar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NDIP
Pulsar
Commits
d3a76e29
Commit
d3a76e29
authored
10 years ago
by
John Chilton
Browse files
Options
Downloads
Patches
Plain Diff
Slight code duplication reduction related to serializing ssh keys.
parent
b4af0ee9
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
pulsar/client/action_mapper.py
+21
-18
21 additions, 18 deletions
pulsar/client/action_mapper.py
with
21 additions
and
18 deletions
pulsar/client/action_mapper.py
+
21
−
18
View file @
d3a76e29
from
contextlib
import
contextmanager
from
json
import
load
from
os
import
makedirs
from
os
import
unlink
...
...
@@ -436,7 +437,13 @@ class PubkeyAuthenticatedTransferAction(BaseAction):
ssh_user
=
self
.
ssh_user
,
ssh_host
=
self
.
ssh_host
,
ssh_port
=
self
.
ssh_port
)
def
serialize_ssh_key
(
self
):
@contextmanager
def
_serialized_key
(
self
):
key_file
=
self
.
__serialize_ssh_key
()
yield
key_file
self
.
__cleanup_ssh_key
(
key_file
)
def
__serialize_ssh_key
(
self
):
f
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
)
if
self
.
ssh_key
is
not
None
:
f
.
write
(
self
.
ssh_key
)
...
...
@@ -444,7 +451,7 @@ class PubkeyAuthenticatedTransferAction(BaseAction):
raise
Exception
(
"
SSH_KEY not available
"
)
return
f
.
name
def
cleanup_ssh_key
(
self
,
keyfile
):
def
__
cleanup_ssh_key
(
self
,
keyfile
):
if
exists
(
keyfile
):
unlink
(
keyfile
)
...
...
@@ -461,16 +468,14 @@ class RsyncTransferAction(PubkeyAuthenticatedTransferAction):
ssh_key
=
action_dict
[
"
ssh_key
"
])
def
write_to_path
(
self
,
path
):
key_file
=
self
.
serialize_ssh_key
()
rsync_get_file
(
self
.
path
,
path
,
self
.
ssh_user
,
self
.
ssh_host
,
self
.
ssh_port
,
key_file
)
self
.
cleanup_ssh_key
(
key_file
)
with
self
.
_serialized_key
()
as
key_file
:
rsync_get_file
(
self
.
path
,
path
,
self
.
ssh_user
,
self
.
ssh_host
,
self
.
ssh_port
,
key_file
)
def
write_from_path
(
self
,
pulsar_path
):
key_file
=
self
.
serialize_ssh_key
()
rsync_post_file
(
pulsar_path
,
self
.
path
,
self
.
ssh_user
,
self
.
ssh_host
,
self
.
ssh_port
,
key_file
)
self
.
cleanup_ssh_key
(
key_file
)
with
self
.
_serialized_key
()
as
key_file
:
rsync_post_file
(
pulsar_path
,
self
.
path
,
self
.
ssh_user
,
self
.
ssh_host
,
self
.
ssh_port
,
key_file
)
class
ScpTransferAction
(
PubkeyAuthenticatedTransferAction
):
...
...
@@ -485,16 +490,14 @@ class ScpTransferAction(PubkeyAuthenticatedTransferAction):
ssh_key
=
action_dict
[
"
ssh_key
"
])
def
write_to_path
(
self
,
path
):
key_file
=
self
.
serialize_ssh_key
()
scp_get_file
(
self
.
path
,
path
,
self
.
ssh_user
,
self
.
ssh_host
,
self
.
ssh_port
,
key_file
)
self
.
cleanup_ssh_key
(
key_file
)
with
self
.
_serialized_key
()
as
key_file
:
scp_get_file
(
self
.
path
,
path
,
self
.
ssh_user
,
self
.
ssh_host
,
self
.
ssh_port
,
key_file
)
def
write_from_path
(
self
,
pulsar_path
):
key_file
=
self
.
serialize_ssh_key
()
scp_post_file
(
pulsar_path
,
self
.
path
,
self
.
ssh_user
,
self
.
ssh_host
,
self
.
ssh_port
,
key_file
)
self
.
cleanup_ssh_key
(
key_file
)
with
self
.
_serialized_key
()
as
key_file
:
scp_post_file
(
pulsar_path
,
self
.
path
,
self
.
ssh_user
,
self
.
ssh_host
,
self
.
ssh_port
,
key_file
)
class
MessageAction
(
object
):
...
...
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