<commit_before>package main

import "encoding/json"
import "flag"
import "fmt"
import "log"
import "net/http"
import "net/url"
import "os"
import "strings"
import "time"

import "lib/jetpack"

var Host *jetpack.Host

func getPod(ip string) *jetpack.Pod {
	for _, pod := range Host.Pods() {
		if podIp, _ := pod.Manifest.Annotations.Get("ip-address"); podIp == ip {
			return pod
		}
	}
	return nil
}

func clientIP(r *http.Request) string {
	return strings.SplitN(r.RemoteAddr, ":", 2)[0]
}

func resp200(v interface{}) (int, []byte) {
	return http.StatusOK, []byte(fmt.Sprintf("%v", v))
}

func resp404() (int, []byte) {
	return http.StatusNotFound, nil
}

func resp500(err error) (int, []byte) {
	return http.StatusInternalServerError, []byte(err.Error())
}

func doServeMetadata(r *http.Request) (int, []byte) {
	if r.URL.Path == "/" {
		// Root URL. We introduce ourselves, no questions asked.
		return http.StatusOK, []byte(fmt.Sprintf(
			"Jetpack metadata service version %v (%v) built on %v\n",
			jetpack.Version,
			jetpack.Revision,
			jetpack.BuildTimestamp))
	}

	if !strings.HasPrefix(r.URL.Path, "/acMetadata/v1/") {
		// Not a metadata service request.
		return resp404()
	}

	// API request. Ensure it has required `Metadata-Flavor:
	// AppContainter' header and it comes from a container's IP.

	if hdr, ok := r.Header["Metadata-Flavor"]; !ok || len(hdr) != 1 || hdr[0] != "AppContainer" {
		return http.StatusBadRequest, []byte("Metadata-Flavor header missing or invalid")
	}

	pod := getPod(clientIP(r))
	if pod == nil {
		return http.StatusTeapot, []byte("You are not a pod. For you, I am a teapot.")
	}

	// hack hack hack
	r.URL.User = url.User(pod.UUID.String())

	path := r.URL.Path[len("/acMetadata/v1/"):]
	switch {

	case path == "pod/uuid":
		return resp200(pod.UUID)

	case path == "pod/manifest":<commit_msg>Drop Metadata-Flavour header requirement.<commit_after>package main

import "encoding/json"
import "flag"
import "fmt"
import "log"
import "net/http"
import "net/url"
import "os"
import "strings"
import "time"

import "lib/jetpack"

var Host *jetpack.Host

func getPod(ip string) *jetpack.Pod {
	for _, pod := range Host.Pods() {
		if podIp, _ := pod.Manifest.Annotations.Get("ip-address"); podIp == ip {
			return pod
		}
	}
	return nil
}

func clientIP(r *http.Request) string {
	return strings.SplitN(r.RemoteAddr, ":", 2)[0]
}

func resp200(v interface{}) (int, []byte) {
	return http.StatusOK, []byte(fmt.Sprintf("%v", v))
}

func resp404() (int, []byte) {
	return http.StatusNotFound, nil
}

func resp500(err error) (int, []byte) {
	return http.StatusInternalServerError, []byte(err.Error())
}

func doServeMetadata(r *http.Request) (int, []byte) {
	if r.URL.Path == "/" {
		// Root URL. We introduce ourselves, no questions asked.
		return http.StatusOK, []byte(fmt.Sprintf(
			"Jetpack metadata service version %v (%v) built on %v\n",
			jetpack.Version,
			jetpack.Revision,
			jetpack.BuildTimestamp))
	}

	if !strings.HasPrefix(r.URL.Path, "/acMetadata/v1/") {
		// Not a metadata service request.
		return resp404()
	}

	pod := getPod(clientIP(r))
	if pod == nil {
		return http.StatusTeapot, []byte("You are not a pod. For you, I am a teapot.")
	}

	// hack hack hack
	r.URL.User = url.User(pod.UUID.String())

	path := r.URL.Path[len("/acMetadata/v1/"):]
	switch {

	case path == "pod/uuid":
		return resp200(pod.UUID)

	case path == "pod/manifest":
{'fraction_non_alphanumeric': 0.1660787771898883, 'fraction_numerical': 0.011757789535567314, 'mean_word_length': 3.946220930232558, 'pattern_counts': {'":': 6, '<': 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': '7023227', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1228, 'n_words': 328}