l#gk,ddlZddlZddlZddlmZmZddlmZddlm Z m Z m Z m Z m Z mZddlmZddlmZddlmZddlmZdd lmZGd d Zd ZGd dZdZdZdZdZ dZ!dZ"eddZ#dS)N) lru_cachepartial)chain)AnyDictIterableIteratorMappingTuple)app)Core)prepare_schema) RpcClient)EXITCODE_NOT_FOUNDceZdZeeeefZdZe defdZ e dZ defdZ defdZ defdZdefdZdefd Zd Zd S) SchemaToArgparsec||_|d|_|d|_|dd|_|d|_|dd|_|d|_|dd|_|d |_ dS) NalloweddefaultenvvarFhelp positionalrenamerequiredtype) _argumentget_allowed_default_envvar_help _positional_rename _required_type)selfargumentoptionss R/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/utils/parsers.py__init__zSchemaToArgparse.__init__s&")++i"8"8 $[[33 #KK%88 !++f-- !(\5!A!A#KK11 &{{:u==!++f-- returncZ|jr|jSd|jddzS)N--_-)r"rreplacer&s r)argnamezSchemaToArgparse.argnames2   "> !dn,,S#6666r+c  tt||||||}|SN)dictrchoicesrrmetavarnargsr)r&argparse_optionss r)r(zSchemaToArgparse.options%si              r+c#Kd}|jdkr%|js|jr|js|dfVdS|dfVdS|jr|js|j |dfVdSdSdS)Nr9list+*?)r%r"r$r rr&options r)r9zSchemaToArgparse.nargs3s :  # " "t| "ck!!!!!ck!!!!!   4< 4=3H#+       3H3Hr+c# Kd|jfVdS)Nr7)rr2s r)r7zSchemaToArgparse.choices?s&&&&&&r+c# Kd|jfVdS)Nr)r!r2s r)rzSchemaToArgparse.helpBsdj      r+c#Kd}|jr||jfVdS|jdkr||jfVdSdS)Nr8r<)r#upperr%rr@s r)r8zSchemaToArgparse.metavarEst < 1$,,,... . . . . . Z6 ! !$...000 0 0 0 0 0" !r+c#lK|j&|js!|jdks|jsd|jfVdSdSdSdS)Nr<r)rr r%r"r2s r)rzSchemaToArgparse.defaultLsZ M %L &v%%T-=%T]* * * * * * & % % %%%r+c#bK|jr|jdkr|js|js dVdSdSdSdSdS)Nr<)rT)r$r%r r"r2s r)rzSchemaToArgparse.requiredTsd N # f$$L%$% # " " " " " # #$$$$$$r+N)__name__ __module__ __qualname__r r strr OptionTyper*propertyr3r(r9r7rr8rrr+r)rrs %S/*J . . .7777X7    X   z    '''''!j!!!!11111+++++#####r+rc|ddkr|do|dd }||}|d|dd z|d |d |dd z|d |jdi||didSt ||}|j|jfi|jdS)NrbooleanrrF)rr.r/r0 store_true)destactionz--no- store_falserrN)radd_mutually_exclusive_group add_argumentr1 set_defaultsrr3r()parserr'r(r bool_parser converters r)schema_to_argparser[_s6{{6i'';;z**O7;;x3O3O/O9989LL   8##C-- - !     h&&sC00 0  !   !  FFHgkk).D.D#EFFFFF$Xw77 I-CC1BCCCCCr+c eZdZedefdZedZededee de e e ffdZ edZ d S) EnvParserenvvar_parameter_optionsc|sdSdddfd|DS)Nc@d|vr|dd|dS|dS)Nrrz rN)r(s r) format_argz)EnvParser.format_help..format_argys5  !(+BBBBB8$ $r+z environment variables: {}z c3.K|]}|VdSr5rN).0r(rbs r) z(EnvParser.format_help..sA 7##r+)formatjoinvalues)r^rbs @r) format_helpzEnvParser.format_helpts|' 2 % % % 177 KK7>>@@     r+cpd|vr1 |dn#t$r d|d|dfcYSwxYwdS)Nisasciiasciizerror: =z must only contain ascii symbols)encodeUnicodeEncodeError)rvaluer(s r) _validatezEnvParser._validatess     W%%%%%   NfNNuNNN ts 33environexcluder,c li}|D]\}}||vr |d} ||x} ||<||| |x} rK|||| } t| tjt jt#t$rd|vr |d||<Y| dsY|||d |} t| tjt jtYwxYw|S)Nr)filerrz-error: environment variable {} is not defined) itemsrq _format_errorprintsysstderrexitrKeyErrorrrf) clsrrcommandr^rskwargs parameterr( envvar_namerperrmsgs r)parsezEnvParser.parsesz":"@"@"B"B 1 1 IwG##!(+K 1,3K,@@y)"-- UGDDD31++!93C#CJ////H/000+ - - -''(/ (:F9%H{{:..H'',CJJ#c +++++,,,,, -, s BD18D1AD10D1c~dd||||S)Nz{command}: {help} {message} )r~rmessage)rfrgri)r}r~r^rs r)rwzEnvParser._format_errorsA077HHW%%!9::8   r+N) rHrIrJ staticmethodr rirq classmethodrrKrrrwrNr+r)r]r]ss g   \ \$$ # $ c3h $$$[$L  [   r+r]c^ tj|n#tj$rYdSwxYwdS)NFT) ipaddress IPv4AddressAddressValueError)addrs r)is_valid_ipv4_addrrsEd####  &uu 4s **c#K|D]7\}}||didgvr||fV8dS)Ncliusers)rvr)schemauserkeyrhs r) _filter_userrse||~~ V 6::eR((,,Wb99 9 9v+   r+c >t|j|di|S)N)require_svc_is_runningrN)rcmd)r~ require_rpcparamss r) rpc_endpointrs9 F <9K 8 8 8 .sT'\Bg>S\\>1B&Br+Available commandsr)rrzparser is not definedrr envvar_onlyFrrrz--jsonrQzreturn data in JSON format)rSrz --verbosez-vcount)rSrrrunning)r)endpointrr^r~rN)sortedkeys isinstancetupler< enumerater add_parserrargparseRawDescriptionHelpFormatteranyadd_subparsersrvupdater[r]riepilogrVrWrrr) subparsersr _subparserscommandsrhrX subparserir~hashableexists_subparserr^r'r(rrs @r) apply_parserrswKfkkmm$$HP P 'E4=11111 #G,," 1" 1JAwCLL1$$$"-- F++$,$H. %,2+@+@1,A,,K(!1q5!122#.??8#<#< '18A8L8L$#ZZ//9M99%n*>n??@I H 5 5 !1II.....v$& !'Hb!9!9!?!?!A!A : : Hg7""5<(2;;}e447""EE!1'(2C!DEEE&+ #(- % vx 9 9 9 9!--.FGG  \0L     Kg>>>jj++// yII  \7K@@%,( **Xr227799&&&&>  GP P r+cttttj|}t ||dSr5)r6rrr SCHEMA_PATHSr)rrrs r)_apply_subparsersr5s: ,~c.>??FF G GFV$$$$$r+r)maxsizec*tjdtjz}|dd|dgdd |d d d |d}t |d|S)Nz CLI for %s.) descriptionz --log-configzlogging config filenamerz--console-log-level)ERRORWARNINGINFODEBUGz%Level of logging input to the console)r7rz --remote-addrc(t|r|ndSr5)r)ips r)z#create_cli_parser..Fs044>$r+z2Client's IP address for adding it to the whitelist)rrrroot)rArgumentParserConfigNAMErVrr)rXrs r)create_cli_parserr:s  $1L M M MF -FGGG 555 4   > > A &&,@&AAJj&))) Mr+)$rrry functoolsrr itertoolsrtypingrrrr r r defence360agent.applicationr defence360agent.contracts.configr rdefence360agent.rpc_tools.utilsrdefence360agent.simple_rpcrdefence360agent.utils.clirrr[r]rrrrrrrrNr+r)rs ((((((((@@@@@@@@@@@@@@@@++++++;;;;;;::::::000000888888M#M#M#M#M#M#M#M#`DDD(J J J J J J J J Z  S S S l%%%  1r+