
                            d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlmZ ddl	m
Z
 dd	l	mZ dd
l	mZ ddl	mZ ddl	mZ ddl	mZ ddlmZ ddlmZ ddlmZ ddlmZ ej.                   ej0                  ej2                  j4                  ej2                  j6                        ej8                   G d dej:                                             Zy)z@Command for remediating a Cloud Security Command Center Finding.    )absolute_import)division)print_function)unicode_literalsN)Any)findings)git)llm)prompt)pull_requests)	terraform)base)errors)flags)logc                   :    e Zd ZdZdddZed        ZdeddfdZy)	Createz-Remediates a Security Command Center finding.a\  
          Sample usage:

          $ {{command}} scc iac-remediation create --finding-org-id=123456789
          --finding-name=projects/123456789/sources/123456789/locations/global/findings/123456789
          --tfstate-file-paths=/path/to/file1.tfstate,/path/to/file2.tfstate --project-id=my-proj
          --git-config-path=/path/to/config.yaml)DESCRIPTIONEXAMPLESc                 :   t         j                  j                  |        t         j                  j                  |        t         j                  j                  |        t         j
                  j                  |        t         j                  j                  |        y )N)r   FINDING_ORG_ID_FLAGAddToParserFINDING_NAME_FLAGLLM_PROJ_ID_FLAGTFSTATE_FILE_PATHS_LIST_FLAGGIT_CONFIG_FILE_PATH_FLAG)parsers    )lib/surface/scc/iac_remediation/create.pyArgszCreate.Args6   sf    	))&1	''/	&&v.	&&226:	##//7    argsreturnNc           
      R   t        j                         \  }}|st        j                         t        j                  |j
                         |j
                  }t        j                  |       t        j                  d|       t        j                  |j                  |j                        }t        j                  |      }t        j                  |      }t        j                  |      }t!        j"                  |j$                  |      }	|	st        j                  d       yt!        j&                  ||	|      }
|
s|	D ]	  }d|v sd}
 t!        j(                  |      }t!        j*                  |      }|j-                         D ]!  \  }}d}|
r	||
v r|
|   }t/        j0                  |||||      }t3        j4                  ||j6                        }t/        j8                  |      }t!        j:                  |      \  }}|s*t!        j<                  |       t        j>                  |      t        j                  |       t        j@                  |tC        jD                  ||      |d   |d   t        jF                  |j                        z          t!        j<                  |       $ t        jH                  tC        jJ                  |      tC        jJ                  |      |d   |d   t        jF                  |j                        z   |d          t!        j<                  |       y)	zdRemediates a Security Command Center finding.

    Args:
      args: Arguments for the command.
    zrepo_root_dir: zNo TFState files found.Ngoogle_project_iam_policy remotezbranch-prefixzmain-branch-name)&r	   is_git_repor   GitRepoNotFoundErrorvalidate_git_configgit_config_pathr   Printr   MakeApiCallfinding_org_idfinding_namejsonloadsFetchIAMBindingFetchResourceNamer   fetch_tfstate_listtfstate_file_paths"get_tfstate_information_per_memberfind_tf_filesread_original_files_contentitemsr   fetch_input_promptr
   MakeLLMCall
project_idllm_response_parservalidate_tf_filesupdate_tf_filesInvalidLLMResponseErrorpush_commitr   CreateCommitMessage	ParseNameraise_prCreatePRMessage)selfr!   git_flagrepo_root_dirgit_config_dataresp	json_respiam_bindingsresource_nametfstate_json_listtfstate_informationtfstate_jsontf_filesoriginal_files_contentmember	role_datatfstate_datainput_promptresponseresponse_dictchecks                        r   Runz
Create.Run>   s    "oo/Hm''))D001**OIIoII/ 3 3T5F5FGD

4 I++I6L..y9M!44 	ii)*#FF' +,&,6 ;
 , &&}5H&BB8L)//1	l	+>!>*62..




l t?h00:m!33MBoeX!!"89,,X66		(--dF;H%O,  !2!234		
 	!!-05 26 LL%%d+%%d+!(


T..
/	0*+ 45r    )	__name__
__module____qualname____doc__detailed_helpstaticmethodr   r   rY    r    r   r   r   %   sC     6 E4	- 8 8C6c C6d C6r    r   )r]   
__future__r   r   r   r   r/   typingr   *googlecloudsdk.api_lib.scc.iac_remediationr   r	   r
   r   r   r   googlecloudsdk.callioper   .googlecloudsdk.command_lib.scc.iac_remediationr   r   googlecloudsdk.corer   HiddenReleaseTracksReleaseTrackALPHAGAUniverseCompatibleCreateCommandr   r`   r    r   <module>rn      s    G &  % '   ? : : = D @ ( A @ # D%%++T->->-A-ABY6T Y6  C Y6r    