Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2: rename package from tailscale -> tsclient #94

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions v2/client.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Package tailscale contains a basic implementation of a client for the Tailscale HTTP api. Documentation is here:
// Package tsclient contains a basic implementation of a client for the Tailscale HTTP api. Documentation is here:
// https://github.com/tailscale/tailscale/blob/main/api.md
//
// WARNING - this v2 implementation is under active development, use at your own risk.
package tailscale
package tsclient

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion v2/client_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tailscale
package tsclient

import (
_ "embed"
Expand Down
2 changes: 1 addition & 1 deletion v2/contacts.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tailscale
package tsclient

import (
"context"
Expand Down
18 changes: 9 additions & 9 deletions v2/contacts_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tailscale_test
package tsclient_test

import (
"context"
Expand All @@ -7,7 +7,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/tailscale/tailscale-client-go/v2"
tsclient "github.com/tailscale/tailscale-client-go/v2"
)

func TestClient_Contacts(t *testing.T) {
Expand All @@ -16,17 +16,17 @@ func TestClient_Contacts(t *testing.T) {
client, server := NewTestHarness(t)
server.ResponseCode = http.StatusOK

expectedContacts := &tailscale.Contacts{
Account: tailscale.Contact{
expectedContacts := &tsclient.Contacts{
Account: tsclient.Contact{
Email: "[email protected]",
FallbackEmail: "[email protected]",
NeedsVerification: false,
},
Support: tailscale.Contact{
Support: tsclient.Contact{
Email: "[email protected]",
NeedsVerification: false,
},
Security: tailscale.Contact{
Security: tsclient.Contact{
Email: "[email protected]",
FallbackEmail: "[email protected]",
NeedsVerification: true,
Expand All @@ -49,14 +49,14 @@ func TestClient_UpdateContact(t *testing.T) {
server.ResponseBody = nil

email := "[email protected]"
updateRequest := tailscale.UpdateContactRequest{
updateRequest := tsclient.UpdateContactRequest{
Email: &email,
}
err := client.Contacts().Update(context.Background(), tailscale.ContactAccount, updateRequest)
err := client.Contacts().Update(context.Background(), tsclient.ContactAccount, updateRequest)
assert.NoError(t, err)
assert.Equal(t, http.MethodPatch, server.Method)
assert.Equal(t, "/api/v2/tailnet/example.com/contacts/account", server.Path)
var receivedRequest tailscale.UpdateContactRequest
var receivedRequest tsclient.UpdateContactRequest
err = json.Unmarshal(server.Body.Bytes(), &receivedRequest)
assert.NoError(t, err)
assert.EqualValues(t, updateRequest, receivedRequest)
Expand Down
4 changes: 2 additions & 2 deletions v2/devices.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tailscale
package tsclient

import (
"context"
Expand Down Expand Up @@ -143,7 +143,7 @@ func (dr *DevicesResource) SetKey(ctx context.Context, deviceID string, key Devi
}

// SetDeviceIPv4Address sets the Tailscale IPv4 address of the device.
func (dr *DevicesResource) SetDeviceIPv4Address(ctx context.Context, deviceID string, ipv4Address string) error {
func (dr *DevicesResource) SetIPv4Address(ctx context.Context, deviceID string, ipv4Address string) error {
req, err := dr.buildRequest(ctx, http.MethodPost, dr.buildURL("device", deviceID, "ip"), requestBody(map[string]string{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by: remove stuttering Device.

"ipv4": ipv4Address,
}))
Expand Down
52 changes: 26 additions & 26 deletions v2/devices_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tailscale_test
package tsclient_test

import (
"context"
Expand All @@ -9,7 +9,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/tailscale/tailscale-client-go/v2"
tsclient "github.com/tailscale/tailscale-client-go/v2"
)

var (
Expand Down Expand Up @@ -38,7 +38,7 @@ func TestClient_SetDeviceSubnetRoutes(t *testing.T) {
func TestClient_Devices_Get(t *testing.T) {
t.Parallel()

expectedDevice := &tailscale.Device{
expectedDevice := &tsclient.Device{
Addresses: []string{"127.0.0.1"},
Name: "test",
ID: "testid",
Expand All @@ -50,11 +50,11 @@ func TestClient_Devices_Get(t *testing.T) {
},
BlocksIncomingConnections: false,
ClientVersion: "1.22.1",
Created: tailscale.Time{time.Date(2022, 2, 10, 11, 50, 23, 0, time.UTC)},
Expires: tailscale.Time{time.Date(2022, 8, 9, 11, 50, 23, 0, time.UTC)},
Created: tsclient.Time{time.Date(2022, 2, 10, 11, 50, 23, 0, time.UTC)},
Expires: tsclient.Time{time.Date(2022, 8, 9, 11, 50, 23, 0, time.UTC)},
Hostname: "test",
IsExternal: false,
LastSeen: tailscale.Time{time.Date(2022, 3, 9, 20, 3, 42, 0, time.UTC)},
LastSeen: tsclient.Time{time.Date(2022, 3, 9, 20, 3, 42, 0, time.UTC)},
MachineKey: "mkey:test",
NodeKey: "nodekey:test",
OS: "windows",
Expand All @@ -75,7 +75,7 @@ func TestClient_Devices_Get(t *testing.T) {
func TestClient_Devices_List(t *testing.T) {
t.Parallel()

expectedDevices := map[string][]tailscale.Device{
expectedDevices := map[string][]tsclient.Device{
"devices": {
{
Addresses: []string{"127.0.0.1"},
Expand All @@ -89,11 +89,11 @@ func TestClient_Devices_List(t *testing.T) {
},
BlocksIncomingConnections: false,
ClientVersion: "1.22.1",
Created: tailscale.Time{time.Date(2022, 2, 10, 11, 50, 23, 0, time.UTC)},
Expires: tailscale.Time{time.Date(2022, 8, 9, 11, 50, 23, 0, time.UTC)},
Created: tsclient.Time{time.Date(2022, 2, 10, 11, 50, 23, 0, time.UTC)},
Expires: tsclient.Time{time.Date(2022, 8, 9, 11, 50, 23, 0, time.UTC)},
Hostname: "test",
IsExternal: false,
LastSeen: tailscale.Time{time.Date(2022, 3, 9, 20, 3, 42, 0, time.UTC)},
LastSeen: tsclient.Time{time.Date(2022, 3, 9, 20, 3, 42, 0, time.UTC)},
MachineKey: "mkey:test",
NodeKey: "nodekey:test",
OS: "windows",
Expand All @@ -119,53 +119,53 @@ func TestDevices_Unmarshal(t *testing.T) {
tt := []struct {
Name string
DevicesContent []byte
Expected []tailscale.Device
Expected []tsclient.Device
UnmarshalFunc func(data []byte, v interface{}) error
}{
{
Name: "It should handle badly formed devices",
DevicesContent: jsonDevices,
UnmarshalFunc: json.Unmarshal,
Expected: []tailscale.Device{
Expected: []tsclient.Device{
{
Addresses: []string{"100.101.102.103", "fd7a:115c:a1e0:ab12:4843:cd96:6265:6667"},
Authorized: true,
BlocksIncomingConnections: false,
ClientVersion: "",
Created: tailscale.Time{},
Expires: tailscale.Time{
Created: tsclient.Time{},
Expires: tsclient.Time{
time.Date(1, 1, 1, 00, 00, 00, 0, time.UTC),
},
Hostname: "hello",
ID: "50052",
IsExternal: true,
KeyExpiryDisabled: true,
LastSeen: tailscale.Time{
LastSeen: tsclient.Time{
time.Date(2022, 4, 15, 13, 24, 40, 0, time.UTC),
},
MachineKey: "",
Name: "hello.tailscale.com",
Name: "hello.example.com",
NodeKey: "nodekey:30dc3c061ac8b33fdc6d88a4a67b053b01b56930d78cae0cf7a164411d424c0d",
OS: "linux",
UpdateAvailable: false,
User: "services@tailscale.com",
User: "services@example.com",
},
{
Addresses: []string{"100.121.200.21", "fd7a:115c:a1e0:ab12:4843:cd96:6265:e618"},
Authorized: true,
BlocksIncomingConnections: false,
ClientVersion: "1.22.2-t60b671955-gecc5d9846",
Created: tailscale.Time{
Created: tsclient.Time{
time.Date(2022, 3, 5, 17, 10, 27, 0, time.UTC),
},
Expires: tailscale.Time{
Expires: tsclient.Time{
time.Date(2022, 9, 1, 17, 10, 27, 0, time.UTC),
},
Hostname: "foo",
ID: "50053",
IsExternal: false,
KeyExpiryDisabled: true,
LastSeen: tailscale.Time{
LastSeen: tsclient.Time{
time.Date(2022, 4, 15, 13, 25, 21, 0, time.UTC),
},
MachineKey: "mkey:30dc3c061ac8b33fdc6d88a4a67b053b01b56930d78cae0cf7a164411d424c0d",
Expand All @@ -181,7 +181,7 @@ func TestDevices_Unmarshal(t *testing.T) {

for _, tc := range tt {
t.Run(tc.Name, func(t *testing.T) {
actual := make(map[string][]tailscale.Device)
actual := make(map[string][]tsclient.Device)

assert.NoError(t, tc.UnmarshalFunc(tc.DevicesContent, &actual))
assert.EqualValues(t, tc.Expected, actual["devices"])
Expand All @@ -207,7 +207,7 @@ func TestClient_DeviceSubnetRoutes(t *testing.T) {

client, server := NewTestHarness(t)
server.ResponseCode = http.StatusOK
server.ResponseBody = &tailscale.DeviceRoutes{
server.ResponseBody = &tsclient.DeviceRoutes{
Advertised: []string{"127.0.0.1"},
Enabled: []string{"127.0.0.1"},
}
Expand Down Expand Up @@ -265,7 +265,7 @@ func TestClient_SetDeviceKey(t *testing.T) {
server.ResponseCode = http.StatusOK

const deviceID = "test"
expected := tailscale.DeviceKey{
expected := tsclient.DeviceKey{
KeyExpiryDisabled: true,
}

Expand All @@ -274,7 +274,7 @@ func TestClient_SetDeviceKey(t *testing.T) {
assert.EqualValues(t, http.MethodPost, server.Method)
assert.EqualValues(t, "/api/v2/device/"+deviceID+"/key", server.Path)

var actual tailscale.DeviceKey
var actual tsclient.DeviceKey
assert.NoError(t, json.Unmarshal(server.Body.Bytes(), &actual))
assert.EqualValues(t, expected, actual)

Expand All @@ -288,7 +288,7 @@ func TestClient_SetDeviceIPv4Address(t *testing.T) {
const deviceID = "test"
address := "100.64.0.1"

assert.NoError(t, client.Devices().SetDeviceIPv4Address(context.Background(), deviceID, address))
assert.NoError(t, client.Devices().SetIPv4Address(context.Background(), deviceID, address))
assert.Equal(t, http.MethodPost, server.Method)
assert.EqualValues(t, "/api/v2/device/"+deviceID+"/ip", server.Path)
}
Expand All @@ -303,7 +303,7 @@ func TestClient_UserAgent(t *testing.T) {
assert.Equal(t, "tailscale-client-go", server.Header.Get("User-Agent"))

// Check a custom user-agent.
client = &tailscale.Client{
client = &tsclient.Client{
APIKey: "fake key",
BaseURL: server.BaseURL,
UserAgent: "custom-user-agent",
Expand Down
9 changes: 4 additions & 5 deletions v2/tailscale_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tailscale_test
package tsclient_test

import (
"bytes"
Expand All @@ -11,8 +11,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/tailscale/tailscale-client-go/v2"
tsclient "github.com/tailscale/tailscale-client-go/v2"
)

type TestServer struct {
Expand All @@ -29,7 +28,7 @@ type TestServer struct {
ResponseBody interface{}
}

func NewTestHarness(t *testing.T) (*tailscale.Client, *TestServer) {
func NewTestHarness(t *testing.T) (*tsclient.Client, *TestServer) {
t.Helper()

testServer := &TestServer{
Expand Down Expand Up @@ -58,7 +57,7 @@ func NewTestHarness(t *testing.T) (*tailscale.Client, *TestServer) {
baseURL := fmt.Sprintf("http://localhost:%v", listener.Addr().(*net.TCPAddr).Port)
testServer.BaseURL, err = url.Parse(baseURL)
assert.NoError(t, err)
client := &tailscale.Client{
client := &tsclient.Client{
BaseURL: testServer.BaseURL,
APIKey: "not a real key",
Tailnet: "example.com",
Expand Down
4 changes: 2 additions & 2 deletions v2/testdata/devices.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"keyExpiryDisabled": true,
"lastSeen": "2022-04-15T13:24:40Z",
"machineKey": "",
"name": "hello.tailscale.com",
"name": "hello.example.com",
"nodeKey": "nodekey:30dc3c061ac8b33fdc6d88a4a67b053b01b56930d78cae0cf7a164411d424c0d",
"os": "linux",
"updateAvailable": false,
"user": "services@tailscale.com"
"user": "services@example.com"
},
{
"addresses": [
Expand Down
2 changes: 1 addition & 1 deletion v2/webhooks.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tailscale
package tsclient

import (
"context"
Expand Down
Loading
Loading