Skip to content

Commit 8016f5e

Browse files
committed
v2: stop using factored type blocks
Updates #cleanup Signed-off-by: Percy Wegmann <[email protected]>
1 parent d22e281 commit 8016f5e

File tree

11 files changed

+310
-334
lines changed

11 files changed

+310
-334
lines changed

v2/client.go

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,51 +20,49 @@ import (
2020
"github.com/tailscale/hujson"
2121
)
2222

23-
type (
24-
// Client is used to perform actions against the Tailscale API.
25-
Client struct {
26-
// BaseURL is the base URL for accessing the Tailscale API server. Defaults to https://api.tailscale.com.
27-
BaseURL *url.URL
28-
// UserAgent configures the User-Agent HTTP header for requests. Defaults to "tailscale-client-go".
29-
UserAgent string
30-
// APIKey allows specifying an APIKey to use for authentication.
31-
// To use OAuth Client credentials, construct an [http.Client] using [OAuthConfig] and specify that below.
32-
APIKey string
33-
// Tailnet allows specifying a specific Tailnet by name, to which this Client will connect by default.
34-
Tailnet string
35-
36-
// HTTP is the [http.Client] to use for requests to the API server.
37-
// If not specified, a new [http.Client] with a Timeout of 1 minute will be used.
38-
HTTP *http.Client
39-
40-
initOnce sync.Once
41-
42-
// Specific resources
43-
contacts *ContactsResource
44-
devicePosture *DevicePostureResource
45-
devices *DevicesResource
46-
dns *DNSResource
47-
keys *KeysResource
48-
logging *LoggingResource
49-
policyFile *PolicyFileResource
50-
tailnetSettings *TailnetSettingsResource
51-
users *UsersResource
52-
webhooks *WebhooksResource
53-
}
23+
// Client is used to perform actions against the Tailscale API.
24+
type Client struct {
25+
// BaseURL is the base URL for accessing the Tailscale API server. Defaults to https://api.tailscale.com.
26+
BaseURL *url.URL
27+
// UserAgent configures the User-Agent HTTP header for requests. Defaults to "tailscale-client-go".
28+
UserAgent string
29+
// APIKey allows specifying an APIKey to use for authentication.
30+
// To use OAuth Client credentials, construct an [http.Client] using [OAuthConfig] and specify that below.
31+
APIKey string
32+
// Tailnet allows specifying a specific Tailnet by name, to which this Client will connect by default.
33+
Tailnet string
34+
35+
// HTTP is the [http.Client] to use for requests to the API server.
36+
// If not specified, a new [http.Client] with a Timeout of 1 minute will be used.
37+
HTTP *http.Client
38+
39+
initOnce sync.Once
40+
41+
// Specific resources
42+
contacts *ContactsResource
43+
devicePosture *DevicePostureResource
44+
devices *DevicesResource
45+
dns *DNSResource
46+
keys *KeysResource
47+
logging *LoggingResource
48+
policyFile *PolicyFileResource
49+
tailnetSettings *TailnetSettingsResource
50+
users *UsersResource
51+
webhooks *WebhooksResource
52+
}
5453

55-
// APIError type describes an error as returned by the Tailscale API.
56-
APIError struct {
57-
Message string `json:"message"`
58-
Data []APIErrorData `json:"data"`
59-
status int
60-
}
54+
// APIError type describes an error as returned by the Tailscale API.
55+
type APIError struct {
56+
Message string `json:"message"`
57+
Data []APIErrorData `json:"data"`
58+
status int
59+
}
6160

62-
// APIErrorData type describes elements of the data field within errors returned by the Tailscale API.
63-
APIErrorData struct {
64-
User string `json:"user"`
65-
Errors []string `json:"errors"`
66-
}
67-
)
61+
// APIErrorData type describes elements of the data field within errors returned by the Tailscale API.
62+
type APIErrorData struct {
63+
User string `json:"user"`
64+
Errors []string `json:"errors"`
65+
}
6866

6967
const defaultContentType = "application/json"
7068
const defaultHttpClientTimeout = time.Minute

v2/contacts.go

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,29 @@ const (
1919
ContactSecurity ContactType = "security"
2020
)
2121

