More type info

main
Gerard Braad 2023-06-22 15:35:11 +08:00
parent 54fdb6f0b4
commit 0f65b1f0ff
2 changed files with 38 additions and 17 deletions

View File

@ -1,17 +1,16 @@
import React from 'react'; import React from 'react';
import { TailscaleBackendState, TailscaleStatusResponse, TailscaleUpResponse } from './types'; import { TailscaleBackendState, TailscaleStatus, TailscaleUp } from './types';
import { Card, CardTitle, CardBody } from '@patternfly/react-core'; import { Card, CardTitle, CardBody } from '@patternfly/react-core';
type ApplicationProps = { type ApplicationProps = {
} }
type ApplicationState = { type ApplicationState = {
Status: TailscaleStatusResponse Status: TailscaleStatus
} }
export class Application extends React.Component<ApplicationProps, ApplicationState> { export class Application extends React.Component<ApplicationProps, ApplicationState> {
state: ApplicationState = { state: ApplicationState = {
Status: null Status: null
@ -21,7 +20,7 @@ export class Application extends React.Component<ApplicationProps, ApplicationSt
super(props); super(props);
cockpit.spawn(['tailscale', 'status', '--json']).done(content => { cockpit.spawn(['tailscale', 'status', '--json']).done(content => {
const status: TailscaleStatusResponse = JSON.parse(content) const status: TailscaleStatus = JSON.parse(content)
this.setState(state => ({Status: status})); this.setState(state => ({Status: status}));
}); });
} }
@ -34,7 +33,7 @@ export class Application extends React.Component<ApplicationProps, ApplicationSt
<pre> <pre>
{ {
this.state.Status != null this.state.Status != null
? this.state.Status.Self.TailscaleIPs[0] ? this.state.Status.Self.HostName + " " + this.state.Status.Self.TailscaleIPs[0]
: <p>Loading...</p> : <p>Loading...</p>
} }
</pre> </pre>

View File

@ -9,25 +9,47 @@ export type TailscaleBackendState =
| 'Starting' | 'Starting'
| 'Running'; | 'Running';
export type TailscaleStatusResponse = { export enum OS {
BackendState: TailscaleBackendState; Android = "android",
AuthURL: string; IOS = "iOS",
Self: { Linux = "linux",
MACOS = "macOS",
Windows = "windows",
}
export type TailscalePeer = {
ID: string; ID: string;
UserID: number; PublicKey: string;
HostName: string; HostName: string;
DNSName: string; DNSName: string;
OS: string; OS: OS;
UserID: string;
TailscaleIPs: string[]
Tags?: string[];
Online: boolean;
Capabilities?: string[];
}
export interface TailscaleExitNodeStatus {
ID: string;
Online: boolean;
TailscaleIPs: string[]; TailscaleIPs: string[];
Capabilities: string[]; }
Online: boolean
}; export type TailscaleStatus = {
BackendState: TailscaleBackendState;
AuthURL: string;
Self: TailscalePeer,
User: Record<string, TailscaleUser> | null; User: Record<string, TailscaleUser> | null;
CurrentTailnet: { CurrentTailnet: {
Name: string; Name: string;
MagicDNSSuffix: string; MagicDNSSuffix: string;
MagicDNSEnabled: boolean; MagicDNSEnabled: boolean;
} | null; } | null;
ExitNodeStatus: TailscaleExitNodeStatus | null;
Peer: {
[key: string]: TailscalePeer
};
}; };
export type TailscaleUser = { export type TailscaleUser = {
@ -38,8 +60,8 @@ export type TailscaleUser = {
Roles: string[]; Roles: string[];
}; };
export type TailscaleUpResponse = { export type TailscaleUp = {
BackendState: TailscaleBackendState; BackendState: TailscaleBackendState;
AuthURL?: string; // e.g. https://login.tailscale.com/a/0123456789abcdef AuthURL?: string;
QR?: string; // a DataURL-encoded QR code PNG of the AuthURL QR?: string;
}; };