a ì)gã@sÞddlmZmZmZeZddlZddlZddlZddl m Z m Z ddl m ZddlmZddlmZmZmZddlmZmZddlmZdd lmZeƒZGd d „d eƒZGd d „d eƒZGdd„deƒZ Gdd„deƒZ!dS)é)Úabsolute_importÚdivisionÚprint_functionN)ÚS_IRUSRÚS_IWUSR)Ú constants)Ú user_agent)Úto_bytesÚ to_nativeÚto_text)Ú yaml_dumpÚ yaml_load)Úopen_url)ÚDisplayc@seZdZdZdd„ZdS)ÚNoTokenSentinelze Represents an ansible.cfg server with not token defined (will ignore cmdline and GALAXY_TOKEN_PATH. cOs|S©N©)ÚclsÚargsÚkwargsrrú8/usr/lib/python3.9/site-packages/ansible/galaxy/token.pyÚ__new__)szNoTokenSentinel.__new__N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrr'src@s6eZdZdZdZd dd„Zdd„Zd d „Zd d „ZdS)Ú KeycloakTokenzpA token granted by a Keycloak server. Like sso.redhat.com as used by cloud.redhat.com ie Automation HubZBearerNTcCs2||_||_d|_||_||_|jdur.d|_dS)Nzcloud-services)Ú access_tokenÚauth_urlÚ_tokenÚvalidate_certsÚ client_id)Úselfrrr r!rrrÚ__init__5s zKeycloakToken.__init__cCsd|j|jfS)Nz6grant_type=refresh_token&client_id=%s&refresh_token=%s)r!r©r"rrrÚ _form_payload>sÿzKeycloakToken._form_payloadcCsX|jr |jS| ¡}tt|jƒ||jdtƒd�}t t |  ¡dd�¡}|  d¡|_|jS)NZPOST)Údatar ÚmethodZ http_agentÚsurrogate_or_strict©Úerrorsr) rr%rr rr rÚjsonÚloadsr ÚreadÚget)r"ZpayloadZrespr&rrrr.Bs  ü zKeycloakToken.getcCsi}d|j| ¡f|d<|S©Nú%s %sZ Authorization©Ú token_typer.©r"Úheadersrrrr4_szKeycloakToken.headers)NNTN) rrrrr2r#r%r.r4rrrrr-s  rc@sReZdZdZdZddd„Zedd„ƒZdd „Zd d „Z d d „Z dd„Z dd„Z dS)Ú GalaxyTokenz4 Class to storing and retrieving local galaxy token ÚTokenNcCs ttjdd�|_d|_||_dS)Nr(r))r ÚCZGALAXY_TOKEN_PATHÚb_fileÚ_configr©r"Útokenrrrr#jszGalaxyToken.__init__cCs:|jdur| ¡|_|jr4|jtur(dn|j|jd<|jS©Nr;)r9Ú_readrrr$rrrÚconfigps   zGalaxyToken.configcCs²d}tj |j¡s8t|jdƒ ¡t |jttB¡d}t|jdƒ�}t |ƒ}Wdƒn1sb0Yt   d|t |jƒf¡|rªt |tƒsªt   dt |jƒ¡iS|p°iS)NZOpenedÚwZCreatedÚrr0z1Galaxy token file %s malformed, unable to read it)ÚosÚpathÚisfiler8ÚopenÚcloseÚchmodrrr ÚdisplayZvvvr Ú isinstanceÚdict)r"ÚactionÚfr>rrrr={s&zGalaxyToken._readcCs||_| ¡dSr)rÚsaver:rrrÚsetŽszGalaxyToken.setcCs|j dd¡Sr<)r>r.r$rrrr.’szGalaxyToken.getcCs@t|jdƒ� }t|j|dd�Wdƒn1s20YdS)Nr?F)Zdefault_flow_style)rDr8r r>)r"rKrrrrL•szGalaxyToken.savecCs*i}| ¡}|r&d|j| ¡f|d<|Sr/)r.r2)r"r4r;rrrr4™s zGalaxyToken.headers)N) rrrrr2r#Úpropertyr>r=rMr.rLr4rrrrr5es  r5c@s6eZdZdZd dd„Zedd„ƒZdd„Zd d „ZdS) ÚBasicAuthTokenZBasicNcCs||_||_d|_dSr)ÚusernameÚpasswordr)r"rPrQrrrr#¤szBasicAuthToken.__init__cCs>dt|dd�t|ddd�pdf}t t|ddd�¡}t|ƒS) Nz%s:%sr(r)Zpassthru)r*Z nonstringÚzutf-8)Úencodingr*)r Úbase64Z b64encoder )rPrQr;Zb64_valrrrÚ _encode_token©s  ÿzBasicAuthToken._encode_tokencCs$|jr |jS| |j|j¡|_|jSr)rrUrPrQr$rrrr.°szBasicAuthToken.getcCsi}d|j| ¡f|d<|Sr/r1r3rrrr4¸szBasicAuthToken.headers)N) rrrr2r#Ú staticmethodrUr.r4rrrrrO¡s   rO)"Z __future__rrrÚtypeZ __metaclass__rTrAr+ÚstatrrZansiblerr7Zansible.galaxy.user_agentrZansible.module_utils._textr r r Z ansible.module_utils.common.yamlr r Zansible.module_utils.urlsrZansible.utils.displayrrGÚobjectrrr5rOrrrrÚs     8<