-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontacts.go
65 lines (53 loc) · 1.92 KB
/
contacts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) David Bond, Tailscale Inc, & Contributors
// SPDX-License-Identifier: MIT
package tailscale
import (
"context"
"net/http"
)
// ContactsResource provides access to https://tailscale.com/api#tag/contacts.
type ContactsResource struct {
*Client
}
const (
ContactAccount ContactType = "account"
ContactSupport ContactType = "support"
ContactSecurity ContactType = "security"
)
// ContactType defines the type of contact.
type ContactType string
// Contacts type defines the object returned when retrieving contacts.
type Contacts struct {
Account Contact `json:"account"`
Support Contact `json:"support"`
Security Contact `json:"security"`
}
// Contact type defines the structure of an individual contact for the tailnet.
type Contact struct {
Email string `json:"email"`
// FallbackEmail is the email used when Email has not been verified.
FallbackEmail string `json:"fallbackEmail,omitempty"`
// NeedsVerification is true if Email needs to be verified.
NeedsVerification bool `json:"needsVerification"`
}
// UpdateContactRequest type defines the structure of a request to update a Contact.
type UpdateContactRequest struct {
Email *string `json:"email,omitempty"`
}
// Get retieves the [Contacts] for the tailnet.
func (cr *ContactsResource) Get(ctx context.Context) (*Contacts, error) {
req, err := cr.buildRequest(ctx, http.MethodGet, cr.buildTailnetURL("contacts"))
if err != nil {
return nil, err
}
return body[Contacts](cr, req)
}
// Update updates the email for the specified [ContactType] within the tailnet.
// If the email address changes, the system will send a verification email to confirm the change.
func (cr *ContactsResource) Update(ctx context.Context, contactType ContactType, contact UpdateContactRequest) error {
req, err := cr.buildRequest(ctx, http.MethodPatch, cr.buildTailnetURL("contacts", contactType), requestBody(contact))
if err != nil {
return err
}
return cr.do(req, nil)
}