Ë
    €ÏÌ  ã                   ó†   — d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ d	„ Zd
„ Zd„ Zd„ Zd„ Zy)z'Utils for handing transfer credentials.é    )Úabsolute_import)Údivision)Úunicode_literalsN)Úresource_property)Úfiles)Úconfigparserc                 óJ   — | |v rt        dj                  | «      «      ‚||| <   y)z@Assigns value to results_dict and raises error on duplicate key.zDuplicate key in file: {}N)ÚKeyErrorÚformat)ÚkeyÚvalueÚresult_dicts      ú5lib/googlecloudsdk/command_lib/transfer/creds_util.pyÚ_assign_with_error_on_duplicater      s+   € àˆKÑÜ
Ð.×5Ñ5°cÓ:Ó
;Ð;Ø€+ˆcÒó    c                 óâ   — | D ]j  }||v rt        |||   |«       Œt        j                  |«      }t        j                  |«      }||v rt        |||   |«       ||v sŒ[t        |||   |«       Œl y)zHConverts key to multiple cases and attempts to extract from search_dict.N)r   r   ÚConvertToCamelCaseÚConvertToSnakeCase)ÚkeysÚsearch_dictr   Úoriginal_keyÚcamel_case_keyÚsnake_case_keys         r   Ú_extract_keysr   &   s†   € ã€lØ{Ñ"Ü% l°KÀÑ4MØ&1õ3ô )×;Ñ;¸LÓI€nÜ(×;Ñ;¸LÓI€nØ	˜;Ñ	&Ü'¨Ø(3°NÑ(CØ(3ô	5ð 
˜;Ò	&Ü'¨Ø(3°NÑ(CØ(3õ	5ñ r   c                 óB  — i }t         j                  j                  t         j                  j                  | «      «      }t	        j
                  |«      5 }	 t        j                  |j                  «       «      }t        |||«       ddd«       |S # t        j                  $ rn t        j                  «       }	 |j                  |«       n"# t        j                  $ r t        d«      ‚w xY w|D ]  }t        ||   «      }t        |||«       Œ Y ŒŠw xY w# 1 sw Y   |S xY w)a¦  Reads JSON or INI file and returns dict with values for requested keys.

  JSON file keys should be top level.
  INI file sections will be flattened.

  Args:
    file_path (str): Path of JSON or INI file to read.
    keys (list[str]): Search for these keys to return from file.

  Returns:
    Dict[cred_key: cred_value].

  Raises:
    ValueError: The file was the incorrect format.
    KeyError: Duplicate key found.
  z-Source creds file must be JSON or INI format.N)ÚosÚpathÚrealpathÚ
expanduserr   Ú
FileReaderÚjsonÚloadsÚreadr   ÚJSONDecodeErrorr   ÚConfigParserÚParsingErrorÚ
ValueErrorÚdict)	Ú	file_pathr   ÚresultÚ	real_pathÚfile_readerÚ	file_dictÚconfigÚsectionÚsection_dicts	            r   Úget_values_for_keys_from_filer1   <   sý   € ð" €&Üg‰g×ÑœrŸw™w×1Ñ1°)Ó<Ó=€)Ü×Ñ˜	Ô" kð2Ü—*‘*˜[×-Ñ-Ó/Ó0€iÜD˜) VÔ,÷ #ð  
€-øô ×Ñò 
2ä×(Ñ(Ó*€fðJØ‰IÕøÜ×&Ñ&ò JÜÐHÓIÐIðJúó ˆ'Ü˜F 7™OÓ,ˆÜd˜L¨&Õ1ò ð
2ú÷	 #ð  
€-úsB   ÁDÁ0BÂ'DÂ8C
Ã	DÃ
C)Ã)%DÄDÄDÄDÄDc                 óÔ   — t        | g d¢«      }|j                  d|j                  dd«      «      }|j                  d|j                  dd«      «      }|j                  dd«      }|||fS )z÷Scans file for AWS credentials keys.

  Key fields prefixed with "aws" take precedence.

  Args:
    file_path (str): Path to creds file.

  Returns:
    Tuple of (access_key_id, secret_access_key).
    Each tuple entry can be a string or None.
  )Úaws_access_key_idÚaws_secret_access_keyÚaccess_key_idÚsecret_access_keyÚrole_arnr3   r5   Nr4   r6   r7   )r1   Úget)r)   Ú
creds_dictr5   r6   r7   s        r   Úget_aws_creds_from_filer:   b   sw   € ô -¨Yò 9ó €*ð —.‘.Ð!4Ø!+§¡°ÀÓ!FóH€-à —n‘nÐ%<Ø%/§^¡^Ð4GÈÓ%NóPÐà^‰^˜J¨Ó-€(Ø	Ð)¨8Ð	3Ð3r   c                  ó   — t         j                  j                  «       j                  «       } | r| j                  | j
                  fS y)a  Returns creds from common AWS config file paths.

  Currently does not return "role_arn" because there is no way to extract
  this data from a boto3 Session object.

  Returns:
    Tuple of (access_key_id, secret_access_key, role_arn).
    Each tuple entry can be a string or None.
  )NN)Úboto3ÚsessionÚSessionÚget_credentialsÚ
access_keyÚ
secret_key)Úcredentialss    r   Úget_default_aws_credsrC   z   s<   € ô —‘×%Ñ%Ó'×7Ñ7Ó9€+ÙØ×!Ñ! ;×#9Ñ#9Ð9Ð9Ø	r   )Ú__doc__Ú
__future__r   r   r   r!   r   r<   Úgooglecloudsdk.core.resourcer   Úgooglecloudsdk.core.utilr   Ú	six.movesr   r   r   r1   r:   rC   © r   r   Ú<module>rJ      s?   ðñ .å &Ý Ý 'ã Û 	ã Ý :Ý *å "òò5ò,#òL4ó0r   