def parse_args()

in packages/aws-rfdk/lib/deadline/scripts/python/client-rq-connection.py [0:0]


def parse_args(args):
    """
    Parses all command line arguments and convert them into named tuples

    :param args: A list of command line arguments
    :return: A configuration object containing the parsed arguments
    """

    def _secret(value):
        """
        A type function for converting args that represent secrets into a named Tuple

        :param value: The string representing the argument
        :return: AwsSecret or FileSecret based on the value
        :exception argparse.ArgumentTypeError: if the argument cannot be converted properly.
        """

        match = SECRET_ARN_RE.match(value)
        if match:
            named_groups = match.groupdict()
            return AwsSecret( arn=value,region=named_groups["Region"] )

        match = FILE_URI_RE.match( value )
        if match:
            named_groups = match.groupdict()
            return FileSecret( arn=named_groups['FilePath'] )

        raise argparse.ArgumentTypeError('Given argument "%s" is not a valid secret' % value)

    def _render_queue(value):
        """
        A type function for converting args that represent render queue URI's into a named Tuple

        :param value: The string representing the argument
        :return: A RenderQueue named tuple
        :exception argparse.ArgumentTypeError: if the argument cannot be converted properly.
        """

        match = RENDER_QUEUE_URI_RE.match(value)
        if match:
            named_groups = match.groupdict()
            return RenderQueue(
                uri=value,
                scheme=named_groups['Scheme'],
                address=named_groups['Address']
            )
        raise argparse.ArgumentTypeError()

    parser = argparse.ArgumentParser(description="Configures the Deadline Client to connect to the Render Queue")
    parser.add_argument(
        '--render-queue',
        required=True,
        type=_render_queue,
        help="Specifies how to connect to the Deadline Render Queue. The URI must must include"
             " the scheme (http vs https), a hostname and an optional port number.\n\n"
             "    http[s]://<HOSTNAME>[:<PORT>]\n\n"
             "When the URI is https, then one (and only one) of tls-ca and client-tls-cert may be specified"
    )
    parser.add_argument(
        '--tls-ca',
        type=_secret,
        help="Specifies a X509 CA certificate to use to validate the TLS server certificate."
    )
    parser.add_argument(
        '--client-tls-cert',
        type=_secret,
        help="Specifies a TLS client certificate that will be presented for authentication to the Deadline Render Queue."
    )
    parser.add_argument(
        '--client-tls-cert-passphrase',
        type=_secret,
        help="Specifies a X509 CA certificate to use to validate the TLS server certificate."
    )

    return parser.parse_args(args)