Files
VPNaaS-Migrator/ipsec_migrator/__pycache__/keystone_auth.cpython-311.pyc
T

51 lines
7.4 KiB
Plaintext
Raw Normal View History

2026-07-21 15:05:52 +03:00
§
Z_j¸ãó\dZddlmZddlZddlZddlZdZdd „Zdd Zdd Z ddZ
dddZ dS)anKeystone v3 password authentication via `requests`, replacing the
`openstack token issue` subprocess call.
Mirrors the auth flow the `openstack` CLI itself performs when reading
`OS_*` environment variables: POST a project-scoped password auth request
to `{OS_AUTH_URL}/auth/tokens`, read the token back from the
`X-Subject-Token` response header, and keep the returned service catalog
around so the Neutron endpoint can be resolved from it (same as the CLI
does) instead of being hardcoded.
No `clouds.yaml` support -- the only auth pattern actually in use here
(`test_openrc.sh`) is password auth via `OS_*` env vars.
é)Ú annotationsN)Ú OS_AUTH_URLÚ OS_USERNAMEÚ OS_PASSWORDÚnameÚstrÚreturnú
str | NonecóLtj |¦«}|r|ndS)N)ÚosÚenvironÚget)rÚvalues ú4/root/vkcloud/vpnaas/ipsec_migrator/keystone_auth.pyÚ_envrs$Ý ŒJNŠN˜4Ñ Ô €EØÐ #ˆ5ˆ5˜tÐÚdictcóRtd¦«x}rd|iSdtd¦«pdiS)OS_USER_DOMAIN_IDÚidrÚOS_USER_DOMAIN_NAMEÚDefault©r)Ú domain_ids rÚ _user_domainrs<ÝÐ-€yð Ð Ø •DÐ<°9Ð =rcótd¦«x}rd|iStd¦«}|s/tdtj¬¦«tjd¦«td¦«x}rd|i}ndtd ¦«pd
i}||d œS)
OS_PROJECT_IDrÚOS_PROJECT_NAMEz8Error: neither OS_PROJECT_ID nor OS_PROJECT_NAME is set.©ÚfileéÚOS_PROJECT_DOMAIN_IDrÚOS_PROJECT_DOMAIN_NAMEr)rÚdomain)rÚprintÚsysÚstderrÚexit)Ú
project_idÚ project_nameÚproject_domain_idr$s rÚ_project_scoper,#ݘ*€zðÐ*€LØ ðÝ
Ø ð
ñ
ô
ð
õ Œ Œ ˆ å Ð!7ÑðGØÐˆàE¸IÐà ¨FÐ 3rútuple[str, list[dict]]cóVdtD¦«}|rEtdd |¦«tj¬¦«tjd¦«t
d¦« d¦«}dd gd
t
d ¦«t¦«t
d ¦«d
œidœdt¦«idœi} tj |d|d¬¦«}nS#tj j
$r<}td|tj¬¦«tjd¦«Yd}~nd}~wwxYwd|jcxkrdks]ntd|jdtj¬¦«td|jtj¬¦«tjd¦«|j d¦«}|s/tdtj¬¦«tjd¦«| ¦« d¦«pi d¦«pg}||fS)z!Returns (token, service_catalog).có0g|]}t|¦«°|ŒS©r)Ú.0rs rú
<listcomp>z authenticate.<locals>.<listcomp>9s#Ð<˜µ°d±´Ð<ˆ<rz1Error: required environment variable(s) not set: z, rr!rúauthÚpasswordÚuserrr)rr$r5)Úmethodsr5Úproject)ÚidentityÚscopez /auth/tokensg>@)ÚjsonÚtimeoutz/Error: Keystone authentication request failed: NéÈi,z,Error: Keystone authentication failed (HTTP ú)z
Response: zX-Subject-Tokenz9Error: Keystone response did not include X-Subject-Token.ÚtokenÚcatalog)Ú _REQUIREDr%Újoinr&r'r(rÚrstriprr,ÚrequestsÚpostÚ
exceptionsÚRequestExceptionÚ status_codeÚtextÚheadersrr;)ÚmissingÚauth_urlÚbodyÚresponseÚexcr?r@s rÚ authenticaterP7sKà<¥ Ð<€GØðÝ
ÐVÀ$Ç)Â)ÈGÑBTÔBTÐVÕ]`Ô]gÐ Œ Œ ˆ å"×)¨#Ñ.€Hàà&˜Ý $ ]Ñ 3Ô 3Ý".¡.¤.Ý$(¨Ñ$7Ô$7ðððð ð ð ¥Ñ!1Ô!1Ð 
ð 
ð €Dð Ý”= HÐ!:Ð!:Ð!:ÀÈtЈøÝ Ô Ô ððÝ
ÐÐEÍCÌJÐ Œ Œ ˆ ˆ ˆ ˆ ˆ ˆ øøøøðøøøð  Ò 
ÐT¸XÔ=QÐTÕ[^Ô[eÐ
Ð*˜8œ=дРŒ Œ ˆ à Ô × Ò Ð!2Ñ 3€EØ ðÝ
ÐIÕPSÔPZÐ Œ Œ ˆ à}Š}‰Œ×" 1¨r×6°yÑGÀR€GØ 'ˆsÃCÃD,Ã02D'Ä'D,Únetworkr@ú
list[dict]Ú service_typecóºtd¦«pdŠtd¦«Štˆfd|D¦«d¦«}|€3tddtj¬¦«tjd¦«ˆfd „| d
g¦«D¦«}rˆfd |D¦«}|r|}|sAtd d
drddndztj¬¦«tjd¦«|dd d¦«}dkrF| d¦«s| d¦«r|  dd¦«d}|S) OS_INTERFACEÚpublicÚOS_REGION_NAMEc3óNK|]}| d¦«k¯|VŒ dS)ÚtypeN©r)r1ÚentryrSs €rú <genexpr>z#resolve_endpoint.<locals>.<genexpr>gs9øèèÐT˜e°%·)²)¸FÑ2CÔ2CÀ|Ò2SÐ2SEÐ2SÐ2SÐ2SÐ2SÐTrzError: service type 'z ' not found in Keystone catalog.rr!cóFg|]}| d¦«k¯|ŒS)Ú interfacerZ)r1Úepr^s €rr2z$resolve_endpoint.<locals>.<listcomp>ls0ø€Ð`˜¸r¿vºvÀkÑ?RÔ?RÐV_Ò?_Ð?_"Ð?_Ð?_Ð?_rÚ endpointscóFg|]}| d¦«k¯|ŒS)ÚregionrZ)r1r_rbs €rr2z$resolve_endpoint.<locals>.<listcomp>ns/ø€ÐP °R·V²V¸HÑ5EÔ5EÈÒ5OÐ5O˜"Ð5OÐ5OÐ5Orz Error: no 'z' endpoint for service type 'z' in Keystone catalogz (region r>ÚrÚurlr3rQz/v2.0z/v2)
rÚnextr%r&r'r(rrCÚendswithÚrsplit)r@rSÚserviceÚ
candidatesÚregion_matchesrdr^rbs ` @@rÚresolve_endpointrkcøøø€Ý€IÝ
Ð
#€FåÐT TÐVZÑ[€GØÝ
ÐT TÕ[^Ô[eÐ Œ Œ ˆ à`˜wŸ{š{¨;¸Ñ`€JØ
ðP zÐPˆØ ð'ˆ ðÝ
Ø e˜)Ð eÀ,Ð eØ(.Ð$˜$°Bñ