#!/usr/bin/env python
# -*- mode: python -*-
# Copyright 2014 Cloudbase Solutions SRL.
# Copyright 2014 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Generates a x509 certificate used for WinRM service on Windows nodes."""

from __future__ import (
    absolute_import,
    print_function,
    unicode_literals,
    )

str = None

__metaclass__ = type

from maasserver.x509 import WinRMX509
import argparse


def make_argparser(description):
    """Create an `ArgumentParser` for this script."""
    x509 = WinRMX509("winrm_client_cert")
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument(
        '--certname', '-c', default="winrm_client_cert",
        help="x509 certificate name. (Default: winrm_client_cert)")
    parser.add_argument(
        '--store', '-s',
        help="Destination folder for x509 cert. (Default: ~/.ssl)")
    parser.add_argument(
        '--upn', '-u',
        help="UPN name for certificate. (Default: %s)" % x509.upn_name)
    return parser


if __name__ == "__main__":
    parser = make_argparser(__doc__)
    args = parser.parse_args()
    x509 = WinRMX509(args.certname, upn_name=args.upn, cert_dir=args.store)
    x509.create_cert(print_cert=True)
