#!/usr/bin/python3
"""Get an API token for lavtomate via Kerberos authentication.

Usage:
  lavtomate-get-token [TTL] [DESCRIPTION]

Arguments:
  TTL          token lifetime: "8h" (hours), "7d" (days), "30m" or seconds (default: 8h)
  DESCRIPTION  token description (default: ssh-session-HOSTNAME-DATE)

Token caching:
  Tokens are cached in ~/.cache/lavtomate/ per server URL and description, files
  0600, with the expiry the server reported. Use LAVTOMATE_NO_CACHE=1 to force
  creating a new token. A new token revokes the previous one of the description.

Without a Kerberos ticket, a token forwarded in LAVTOMATE_API_KEY (lavtomate-ssh)
is printed as is.

Compatibility wrapper for 'lavtomate-api token' (python3-module-lavtomate-client).
"""

import sys

from lavtomate_client.cli import token

if __name__ == "__main__":
    args = sys.argv[1:]
    if args and args[0] in ("-h", "--help"):
        print(__doc__.strip())
        sys.exit(0)
    if len(args) > 2:
        print("Usage: lavtomate-get-token [TTL] [DESCRIPTION]", file=sys.stderr)
        sys.exit(2)
    sys.exit(token(*args))
