func NewRequest()

in cli/cmd/provider.go [21:46]


func NewRequest() (*resty.Request, error) {
	ctx := context.Background()
	scopes := []string{
		"https://www.googleapis.com/auth/cloud-platform",
	}
	ts, err := google.DefaultTokenSource(ctx, scopes...)
	if err != nil {
		fmt.Println("Failed to create new token source")
		return nil, err
	}
	token, err := ts.Token()
	if err != nil {
		fmt.Println("Failed to get token")
		return nil, err
	}

	request := resty.New().
		SetDebug(Verbose).
		NewRequest().
		SetAuthScheme(token.TokenType).
		// Use identity token to invoke Cloud Function
		// https://cloud.google.com/functions/docs/securing/authenticating#authenticating_developer_testing
		SetAuthToken(token.Extra("id_token").(string))

	return request, nil
}