<commit_before>package metadata

var SupportedProviders = map[ProviderType]Source{
	GCE: &Provider{
		Name:              "Google Compute Engine",
		SupportedVersions: map[Version]bool{"v1": true},

		URL: "http://metadata.google.internal/computeMetadata/%s/instance/?recursive=true",
	},
	EC2: &Provider{
		Name:              "Amazon Elastic Compute Cloud",
		SupportedVersions: map[Version]bool{"latest": true},

		URL: "http://169.254.169.254/%s/meta-data/",
	},
}<commit_msg>Include supported meta-data providers<commit_after>package metadata

import (
	"time"

	"github.com/tmrts/flamingo/pkg/datasrc/metadata/gce"
	"github.com/tmrts/flamingo/pkg/request"
)

type ProviderType string

// List of currently supported providers
var SupportedProviders = map[string]Provider{
	"GCE":       gce.MetadataService,
	"Openstack": configdrive.Mount,
	/*
	 *        Name: "Google Compute Engine",
	 *
	 *        URL: "http://metadata.google.internal/computeMetadata/%s/instance/?recursive=true",
	 */
	/*
	 *    "EC2": &Provider{
	 *        Name: "Amazon Elastic Compute Cloud",
	 *        SupportedVersions: []Version{
	 *            "latest",
	 *        },
	 *
	 *        URL: "http://169.254.169.254/%s/meta-data/",
	 *    },
	 */
}

// Get queries metadata services and returns the available metadata digest
// Since there will be only one metadata service operational (or multiple ones returning the same),
// it queries each known service and returns at timeout or a successful response.
func Get(timeout time.Duration) (digest Digest) {
	if configdrive.Available() {
		return configdrive.Metadata()
	}

	metadataChan := make(chan Digest, len(SupportedProviders))
	defer close(metadataChan)

	go func(mdchan chan Digest) {
		for _, p := range SupportedProviders {
			go func(c chan Digest) {
				metadata, err := p.Metadata(request.DefaultClient)
				if err != nil {
					return
				}

				c <- Digest()
			}(mdchan)
		}

		time.Sleep(timeout)
		c <- nil
		close(c)
	}(metadataChan)

	return <-metadataChan
}
{'fraction_non_alphanumeric': 0.13203786746387644, 'fraction_numerical': 0.013452914798206279, 'mean_word_length': 3.2997858672376874, 'pattern_counts': {'":': 5, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1358736', 'n_tokens_mistral': 707, 'n_tokens_neox': 612, 'n_words': 152}