#!/usr/bin/env python
DOCUMENTATION = '''
---
module: hashivault_auth_enable
version_added: "3.5.2"
short_description: Hashicorp Vault auth enable module
description:
    - Module to enable authentication backends in Hashicorp Vault.
options:
    url:
        description:
            - url for vault
        default: to environment variable VAULT_ADDR
    ca_cert:
        description:
            - "path to a PEM-encoded CA cert file to use to verify the Vault server TLS certificate"
        default: to environment variable VAULT_CACERT
    ca_path:
        description:
            - "path to a directory of PEM-encoded CA cert files to verify the Vault server TLS certificate : if ca_cert is specified, its value will take precedence"
        default: to environment variable VAULT_CAPATH
    client_cert:
        description:
            - "path to a PEM-encoded client certificate for TLS authentication to the Vault server"
        default: to environment variable VAULT_CLIENT_CERT
    client_key:
        description:
            - "path to an unencrypted PEM-encoded private key matching the client certificate"
        default: to environment variable VAULT_CLIENT_KEY
    verify:
        description:
            - "if set, do not verify presented TLS certificate before communicating with Vault server : setting this variable is not recommended except during testing"
        default: to environment variable VAULT_SKIP_VERIFY
    authtype:
        description:
            - "authentication type to use: token, userpass, github, ldap"
        default: token
    token:
        description:
            - token for vault
        default: to environment variable VAULT_TOKEN
    username:
        description:
            - username to login to vault.
    password:
        description:
            - password to login to vault.
    name:
        description:
            - name of authenticator
    description:
        description:
            - description of authenticator
    mount_point
        description:
            - location where this auth backend will be mounted 
'''
EXAMPLES = '''
---
- hosts: localhost
  tasks:
    - hashivault_auth_enable:
        name: "userpass"
'''


def main():
    argspec = hashivault_argspec()
    argspec['mount_point'] = dict(required=True, type='str')
    argspec['default_lease_ttl'] = dict(required=False, type='int', default=None)
    argspec['max_lease_ttl'] = dict(required=False, type='int', default=None)
    module = hashivault_init(argspec)
    result = hashivault_mount_tune(module)
    if result.get('failed'):
        module.fail_json(**result)
    else:
        module.exit_json(**result)


from ansible.module_utils.basic import *
from ansible.module_utils.hashivault import *

@hashiwrapper
def hashivault_mount_tune(module):
    client = hashivault_auth_client(module.params)
    mount_point = module.params.get('mount_point')
    default_lease_ttl = module.params.get('default_lease_ttl')
    max_lease_ttl = module.params.get('max_lease_ttl')

    changed = False
    current_tuning = client.get_secret_backend_tuning(None, mount_point=mount_point)
    current_default_lease_ttl = current_tuning.get('default_lease_ttl')
    current_max_lease_ttl = current_tuning.get('max_lease_ttl')

    if (current_default_lease_ttl != default_lease_ttl) or (current_max_lease_ttl != max_lease_ttl):
        changed = True

    if not module.check_mode:
        client.tune_secret_backend(None, mount_point=mount_point, default_lease_ttl=default_lease_ttl, max_lease_ttl=max_lease_ttl)

    return {'changed': changed}

if __name__ == '__main__':
    main()

@@ -58,26 +58,25 @@
 hivault_
-auth_enabl
+mount_tun
 e%0Aversio
@@ -131,26 +131,20 @@
 ult 
-auth enable module
+tune backend
 %0Ades
@@ -176,30 +176,25 @@
  enable 
-authentication
+tuning of
  backend
@@ -199,25 +199,25 @@
 nds in Hashi
-c
+C
 orp Vault.%0Ao
@@ -1829,21 +1829,27 @@
 lt.%0A    
-name:
+mount_point
 %0A       
@@ -1880,211 +1880,366 @@
   - 
-name of authenticator%0A    description:%0A        description:%0A            - description of authenticator%0A    mount_point%0A        description:%0A            - location where this auth backend will be mounted 
+location where this auth backend will be mounted%0A    default_lease_ttl:%0A        description:%0A            - Configures the default lease duration for tokens and secrets. This is an integer value in seconds.%0A    max_lease_ttl:%0A        description:%0A            - Configures the maximum lease duration for tokens and secrets. This is an integer value in seconds.
 %0A'''

Update docs