netmaker/models/structs.go

131 lines
4.3 KiB
Go
Raw Normal View History

2021-03-26 00:17:52 +08:00
package models
import jwt "github.com/dgrijalva/jwt-go"
type AuthParams struct {
2021-04-30 06:14:13 +08:00
MacAddress string `json:"macaddress"`
Password string `json:"password"`
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"`
}
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
}
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
}
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
}
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 {
2021-04-30 06:14:13 +08:00
Network string
MacAddress string
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
}
type ErrorResponse struct {
2021-04-30 06:14:13 +08:00
Code int
Message string
2021-03-26 00:17:52 +08:00
}
type NodeAuth struct {
2021-04-30 06:14:13 +08:00
Network string
Password string
MacAddress 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
}
type AccessKey struct {
2021-05-01 19:57:49 +08:00
Name string `json:"name" bson:"name" validate:"omitempty,alphanum,max=20"`
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"`
Uses int `json:"uses" bson:"uses"`
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
}
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-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
}
type PeersResponse struct {
2021-07-24 06:24:34 +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 bool `json:"isegressgateway" bson:"isegressgateway"`
EgressGatewayRange string `json:"egressgatewayrange" bson:"egressgatewayrange"`
ListenPort int32 `json:"listenport" bson:"listenport"`
KeepAlive int32 `json:"persistentkeepalive" bson:"persistentkeepalive"`
}
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-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
}