22-
type (
23-
// ContactType defines the type of contact.
24-
ContactType string
22+
// ContactType defines the type of contact.
23+
type ContactType string
2524

26-
// Contacts type defines the object returned when retrieving contacts.
27-
Contacts struct {
28-
Account Contact `json:"account"`
29-
Support Contact `json:"support"`
30-
Security Contact `json:"security"`
31-
}
25+
// Contacts type defines the object returned when retrieving contacts.
26+
type Contacts struct {
27+
Account Contact `json:"account"`
28+
Support Contact `json:"support"`
29+
Security Contact `json:"security"`
30+
}
3231

33-
// Contact type defines the structure of an individual contact for the tailnet.
34-
Contact struct {
35-
Email string `json:"email"`
36-
// FallbackEmail is the email used when Email has not been verified.
37-
FallbackEmail string `json:"fallbackEmail,omitempty"`
38-
// NeedsVerification is true if Email needs to be verified.
39-
NeedsVerification bool `json:"needsVerification"`
40-
}
32+
// Contact type defines the structure of an individual contact for the tailnet.
33+
type Contact struct {
34+
Email string `json:"email"`
35+
// FallbackEmail is the email used when Email has not been verified.
36+
FallbackEmail string `json:"fallbackEmail,omitempty"`
37+
// NeedsVerification is true if Email needs to be verified.
38+
NeedsVerification bool `json:"needsVerification"`
39+
}
4140

42-
// UpdateContactRequest type defines the structure of a request to update a Contact.
43-
UpdateContactRequest struct {
44-
Email *string `json:"email,omitempty"`
45-
}
46-
)
41+
// UpdateContactRequest type defines the structure of a request to update a Contact.
42+
type UpdateContactRequest struct {
43+
Email *string `json:"email,omitempty"`
44+
}
4745

