<commit_before>package common

import (
	"fmt"
	"github.com/mitchellh/goamz/ec2"
	"github.com/mitchellh/multistep"
	"github.com/mitchellh/packer/packer"
)

type StepModifyAttributes struct {
	Users        []string
	Groups       []string
	ProductCodes []string
	Description  string
}

func (s *StepModifyAttributes) Run(state map[string]interface{}) multistep.StepAction {
	ec2conn := state["ec2"].(*ec2.EC2)
	ui := state["ui"].(packer.Ui)
	amis := state["amis"].(map[string]string)
	ami := amis[ec2conn.Region.Name]

	options := &ec2.ModifyImageAttribute{
		Description:  s.Description,
		AddUsers:     s.Users,
		AddGroups:    s.Groups,
		ProductCodes: s.ProductCodes,
	}

	ui.Say("Modifying AMI attributes...")
	_, err := ec2conn.ModifyImageAttribute(ami, options)
	if err != nil {
		err := fmt.Errorf("Error modify AMI attributes: %s", err)
		state["error"] = err
		ui.Error(err.Error())
		return multistep.ActionHalt
	}

	return multistep.ActionContinue
}

func (s *StepModifyAttributes) Cleanup(state map[string]interface{}) {
	// No cleanup...
}<commit_msg>builder/amazon/common: on modify AMI attributes, skip if no work<commit_after>package common

import (
	"fmt"
	"github.com/mitchellh/goamz/ec2"
	"github.com/mitchellh/multistep"
	"github.com/mitchellh/packer/packer"
)

type StepModifyAttributes struct {
	Users        []string
	Groups       []string
	ProductCodes []string
	Description  string
}

func (s *StepModifyAttributes) Run(state map[string]interface{}) multistep.StepAction {
	ec2conn := state["ec2"].(*ec2.EC2)
	ui := state["ui"].(packer.Ui)
	amis := state["amis"].(map[string]string)
	ami := amis[ec2conn.Region.Name]

	// Determine if there is any work to do.
	valid := false
	valid = valid || s.Description != ""
	valid = valid || (s.Users != nil && len(s.Users) > 0)
	valid = valid || (s.Groups != nil && len(s.Groups) > 0)
	valid = valid || (s.ProductCodes != nil && len(s.ProductCodes) > 0)

	if !valid {
		return multistep.ActionContinue
	}

	options := &ec2.ModifyImageAttribute{
		Description:  s.Description,
		AddUsers:     s.Users,
		AddGroups:    s.Groups,
		ProductCodes: s.ProductCodes,
	}

	ui.Say("Modifying AMI attributes...")
	_, err := ec2conn.ModifyImageAttribute(ami, options)
	if err != nil {
		err := fmt.Errorf("Error modify AMI attributes: %s", err)
		state["error"] = err
		ui.Error(err.Error())
		return multistep.ActionHalt
	}

	return multistep.ActionContinue
}

func (s *StepModifyAttributes) Cleanup(state map[string]interface{}) {
	// No cleanup...
}
{'fraction_non_alphanumeric': 0.1512370311252993, 'fraction_numerical': 0.007581803671189146, 'mean_word_length': 4.158436213991769, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5518593', 'n_tokens_mistral': 924, 'n_tokens_neox': 892, 'n_words': 187}