
                            S r SSKJr  SSKJr  SSKJr  SSKrSSKJrJr  SSK	J
r
  SSKJr  S	\S
\4S jrS\S\\\\\\   4   4   S\S\\   S\S
\4S jrS\\\\\\   4   4   S\S\S\\   S\S\S
\4S jrS\S
\\\4   4S jrg)zLibrary for fetching TF Files.    )absolute_import)division)unicode_literalsN)DictList)prompt_format)files	file_pathreturnc                 2    [         R                  " U 5      nU$ )zkReads the TF file.

Args:
  file_path: The path of the file to read.

Returns:
  The contents of the file.
)r	   ReadFileContents)r
   files     8lib/googlecloudsdk/api_lib/scc/iac_remediation/prompt.py	read_filer      s     
				*$	+    tfstate_informationiam_bindingsresource_nametf_filesmemberc                     [         R                  " 5       nSU ;   a  UR                  5       nOUR                  5       n[	        UU UUUU5      $ )aS  Generates the prompt for iam policy.

Args:
  tfstate_information: TFState information for the given IAM bindings.
  iam_bindings: IAM bindings for the resource.
  resource_name: Resource name for which the finding was generated.
  tf_files: List of TF files.
  member: Member for which the prompt is generated.

Returns:
  Prompt string.
google_project_iam_policy)r   PromptFormatLookupget_policy_prompt_templateget_binding_prompt_template_fetch_prompt)r   r   r   r   r   prompt_format_data
prompt_strs          r   fetch_input_promptr   )   sW    & %779 $77#>>@J#??AJ	
 r   r   c                    SU-   S-   nU R                  5        H&  u  pxXgS-   [        R                  " U5      -   S-   -  nM(     UR                  SU5      nUR                  S[        R                  " U5      5      nUR                  SU5      nSn	U H"  n
U	SU
-   S-   S	-   -  n	U	[	        U
5      S
-   -  n	M$     UR                  SU	5      nU$ )as  Generates the prompt string.

Args:
  iam_bindings: IAM bindings for the resource.
  tfstate_information: TFState information for the given IAM bindings.
  resource_name: Resource name for which the finding was generated.
  tf_files: List of TF files.
  prompt_str: Prompt file name.
  member: Member for which the prompt is generated.

Returns:
  Prompt for iam policy.
zmember: 
z : 
z{{iam_bindings}}z{{tfstate_information}}z{{resource_name}} z
FilePath= ```
z
```
z{{input_tf_files}})itemsjsondumpsreplacer   )r   r   r   r   r   r   iam_bindings_stractionroles	files_strtf_files              r   r   r   K   s    *  &(4/#))+mf(4::e+<<tCC ,!!** !!,?!@* !!"5}E*)g'$.88I7#i//I  !!"6	B*	r   responsec                    0 nSnSnU R                  5        H  nUR                  S5      (       ag  U(       a:  UR                  SS5      nUR                  SS5      nUR                  SS5      nX1U'   UR                  S5      S   R	                  5       nSnM  X4S-   -  nM     U(       a:  UR                  SS5      nUR                  SS5      nUR                  SS5      nX1U'   U$ )	zjParses the LLM response.

Args:
  response: LLM response.

Returns:
  Dict of file path and file content.
r"   FilePathr#   z
```z```=   r!   )
splitlines
startswithr'   splitstrip)r-   response_dictr
   file_contentlines        r   llm_response_parserr9   r   s     -),!!#dz""	#++GR8#++GR8#++E26#/i **S/!$**,ilTk!l $ ''4L''4L''r2L+)	r   )__doc__
__future__r   r   r   r%   typingr   r   *googlecloudsdk.api_lib.scc.iac_remediationr   googlecloudsdk.core.utilr	   strr   r   r   r9    r   r   <module>rA      s   % &  '   D *
 
 
sDd3i001  3i	
  	D$sDd3i001$$ $ 3i	$
 $ $ 	$NcNr   