netmaker/models/structs.go

172 lines
5.7 KiB
Go
Raw Normal View History

2021-03-26 00:17:52 +08:00
package models
2021-08-10 05:57:40 +08:00
import jwt "github.com/golang-jwt/jwt/v4"
2021-03-26 00:17:52 +08:00
2021-11-17 01:20:48 +08:00
const PLACEHOLDER_KEY_TEXT = "ACCESS_KEY"
const PLACEHOLDER_TOKEN_TEXT = "ACCESS_TOKEN"
2021-10-09 03:07:12 +08:00
// AuthParams - struct for auth params
2021-03-26 00:17:52 +08:00
type AuthParams struct {
2021-04-30 06:14:13 +08:00
MacAddress string `json:"macaddress"`
2022-01-11 06:52:21 +08:00
ID string `json:"id"`
2021-04-30 06:14:13 +08:00
Password string `json:"password"`
2021-03-26 00:17:52 +08:00
}
2021-10-09 03:07:12 +08:00
// User struct - struct for Users
2021-03-26 00:17:52 +08:00
type User struct {
2021-07-24 06:24:34 +08:00
UserName string `json:"username" bson:"username" validate:"min=3,max=40,regexp=^(([a-zA-Z,\-,\.]*)|([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})){3,40}$"`
Password string `json:"password" bson:"password" validate:"required,min=5"`
2021-07-02 12:03:46 +08:00
Networks []string `json:"networks" bson:"networks"`
2021-07-24 06:24:34 +08:00
IsAdmin bool `json:"isadmin" bson:"isadmin"`
}
2021-10-09 03:07:12 +08:00
// ReturnUser - return user struct
2021-07-24 06:24:34 +08:00
type ReturnUser struct {
UserName string `json:"username" bson:"username" validate:"min=3,max=40,regexp=^(([a-zA-Z,\-,\.]*)|([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})){3,40}$"`
Networks []string `json:"networks" bson:"networks"`
IsAdmin bool `json:"isadmin" bson:"isadmin"`
2021-03-26 00:17:52 +08:00
}
2021-10-09 03:07:12 +08:00
// UserAuthParams - user auth params struct
2021-03-26 00:17:52 +08:00
type UserAuthParams struct {
2021-04-30 06:14:13 +08:00
UserName string `json:"username"`
Password string `json:"password"`
2021-03-26 00:17:52 +08:00
}
2021-10-09 03:07:12 +08:00
// UserClaims - user claims struct
2021-03-26 00:17:52 +08:00
type UserClaims struct {
2021-04-30 06:14:13 +08:00
IsAdmin bool
UserName string
2021-07-02 12:03:46 +08:00
Networks []string
2021-04-30 06:14:13 +08:00
jwt.StandardClaims
2021-03-26 00:17:52 +08:00
}
2021-10-09 03:07:12 +08:00
// SuccessfulUserLoginResponse - successlogin struct
2021-03-26 00:17:52 +08:00
type SuccessfulUserLoginResponse struct {
2021-04-30 06:14:13 +08:00
UserName string
AuthToken string
2021-03-26 00:17:52 +08:00
}
// Claims is a struct that will be encoded to a JWT.
// jwt.StandardClaims is an embedded type to provide expiry time
type Claims struct {
2022-01-11 06:52:21 +08:00
ID string
2021-04-30 06:14:13 +08:00
MacAddress string
2022-01-11 06:52:21 +08:00
Network string
2021-04-30 06:14:13 +08:00
jwt.StandardClaims
2021-03-26 00:17:52 +08:00
}
// SuccessfulLoginResponse is struct to send the request response
type SuccessfulLoginResponse struct {
2021-04-30 06:14:13 +08:00
MacAddress string
AuthToken string
2021-03-26 00:17:52 +08:00
}
2021-10-09 03:07:12 +08:00
// ErrorResponse is struct for error
2021-03-26 00:17:52 +08:00
type ErrorResponse struct {
2021-04-30 06:14:13 +08:00
Code int
Message string
2021-03-26 00:17:52 +08:00
}
2021-10-09 03:07:12 +08:00
// NodeAuth - struct for node auth
2021-03-26 00:17:52 +08:00
type NodeAuth struct {
2021-04-30 06:14:13 +08:00
Network string
Password string
2022-01-11 06:52:21 +08:00
MacAddress string // Depricated
ID string
2021-03-26 00:17:52 +08:00
}
// SuccessResponse is struct for sending error message with code.
type SuccessResponse struct {
2021-04-30 06:14:13 +08:00
Code int
Message string
Response interface{}
2021-03-26 00:17:52 +08:00
}
2021-10-09 03:07:12 +08:00
// AccessKey - access key struct
2021-03-26 00:17:52 +08:00
type AccessKey struct {
2021-08-31 03:58:23 +08:00
Name string `json:"name" bson:"name" validate:"omitempty,max=20"`
2021-05-01 19:57:49 +08:00
Value string `json:"value" bson:"value" validate:"omitempty,alphanum,max=16"`
2021-04-30 06:14:13 +08:00
AccessString string `json:"accessstring" bson:"accessstring"`
2021-12-11 10:09:42 +08:00
Uses int `json:"uses" bson:"uses" validate:"numeric,min=0"`
2021-03-26 00:17:52 +08:00
}
2021-10-09 03:07:12 +08:00
// DisplayKey - what is displayed for key
2021-03-26 00:17:52 +08:00
type DisplayKey struct {
2021-04-30 06:14:13 +08:00
Name string `json:"name" bson:"name"`
Uses int `json:"uses" bson:"uses"`
2021-03-26 00:17:52 +08:00
}
2021-10-09 03:07:12 +08:00
// GlobalConfig - global config
type GlobalConfig struct {
2021-04-30 06:14:13 +08:00
Name string `json:"name" bson:"name"`
PortGRPC string `json:"portgrpc" bson:"portgrpc"`
ServerGRPC string `json:"servergrpc" bson:"servergrpc"`
}
2021-10-09 03:07:12 +08:00
// CheckInResponse - checkin response
2021-04-30 06:14:13 +08:00
type CheckInResponse struct {
Success bool `json:"success" bson:"success"`
NeedPeerUpdate bool `json:"needpeerupdate" bson:"needpeerupdate"`
NeedConfigUpdate bool `json:"needconfigupdate" bson:"needconfigupdate"`
NeedKeyUpdate bool `json:"needkeyupdate" bson:"needkeyupdate"`
NeedDelete bool `json:"needdelete" bson:"needdelete"`
NodeMessage string `json:"nodemessage" bson:"nodemessage"`
IsPending bool `json:"ispending" bson:"ispending"`
2021-03-26 00:17:52 +08:00
}
2021-10-09 03:07:12 +08:00
// PeersResponse - peers response
2021-03-26 00:17:52 +08:00
type PeersResponse struct {
2021-08-31 03:58:23 +08:00
PublicKey string `json:"publickey" bson:"publickey"`
Endpoint string `json:"endpoint" bson:"endpoint"`
Address string `json:"address" bson:"address"`
Address6 string `json:"address6" bson:"address6"`
LocalAddress string `json:"localaddress" bson:"localaddress"`
IsEgressGateway string `json:"isegressgateway" bson:"isegressgateway"`
2021-07-27 22:48:58 +08:00
EgressGatewayRanges string `json:"egressgatewayrange" bson:"egressgatewayrange"`
2021-08-31 03:58:23 +08:00
ListenPort int32 `json:"listenport" bson:"listenport"`
KeepAlive int32 `json:"persistentkeepalive" bson:"persistentkeepalive"`
2021-07-24 06:24:34 +08:00
}
2021-10-09 03:07:12 +08:00
// ExtPeersResponse - ext peers response
2021-07-24 06:24:34 +08:00
type ExtPeersResponse struct {
2021-04-30 06:14:13 +08:00
PublicKey string `json:"publickey" bson:"publickey"`
Endpoint string `json:"endpoint" bson:"endpoint"`
Address string `json:"address" bson:"address"`
Address6 string `json:"address6" bson:"address6"`
2021-04-30 06:14:13 +08:00
LocalAddress string `json:"localaddress" bson:"localaddress"`
ListenPort int32 `json:"listenport" bson:"listenport"`
KeepAlive int32 `json:"persistentkeepalive" bson:"persistentkeepalive"`
2021-03-26 00:17:52 +08:00
}
2021-10-09 03:07:12 +08:00
// EgressGatewayRequest - egress gateway request
2021-05-20 01:59:10 +08:00
type EgressGatewayRequest struct {
2021-04-30 06:14:13 +08:00
NodeID string `json:"nodeid" bson:"nodeid"`
NetID string `json:"netid" bson:"netid"`
RangeString string `json:"rangestring" bson:"rangestring"`
Ranges []string `json:"ranges" bson:"ranges"`
Interface string `json:"interface" bson:"interface"`
PostUp string `json:"postup" bson:"postup"`
PostDown string `json:"postdown" bson:"postdown"`
2021-04-13 11:19:01 +08:00
}
2021-10-09 03:07:12 +08:00
// RelayRequest - relay request struct
type RelayRequest struct {
2021-09-18 22:33:14 +08:00
NodeID string `json:"nodeid" bson:"nodeid"`
NetID string `json:"netid" bson:"netid"`
2021-09-18 23:01:34 +08:00
RelayAddrs []string `json:"relayaddrs" bson:"relayaddrs"`
2021-09-18 22:33:14 +08:00
}
2022-01-18 22:06:43 +08:00
// ServerUpdateData - contains data to configure server
// and if it should set peers
type ServerUpdateData struct {
UpdatePeers bool `json:"updatepeers" bson:"updatepeers"`
2022-01-18 23:14:27 +08:00
Node Node `json:"servernode" bson:"servernode"`
2022-01-18 22:06:43 +08:00
}
2022-01-21 06:50:42 +08:00
2022-01-21 06:52:49 +08:00
// Telemetry - contains UUID of the server and timestamp of last send to posthog
2022-01-21 06:50:42 +08:00
type Telemetry struct {
UUID string `json:"uuid" bson:"uuid"`
LastSend int64 `json:"lastsend" bson:"lastsend"`
}