github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/internal/adapters/cloudformation/aws/redshift/cluster.go (about)

     1  package redshift
     2  
     3  import (
     4  	"github.com/khulnasoft-lab/defsec/pkg/providers/aws/redshift"
     5  	"github.com/khulnasoft-lab/defsec/pkg/scanners/cloudformation/parser"
     6  	"github.com/khulnasoft-lab/defsec/pkg/types"
     7  )
     8  
     9  func getClusters(ctx parser.FileContext) (clusters []redshift.Cluster) {
    10  	for _, r := range ctx.GetResourcesByType("AWS::Redshift::Cluster") {
    11  
    12  		cluster := redshift.Cluster{
    13  			Metadata:                         r.Metadata(),
    14  			ClusterIdentifier:                r.GetStringProperty("ClusterIdentifier"),
    15  			AllowVersionUpgrade:              r.GetBoolProperty("AllowVersionUpgrade"),
    16  			NodeType:                         r.GetStringProperty("NodeType"),
    17  			NumberOfNodes:                    r.GetIntProperty("NumberOfNodes"),
    18  			PubliclyAccessible:               r.GetBoolProperty("PubliclyAccessible"),
    19  			MasterUsername:                   r.GetStringProperty("MasterUsername"),
    20  			VpcId:                            types.String("", r.Metadata()),
    21  			LoggingEnabled:                   types.Bool(false, r.Metadata()),
    22  			AutomatedSnapshotRetentionPeriod: r.GetIntProperty("AutomatedSnapshotRetentionPeriod"),
    23  			Encryption: redshift.Encryption{
    24  				Metadata: r.Metadata(),
    25  				Enabled:  r.GetBoolProperty("Encrypted"),
    26  				KMSKeyID: r.GetStringProperty("KmsKeyId"),
    27  			},
    28  			EndPoint: redshift.EndPoint{
    29  				Metadata: r.Metadata(),
    30  				Port:     r.GetIntProperty("Endpoint.Port"),
    31  			},
    32  			SubnetGroupName: r.GetStringProperty("ClusterSubnetGroupName", ""),
    33  		}
    34  
    35  		clusters = append(clusters, cluster)
    36  	}
    37  	return clusters
    38  }
    39  
    40  func getParameters(ctx parser.FileContext) (parameter []redshift.ClusterParameter) {
    41  
    42  	paraRes := ctx.GetResourcesByType("AWS::Redshift::ClusterParameterGroup")
    43  	var parameters []redshift.ClusterParameter
    44  	for _, r := range paraRes {
    45  		for _, par := range r.GetProperty("Parameters").AsList() {
    46  			parameters = append(parameters, redshift.ClusterParameter{
    47  				Metadata:       par.Metadata(),
    48  				ParameterName:  par.GetStringProperty("ParameterName"),
    49  				ParameterValue: par.GetStringProperty("ParameterValue"),
    50  			})
    51  		}
    52  	}
    53  	return parameters
    54  }