<commit_before>package sparta

import (
	"bytes"
	"fmt"
	"strings"
	"text/template"

	gocf "github.com/mweagle/go-cloudformation"
	"github.com/rs/zerolog"
)

// Utility function to marshal an interface
func marshalInterface(item interface{}) interface{} {
	if item != nil {
		return item
	}
	return nil
}

// Utility function to marshal an int
func marshalInt(intVal int64) *gocf.IntegerExpr {
	if intVal != 0 {
		return gocf.Integer(intVal)
	}
	return nil
}

// Utility function to marshal a string
func marshalString(stringVal string) *gocf.StringExpr {
	if stringVal != "" {
		return gocf.String(stringVal)
	}
	return nil
}

func marshalStringExpr(stringExpr gocf.Stringable) *gocf.StringExpr {
	if stringExpr != nil {
		return stringExpr.String()
	}
	return nil
}

// Utility function to marshal a string lsit
func marshalStringList(stringVals []string) *gocf.StringListExpr {
	if len(stringVals) != 0 {
		stringableList := make([]gocf.Stringable, len(stringVals))
		for eachIndex, eachStringVal := range stringVals {
			stringableList[eachIndex] = gocf.String(eachStringVal)
		}
		return gocf.StringList(stringableList...)
	}
	return nil
}

// Utility function to marshal a boolean
func marshalBool(boolValue bool) *gocf.BoolExpr {
	if !boolValue {
		return gocf.Bool(boolValue)
	}
	return nil
}

// resourceOutputs is responsible for returning the conditional
// set of CloudFormation outputs for a given resource type.
func resourceOutputs(resourceName string,
	resource gocf.ResourceProperties,
	logger *zerolog.Logger) ([]string, error) {

	outputProps := []string{}
	switch typedResource := resource.(type) {
	case gocf.IAMRole:
		// NOP
	case *gocf.DynamoDBTable:
		if typedResource.StreamSpecification != nil {
			outputProps = append(outputProps, "StreamArn")
		}
	case gocf.DynamoDBTable:
		if typedResource.StreamSpecification != nil {
			outputProps = append(outputProps, "StreamArn")
		}
	case gocf.KinesisStream,
		*gocf.KinesisStream:
		outputProps = append(outputProps, "Arn")
	case gocf.Route53RecordSet,
		*gocf.Route53RecordSet:
		// NOP
	case gocf.S3Bucket,
		*gocf.S3Bucket:
		outputProps = append(outputProps, "DomainName", "WebsiteURL")
	case gocf.SNSTopic,
		*gocf.SNSTopic:
		outputProps = append(outputProps, "TopicName")
	case gocf.SQSQueue,
		*gocf.SQSQueue:
		outputProps = append(outputProps, "Arn", "QueueName")
	default:
		logger.Warn().
			Str("ResourceType", fmt.Sprintf("%T", typedResource)).
			Msg("Discovery information for dependency not yet implemented")
	}
	return outputProps, nil
}

func newCloudFormationResource(resourceType string, logger *zerolog.Logger) (gocf.ResourceProperties, error) {
	resProps := gocf.NewResourceByType(resourceType)
	if nil == resProps {

		logger.Fatal().
			Str("Type", resourceType).
			Msg("Failed to create CloudFormation CustomResource!")<commit_msg>Prefer schema outputs to hardcoded list<commit_after>package sparta

import (
	"bytes"
	"fmt"
	"strings"
	"text/template"

	gocf "github.com/mweagle/go-cloudformation"
	"github.com/rs/zerolog"
)

// Utility function to marshal an interface
func marshalInterface(item interface{}) interface{} {
	if item != nil {
		return item
	}
	return nil
}

// Utility function to marshal an int
func marshalInt(intVal int64) *gocf.IntegerExpr {
	if intVal != 0 {
		return gocf.Integer(intVal)
	}
	return nil
}

// Utility function to marshal a string
func marshalString(stringVal string) *gocf.StringExpr {
	if stringVal != "" {
		return gocf.String(stringVal)
	}
	return nil
}

func marshalStringExpr(stringExpr gocf.Stringable) *gocf.StringExpr {
	if stringExpr != nil {
		return stringExpr.String()
	}
	return nil
}

// Utility function to marshal a string lsit
func marshalStringList(stringVals []string) *gocf.StringListExpr {
	if len(stringVals) != 0 {
		stringableList := make([]gocf.Stringable, len(stringVals))
		for eachIndex, eachStringVal := range stringVals {
			stringableList[eachIndex] = gocf.String(eachStringVal)
		}
		return gocf.StringList(stringableList...)
	}
	return nil
}

// Utility function to marshal a boolean
func marshalBool(boolValue bool) *gocf.BoolExpr {
	if !boolValue {
		return gocf.Bool(boolValue)
	}
	return nil
}

// resourceOutputs is responsible for returning the conditional
// set of CloudFormation outputs for a given resource type. These are
// produced from the schema
func resourceOutputs(resourceName string,
	resource gocf.ResourceProperties,
	logger *zerolog.Logger) ([]string, error) {

	outputProps := resource.CfnResourceAttributes()
	return outputProps, nil
}

func newCloudFormationResource(resourceType string, logger *zerolog.Logger) (gocf.ResourceProperties, error) {
	resProps := gocf.NewResourceByType(resourceType)
	if nil == resProps {

		logger.Fatal().
			Str("Type", resourceType).
			Msg("Failed to create CloudFormation CustomResource!")
{'fraction_non_alphanumeric': 0.10783907092492742, 'fraction_numerical': 0.002903359601824969, 'mean_word_length': 4.728028503562945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '895106', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1603, 'n_words': 404}