K6hdZddlZddlZddlmZddlmZddlmZm Z m Z ddl Z ddl m Z mZejeZGddeZGd d ZGd d eZdS) u  This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.  If not, see . Copyright © 2019 Cloud Linux Software Inc. This software is also available under ImunifyAV commercial license, see N)StrEnum)Path)AnyDictList) check_run nice_iteratorceZdZdZdZdS)PatchmanCustomIntegrationTypefilescriptN)__name__ __module__ __qualname__FILESCRIPTU/opt/imunify360/venv/lib/python3.11/site-packages/imav/patchman/custom_integration.pyr r #s D FFFrr c eZdZdZdddddddddddddddddgddd d ddd Zd ed efdZedZedZ de de fdZ de fdZ de eeeffdZdS)PatchmanCustomIntegrationa` Patchman custom integration uses pre-defined user files that can be either files with info about users (file integration) or scripts (script integration). This class is designed to retrieve the users and provide them to the DB the same way panels do. More info: https://docs.imunify360.com/Patchman_custom_integration.pdf stringT)typerequired)rrnullablebooleaninteger))rallowedrdict)homediremailparentlanguage suspendedleveldomainsintegration_type metadata_pathc"||_||_dSN)_integration_type_metadata_path)selfr*r+s r__init__z"PatchmanCustomIntegration.__init__=s!1+rc*t|jSr-)r r.r0s rr*z*PatchmanCustomIntegration.integration_typeAs,T-CDDDrc*t|jSr-)rr/r3s rr+z'PatchmanCustomIntegration.metadata_pathEsD'(((r users_datareturnctj|j}i}|D]A\}}||s"t d||j<|||<B|S)z0 Return only valid *users_data* z Skip not valid data for '%s': %s)cerberus ValidatorUSER_DATA_SCHEMAitemsvalidateloggerwarningerrors)r0r5 validatorresultusernamedatas rr<z"PatchmanCustomIntegration.validateIs&t'<== (..00 $ $NHd%%d++ 6$ #F8   rcKi}|jtjkrx|jst dt t|jgd{V}tj | }n,|j st dt|j dd23d{V} |d5}tj|}dddn #1swxYwYn=#tj$r+t"dt|YwxYwt'|d kr)t"d t|||6||S) Nz$Provided metadata path is not a filez)Provided metadata path is not a directoryz*.json2) chunk_sizezutf-8)encodingzSkip invalid JSON file: %srz(Skip %s: expect one JSON object per file)r*r rr+is_filePatchmanCustomIntegrationErrorrstrjsonloadsdecodeis_dirr globopenloadJSONDecodeErrorr=r>lenupdater<)r0r5rAuser_data_filefrCs r_get_users_dataz)PatchmanCustomIntegration._get_users_dataZs<  $A$H H H%--// 4:%c$*<&=&=%>????????FFMMOO44JJ%,,.. 4?)6"''11b))) ( ( ( ( ( ( (n',,g,>>,!#y||,,,,,,,,,,,,,,,+NN4c.6I6IH  t99>>NNBN++!!$''''#)$}}Z(((s<#F=+D.D" D."D& &D.)D& *D..7E('E(c\K g}|d{V}|D]S\}}|di}d|D}|||d|T|S#t$rt $r }t|d}~wwxYw)Nr)cg|] \}}||d S))domainpathsr).0 domain_namer[s r z.s4* U +U;;r)rBr))rWr;popappendrI Exception)r0users metadata_dictrBdetails orig_domainsr)es rpatchman_usersz(PatchmanCustomIntegration.patchman_userss 8E"&"6"6"8"8888888M%2%8%8%:%:  !'&{{9b99 .:.@.@.B.B !)gIIIL-     8 8 80a 7 8sBB B+B&&B+N)rrr__doc__r:rJr1propertyr*r+r"r<rWrrrrgrrrrr(sC%$77"55#4HH%488'T::# tLL"55,,S,,,,EEXE))X)4D"#)t#)#)#)#)J8d4S>&:888888rrceZdZdS)rIN)rrrrrrrIrIsDrrI)rhrKloggingenumrpathlibrtypingrrrr8defence360agent.utilsrr getLoggerrr=r rrarIrrrrqs'* """"""""""::::::::  8 $ $G i8i8i8i8i8i8i8i8X     Y     r