Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
proxy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
7
Issues
7
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
haas
proxy
Commits
544efe50
Verified
Commit
544efe50
authored
Jun 24, 2020
by
Štěpán Henek
🐻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend KeyError Ignored methods (when channel not opened)
parent
945658cc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
11 deletions
+32
-11
haas_proxy/proxy.py
haas_proxy/proxy.py
+32
-11
No files found.
haas_proxy/proxy.py
View file @
544efe50
...
...
@@ -40,11 +40,42 @@ class ProxyService(service.Service):
return
self
.
_port
.
stopListening
()
class
SSHConnection
(
SSHConnectionTwisted
):
class
SilenceKeyErrorsMeta
(
type
):
"""
Meta class to silence KeyErrors from given set of methods,
Note that the methods will return None on failure
"""
def
__new__
(
cls
,
name
,
bases
,
dct
):
wrapped_type
=
super
().
__new__
(
cls
,
name
,
bases
,
dct
)
for
method_name
in
wrapped_type
.
IGNORED_KEY_ERROR_METHODS
:
# pylint: disable=invalid-name,inconsistent-return-statements
def
silenced_method
(
*
args
,
**
kwargs
):
try
:
# pylint: disable=cell-var-from-loop
return
getattr
(
SSHConnectionTwisted
,
method_name
)(
*
args
,
**
kwargs
)
except
KeyError
:
pass
setattr
(
wrapped_type
,
method_name
,
silenced_method
)
return
wrapped_type
class
SSHConnection
(
SSHConnectionTwisted
,
metaclass
=
SilenceKeyErrorsMeta
):
"""
Overridden SSHConnection for disabling logs a traceback about a failed direct-tcpip connections
"""
# Some packets send data to the channel even it's not successfully opened.
# Very probably direct-tcpip types which has bad packet resulting in not
# responding in `ssh_CHANNEL_OPEN`. Ignore it as it's unimportant.
IGNORED_KEY_ERROR_METHODS
=
(
"ssh_CHANNEL_DATA"
,
"ssh_CHANNEL_CLOSE"
,
"ssh_CHANNEL_EOF"
,
)
# pylint: disable=invalid-name,inconsistent-return-statements
def
ssh_CHANNEL_OPEN
(
self
,
packet
):
# pylint: disable=unbalanced-tuple-unpacking
...
...
@@ -66,16 +97,6 @@ class SSHConnection(SSHConnectionTwisted):
common
.
NS
(
networkString
(
'unknown failure'
))
+
common
.
NS
(
b
''
)
)
# pylint: disable=invalid-name,inconsistent-return-statements
def
ssh_CHANNEL_DATA
(
self
,
packet
):
try
:
return
SSHConnectionTwisted
.
ssh_CHANNEL_DATA
(
self
,
packet
)
except
KeyError
:
# Some packets send data to the channel even it's not successfully opened.
# Very probably direct-tcpip types which has bad packet resulting in not
# responding in `ssh_CHANNEL_OPEN`. Ignore it as it's unimportant.
pass
# pylint: disable=abstract-method
class
ProxySSHFactory
(
factory
.
SSHFactory
):
...
...
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