B?ZJdZddlZddlZddlmZmZddlmZmZddl m Z ddl m Z ddl mZddlmZmZdd lmZdd lmZmZdd lmZdd lmZejeZed dGddZGddeZ GddeZ!de"de#fdZ$dS)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) dataclassfields)AnySelf)urljoin)Request) alru_cache)APIAPIError) LicenseCLN)IAIDTokenErrorIndependentAgentIDAPI) HostingPanel)ImunifyPatchSubscriptionTF)frozeneqcbeZdZUdZeed<dZedzed<ede ee fde fdZ dS)PurchaseEligibilityFeligibleN purchase_urldatareturncdt|Dfd|D}|di|S)Nch|] }|j S)name).0fs c/opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/api/imunify_patch_subscription.py z0PurchaseEligibility.from_dict..2s4441444c$i|] \}}|v || Srr)rkv allowed_keyss r z1PurchaseEligibility.from_dict..3s)LLL$!Q!|:K:KA:K:K:Kr!r)ritems)clsr filtered_datar%s @r from_dictzPurchaseEligibility.from_dict0sS44s 444 LLLL$**,,LLL s##]###r!) __name__ __module__ __qualname__rbool__annotations__rstr classmethoddictrrr*rr!rrr+snHd#L#*###$T#s(^$$$$[$$$r!rceZdZdS)PurchaseEligibilityErrorN)r+r,r-rr!rr4r47sDr!r4ceZdZeejdZeejdZdZe de e de e dzfdZ e de fdZe ee de fd Zed d e dzde dzfd ZdS)ImunifyPatchSubscriptionAPIz/api/patch/subscriptions/checkz//api/products/patch/agent/generate-product-dataiidsrNc|K|sgS|dd{Vx}sdSt|jtjd|i|dd} ||d{V}n3#t$r&}t d|Yd}~dSd}~wwxYw|dS) zrGet active subscriptions for specific ids. Return None if interaction with the remote API failed. z9Can't get iaid token: %s. Return empty subscription list.Nusersapplication/jsonzX-Authz Content-TyperheaderszHFailed to get subscriptions details: %s. Return empty subscription list. patchActive) _get_tokenrSUBSCRIPTION_URLjsondumpsencode async_requestr loggererror)r(r7tokenrequestresultexcs rget_subscriptionsz-ImunifyPatchSubscriptionAPI.get_subscriptionsBs$  I>>K E  4  WcN++2244$6HII     ,,W55555555FF    LL2    44444  m$$s'B B3 B..B3cxK |d{VS#t$rtcYSwxYwN)_get_purchase_eligibilityr4r)r(s rget_purchase_eligibilityz4ImunifyPatchSubscriptionAPI.get_purchase_eligibilitybs\ )6688888888 8' ) ) )&(( ( ( ( )s 99)ttlcK|d{Vx}stttd{Vt jd}t|jtj | |dd} | |d{V}n;#t$r.}td|td}~wwxYwd|vsd|vr)td |tt |S) a Asynchronously retrieves the customer's host purchase eligibility status for Imunify Patch. Sends an authenticated request to the configured external service to determine whether the system is eligible for a purchase offer and, if so, obtains the associated purchase URL. Returns: PurchaseEligibility: An instance of PurchaseEligibility containing the eligibility flag and optional purchase URL. In case of any of the following, the PurchaseEligibilityError is raised: - Missing or invalid authentication token - Failure to make a request (e.g. APIError) - Malformed or incomplete response (missing required keys) N)r9custom_reseller_configuredr:r;r<zFailed to get purchase URL: %s.rrzBad response from server %s.)r?r4lenr get_usersr is_custom_reseller_configuredrELIGIBILITY_URLrArBrCrDr rErFrr*)r(rGrrHrIrJs rrNz5ImunifyPatchSubscriptionAPI._get_purchase_eligibilityis}, #~~///////// -*,, ,|~~7799999999::*4*R*T*T    D!!((**$6HII     -,,W55555555FF - - - LL:C @ @ @*,, , - & ( (j.F.F LL7 @ @ @*,, ,",,V444s3C D)DD error_messagecK tjd{VS#t$r(}t|pd|Yd}~dSd}~wwxYw)NzCan't get IAID Token: %s.)r get_tokenr rErF)rWrJs rr?z&ImunifyPatchSubscriptionAPI._get_tokens| .8:::::::: :    LL)/B)))[) ZI*5 *5*5*5[*5Xd cDj\r!r6_rcLtjSrM)rselectexists)r^s rhas_imunify_patch_subscriptionsrbs # * , , 3 3 5 55r!)%__doc__rAlogging dataclassesrrtypingrr urllib.parserurllib.requestr async_lrur defence360agent.api.serverr r !defence360agent.contracts.licenser defence360agent.internals.iaidr r+defence360agent.subsys.panels.hosting_panelrimav.malwarelib.modelr getLoggerr+rEr Exceptionr4r6r0r.rbrr!rrqs* )))))))) """""" 44444444888888EDDDDD::::::  8 $ $ $5!!!$$$$$$$"!$     y   eeeee#eeeP6s6t666666r!