<commit_before>package amazon

import (
	"fmt"

	"github.com/mitchellh/goamz/ec2"
)

func (a *Amazon) Image(id string) (*ec2.Image, error) {
	resp, err := a.Client.Images([]string{id}, ec2.NewFilter())
	if err != nil {
		return nil, err
	}

	if len(resp.Images) != 1 {
		return nil, fmt.Errorf("the source AMI '%s' could not be found", id)
	}

	image := resp.Images[0]

	return &image, nil
}

// ImageByName returns an ec2.Image associated to the provided name
func (a *Amazon) ImageByName(name string) (*ec2.Image, error) {
	// Get new filter
	f := ec2.NewFilter()

	// Only with the name we want
	f.Add("name", name)

	resp, err := a.Client.Images([]string{}, f)
	if err != nil {
		return nil, err
	}

	if len(resp.Images) != 1 {
		return nil, fmt.Errorf("The AMI image named '%s' could not be found", name)
	}

	return &resp.Images[0], nil
}

// ImageByName returns an ec2.Image associated to the provided name
func (a *Amazon) ImageByTag(tagValue string) (*ec2.Image, error) {
	// Get new filter
	f := ec2.NewFilter()

	// Only with the name we want
	f.Add("tag-value", tagValue)

	resp, err := a.Client.Images([]string{}, f)
	if err != nil {
		return nil, err
	}

	if len(resp.Images) != 1 {
		return nil, fmt.Errorf("The AMI image with tag '%s' could not be found", tagValue)<commit_msg>kloud/api/amazon: speed up image lookup<commit_after>package amazon

import (
	"fmt"

	"github.com/mitchellh/goamz/ec2"
)

func (a *Amazon) Image(id string) (*ec2.Image, error) {
	resp, err := a.Client.Images([]string{id}, ec2.NewFilter())
	if err != nil {
		return nil, err
	}

	if len(resp.Images) != 1 {
		return nil, fmt.Errorf("the source AMI '%s' could not be found", id)
	}

	image := resp.Images[0]

	return &image, nil
}

// ImageByName returns an ec2.Image associated to the provided name
func (a *Amazon) ImageByName(name string) (*ec2.Image, error) {
	// Get new filter
	f := ec2.NewFilter()

	// Only with the name we want
	f.Add("name", name)

	resp, err := a.Client.Images([]string{}, f)
	if err != nil {
		return nil, err
	}

	if len(resp.Images) != 1 {
		return nil, fmt.Errorf("The AMI image named '%s' could not be found", name)
	}

	return &resp.Images[0], nil
}

// ImageByName returns an ec2.Image associated to the provided name
func (a *Amazon) ImageByTag(tagValue string) (*ec2.Image, error) {
	// Get new filter
	f := ec2.NewFilter()

	// Only with the name we want
	f.Add("tag:Name", tagValue)

	resp, err := a.Client.Images([]string{}, f)
	if err != nil {
		return nil, err
	}

	if len(resp.Images) != 1 {
		return nil, fmt.Errorf("The AMI image with tag '%s' could not be found", tagValue)
{'fraction_non_alphanumeric': 0.15511298353121408, 'fraction_numerical': 0.010723860589812333, 'mean_word_length': 3.5664335664335662, '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': '4370006', 'n_tokens_mistral': 981, 'n_tokens_neox': 939, 'n_words': 309}