github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/providers/google/iam/iam.go (about)

     1  package iam
     2  
     3  import (
     4  	defsecTypes "github.com/khulnasoft-lab/defsec/pkg/types"
     5  )
     6  
     7  type IAM struct {
     8  	Organizations                 []Organization
     9  	WorkloadIdentityPoolProviders []WorkloadIdentityPoolProvider
    10  }
    11  
    12  type Organization struct {
    13  	Metadata defsecTypes.Metadata
    14  	Folders  []Folder
    15  	Projects []Project
    16  	Members  []Member
    17  	Bindings []Binding
    18  }
    19  
    20  type Folder struct {
    21  	Metadata defsecTypes.Metadata
    22  	Folders  []Folder
    23  	Projects []Project
    24  	Members  []Member
    25  	Bindings []Binding
    26  }
    27  
    28  type Project struct {
    29  	Metadata          defsecTypes.Metadata
    30  	AutoCreateNetwork defsecTypes.BoolValue
    31  	Members           []Member
    32  	Bindings          []Binding
    33  }
    34  
    35  type Binding struct {
    36  	Metadata                      defsecTypes.Metadata
    37  	Members                       []defsecTypes.StringValue
    38  	Role                          defsecTypes.StringValue
    39  	IncludesDefaultServiceAccount defsecTypes.BoolValue
    40  }
    41  
    42  type Member struct {
    43  	Metadata              defsecTypes.Metadata
    44  	Member                defsecTypes.StringValue
    45  	Role                  defsecTypes.StringValue
    46  	DefaultServiceAccount defsecTypes.BoolValue
    47  }
    48  
    49  type WorkloadIdentityPoolProvider struct {
    50  	Metadata                       defsecTypes.Metadata
    51  	WorkloadIdentityPoolId         defsecTypes.StringValue
    52  	WorkloadIdentityPoolProviderId defsecTypes.StringValue
    53  	AttributeCondition             defsecTypes.StringValue
    54  }
    55  
    56  func (p *IAM) AllProjects() []Project {
    57  	var projects []Project
    58  	for _, org := range p.Organizations {
    59  		projects = append(projects, org.Projects...)
    60  		for _, folder := range org.Folders {
    61  			projects = append(projects, folder.Projects...)
    62  			for _, desc := range folder.AllFolders() {
    63  				projects = append(projects, desc.Projects...)
    64  			}
    65  		}
    66  	}
    67  	return projects
    68  }
    69  
    70  func (p *IAM) AllFolders() []Folder {
    71  	var folders []Folder
    72  	for _, org := range p.Organizations {
    73  		folders = append(folders, org.Folders...)
    74  		for _, folder := range org.Folders {
    75  			folders = append(folders, folder.AllFolders()...)
    76  		}
    77  	}
    78  	return folders
    79  }
    80  
    81  func (f *Folder) AllFolders() []Folder {
    82  	var folders []Folder
    83  	for _, folder := range f.Folders {
    84  		folders = append(folders, folder)
    85  		folders = append(folders, folder.AllFolders()...)
    86  	}
    87  	return folders
    88  }