o .&a.V@s(ddlZddlZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl mZmZmZmZddlmZddlmZdd lmZd d ZGd d d eZGdddeZGdddeZGdddeZGdddeZGdddeZ GdddeZ!GdddeZ"dS)N)datetime)tzutc) relativedelta)parse_timestamp) is_windowsurlparseRawConfigParserStringIO)utils) BasicCommand) uni_printcCs|g}d}dD]0}t||}|dkr.|r|d|t|||dkr+|ddn||r2n|dk}qd|}|S)NF)yearsmonthsdayshoursminutesrand )getattrappendstrjoin) remainingvaluesprev_non_zero_attrattrvaluemessager J/usr/lib/python3/dist-packages/awscli/customizations/codeartifact/login.pyget_relative_expiration_times    r"c@sLeZdZdZ dddZdddZdd Zd d Zdd d Ze ddZ dS) BaseLoginz-%s was not found. Please verify installation.NcCs.||_||_||_||_||_||_||_dSN) auth_token expirationrepository_endpointdomain repositorysubprocess_utils namespace)selfr%r&r'r(r)r*r+r r r!__init__(s zBaseLogin.__init__FcCtd)Nzlogin()NotImplementedError)r,dry_runr r r!login2zBaseLogin.logincCs<|D]}tjd|tjtjtjtjqdS)Nr)sysstdoutwriteroslinesep)r,toolcommandscommandr r r!_dry_run_commands5s zBaseLogin._dry_run_commandscCsrt|jtttdd}t|}tjd ||j tjt j tjd ||jtjt j dS)N)secondszASuccessfully configured {} to use AWS CodeArtifact repository {} zLogin expires in {} at {}) rr&rnowrr"r4r5r6formatr'r7r8)r,r9rexpiration_messager r r!_write_success_message;s  z BaseLogin._write_success_messagec Cs|r |||dS|D],}z|jj||jj|jjdWq ty8}z|jtjkr2t|j||d}~ww| |dS)N)r5stderr) r<r* check_callPIPEOSErrorerrnoENOENT ValueError_TOOL_NOT_FOUND_MESSAGErB)r,r9r:r1r;exr r r! _run_commandsKs&   zBaseLogin._run_commandscKr.)Nzget_commands()r/)clsendpointr%kwargsr r r! get_commands`szBaseLogin.get_commandsr$F) __name__ __module__ __qualname__rJr-r2r<rBrL classmethodrPr r r r!r#%s  r#c@sZeZdZdZdZdZdddZddZd d Zd d Z d dZ ddZ ddZ ddZ dS)NuGetBaseLoginz{endpoint}v3/index.jsonz/Added source %s to the user level NuGet.Config z&Updated source %s in the NuGet.Config Fc Csz|}Wnty#}z|jtjkrt|j||d}~ww|jj|j d}| ||\}}|rA| d||}|j }n | d||}|j }|raddd|D} t| tddSz |jj||jjdWntjy} ztd | d} ~ wwt|||d dS) N)rNupdateaddrcSsg|]}t|qSr )r).0cdr r r! sz(NuGetBaseLogin.login.. rCz"Failed to update the NuGet.Config nuget)_get_source_to_url_dictrFrGrHrIrJ_get_tool_name_NUGET_INDEX_URL_FMTr@r'_get_source_name_get_configure_command_SOURCE_UPDATED_MESSAGE_SOURCE_ADDED_MESSAGErr r* check_outputrE subprocessCalledProcessErrorrB) r,r1source_to_url_dictrKnuget_index_url source_namealready_existsr;source_configured_messagedry_run_commander r r!r2rsP     zNuGetBaseLogin.logincCsr|jj||jjd}|d}dd|D}i}tdt|dD]}|||d|| ||<q$|S)Nr]zutf-8cSsg|] }|dkr|qSstrip)rYliner r r!r[sz:NuGetBaseLogin._get_source_to_url_dict..r) r*rf_get_list_commandrEdecode splitlinesrangelen_parse_source_url_parse_source_name)r,responselinesriir r r!r_sz&NuGetBaseLogin._get_source_to_url_dictcCs$|ddd}|dddS)Nz [rr)rsrsplitsplit)r,rtline_without_tagr r r!r|sz!NuGetBaseLogin._parse_source_namecCs|Sr$rr)r,rtr r r!r{sz NuGetBaseLogin._parse_source_urlcCs`d|j|j}|D]\}}||kr|dfSq |D] }||kr+|dfSq|dfS)Nz{}/{}TF)r@r(r)itemskeys)r,codeartifact_url source_dict default_namerk source_urlr r r!rbs   zNuGetBaseLogin._get_source_namecCr.)Nz_get_tool_name()r/r,r r r!r`r3zNuGetBaseLogin._get_tool_namecCr.)Nz_get_list_command()r/rr r r!rvr3z NuGetBaseLogin._get_list_commandcCr.)Nz_get_configure_command()r/r, operationrjrkr r r!rcr3z%NuGetBaseLogin._get_configure_commandNrQ)rRrSrTrarerdr2r_r|r{rbr`rvrcr r r r!rVes  ,'  rVc@$eZdZddZddZddZdS) NuGetLogincCdS)Nr^r rr r r!r`zNuGetLogin._get_tool_namecCgdS)N)r^sourceslistz-formatdetailedr rr r r!rvr3zNuGetLogin._get_list_commandc Csdd|d|d|ddd|jg S)Nr^rz-namez-sourcez -usernameawsz -password)r%rr r r!rcs z!NuGetLogin._get_configure_commandNrRrSrTr`rvrcr r r r!r rc@r) DotNetLogincCr)Ndotnetr rr r r!r`rzDotNetLogin._get_tool_namecCr)N)rr^rsourcez--formatrr rr r r!rv r3zDotNetLogin._get_list_commandcCsfdd|dg}|dkr|||d|g7}n |||d|g7}|ddd |jg7}ts1|d |S) Nrr^rrXz--namez--sourcez --usernamerz --passwordz--store-password-in-clear-text)rr%r)r,rrjrkr;r r r!rc s     z"DotNetLogin._get_configure_commandNrr r r r!rrrc@sFeZdZedkrdndZd ddZeddZ ed d Z d S) NpmLoginwindowsznpm.cmdnpmFcCs2||j}|j|j|j|d}|d||dS)N)scoper) get_scoper+rPr'r%rL)r,r1rr:r r r!r2)s zNpmLogin.logincCsFtd}|dur |S|dr|}nd|}||s!td|S)Nz^(@[a-z0-9-~][a-z0-9-._~]*)@z@{}zZInvalid scope name, scope must contain URL-safe characters, no leading dots or underscores)recompile startswithr@matchrI)rMr+valid_scope_namerr r r!r2s    zNpmLogin.get_scopec Ksg}|d}|rd|nd}||jdd||gt|}d|j|j}||jdd|dgd|j|j} ||jdd| |g|S) Nrz {}:registryregistryconfigsetz//{}{}:always-authtruez//{}{}:_authToken)getr@rNPM_CMDrurlsplitnetlocpath) rMrNr%rOr:rrrepo_urialways_auth_configauth_token_configr r r!rPHs(  zNpmLogin.get_commandsNrQ) rRrSrTplatformsystemlowerrr2rUrrPr r r r!r#s  rc@s&eZdZdZdddZeddZdS) PipLoginz1{scheme}://aws:{auth_token}@{netloc}{path}simple/FcCs"||j|j}|d||dS)Npip)rPr'r%rL)r,r1r:r r r!r2nszPipLogin.logincKs4t|}|jj|j||j|jd}dddd|ggS)N)schemer%rrrrrzglobal.index-url)rrPIP_INDEX_URL_FMTr@rrr)rMrNr%rOr pip_index_urlr r r!rPts zPipLogin.get_commandsNrQ)rRrSrTrr2rUrPr r r r!rjs  rcsFeZdZdZ d fdd ZeddZd dd Zed d ZZ S) TwineLoginz[distutils] index-servers= pypi codeartifact [codeartifact] repository: {repository_endpoint} username: aws password: {auth_token}Ncs4|dur|}||_tt|||||||dSr$)get_pypi_rc_path pypi_rc_pathsuperrr-)r,r%r&r'r(r)r*r __class__r r!r-s  zTwineLogin.__init__c Ks@d|vsJd|d}|jj||d}t}tj|rzL|||dd}dd|dD}d |vrH| d | dddd |d | vrS| d | d d || d d d | d d |Wn$ty} ztjd|tjtj| d} ~ ww|t|t} || | } | | S)Nrzpypi_rc_path must be provided.)r'r% distutilsz index-serverscSs g|] }|dkr|qSrprr)rYserverr r r!r[s  z+TwineLogin.get_commands..r\ codeartifactr)usernamerpasswordz%s is in an invalid state.)DEFAULT_PYPI_RC_FMTr@rr7rexistsreadrrrrrsections add_section Exceptionr4r5r6r8readfpr getvalueclose) rMrNr%rOrdefault_pypi_rcpypi_rc index_serversserversropypi_rc_stream pypi_rc_strr r r!rPsH        zTwineLogin.get_commandsFcCs|j|j|j|jd}|r@tjdtjtjtjd|jtjtjtjtjtj|tjtjdSt |jd }||Wdn1sVwY| ddS)N)rz.Dryrun mode is enabled, not writing to pypirc.z(%s would have been set to the following:zw+twine) rPr'r%rr4r5r6r7r8openrB)r,r1rfpr r r!r2s&   zTwineLogin.logincCstjtjddS)N~z.pypirc)r7rr expanduser)rMr r r!rszTwineLogin.get_pypi_rc_pathr$rQ) rRrSrTrr-rUrPr2r __classcell__r r rr!rs  7rc @seZdZdZdedddedddedddedddedddZ d Z d Z d d e e dd dddddddddddddddddddddddddddgZdd Zd!d"Zd#d$Zd%d&Zd'S)(CodeArtifactLoginz>Log in to the idiomatic tool for the requested package format.r^F)package_format login_clsnamespace_supportrTpypi)r^rrrrr2zSets up the idiomatic tool for your package format to use your CodeArtifact repository. Your login information is valid for up to 12 hours after which you must login again.r9z1The tool you want to connect with your repository)name help_textchoicesrequiredr(zYour CodeArtifact domain name)rrrz domain-ownerz5The AWS account ID that owns your CodeArtifact domainr+z0Associates a namespace with your repository toolzduration-secondsintegerz9The time, in seconds, that the login information is valid)r cli_type_namerrr)z!Your CodeArtifact repository namezdry-run store_truezOnly print the commands that would be executed to connect your tool with your repository without making any changes to your configuration)ractionrrdefaultcCs,|j|d}|s|jrtd||jS)Nrz,Argument --namespace is not supported for {})TOOL_MAPr+rIr@)r,r9 parsed_argsnamespace_compatibler r r!_get_namespaceJs  z CodeArtifactLogin._get_namespacecCs8|j|j|d}|jr|j|d<|jdi|}|dS)N)r(r)r@ domainOwnerrepositoryEndpointr )r(r) domain_ownerget_repository_endpoint)r,codeartifact_clientrrrO get_repository_endpoint_responser r r!_get_repository_endpointTs z*CodeArtifactLogin._get_repository_endpointcCs>d|ji}|jr |j|d<|jr|j|d<|jdi|}|S)Nr(rdurationSecondsr )r(rduration_secondsget_authorization_token)r,rrrO get_authorization_token_responser r r!_get_authorization_tokends  z*CodeArtifactLogin._get_authorization_tokencCs|j}|j|d}t|jd|}|||}||||}|j}|j } | ||} |d} t |d} |j|d| | ||| t | } | |jdS)NrrauthorizationTokenr&rr)r9rr cli_utils!create_client_from_parsed_globals_sessionrrr(r)rrrgr2r1)r,rparsed_globalsr9rrauth_token_resr'r(r)r+r%r&r2r r r! _run_mainss,     zCodeArtifactLogin._run_mainN)rRrSrT__doc__rrrrrrNAME DESCRIPTIONrr ARG_TABLErrrrr r r r!rs~ .  r)#rGr7rr4rgrr dateutil.tzrdateutil.relativedeltarbotocore.utilsr awscli.compatrrrr awscli.customizationsr rawscli.customizations.commandsr awscli.customizations.utilsr r"objectr#rVrrrrrrr r r r!s0       @Gt