a œ•ºfâ,ã@s@ddlZddlZddlZddlZddlZddlZddlZddlmZddl Zddl m Z m Z ddl Z ej dd¡ddlmZddlmZddlmZddlmZmZmZd Ze d ƒZe d ƒZe d ƒZe d ƒZe dƒZe dƒZe dƒZ e dƒZ!Gdd„dej"ƒZ#Gdd„dej$j%ƒZ&dd„Z'Gdd„de(ƒZ)dd„Z*dd„Z+dS)éN)ÚPRIO_PLUGINCONFIG)Ú_Úloggerz*/usr/share/oracle-cloud-agent/plugins/osms)Úactions)Úconfig)Úustr)Ú get_cacertÚ get_proxyÚ OsmsServerz _osms.jsonz)OSMS based repositories will be disabled.z2There was an error communicating with OSMS server.z/This system is not registered with OSMS server.z2This system is receiving updates from OSMS server.zFor security reasons packages from OSMS based repositories can be verified only with locally installed gpg keys. GPG key '%s' has been rejected.z.Package profile information could not be sent.z/Missing required login information for OSMS: %sz9OSMS plugin has to be run under with the root privileges.csJeZdZdZ‡fdd„Zdd„Zddd„Zd d „Zd d „Zd d„Z ‡Z S)Ú OsmsPluginZ osmsplugincstt|ƒ ||¡||_||_tj |jjj t ¡|_ d|_ i|_ t |jj¡|_| |j¡|_d|j ¡vr–|j d¡}|D]\}}|j ||t¡q|tj ¡s²t t¡d|j_|jjs¾dS|jjdkrÐd}n"|jjdkrâd}n|jjdkròd}t|ƒt d¡| ¡dS)NFÚmainéÚINFOÚDEBUGÚWARNINGzinitialized OSMS plugin) Úsuperr Ú__init__ÚbaseÚcliÚosÚpathÚjoinÚconfÚ persistdirÚSTORED_CHANNELS_NAMEÚstored_channels_pathÚconnected_to_osmsÚ up2date_cfgÚcopyÚ read_configÚparserÚsectionsÚitemsÚ _set_valuerÚdnfÚutilÚ am_i_rootrÚwarningÚ MUST_BE_ROOTÚenabledÚ debuglevelÚinit_root_loggerÚdebugÚactivate_channels)ÚselfrrÚoptionsÚkeyÚvalueÚ log_level©Ú __class__©ú:/usr/lib/python3.9/site-packages/dnf-plugins/osmsplugin.pyr,s4        zOsmsPlugin.__init__cCs |jjs dS|jrd|jj_dS)NT)rr)rÚdemandsÚ root_user©r.r5r5r6rHszOsmsPlugin.configTc Cs<i}d}d}d}d}d}d}| ¡} |s0| }nDt ¡|_t|jdd\}}}t|jƒ}|jd}zt|jjd  ¡}Wn6t y®} zt   dt t| ¡WYd} ~ dSd} ~ 00t ¡} |rÀ| sÜt   dtt¡| i¡dSzt|jjdj | ¡} Wn8t y.} zt   dt t| ¡WYd} ~ dSd} ~ 00d|_t  t¡| D]$} | drDt|  ¡ƒ|| d <qD| |¡|jj}| ¡D]¨\}}|  |¡}d}|rª| d¡}t |j¡}||j ¡vrð|j |¡}|D]\}}| ||t ¡qÖ|jj||||j|||||j!|j"d œ }t#||ƒ}| $|¡q„t  %|¡dS) NrT)ZexternalZuseNoSSLForPackages©Útimeoutú%s %s %sz%s %sÚ last_modifiedÚlabel) rÚproxyÚproxy_usernameÚproxy_passwordr;Ú sslcacertÚ force_httpÚcached_versionÚ login_infoÚgpgcheckr))&Ú_read_channels_filerÚinitUp2dateConfigrr rr rr;ÚloginÚ ExceptionrÚerrorÚCOMMUNICATION_ERRORÚ RHN_DISABLEDZ getSystemIdÚNOT_REGISTERED_ERRORÚ_write_channels_fileZup2dateZ listChannelsrÚinfoÚUPDATES_FROM_OSMSÚdictr"rÚreposÚgetrr r!r#rrFr)ÚOsmsRepoÚaddr,)r.Z networkingZenabled_channelsrBrCZ proxy_urlr@rArEZcached_channelsÚeZ system_idÚchannelsÚchannelrSZ channel_idZ channel_dictZcached_channelrDrr/r0r1ÚoptsÚrepor5r5r6r-Nsz            õ zOsmsPlugin.activate_channelsc Csd|jjs dS|jsdSztj|jjdWn4ty^}zt dt t |¡WYd}~n d}~00dS)z, Update system's profile after transaction. Nr:r<) rr)rrZpackage_refresh_listr;rJrrKrLÚPROFILE_NOT_SENT)r.rWr5r5r6Ú transaction˜szOsmsPlugin.transactionc Cs˜zHt|jdƒ(}| ¡}t |¡}|WdƒWS1s<0YWnJttfy~}z|jtjkrj‚WYd}~nd}~0tj j y’Yn0iS)NÚr) ÚopenrÚreadÚjsonÚloadsÚFileNotFoundErrorÚIOErrorÚerrnoÚENOENTÚdecoderÚJSONDecodeError)r.Ú channels_fileÚcontentrXrWr5r5r6rG¤s ( zOsmsPlugin._read_channels_filec Cs|z@t|jdƒ }tj||ddWdƒn1s40YWn6ttfyv}z|jtjkrb‚WYd}~n d}~00dS)NÚwé)Úindent)r_rraÚdumprcrdrerf)r.ÚvarrirWr5r5r6rO²s 2 zOsmsPlugin._write_channels_file)T) Ú__name__Ú __module__Ú __qualname__Únamerrr-r]rGrOÚ __classcell__r5r5r3r6r (s  J r cs:eZdZgd¢Z‡fdd„Zdd„Zd ‡fdd„ Z‡ZS) rU)zX-RHN-Server-IdzX-RHN-Auth-User-Idz X-RHN-AuthzX-RHN-Auth-Server-TimezX-RHN-Auth-Expire-Offsetc sttˆƒ t|dƒ| d¡¡t|dƒˆ_‡fdd„t ¡Dƒˆ_| d¡ˆ_ | d¡ˆ_ | d¡ˆ_ | d ¡ˆ_ zt |d ƒˆ_Wn>tyÆ}z&t ttj |¡¡gˆ_WYd}~n d}~00|d | d ¡kràd ˆ_| d¡ˆ_dˆ_dˆ_d ˆ_dˆ_| d¡ˆ_| d¡ˆ_| d¡ˆ_ˆj  d¡rJt !dˆj¡dˆ_"| d¡r`ˆ #¡nˆ $¡t%ˆdƒrŒˆ &¡}|rŒˆ '|¡dS)Nr>rrscsg|]}|dˆj‘qS)z /GET-REQ/)Úid)Ú.0Úurlr9r5r6Ú Èóz%OsmsRepo.__init__..rBr?r@rAZ gpg_key_urlr=rDérErr;rFrCZocidz3Set module_hotfixes = True for custom repository %sTr)Úset_http_headers)(rrUrrrTrsrZ getServerlURLÚbaseurlrBr?r@rAÚget_gpg_key_urlsÚgpgkeyÚInvalidGpgKeyLocationrr'ÚGPG_KEY_REJECTEDr$Úi18nÚucdÚmetadata_expirerEZ keepaliveÚ bandwidthÚretriesÚthrottler;rFrCruÚ startswithr,Úmodule_hotfixesÚenableÚdisableÚhasattrÚcreate_http_headersr{)r.rYrZrWÚ http_headersr3r9r6rÅs@            zOsmsRepo.__init__cCs¤g}|jD]X}||jvr,t|}tj |¡‚|j|dvrJ| d|¡q | d||j|f¡q t ¡}|dr†| d|d¡|j s–| d¡| d¡|S)N)NÚz*%s: X-libcurl-Empty-Header-Workaround: *z%s: %sZtenantIdzX-Tenant-Id: %sz.X-RHN-Transport-Capability: follow-redirects=3zContent-Length: 0) Úneeded_headersrEÚMISSING_HEADERr$ÚErrorÚ RepoErrorÚappendrrHrC)r.rÚheaderrKrr5r5r6rŒís     zOsmsRepo.create_http_headersTcs0tt|ƒ ||¡}| ¡}|r,| tj|¡|S)N)rrUÚ_handle_new_remoterŒZsetoptÚlibrepoZLRO_HTTPHEADER)r.ÚdestdirZ mirror_setupÚhandlerr3r5r6r•s zOsmsRepo._handle_new_remote)T)rprqrrrrrŒr•rtr5r5r3r6rU»s (rUcCs&| ¡}|D]}t|ƒs t|ƒ‚q |S)a Parse the key urls and validate them. key_url_string is a space seperated list of gpg key urls that must be located in /etc/pkg/rpm-gpg/. Return a list of strings containing the key urls. Raises InvalidGpgKeyLocation if any of the key urls are invalid. )ÚsplitÚis_valid_gpg_key_urlr)Zkey_url_stringZkey_urlsÚkey_urlr5r5r6r}s  r}c@s eZdZdS)rN)rprqrrr5r5r5r6r!srcCsP| d¡}t|ƒdkrdS|\}}| ¡dkr2dStj |¡}| d¡sLdSdS)Nz://r FÚfilez/etc/pki/rpm-gpg/T)r™ÚlenÚlowerrrÚnormpathr‡)r›Z proto_splitÚprotorr5r5r6rš%s     ršcCs6t ¡}| ¡rdSd|_| t ¡¡| |¡dS)Nr)ÚloggingÚ getLoggerÚ hasHandlersÚ propagateÚ addHandlerÚ NullHandlerÚsetLevel)r2Z root_loggerr5r5r6r+4s r+),rrerar¡rÚsysr$Údnf.conf.configrÚdnf.exceptionsÚdnfpluginscorerrr–rÚinsertZosmsrrZ osms.i18nrZ osms.serverrr r rrMrLrNrQr€r\rr(ÚPluginr r[ÚReporUr}rJrršr+r5r5r5r6ÚsB    ÿV