github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/internal/adapters/terraform/github/branch_protections/adapt.go (about)

     1  package branch_protections
     2  
     3  import (
     4  	"github.com/khulnasoft-lab/defsec/pkg/providers/github"
     5  	"github.com/khulnasoft-lab/defsec/pkg/terraform"
     6  )
     7  
     8  func Adapt(modules terraform.Modules) []github.BranchProtection {
     9  	return adaptBranchProtections(modules)
    10  }
    11  
    12  func adaptBranchProtections(modules terraform.Modules) []github.BranchProtection {
    13  	var branchProtections []github.BranchProtection
    14  	for _, module := range modules {
    15  		for _, resource := range module.GetResourcesByType("github_branch_protection") {
    16  			branchProtections = append(branchProtections, adaptBranchProtection(resource))
    17  		}
    18  	}
    19  	return branchProtections
    20  }
    21  
    22  func adaptBranchProtection(resource *terraform.Block) github.BranchProtection {
    23  
    24  	branchProtection := github.BranchProtection{
    25  		Metadata:             resource.GetMetadata(),
    26  		RequireSignedCommits: resource.GetAttribute("require_signed_commits").AsBoolValueOrDefault(false, resource),
    27  	}
    28  
    29  	return branchProtection
    30  }