mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Auth to become (#33319)
* terminal.on_(de)?authorize -> terminal.on_(un)?become * Update network_cli * Readd on_(de)?authorize as wrappers * Update tests
This commit is contained in:
@@ -91,7 +91,7 @@ class TerminalBase(with_metaclass(ABCMeta, object)):
|
||||
"""
|
||||
pass
|
||||
|
||||
def on_authorize(self, passwd=None):
|
||||
def on_become(self, passwd=None):
|
||||
"""Called when privilege escalation is requested
|
||||
|
||||
:kwarg passwd: String containing the password
|
||||
@@ -103,7 +103,7 @@ class TerminalBase(with_metaclass(ABCMeta, object)):
|
||||
"""
|
||||
pass
|
||||
|
||||
def on_deauthorize(self):
|
||||
def on_unbecome(self):
|
||||
"""Called when privilege deescalation is requested
|
||||
|
||||
This method is called when the privilege changed from escalated
|
||||
@@ -111,3 +111,15 @@ class TerminalBase(with_metaclass(ABCMeta, object)):
|
||||
of this method to actually perform the deauthorization procedure
|
||||
"""
|
||||
pass
|
||||
|
||||
def on_authorize(self, passwd=None):
|
||||
"""Deprecated method for privilege escalation
|
||||
|
||||
:kwarg passwd: String containing the password
|
||||
"""
|
||||
return self.on_become(passwd)
|
||||
|
||||
def on_deauthorize(self):
|
||||
"""Deprecated method for privilege deescalation
|
||||
"""
|
||||
return self.on_unbecome()
|
||||
|
||||
@@ -50,7 +50,7 @@ class TerminalModule(TerminalBase):
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to disable terminal pager')
|
||||
|
||||
def on_authorize(self, passwd=None):
|
||||
def on_become(self, passwd=None):
|
||||
if self._get_prompt().strip().endswith(b'#'):
|
||||
return
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ class TerminalModule(TerminalBase):
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
||||
|
||||
def on_authorize(self, passwd=None):
|
||||
def on_become(self, passwd=None):
|
||||
if self._get_prompt().endswith(b'#'):
|
||||
return
|
||||
|
||||
@@ -67,7 +67,7 @@ class TerminalModule(TerminalBase):
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to elevate privilege to enable mode')
|
||||
|
||||
def on_deauthorize(self):
|
||||
def on_unbecome(self):
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None:
|
||||
# if prompt is None most likely the terminal is hung up at a prompt
|
||||
|
||||
@@ -42,7 +42,7 @@ class TerminalModule(TerminalBase):
|
||||
re.compile(br"'[^']' +returned error code: ?\d+"),
|
||||
]
|
||||
|
||||
def on_authorize(self, passwd=None):
|
||||
def on_become(self, passwd=None):
|
||||
if self._get_prompt().endswith('#'):
|
||||
return
|
||||
|
||||
@@ -60,7 +60,7 @@ class TerminalModule(TerminalBase):
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
||||
|
||||
def on_deauthorize(self):
|
||||
def on_unbecome(self):
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None:
|
||||
# if prompt is None most likely the terminal is hung up at a prompt
|
||||
|
||||
@@ -51,7 +51,7 @@ class TerminalModule(TerminalBase):
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
||||
|
||||
def on_authorize(self, passwd=None):
|
||||
def on_become(self, passwd=None):
|
||||
if self._get_prompt().endswith(b'#'):
|
||||
return
|
||||
|
||||
@@ -65,7 +65,7 @@ class TerminalModule(TerminalBase):
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to elevate privilege to enable mode')
|
||||
|
||||
def on_deauthorize(self):
|
||||
def on_unbecome(self):
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None:
|
||||
# if prompt is None most likely the terminal is hung up at a prompt
|
||||
|
||||
@@ -67,7 +67,7 @@ class TerminalModule(TerminalBase):
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
||||
|
||||
def on_authorize(self, passwd=None):
|
||||
def on_become(self, passwd=None):
|
||||
if self._get_prompt().endswith(b'#'):
|
||||
return
|
||||
|
||||
@@ -87,7 +87,7 @@ class TerminalModule(TerminalBase):
|
||||
msg = 'unable to elevate privilege to enable mode'
|
||||
raise AnsibleConnectionFailure(msg)
|
||||
|
||||
def on_deauthorize(self):
|
||||
def on_unbecome(self):
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None:
|
||||
# if prompt is None most likely the terminal is hung up at a prompt
|
||||
|
||||
@@ -55,7 +55,7 @@ class TerminalModule(TerminalBase):
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
||||
|
||||
def on_authorize(self, passwd=None):
|
||||
def on_become(self, passwd=None):
|
||||
if self._get_prompt().endswith(b'#'):
|
||||
return
|
||||
|
||||
@@ -69,7 +69,7 @@ class TerminalModule(TerminalBase):
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to elevate privilege to enable mode')
|
||||
|
||||
def on_deauthorize(self):
|
||||
def on_unbecome(self):
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None:
|
||||
# if prompt is None most likely the terminal is hung up at a prompt
|
||||
|
||||
@@ -52,7 +52,7 @@ class TerminalModule(TerminalBase):
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to set terminal parameters')
|
||||
|
||||
def on_authorize(self, passwd=None):
|
||||
def on_become(self, passwd=None):
|
||||
if self._get_prompt().endswith(b'#'):
|
||||
return
|
||||
|
||||
@@ -68,7 +68,7 @@ class TerminalModule(TerminalBase):
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to elevate privilege to enable mode')
|
||||
|
||||
def on_deauthorize(self):
|
||||
def on_unbecome(self):
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None:
|
||||
# if prompt is None most likely the terminal is hung up at a prompt
|
||||
|
||||
@@ -48,7 +48,7 @@ class TerminalModule(TerminalBase):
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to disable terminal pager')
|
||||
|
||||
def on_authorize(self, passwd=None):
|
||||
def on_become(self, passwd=None):
|
||||
if self._get_prompt().strip().endswith(b'#'):
|
||||
return
|
||||
|
||||
@@ -64,7 +64,7 @@ class TerminalModule(TerminalBase):
|
||||
except AnsibleConnectionFailure:
|
||||
raise AnsibleConnectionFailure('unable to elevate privilege to enable mode')
|
||||
|
||||
def on_deauthorize(self):
|
||||
def on_unbecome(self):
|
||||
prompt = self._get_prompt()
|
||||
if prompt is None:
|
||||
# if prompt is None most likely the terminal is hung up at a prompt
|
||||
|
||||
Reference in New Issue
Block a user