>fFddlZddlZddlZddlZddlmZmZmZmZddl m Z m Z m Z m Z mZddlmZej"ej$eZdZdZdZdZd Zd Zd d d dddZGddeZy)N)AnyDictListOptional) exceptionshttpsecret_managersystemutil)AutoAttachCloudInstancezhttp://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience=contracts.canonical.com&format=full&licenses=TRUEzThttp://metadata.google.internal/computeMetadata/v1/instance/licenses/?recursive=truez&wait_for_change=truez&last_etag={etag}z/sys/class/dmi/id/product_namezGoogle Compute Engine8045211386737108299602242772471989183059995928934984238225928668034199783202176054482269786025)xenialbionicfocaljammynobleceZdZdZeej ejgdde e e ffdZ ede fdZ edefdZdee fdZdefd Zd edefd Zy ) UAAutoAttachGCPInstancecd|_y)Netagselfs 5/usr/lib/python3/dist-packages/uaclient/clouds/gcp.py__init__z UAAutoAttachGCPInstance.__init__%s  )g?r!) retry_sleepsreturnctjtddid}|jdk(r7tj j |jd|jiS|jjd}|r3d|jvr!tj|j| tj|j|j ) NMetadata-FlavorGoogler!)headerstimeout identityTokenerror_descriptionzservice account) status_code error_msg)codebody)rreadurl TOKEN_URLr.r secrets add_secretr/ json_dictgetlowerrGCPServiceAccountErrorCloudMetadataError)rresponse error_descs r identity_docz$UAAutoAttachGCPInstance.identity_doc,s<<  18>* +!++,<=L<#5#5#77r c |jd}tj|jdddz}t j |j d}|jdijdijdgS) zGet a list of licenses from the GCP metadata. Instance identity token (jwt) carries a list of licenses associated with the instance itself. Returns an empty list if licenses are not present in the metadata. r*.r!z===zutf-8googlecompute_engine license_id)r;base64urlsafe_b64decodesplitjsonloadsdecoder5)rtokenidentity identity_dicts rget_licenses_from_identityz2UAAutoAttachGCPInstance.get_licenses_from_identityMs|!!/2++EKK,r rrr$sTZZ --KH d38n I "C4 DI "T66$6r r)rOrRloggingrAtypingrrrruaclientrrr r r uaclient.cloudsr getLoggerreplace_top_level_logger_nameror]r1rcrdrerDrFr\rr>r rr|s  ,,CC3g:::8DE   *  3*$# ! " "  T65T6r