o nnh@sddlmZddlZddlZddlZddlmZmZddlm Z ddl m Z ddl mZmZmZddlmZmZddlmZdd lmZeZGd d d eZGd d d eZGdddeZGdddeZdS)) annotationsN)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)clsargskwargsrr?/usr/local/lib/python3.10/dist-packages/ansible/galaxy/token.py__new__(szNoTokenSentinel.__new__N)__name__ __module__ __qualname____doc__rrrrrr&s rc@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 HubBearerNTcCs6||_||_d|_||_||_|jdurd|_dSdS)Nzcloud-services) access_tokenauth_url_tokenvalidate_certs client_id)selfrrrr rrr__init__4s  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)NPOST)datarmethod http_agentsurrogate_or_stricterrorsr) rr$r rrrrjsonloadsr readget)r!payloadrespr&rrrr/As  zKeycloakToken.getcCi}d|j|f|d<|SN%s %s Authorization token_typer/r!headersrrrr9^zKeycloakToken.headers)NNTN) rrrrr7r"r$r/r9rrrrr,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*)rCGALAXY_TOKEN_PATHb_file_configrr!tokenrrrr"is zGalaxyToken.__init__cCs:|jdur ||_|jr|jturdn|j|jd<|jSNrB)r@_readrrr#rrrconfigos  zGalaxyToken.configcCsd}tj|jst|jdt|jttBd}t|jd }t |}Wdn1s1wYt d|t |jf|rUt |tsUt dt |jiS|pXiS)NOpenedwCreatedrr4z1Galaxy token file %s malformed, unable to read it)ospathisfiler?openclosechmodrrr displayvvvr isinstancedict)r!actionfrErrrrDzs zGalaxyToken._readcCs||_|dSr)rsaverArrrsets zGalaxyToken.setcCs|jddSrC)rEr/r#rrrr/szGalaxyToken.getcCsBt|jd}t|j|ddWddS1swYdS)NrGF)default_flow_style)rMr?r rE)r!rUrrrrVs"zGalaxyToken.savecCs*i}|}|rd|j|f|d<|Sr3)r/r7)r!r9rBrrrr9s zGalaxyToken.headersr) rrrrr7r"propertyrErDrWr/rVr9rrrrr;ds    r;c@s6eZdZdZd ddZeddZddZd d ZdS) BasicAuthTokenBasicNcCs||_||_d|_dSr)usernamepasswordr)r!r\r]rrrr"s zBasicAuthToken.__init__cCs>dt|ddt|dddpdf}tt|ddd}t|S) Nz%s:%sr)r*passthru)r+ nonstringzutf-8)encodingr+)r base64 b64encoder)r\r]rBb64_valrrr _encode_tokens zBasicAuthToken._encode_tokencCs$|jr|jS||j|j|_|jSr)rrer\r]r#rrrr/szBasicAuthToken.getcCr2r3r6r8rrrr9r:zBasicAuthToken.headersr) rrrr7r" staticmethodrer/r9rrrrrZs   rZ) __future__rrbrJr,statrransiblerr=ansible.galaxy.user_agentr+ansible.module_utils.common.text.convertersrrr ansible.module_utils.common.yamlr r ansible.module_utils.urlsr ansible.utils.displayr rPobjectrrr;rZrrrrs     8<