4846
// Get retieves the [Contacts] for the tailnet.
4947
func (cr *ContactsResource) Get(ctx context.Context) (*Contacts, error) {

v2/device_posture.go

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,35 @@ const (
2222
PostureIntegrationProviderSentinelOne PostureIntegrationProvider = "sentinelone"
2323
)
2424

25-
type (
26-
// PostureIntegrationProvider identifies a supported posture integration data provider.
27-
PostureIntegrationProvider string
28-
29-
// PostureIntegration is a configured posture integration.
30-
PostureIntegration struct {
31-
ID string `json:"id,omitempty"`
32-
Provider PostureIntegrationProvider `json:"provider,omitempty"`
33-
CloudID string `json:"cloudId,omitempty"`
34-
ClientID string `json:"clientId,omitempty"`
35-
TenantID string `json:"tenantId,omitempty"`
36-
}
25+
// PostureIntegrationProvider identifies a supported posture integration data provider.
26+
type PostureIntegrationProvider string
27+
28+
// PostureIntegration is a configured posture integration.
29+
type PostureIntegration struct {
30+
ID string `json:"id,omitempty"`
31+
Provider PostureIntegrationProvider `json:"provider,omitempty"`
32+
CloudID string `json:"cloudId,omitempty"`
33+
ClientID string `json:"clientId,omitempty"`
34+
TenantID string `json:"tenantId,omitempty"`
35+
}
3736

38-
// CreatePostureIntegrationRequest is a request to create a posture integration.
39-
CreatePostureIntegrationRequest struct {
40-
Provider PostureIntegrationProvider `json:"provider,omitempty"`
41-
CloudID string `json:"cloudId,omitempty"`
42-
ClientID string `json:"clientId,omitempty"`
43-
TenantID string `json:"tenantId,omitempty"`
44-
ClientSecret string `json:"clientSecret,omitempty"`
45-
}
37+
// CreatePostureIntegrationRequest is a request to create a posture integration.
38+
type CreatePostureIntegrationRequest struct {
39+
Provider PostureIntegrationProvider `json:"provider,omitempty"`
40+
CloudID string `json:"cloudId,omitempty"`
41+
ClientID string `json:"clientId,omitempty"`
42+
TenantID string `json:"tenantId,omitempty"`
43+
ClientSecret string `json:"clientSecret,omitempty"`
44+
}
4645

47-
// UpdatePostureIntegrationRequest is a request to update a posture integration.
48-
UpdatePostureIntegrationRequest struct {
49-
CloudID string `json:"cloudId,omitempty"`
50-
ClientID string `json:"clientId,omitempty"`
51-
TenantID string `json:"tenantId,omitempty"`
52-
// ClientSecret may be omitted to preserve the existing value
53-
ClientSecret *string `json:"clientSecret,omitempty"`
54-
}
55-
)
46+
// UpdatePostureIntegrationRequest is a request to update a posture integration.
47+
type UpdatePostureIntegrationRequest struct {
48+
CloudID string `json:"cloudId,omitempty"`
49+
ClientID string `json:"clientId,omitempty"`
50+
TenantID string `json:"tenantId,omitempty"`
51+
// ClientSecret may be omitted to preserve the existing value
52+
ClientSecret *string `json:"clientSecret,omitempty"`
53+
}
5654

5755
// List lists every configured [PostureIntegration].
5856
func (pr *DevicePostureResource) ListIntegrations(ctx context.Context) ([]PostureIntegration, error) {

v2/devices.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ type DevicesResource struct {
1515
*Client
1616
}
1717

18-
type (
19-
DeviceRoutes struct {
20-
Advertised []string `json:"advertisedRoutes"`
21-
Enabled []string `json:"enabledRoutes"`
22-
}
23-
)
18+
type DeviceRoutes struct {
19+
Advertised []string `json:"advertisedRoutes"`
20+
Enabled []string `json:"enabledRoutes"`
21+
}
2422

2523
// Time wraps a time and allows for unmarshalling timestamps that represent an empty time as an empty string (e.g "")
2624
// this is used by the tailscale API when it returns devices that have no created date, such as its hello service.
@@ -127,13 +125,11 @@ func (dr *DevicesResource) SetTags(ctx context.Context, deviceID string, tags []
127125
return dr.do(req, nil)
128126
}
129127

130-
type (
131-
// DeviceKey type represents the properties of the key of an individual device within
132-
// the tailnet.
133-
DeviceKey struct {
134-
KeyExpiryDisabled bool `json:"keyExpiryDisabled"` // Whether or not this device's key will ever expire.
135-
}
136-
)
128+
// DeviceKey type represents the properties of the key of an individual device within
129+
// the tailnet.
130+
type DeviceKey struct {
131+
KeyExpiryDisabled bool `json:"keyExpiryDisabled"` // Whether or not this device's key will ever expire.
132+
}
137133

138134
// SetKey updates the properties of a device's key.
139135
func (dr *DevicesResource) SetKey(ctx context.Context, deviceID string, key DeviceKey) error {

v2/dns.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ type DNSResource struct {
1313
*Client
1414
}
1515

16-
type (
17-
// SplitDNSRequest is a map from domain names to a list of nameservers.
18-
SplitDNSRequest map[string][]string
16+
// SplitDNSRequest is a map from domain names to a list of nameservers.
17+
type SplitDNSRequest map[string][]string
1918

20-
// SplitDNSResponse is a map from domain names to a list of nameservers.
21-
SplitDNSResponse SplitDNSRequest
19+
// SplitDNSResponse is a map from domain names to a list of nameservers.
20+
type SplitDNSResponse SplitDNSRequest
2221

23-
DNSPreferences struct {
24-
MagicDNS bool `json:"magicDNS"`
25-
}
26-
)
22+
type DNSPreferences struct {
23+
MagicDNS bool `json:"magicDNS"`
24+
}
2725

2826
// SetSearchPaths replaces the list of search paths with the list supplied by the user and returns an error otherwise.
2927
func (dr *DNSResource) SetSearchPaths(ctx context.Context, searchPaths []string) error {

v2/keys.go

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,37 @@ type KeysResource struct {
1414
*Client
1515
}
1616

17-
type (
18-
// KeyCapabilities describes the capabilities of an authentication key.
19-
KeyCapabilities struct {
20-
Devices struct {
21-
Create struct {
22-
Reusable bool `json:"reusable"`
23-
Ephemeral bool `json:"ephemeral"`
24-
Tags []string `json:"tags"`
25-
Preauthorized bool `json:"preauthorized"`
26-
} `json:"create"`
27-
} `json:"devices"`
28-
}
17+
// KeyCapabilities describes the capabilities of an authentication key.
18+
type KeyCapabilities struct {
19+
Devices struct {
20+
Create struct {
21+
Reusable bool `json:"reusable"`
22+
Ephemeral bool `json:"ephemeral"`
23+
Tags []string `json:"tags"`
24+
Preauthorized bool `json:"preauthorized"`
25+
} `json:"create"`
26+
} `json:"devices"`
27+
}
2928

30-
// CreateKeyRequest describes the definition of an authentication key to create.
31-
CreateKeyRequest struct {
32-
Capabilities KeyCapabilities `json:"capabilities"`
33-
ExpirySeconds int64 `json:"expirySeconds"`
34-
Description string `json:"description"`
35-
}
29+
// CreateKeyRequest describes the definition of an authentication key to create.
30+
type CreateKeyRequest struct {
31+
Capabilities KeyCapabilities `json:"capabilities"`
32+
ExpirySeconds int64 `json:"expirySeconds"`
33+
Description string `json:"description"`
34+
}
3635

37-
// Key describes an authentication key within the tailnet.
38-
Key struct {
39-
ID string `json:"id"`
40-
Key string `json:"key"`
41-
Description string `json:"description"`
42-
Created time.Time `json:"created"`
43-
Expires time.Time `json:"expires"`
44-
Revoked time.Time `json:"revoked"`
45-
Invalid bool `json:"invalid"`
46-
Capabilities KeyCapabilities `json:"capabilities"`
47-
UserID string `json:"userId"`
48-
}
49-
)
36+
// Key describes an authentication key within the tailnet.
37+
type Key struct {
38+
ID string `json:"id"`
39+
Key string `json:"key"`
40+
Description string `json:"description"`
41+
Created time.Time `json:"created"`
42+
Expires time.Time `json:"expires"`
43+
Revoked time.Time `json:"revoked"`
44+
Invalid bool `json:"invalid"`
45+
Capabilities KeyCapabilities `json:"capabilities"`
46+
UserID string `json:"userId"`
47+
}
5048

5149
// Create creates a new authentication key. Returns the generated [Key] if successful.
5250
func (kr *KeysResource) Create(ctx context.Context, ckr CreateKeyRequest) (*Key, error) {

v2/logging.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,27 @@ const (
2727
LogTypeNetwork LogType = "network"
2828
)
2929

30-
type (
31-
// LogstreamConfiguration type defines a log stream entity in tailscale.
32-
LogstreamConfiguration struct {
33-
LogType LogType `json:"logType,omitempty"`
34-
DestinationType LogstreamEndpointType `json:"destinationType,omitempty"`
35-
URL string `json:"url,omitempty"`
36-
User string `json:"user,omitempty"`
37-
}
30+
// LogstreamConfiguration type defines a log stream entity in tailscale.
31+
type LogstreamConfiguration struct {
32+
LogType LogType `json:"logType,omitempty"`
33+
DestinationType LogstreamEndpointType `json:"destinationType,omitempty"`
34+
URL string `json:"url,omitempty"`
35+
User string `json:"user,omitempty"`
36+
}
3837

39-
// SetLogstreamConfigurationRequest type defines a request for setting a LogstreamConfiguration.
40-
SetLogstreamConfigurationRequest struct {
41-
DestinationType LogstreamEndpointType `json:"destinationType,omitempty"`
42-
URL string `json:"url,omitempty"`
43-
User string `json:"user,omitempty"`
44-
Token string `json:"token,omitempty"`
45-
}
38+
// SetLogstreamConfigurationRequest type defines a request for setting a LogstreamConfiguration.
39+
type SetLogstreamConfigurationRequest struct {
40+
DestinationType LogstreamEndpointType `json:"destinationType,omitempty"`
41+
URL string `json:"url,omitempty"`
42+
User string `json:"user,omitempty"`
43+
Token string `json:"token,omitempty"`
44+
}
4645

47-
// LogstreamEndpointType describes the type of the endpoint.
48-
LogstreamEndpointType string
46+
// LogstreamEndpointType describes the type of the endpoint.
47+
type LogstreamEndpointType string
4948

50-
// LogType describes the type of logging.
51-
LogType string
52-
)
49+
// LogType describes the type of logging.
50+
type LogType string
5351

5452
// LogstreamConfiguration retrieves the tailnet's [LogstreamConfiguration] for the given [LogType].
5553
func (lr *LoggingResource) LogstreamConfiguration(ctx context.Context, logType LogType) (*LogstreamConfiguration, error) {

0 commit comments

Comments
 (0)