Current File : //proc/self/root/usr/lib/python2.7/site-packages/euca2ools/commands/sts/assumerole.pyo
�
��Xc@s�ddlZddlZddlZddlZddlmZmZddlmZddl	m
Z
de
fd��YZdS(i����N(tArgtMutuallyExclusiveArgList(t
ArgumentError(t
STSRequestt
AssumeRolecBs|eZdZeddddd4dd�eddd	d
ddded
ddd�edd	ddddd�eedd	ddd4dddd�edd	ddd4dddd��eedd	ddddd�ed d	ddd!dedd"��ed#d	d$dd%dd&�ed'd	d(dd)dd*�ed+d	d,dd-dd.�gZd/�Z	d0�Z
d1�Zd2�Zd3�Z
RS(5s�        Assume an IAM role

        The %(prog)s utility obtains credentials for an IAM role and
        outputs them in the form of shellcode that sets environment
        variables that allow euca2ools commands to use them.  Use it
        inside an eval command to make this process seamless:

            $ eval `%(prog)s myrole`

        To stop using the role, use euare-releaserole(1).trolenametmetavartROLEtroute_tothelpsthe role to assumes-ds
--durationtdesttDurationSecondstSECONDSttypetdefaulti�s_number of seconds the
                credentials should be valid for (900-3600) (default: 900)s--session-nametRoleSessionNametPATHscrole session identifier to include in the
                assumed role user ID (default: automatic)s-ct
csh_outputtactiont
store_truesfgenerate C-shell commands on
                    stdout (default if SHELL looks like a csh-style shells-st	sh_outputs�generate Bourne shell
                    commands on stdout (default if SHELL does not look
                    like a csh-style shells--policy-contenttPolicytPOLICY_CONTENTs�an IAM policy
                    further restricting what the credentials will be
                    allowed to do.  This cannot grant additional
                    permissions.s--policy-documenttFILEs�file containing
                    an IAM policy further restricting what the
                    credentials will be allowed to do.  This cannot
                    grant additional permissions.s
--external-idt
ExternalIdtSTRs/external ID to use for comparison with policiess--mfa-serialtSerialNumbertMFAsMFA token serial numbers
--mfa-codet	TokenCodetCODEsMFA token codecCs`|j|jjd��|jd<|jjd�s\tjj�jd�}||jd<ndS(NRtRoleArnRseuca2ools-%Y-%m-%dT%H-%M-%SZ(t_AssumeRole__build_role_arntargstgettparamstdatetimetutcnowtstrftime(tselftsession((sE/usr/lib/python2.7/site-packages/euca2ools/commands/sts/assumerole.pyt
preprocessSs	cCs|jd�dkr<d|kr<dj|jd��}n|jd�dkr�|jd�smd|}ndj|j�|�}n|jd�dkr�d|}n|jd�dkr�d	|}n|jd�d
kr�d|}n|jd�dkrd
|}n|S(sj
        Build an ARN for a role from the fragment that was supplied at
        the command line.
        t:it/s{0}:role/{1}isrole/s{0}:{1}isiam:isaws:isarn:(tcounttformattsplitt
startswitht_AssumeRole__get_account_id(R&tarn((sE/usr/lib/python2.7/site-packages/euca2ools/commands/sts/assumerole.pyt__build_role_arn[s!




cCsC|jjd�}|s*tjd�}n|s?td��n|S(Ns
account-idtEC2_USER_IDsnfailed to determine account ID; set account-id for the user in configuration or EC2_USER_ID in the environment(tconfigtget_user_optiontostgetenvR(R&t
account_id((sE/usr/lib/python2.7/site-packages/euca2ools/commands/sts/assumerole.pyt__get_account_idxscCs |d}|jd|d�|jd|d�|jd|d�|jd|d�|jd|d�|jd	|d�|jd
|d�|jd|d�|jd
|d�|jd|jdjd�d�|jdd�HdGHdjdjd�tjD���GHdS(NtCredentialstAWS_ACCESS_KEY_IDtAccessKeyIdtAWS_ACCESS_KEYtEC2_ACCESS_KEYtAWS_SECRET_ACCESS_KEYtSecretAccessKeytAWS_SECRET_KEYtEC2_SECRET_KEYtAWS_SESSION_TOKENtSessionTokentAWS_SECURITY_TOKENtAWS_CREDENTIAL_EXPIRATIONt
ExpirationR2RR)itAWS_CREDENTIAL_FILEs5# If you can read this, rerun this program with eval:s#     eval `{0}`t css|]}tj|�VqdS(N(tpipestquote(t.0targ((sE/usr/lib/python2.7/site-packages/euca2ools/commands/sts/assumerole.pys	<genexpr>�s(t_AssumeRole__print_varR"R-tNoneR,tjointsystargv(R&tresulttcreds((sE/usr/lib/python2.7/site-packages/euca2ools/commands/sts/assumerole.pytprint_result�s 
$cCs�|jjd�s@|jjd�rXtjdd�jd�rX|rOd}qmd}n|rgd}nd	}|jd
|d|�GHdS(NRRtSHELLttcshssetenv {key} {val};sunsetenv {key};s{key}={val}; export {key};sunset {key};tkeytval(R R!R5R6tendswithR,(R&RXRYtfmt((sE/usr/lib/python2.7/site-packages/euca2ools/commands/sts/assumerole.pyt__print_var�s			N(t__name__t
__module__tDESCRIPTIONRRNtintRtopentARGSR(RR/RTRM(((sE/usr/lib/python2.7/site-packages/euca2ools/commands/sts/assumerole.pyR%sB						(R#R5RIRPtrequestbuilderRRtrequestbuilder.exceptionsRteuca2ools.commands.stsRR(((sE/usr/lib/python2.7/site-packages/euca2ools/commands/sts/assumerole.pyt<module>s