a )g@sddlmZmZmZeZddlZddlZddlZddl m Z m Z ddl m ZddlmZddlmZmZmZddlmZmZddlmZdd lmZeZGd d d eZGd d d eZGdddeZ GdddeZ!dS))absolute_importdivisionprint_functionN)S_IRUSRS_IWUSR) constants) user_agent)to_bytes to_nativeto_text) yaml_dump yaml_load)open_url)Displayc@seZdZdZddZdS)NoTokenSentinelze Represents an ansible.cfg server with not token defined (will ignore cmdline and GALAXY_TOKEN_PATH. cOs|SN)clsargskwargsrr8/usr/lib/python3.9/site-packages/ansible/galaxy/token.py__new__)szNoTokenSentinel.__new__N)__name__ __module__ __qualname____doc__rrrrrr'src@s6eZdZdZdZd ddZddZd 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_tokenauth_url_tokenvalidate_certs client_id)selfrrr r!rrr__init__5s zKeycloakToken.__init__cCsd|j|jfS)Nz6grant_type=refresh_token&client_id=%s&refresh_token=%s)r!rr"rrr _form_payload>szKeycloakToken._form_payloadcCsX|jr |jS|}tt|j||jdtd}tt | dd}| d|_|jS)NZPOST)datar methodZ http_agentsurrogate_or_stricterrorsr) rr%rr rr rjsonloadsr readget)r"ZpayloadZrespr&rrrr.Bs   zKeycloakToken.getcCsi}d|j|f|d<|SN%s %sZ Authorization token_typer.r"headersrrrr4_szKeycloakToken.headers)NNTN) rrrrr2r#r%r.r4rrrrr-s  rc@sReZdZdZdZdddZeddZdd Zd d Z d d Z ddZ ddZ dS) GalaxyTokenz4 Class to storing and retrieving local galaxy token TokenNcCs ttjdd|_d|_||_dS)Nr(r))r CZGALAXY_TOKEN_PATHb_file_configrr"tokenrrrr#jszGalaxyToken.__init__cCs:|jdur||_|jr4|jtur(dn|j|jd<|jSNr;)r9_readrrr$rrrconfigps   zGalaxyToken.configcCsd}tj|js8t|jdt|jttBd}t|jd}t |}Wdn1sb0Yt d|t |jf|rt |tst dt |jiS|piS)NZOpenedwZCreatedrr0z1Galaxy token file %s malformed, unable to read it)ospathisfiler8openclosechmodrrr displayZvvvr isinstancedict)r"actionfr>rrrr={s&zGalaxyToken._readcCs||_|dSr)rsaver:rrrsetszGalaxyToken.setcCs|jddSr<)r>r.r$rrrr.szGalaxyToken.getcCs@t|jd }t|j|ddWdn1s20YdS)Nr?F)Zdefault_flow_style)rDr8r r>)r"rKrrrrLszGalaxyToken.savecCs*i}|}|r&d|j|f|d<|Sr/)r.r2)r"r4r;rrrr4s zGalaxyToken.headers)N) rrrrr2r#propertyr>r=rMr.rLr4rrrrr5es  r5c@s6eZdZdZd ddZeddZddZd d ZdS) BasicAuthTokenZBasicNcCs||_||_d|_dSr)usernamepasswordr)r"rPrQrrrr#szBasicAuthToken.__init__cCs>dt|ddt|dddpdf}tt|ddd}t|S) Nz%s:%sr(r)Zpassthru)r*Z nonstringzutf-8)encodingr*)r base64Z b64encoder )rPrQr;Zb64_valrrr _encode_tokens  zBasicAuthToken._encode_tokencCs$|jr |jS||j|j|_|jSr)rrUrPrQr$rrrr.szBasicAuthToken.getcCsi}d|j|f|d<|Sr/r1r3rrrr4szBasicAuthToken.headers)N) rrrr2r# staticmethodrUr.r4rrrrrOs   rO)"Z __future__rrrtypeZ __metaclass__rTrAr+statrrZansiblerr7Zansible.galaxy.user_agentrZansible.module_utils._textr r r Z ansible.module_utils.common.yamlr r Zansible.module_utils.urlsrZansible.utils.displayrrGobjectrrr5rOrrrrs     8<