func getCustomToken()

in codelabs/health_data_analysis_codelab/src/usleep/workload.go [57:87]


func getCustomToken(nonce string) ([]byte, error) {
	httpClient := http.Client{
		Transport: &http.Transport{
			// Set the DialContext field to a function that creates
			// a new network connection to a Unix domain socket
			DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
				return net.Dial("unix", socketPath)
			},
		},
	}

	body := fmt.Sprintf(`{
		"audience": "uwear",
		"nonces": ["%s"],
		"token_type": "PKI"
	}`, nonce)

	resp, err := httpClient.Post(tokenEndpoint, contentType, strings.NewReader(body))
	if err != nil {
		return nil, err
	}

	fmt.Printf("Response from launcher: %v\n", resp)
	text, err := io.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("Failed to read resp.Body: %w", err)
	}
	fmt.Printf("Token from the attestation service: %s\n", text)

	return text, nil
}