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:
Tim Rupp 2017-12-08 15:39:04 -08:00 committed by GitHub
parent e4abb0de33
commit 11580947f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 90 additions and 29 deletions

View file

@ -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))

View file

@ -642,23 +642,35 @@ class ArgumentSpec(object):
self.f5_product_name = 'bigip'
def main():
def cleanup_tokens(client):
try:
spec = ArgumentSpec()
client = AnsibleF5Client(
argument_spec=spec.argument_spec,
supports_check_mode=spec.supports_check_mode,
f5_product_name=spec.f5_product_name
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(
argument_spec=spec.argument_spec,
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")
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))

View file

@ -945,17 +945,27 @@ class ArgumentSpec(object):
]
def main():
def cleanup_tokens(client):
try:
spec = ArgumentSpec()
client = AnsibleF5Client(
argument_spec=spec.argument_spec,
supports_check_mode=spec.supports_check_mode,
f5_product_name=spec.f5_product_name,
mutually_exclusive=spec.mutually_exclusive
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(
argument_spec=spec.argument_spec,
supports_check_mode=spec.supports_check_mode,
f5_product_name=spec.f5_product_name,
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))

View file

@ -495,16 +495,26 @@ class ArgumentSpec(object):
self.f5_product_name = 'bigip'
def main():
def cleanup_tokens(client):
try:
spec = ArgumentSpec()
client = AnsibleF5Client(
argument_spec=spec.argument_spec,
supports_check_mode=spec.supports_check_mode,
f5_product_name=spec.f5_product_name
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(
argument_spec=spec.argument_spec,
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")
@ -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))

View file

@ -543,16 +543,26 @@ class ArgumentSpec(object):
self.f5_product_name = 'bigip'
def main():
def cleanup_tokens(client):
try:
spec = ArgumentSpec()
client = AnsibleF5Client(
argument_spec=spec.argument_spec,
supports_check_mode=spec.supports_check_mode,
f5_product_name=spec.f5_product_name
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(
argument_spec=spec.argument_spec,
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")
@ -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))