
                             S r SSKrSSKJrJrJr  SSKJr  SSKJ	r	  S\\\
\4      S\
4S jrS\\\
\4      S\
4S	 jrg)
zWModule for storing the functions for parsing the tfstate files for dfifferent findings.    N)SequenceMappingAny)const)	arg_utilsall_resourcesreturnc                 f   / n [         R                  " US5      nU  H  nSnUS   S:X  a<  U H5  nUS   S   UR                  :X  d  M  US   S   UR                  :X  d  M3  Sn  OG   ODUS   S	:X  a;  U H5  nUS   S   UR                  :X  d  M  UR                  US   S
   ;   d  M3  Sn  O   U(       d  M  UR	                  [
        R                  " USS95        UR	                  [        R                  5        M     SR                  U5      $ ! [        [         R                  4 a
  n SnAgSnAff = f)a  Parses the terraform state file for IAM recommender findings.

Args:
  all_resources: List of resources from the tfstate file. Resource Format:
                  {
                    "type": "google_project_iam_member",
                    "value": {
                      "member": "user:test@google.com",
                      "role": "roles/owner"
                    }
                  }
  finding_data: SCC Finding data in form of class
    (securityposture.messages.Finding).

Returns:
  A string containing the terraform resource data blocks in structured format
  for the given finding data.
  Format: (Data block as json string + SEPARATOR ...)
  If any error occurs, returns an empty string.
z+findingMetadata.iamBindingsList.iamBindingsFtypegoogle_project_iam_membervaluememberroleTgoogle_project_iam_bindingmembers   indent N)r   GetFieldValueFromMessager   r   appendjsondumpsr   BLOCK_SEPARATORjoinKeyErrorInvalidFieldPathError)r   finding_datadata_blocksiam_bindingsresourceis_relevant_resourcebinding_s           =lib/googlecloudsdk/api_lib/scc/remediation_intents/parsers.pyiam_recommender_parserr&      s8   . +55CL " #	&	8	8#Gw)W^^;7#F+w||;#'  $ F;;#Gw'7<<7>>Xg%6y%AA#'  $ 
	4::hq9:5001/ "0 77;
I33	4 s1   A D D  )D D %D 4AD D0+D0c                      [         R                  " US5      nU  H1  nUS   S:X  d  M  US   S   U:X  d  M  [        R                  " USS9s  $    g! [        [         R
                  4 a
  n SnAg	SnAff = f)
a  Parses the terraform state file for firewall findings.

Args:
  all_resources: List of resources from the tfstate file. Resource Format: {
    "type": "google_compute_firewall", "value": { "name": "default-allow-ssh"
    } }
  finding_data: SCC Finding data in form of class
    (securityposture.messages.Finding).

Returns:
  A string containing the terraform resource data block in json format
  for the given finding data.
  If any error occurs, returns an empty string.
z!findingMetadata.firewallRule.namer   google_compute_firewallr   namer   r   Nr   )r   r   r   r   r   r   )r   r   firewall_namer!   r$   s        r%   firewall_parserr+   Q   sz    "669M "
6
7
7w'=8zz(1-- " I33	4 s!   #A 
A A A A50A5)__doc__r   typingr   r   r   .googlecloudsdk.api_lib.scc.remediation_intentsr   $googlecloudsdk.command_lib.util.apisr   strr&   r+        r%   <module>r3      sa    ^  ) ) @ :6GCH-.66rGCH-.r2   