
                         |    d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	 deee
ef      de
fdZdeee
ef      de
fd	Zy)
zWModule for storing the functions for parsing the tfstate files for dfifferent findings.    N)SequenceMappingAny)const)	arg_utilsall_resourcesreturnc                 <   g }	 t        j                  |d      }| D ]  }d}|d   dk(  r7|D ]1  }|d   d   |j                  k(  s|d   d   |j                  k(  s/d} n? n=|d   d	k(  r5|D ]0  }|d   d   |j                  k(  s|j                  |d   d
   v s.d} n |s|j	                  t        j                  |d             |j	                  t        j                          dj                  |      S # t        t         j                  f$ r
}Y d}~yd}~ww xY w)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&      s5   . +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 s0   ?C8 C8 (C8 C8 C8  AC8 8DDc                     	 t        j                  |d      }| D ]/  }|d   dk(  s|d   d   |k(  st        j                  |d      c S  y# t        t         j
                  f$ r
}Y d}~y	d}~ww xY w)
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 A0+A0)__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   