tailscale_rest/models/service.rs
1//! Services: a name and a pair of addresses that several devices can host.
2
3use crate::model;
4use crate::models::KnownValues;
5
6/// How far a device hosting a service has got through approval.
7///
8/// The two `approved:` values differ only in how the approval happened, which
9/// is why this is one string and not a boolean and a flag.
10pub const APPROVAL_LEVELS: &[&str] = &["not-approved", "approved:auto", "approved:manual"];
11
12pub const KNOWN_VALUES: &[KnownValues] = &[("ServiceHostInfo.approvalLevel", APPROVAL_LEVELS)];
13
14model! {
15 /// A service, as the tailnet sees it.
16 VipServiceInfo as "VIPServiceInfo" {
17 /// Unique within the tailnet.
18 name: "name" => String,
19 /// A label for the admin console and for clients with access. At most
20 /// 64 characters.
21 display_name: "displayName" => String,
22 /// The IPv4 first, then the IPv6.
23 addrs: "addrs" => Vec<String>,
24 comment: "comment" => String,
25 /// `protocol:port` pairs, where `tcp` is the only protocol so far.
26 /// `do-not-validate` skips the check.
27 ports: "ports" => Vec<String>,
28 tags: "tags" => Vec<String>,
29 }
30
31 /// The body a `PUT` sends, which is the same six fields.
32 ///
33 /// The description declares it separately to re-describe `addrs`, which on
34 /// the way in is a request rather than a report: unset or one IPv4 for a
35 /// new service, and for an existing one an IPv4 that may be changed
36 /// alongside an IPv6 that may not.
37 VipServiceInfoPut as "VIPServiceInfoPut" is VipServiceInfo;
38
39 /// One device hosting a service.
40 ServiceHostInfo {
41 stable_node_id: "stableNodeID" => String,
42 /// One of [`APPROVAL_LEVELS`].
43 approval_level: "approvalLevel" => String,
44 configured: "configured" => String,
45 }
46
47 /// Whether a device may host a service, and how it got there.
48 VipServiceApproval as "VIPServiceApproval" {
49 approved: "approved" => bool,
50 /// `true` where an auto-approver did it rather than a person.
51 auto_approved: "autoApproved" => bool,
52 }
53
54 // -----------------------------------------------------------------------
55 // The shapes the routes carry.
56 // -----------------------------------------------------------------------
57
58 /// Every service the tailnet advertises.
59 ///
60 /// `vipServices` rather than `services`, which is the envelope keeping the
61 /// Go client's spelling where the path does not — see the drift test's
62 /// note on the two names.
63 VipServiceList as "GET /tailnet/{tailnet}/services 200" {
64 vip_services: "vipServices" => Vec<VipServiceInfo>,
65 }
66
67 /// The devices standing behind one service.
68 ServiceHostList as "GET /tailnet/{tailnet}/services/{serviceName}/devices 200" {
69 hosts: "hosts" => Vec<ServiceHostInfo>,
70 }
71
72 /// What approving or unapproving one host sends.
73 ServiceApprovalRequest
74 as "POST /tailnet/{tailnet}/services/{serviceName}/device/{deviceId}/approved body" {
75 approved: "approved" => bool,
76 }
77}