Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_arg_parser(self, doc_parser=False):
description = textwrap.dedent(__doc__)
examples = textwrap.dedent('''
mdt-create-bvec-bval my_protocol.prtcl
mdt-create-bvec-bval my_protocol.prtcl bvec_name.bvec bval_name.bval
''')
epilog = self._format_examples(doc_parser, examples)
parser = argparse.ArgumentParser(description=description, epilog=epilog,
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('protocol', help='the protocol file').completer = FilesCompleter()
parser.add_argument('bvec', help="the output bvec file", nargs='?', default=None).completer = FilesCompleter()
parser.add_argument('bval', help="the output bvec file", nargs='?', default=None).completer = FilesCompleter()
return parser
c.argument('throughput', type=int, help='Offer Throughput (RU/s)')
# SQL database
with self.argument_context('cosmosdb sql database') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('database_name', options_list=['--name', '-n'], help="Database name")
c.argument('throughput', help='The throughput of SQL database (RU/s). Default value is 400')
# SQL container
with self.argument_context('cosmosdb sql container') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('database_name', options_list=['--database-name', '-d'], help="Database name")
c.argument('container_name', options_list=['--name', '-n'], help="Container name")
c.argument('partition_key_path', options_list=['--partition-key-path', '-p'], help='Partition Key Path, e.g., \'/address/zipcode\'')
c.argument('default_ttl', options_list=['--ttl'], type=int, help='Default TTL. If the value is missing or set to "-1", items don’t expire. If the value is set to "n", items will expire "n" seconds after last modified time.')
c.argument('indexing_policy', options_list=['--idx'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Indexing Policy, you can enter it as a string or as a file, e.g., --idx @policy-file.json or ' + SQL_GREMLIN_INDEXING_POLICY_EXAMPLE)
c.argument('unique_key_policy', options_list=['--unique-key-policy', '-u'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Unique Key Policy, you can enter it as a string or as a file, e.g., --unique-key-policy @policy-file.json or ' + SQL_UNIQUE_KEY_POLICY_EXAMPLE)
c.argument('conflict_resolution_policy', options_list=['--conflict-resolution-policy', '-c'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Conflict Resolution Policy, you can enter it as a string or as a file, e.g., --conflict-resolution-policy @policy-file.json or ' + SQL_GREMLIN_CONFLICT_RESOLUTION_POLICY_EXAMPLE)
c.argument('throughput', help='The throughput of SQL container (RU/s). Default value is 400')
# MongoDB
with self.argument_context('cosmosdb mongodb database') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('database_name', options_list=['--name', '-n'], help="Database name")
c.argument('throughput', help='The throughput of MongoDB database (RU/s). Default value is 400')
with self.argument_context('cosmosdb mongodb collection') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('database_name', options_list=['--database-name', '-d'], help="Database name")
c.argument('collection_name', options_list=['--name', '-n'], help="Collection name")
c.argument('shard_key_path', options_list=['--shard'], help="Sharding key path.")
c.argument('indexes', options_list=['--idx'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Indexes, you can enter it as a string or as a file, e.g., --idx @indexes-file.json or ' + MONGODB_INDEXES_EXAMPLE)
def _populate_matches(self, prefix):
from argcomplete.completers import FilesCompleter
completer = FilesCompleter()
self.matches = completer(prefix)
AssignmentLockMode
)
parameter_type = CLIArgumentType(
type=validate_file_or_dict,
options_list=['--parameters', '-p'],
help='Parameters in JSON string or path to JSON file.',
completer=FilesCompleter()
)
template_type = CLIArgumentType(
type=validate_file_or_dict,
options_list=['--template', '-t'],
help='ARM template in JSON string or path to JSON file.',
completer=FilesCompleter()
)
subscription_type = CLIArgumentType(
arg_group='Scope',
options_list=['--subscription', '-s'],
help='Use subscription for the scope of the blueprint. If --management-group is not specified, --subscription value or the default subscription will be used as the scope.'
)
management_group_type = CLIArgumentType(
arg_group='Scope',
options_list=['--management-group', '-m'],
help='Use management group for the scope of the blueprint.'
)
def load_arguments(self, _):
cmd.completer = ChoicesCompleter(("1", "200", "infinite",))
gr_net.add_argument("--follow-redirects", action="store_true", default=None, dest="follow_redirects", help="follow redirects")
gr_net.add_argument("--no-follow-redirects", action="store_false", default=None, dest="follow_redirects", help="do not follow redirects")
gr_net.add_argument("--follow-first", action="store_true", default=None, dest="follow_first_redirect", help="always follow a redirection on the target URL itself")
gr_net.add_argument("--no-follow-first", action="store_false", default=None, dest="follow_first_redirect", help="don't treat a redirection on a target URL as a special case")
gr_net.add_argument("--max-connections", help="maximum number of concurrent connections per host")
gr_net.add_argument("-l", "--max-links", type=int, default=None, help="maximum number of links to analyze (0 => infinite)")
gr_net.add_argument("-pu","--proxy-user", metavar="USER", help="HTTP proxy username")
gr_net.add_argument("-pp","--proxy-pass", metavar="PASS", help="HTTP proxy password")
gr_net.add_argument("-pa","--proxy-addr", metavar="ADDRESS", help="HTTP proxy address")
gr_net.add_argument("-pn","--proxy-port", metavar="PORT", help="HTTP proxy port number")
gr_net.add_argument("--cookie", metavar="COOKIE", help="set cookie for requests")
gr_net.add_argument("--user-agent", metavar="USER_AGENT", help="set a custom user agent or 'random' value")
cmd = gr_net.add_argument("--cookie-file", metavar="FILE", action=ReadValueFromFileAction, dest="cookie", help="load a cookie from file")
if autocomplete_enabled:
cmd.completer = FilesCompleter(directories=False)
gr_net.add_argument("--persistent-cache", action="store_true", dest="use_cache_db", default=True, help="use a persistent network cache [default]")
gr_net.add_argument("--volatile-cache", action="store_false", dest="use_cache_db", help="use a volatile network cache")
gr_plugins = parser.add_argument_group("plugin options")
cmd = gr_plugins.add_argument("-a", "--plugin-arg", metavar="PLUGIN:KEY=VALUE", action=SetPluginArgumentAction, dest="raw_plugin_args", help="pass an argument to a plugin")
if autocomplete_enabled:
cmd.completer = plugins_completer
cmd = gr_plugins.add_argument("-e", "--enable-plugin", metavar="PLUGIN", action=EnablePluginAction, default=[], dest="plugin_load_overrides", help="enable a plugin")
if autocomplete_enabled:
cmd.completer = plugins_completer
cmd = gr_plugins.add_argument("-d", "--disable-plugin", metavar="PLUGIN", action=DisablePluginAction, dest="plugin_load_overrides", help="disable a plugin")
if autocomplete_enabled:
cmd.completer = plugins_completer
gr_plugins.add_argument("--max-concurrent", metavar="N", type=int, default=None, help="maximum number of plugins to run concurrently")
gr_plugins.add_argument("--plugin-timeout", metavar="N", type=float, default=None, help="timeout in seconds for the execution of a plugin")
cmd = gr_plugins.add_argument("--plugins-folder", metavar="PATH", help="customize the location of the plugins" )
completer=get_resource_name_completion_list('Microsoft.ContainerService/ManagedClusters'))
c.argument('kubernetes_version', options_list=['--kubernetes-version', '-k'], validator=validate_k8s_version)
c.argument('node_count', options_list=['--node-count', '-c'], type=int)
c.argument('tags', tags_type)
with self.argument_context('aks create') as c:
c.argument('name', validator=validate_linux_host_name)
c.argument('kubernetes_version', completer=get_k8s_versions_completion_list)
c.argument('admin_username', options_list=['--admin-username', '-u'], default='azureuser')
c.argument('dns_name_prefix', options_list=['--dns-name-prefix', '-p'])
c.argument('generate_ssh_keys', action='store_true', validator=validate_create_parameters)
c.argument('node_vm_size', options_list=['--node-vm-size', '-s'], completer=get_vm_size_completion_list)
c.argument('nodepool_name', type=str, default='nodepool1',
help='Node pool name, upto 12 alphanumeric characters', validator=validate_nodepool_name)
c.argument('ssh_key_value', required=False, type=file_type, default=os.path.join('~', '.ssh', 'id_rsa.pub'),
completer=FilesCompleter(), validator=validate_ssh_key)
c.argument('aad_client_app_id')
c.argument('aad_server_app_id')
c.argument('aad_server_app_secret')
c.argument('aad_tenant_id')
c.argument('dns_service_ip')
c.argument('docker_bridge_address')
c.argument('load_balancer_sku', type=str, validator=validate_load_balancer_sku)
c.argument('load_balancer_managed_outbound_ip_count', type=int)
c.argument('load_balancer_outbound_ips', type=str, validator=validate_load_balancer_outbound_ips)
c.argument('load_balancer_outbound_ip_prefixes', type=str, validator=validate_load_balancer_outbound_ip_prefixes)
c.argument('enable_cluster_autoscaler', action='store_true')
c.argument('min_count', type=int, validator=validate_nodes_count)
c.argument('max_count', type=int, validator=validate_nodes_count)
c.argument('vm_set_type', type=str, validator=validate_vm_set_type)
c.argument('zones', zones_type, options_list=['--zones', '-z'], help='Space-separated list of availability zones where agent nodes will be placed.')
c.argument('enable_addons', options_list=['--enable-addons', '-a'])
if autocomplete_enabled:
cmd.completer = ChoicesCompleter(("console", "disabled")) ##, "web"))
gr_main.add_argument("-v", "--verbose", action="count", help="increase output verbosity")
gr_main.add_argument("-q", "--quiet", action="store_const", dest="verbose", const=0, help="suppress text output")
gr_main.add_argument("--color", action="store_true", default=None, dest="color", help="use colors in console output")
gr_main.add_argument("--no-color", action="store_false", default=None, dest="color", help="suppress colors in console output")
gr_audit = parser.add_argument_group("audit options")
gr_audit.add_argument("--audit-name", metavar="NAME", help="customize the audit name")
cmd = gr_audit.add_argument("-db", "--audit-db", metavar="DATABASE", dest="audit_db", help="specify a database filename")
if autocomplete_enabled:
cmd.completer = FilesCompleter(allowednames=(".db",), directories=False)
gr_audit.add_argument("-nd", "--no-db", dest="audit_db", action="store_const", const=":memory:", help="do not store the results in a database")
cmd = gr_audit.add_argument("-i", "--input", dest="imports", metavar="FILENAME", action="append", help="read results from external tools right before the audit")
if autocomplete_enabled:
cmd.completer = FilesCompleter(allowednames=(".csv", ".xml", ".nessus"), directories=False)
gr_audit.add_argument("-ni", "--no-input", dest="disable_importing", action="store_true", default=False, help="do not read results from external tools")
gr_report = parser.add_argument_group("report options")
cmd = gr_report.add_argument("-o", "--output", dest="reports", metavar="FILENAME", action="append", help="write the results of the audit to this file (use - for stdout)")
if autocomplete_enabled:
cmd.completer = FilesCompleter(allowednames=(".html", ".rst", ".txt"), directories=False)
gr_report.add_argument("-no", "--no-output", dest="disable_reporting", action="store_true", default=False, help="do not output the results")
gr_report.add_argument("--full", action="store_false", default=None, dest="only_vulns", help="produce fully detailed reports")
gr_report.add_argument("--brief", action="store_true", dest="only_vulns", help="report only the highlights")
gr_net = parser.add_argument_group("network options")
gr_net.add_argument("--allow-subdomains", action="store_true", default=None, dest="include_subdomains", help="include subdomains in the target scope")
gr_net.add_argument("--forbid-subdomains", action="store_false", default=None, dest="include_subdomains", help="do not include subdomains in the target scope")
gr_net.add_argument("--parent", action="store_true", default=None, dest="allow_parent", help="include parent folders in the target scope")
gr_net.add_argument("-np", "--no-parent", action="store_false", default=None, dest="allow_parent", help="do not include parent folders in the target scope")
cmd = gr_net.add_argument("-r", "--depth", help="maximum spidering depth (use \"infinite\" for no limit)")
if autocomplete_enabled:
optionally from vault
"""
parser = get_parser()
parser.add_argument("-s", "--stack", help="Stack name for values. " +
"Automatically resolved on ec2" +
" instances")
parser.add_argument("-v", "--vault", help="Use vault values as well." +
"Vault resovled from env " +
"variables or default is used",
action="store_true")
parser.add_argument("-o", "--output", help="Output file")
parser.add_argument("-e", "--encoding", help="Encoding to use for the " +
"file. Defaults to utf-8",
default='utf-8')
parser.add_argument("file", help="File to interpolate").completer = \
FilesCompleter()
argcomplete.autocomplete(parser)
args = parser.parse_args()
interpolate_file(args.file, stack_name=args.stack, use_vault=args.vault,
destination=args.output, encoding=args.encoding)
def list_file_to_json():
""" Convert a file with an entry on each line to a json document with
a single element (name as argument) containg file rows as list.
"""
parser = get_parser()
parser.add_argument("arrayname", help="The name in the json object given" +
"to the array").completer = \
ChoicesCompleter(())
parser.add_argument("file", help="The file to parse").completer = \
FilesCompleter()
argcomplete.autocomplete(parser)
args = parser.parse_args()
if not os.path.isfile(args.file):
parser.error(args.file + " not found")
content = [line.rstrip('\n') for line in open(args.file)]
json.dump({args.arrayname: content}, sys.stdout)