Created
February 27, 2025 17:08
-
-
Save mccv/ce8d7abdd2faf6fc54fe2a8756ae66a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
oauthClientID := os.Getenv("TS_OAUTH_CLIENT_ID") | |
oauthClientSecret := os.Getenv("TS_OAUTH_CLIENT_SECRET") | |
require.NotEmpty(t, oauthClientID, "TS_OAUTH_CLIENT_ID must be set") | |
require.NotEmpty(t, oauthClientSecret, "TS_OAUTH_CLIENT_SECRET must be set") | |
var oauthConfig = &clientcredentials.Config{ | |
ClientID: oauthClientID, | |
ClientSecret: oauthClientSecret, | |
TokenURL: "https://api.tailscale.com/api/v2/oauth/token", | |
} | |
client := oauthConfig.Client(context.Background()) | |
tailscale.I_Acknowledge_This_API_Is_Unstable = true | |
tsClient := tailscale.NewClient("-", nil) | |
tsClient.HTTPClient = client | |
caps := tailscale.KeyCapabilities{ | |
Devices: tailscale.KeyDeviceCapabilities{ | |
Create: tailscale.KeyDeviceCreateCapabilities{ | |
Tags: []string{"tag:smoke"}, | |
Ephemeral: true, | |
}, | |
}, | |
} | |
fmt.Println("Creating authkey") | |
authkey, _, err := tsClient.CreateKey(context.Background(), caps) | |
require.NoError(t, err, "Failed to get token") | |
fmt.Println("Got authkey") | |
hostname := fmt.Sprintf("test-%s", generateCurrentTime()) | |
// Create a tsnet server | |
s := &tsnet.Server{ | |
Hostname: hostname, // Tailscale hostname. Note that tailscale applies a sequence to this to prevent collisions. | |
AuthKey: authkey, | |
Dir: t.TempDir(), // Use test's temp dir for state | |
Ephemeral: true, | |
} | |
// Start the funnel | |
ln, err := s.ListenFunnel("tcp", ":443") | |
require.NoError(t, err, "Failed to get funnel URL") | |
funnelURL := fmt.Sprintf("https://%s", s.CertDomains()[0]) | |
fmt.Println("Funnel URL:", funnelURL) | |
return s, ln, funnelURL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment