Adds token cleanup to some f5 modules (#33728)
The tokens can build up over time and if too many accumulate, it prevents you from logging in. This adds cleanup
This commit is contained in:
parent
e4abb0de33
commit
11580947f8
5 changed files with 90 additions and 29 deletions
|
@ -566,6 +566,16 @@ class ArgumentSpec(object):
|
|||
self.f5_product_name = 'bigip'
|
||||
|
||||
|
||||
def cleanup_tokens(client):
|
||||
try:
|
||||
resource = client.api.shared.authz.tokens_s.token.load(
|
||||
name=client.api.icrs.token
|
||||
)
|
||||
resource.delete()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
spec = ArgumentSpec()
|
||||
|
||||
|
@ -574,6 +584,7 @@ def main():
|
|||
supports_check_mode=spec.supports_check_mode,
|
||||
f5_product_name=spec.f5_product_name
|
||||
)
|
||||
|
||||
try:
|
||||
if not HAS_F5SDK:
|
||||
raise F5ModuleError("The python f5-sdk module is required")
|
||||
|
@ -583,8 +594,10 @@ def main():
|
|||
|
||||
mm = ModuleManager(client)
|
||||
results = mm.exec_module()
|
||||
cleanup_tokens(client)
|
||||
client.module.exit_json(**results)
|
||||
except F5ModuleError as e:
|
||||
cleanup_tokens(client)
|
||||
client.module.fail_json(msg=str(e))
|
||||
|
||||
|
||||
|
|
|
@ -642,8 +642,17 @@ class ArgumentSpec(object):
|
|||
self.f5_product_name = 'bigip'
|
||||
|
||||
|
||||
def main():
|
||||
def cleanup_tokens(client):
|
||||
try:
|
||||
resource = client.api.shared.authz.tokens_s.token.load(
|
||||
name=client.api.icrs.token
|
||||
)
|
||||
resource.delete()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
spec = ArgumentSpec()
|
||||
|
||||
client = AnsibleF5Client(
|
||||
|
@ -652,13 +661,16 @@ def main():
|
|||
f5_product_name=spec.f5_product_name
|
||||
)
|
||||
|
||||
try:
|
||||
if not HAS_F5SDK:
|
||||
raise F5ModuleError("The python f5-sdk module is required")
|
||||
|
||||
mm = ModuleManager(client)
|
||||
results = mm.exec_module()
|
||||
cleanup_tokens(client)
|
||||
client.module.exit_json(**results)
|
||||
except F5ModuleError as e:
|
||||
cleanup_tokens(client)
|
||||
client.module.fail_json(msg=str(e))
|
||||
|
||||
|
||||
|
|
|
@ -945,8 +945,17 @@ class ArgumentSpec(object):
|
|||
]
|
||||
|
||||
|
||||
def main():
|
||||
def cleanup_tokens(client):
|
||||
try:
|
||||
resource = client.api.shared.authz.tokens_s.token.load(
|
||||
name=client.api.icrs.token
|
||||
)
|
||||
resource.delete()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
spec = ArgumentSpec()
|
||||
|
||||
client = AnsibleF5Client(
|
||||
|
@ -956,6 +965,7 @@ def main():
|
|||
mutually_exclusive=spec.mutually_exclusive
|
||||
)
|
||||
|
||||
try:
|
||||
if not HAS_F5SDK:
|
||||
raise F5ModuleError("The python f5-sdk module is required")
|
||||
|
||||
|
@ -964,8 +974,10 @@ def main():
|
|||
|
||||
mm = ModuleManager(client)
|
||||
results = mm.exec_module()
|
||||
cleanup_tokens(client)
|
||||
client.module.exit_json(**results)
|
||||
except F5ModuleError as e:
|
||||
cleanup_tokens(client)
|
||||
client.module.fail_json(msg=str(e))
|
||||
|
||||
|
||||
|
|
|
@ -495,8 +495,17 @@ class ArgumentSpec(object):
|
|||
self.f5_product_name = 'bigip'
|
||||
|
||||
|
||||
def main():
|
||||
def cleanup_tokens(client):
|
||||
try:
|
||||
resource = client.api.shared.authz.tokens_s.token.load(
|
||||
name=client.api.icrs.token
|
||||
)
|
||||
resource.delete()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
spec = ArgumentSpec()
|
||||
|
||||
client = AnsibleF5Client(
|
||||
|
@ -505,6 +514,7 @@ def main():
|
|||
f5_product_name=spec.f5_product_name
|
||||
)
|
||||
|
||||
try:
|
||||
if not HAS_F5SDK:
|
||||
raise F5ModuleError("The python f5-sdk module is required")
|
||||
|
||||
|
@ -513,8 +523,10 @@ def main():
|
|||
|
||||
mm = ModuleManager(client)
|
||||
results = mm.exec_module()
|
||||
cleanup_tokens(client)
|
||||
client.module.exit_json(**results)
|
||||
except F5ModuleError as e:
|
||||
cleanup_tokens(client)
|
||||
client.module.fail_json(msg=str(e))
|
||||
|
||||
|
||||
|
|
|
@ -543,8 +543,17 @@ class ArgumentSpec(object):
|
|||
self.f5_product_name = 'bigip'
|
||||
|
||||
|
||||
def main():
|
||||
def cleanup_tokens(client):
|
||||
try:
|
||||
resource = client.api.shared.authz.tokens_s.token.load(
|
||||
name=client.api.icrs.token
|
||||
)
|
||||
resource.delete()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
spec = ArgumentSpec()
|
||||
|
||||
client = AnsibleF5Client(
|
||||
|
@ -553,6 +562,7 @@ def main():
|
|||
f5_product_name=spec.f5_product_name
|
||||
)
|
||||
|
||||
try:
|
||||
if not HAS_F5SDK:
|
||||
raise F5ModuleError("The python f5-sdk module is required")
|
||||
|
||||
|
@ -561,8 +571,10 @@ def main():
|
|||
|
||||
mm = ModuleManager(client)
|
||||
results = mm.exec_module()
|
||||
cleanup_tokens(client)
|
||||
client.module.exit_json(**results)
|
||||
except F5ModuleError as e:
|
||||
cleanup_tokens(client)
|
||||
client.module.fail_json(msg=str(e))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue