<commit_before>package resources

import (
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
)

type CognitoUserPool struct {
	svc  *cognitoidentityprovider.CognitoIdentityProvider
	name *string
	id   *string
}

func init() {
	register("CognitoUserPool", ListCognitoUserPools)
}

func ListCognitoUserPools(sess *session.Session) ([]Resource, error) {
	svc := cognitoidentityprovider.New(sess)
	resources := []Resource{}

	params := &cognitoidentityprovider.ListUserPoolsInput{
		MaxResults: aws.Int64(50),
	}

	for {
		output, err := svc.ListUserPools(params)
		if err != nil {
			return nil, err
		}

		for _, pool := range output.UserPools {
			resources = append(resources, &CognitoUserPool{
				svc:  svc,
				name: pool.Name,
				id:   pool.Id,
			})
		}

		if output.NextToken == nil {
			break
		}

		params.NextToken = output.NextToken
	}

	return resources, nil
}

func (f *CognitoUserPool) Remove() error {

	_, err := f.svc.DeleteUserPool(&cognitoidentityprovider.DeleteUserPoolInput{
		UserPoolId: f.id,
	})

	return err
}

func (f *CognitoUserPool) String() string {
	return *f.name<commit_msg>Delete the domain from the user pool if it exists before deleting the pool itself<commit_after>package resources

import (
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
)

type CognitoUserPool struct {
	svc    *cognitoidentityprovider.CognitoIdentityProvider
	name   *string
	id     *string
	domain *string
}

func init() {
	register("CognitoUserPool", ListCognitoUserPools)
}

func ListCognitoUserPools(sess *session.Session) ([]Resource, error) {
	svc := cognitoidentityprovider.New(sess)
	resources := []Resource{}

	params := &cognitoidentityprovider.ListUserPoolsInput{
		MaxResults: aws.Int64(50),
	}

	for {
		output, err := svc.ListUserPools(params)
		if err != nil {
			return nil, err
		}

		for _, pool := range output.UserPools {
			describeParams := &cognitoidentityprovider.DescribeUserPoolInput{
				UserPoolId: pool.Id,
			}
			userpool, err := svc.DescribeUserPool(describeParams)
			if err != nil {
				return nil, err
			}
			domain := ""
			if userpool.UserPool.Domain != nil {
				domain = *userpool.UserPool.Domain
			}

			resources = append(resources, &CognitoUserPool{
				svc:    svc,
				name:   pool.Name,
				id:     pool.Id,
				domain: &domain,
			})
		}

		if output.NextToken == nil {
			break
		}

		params.NextToken = output.NextToken
	}

	return resources, nil
}

func (f *CognitoUserPool) Remove() error {
	if *f.domain != "" {
		domainParams := &cognitoidentityprovider.DeleteUserPoolDomainInput{
			Domain:     f.domain,
			UserPoolId: f.id,
		}
		_, err := f.svc.DeleteUserPoolDomain(domainParams)
		if err != nil {
			return err
		}
	}

	_, err := f.svc.DeleteUserPool(&cognitoidentityprovider.DeleteUserPoolInput{
		UserPoolId: f.id,
	})

	return err
}

func (f *CognitoUserPool) String() string {
	return *f.name
{'fraction_non_alphanumeric': 0.12220026350461133, 'fraction_numerical': 0.002635046113306983, 'mean_word_length': 3.7751572327044025, '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': '1660646', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1087, 'n_words': 215}