service

package
v0.0.0-...-a297e19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddNodeToRoleRequest

type AddNodeToRoleRequest struct {
	RoleID int64 `json:"role_id"`
	// Nodes is the node list, at least one node is required
	Nodes RoleNodeListRequest `json:"nodes"`
}

func (*AddNodeToRoleRequest) Validate

func (ar *AddNodeToRoleRequest) Validate() error

type AddUserToRoleRequest

type AddUserToRoleRequest struct {
	// UserIDs is the user id list, at least one user id is required
	UserIDs []int64 `json:"user_ids"`
	RoleID  int64   `json:"-"`
}

func (*AddUserToRoleRequest) Validate

func (aur *AddUserToRoleRequest) Validate() error

type AddUserToSpaceRequest

type AddUserToSpaceRequest struct {
	SpaceID int64 `json:"-"`
	// UserIDs is the user id list, at
	// least one user id is required
	UserIDs []int64 `json:"user_ids"`
}

func (*AddUserToSpaceRequest) Validate

func (a *AddUserToSpaceRequest) Validate() error

type Config

type Config struct {
	CaPassphrase string `yaml:"ca_passphrase"`
	PubKeyPath   string `yaml:"public_key_path"`
	PrivKeyPath  string `yaml:"private_key_path"`
}

func (*Config) Validate

func (c *Config) Validate() error

type CreateNodeRequest

type CreateNodeRequest struct {
	SpaceID int64 `json:"-"`
	// Name is the name of the node
	Name        string `json:"name"`
	Description string `json:"description"`
	// IP is the ip address of the node
	IP string `json:"ip"`
	// Accounts is the account list of the node, it should
	// is account from the machine. If it is empty, the default
	// account is root.
	Accounts []string `json:"accounts"`
}

func (*CreateNodeRequest) Validate

func (cnr *CreateNodeRequest) Validate() error

type CreateNodeResponse

type CreateNodeResponse struct {
	ID int64 `json:"id"`
	// UniqueID is the unique id of the node
	UniqueID string `json:"unique_id"`

	// Secret is the secret of the node, it only show once
	// when the node is created
	Secret string `json:"secret"`
}

type CreateRoleRequest

type CreateRoleRequest struct {
	SpaceID     int64  `json:"-"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

==== Role ====

func (*CreateRoleRequest) Validate

func (crr *CreateRoleRequest) Validate() error

type CreateSpaceRequest

type CreateSpaceRequest struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

==== Space ====

func (*CreateSpaceRequest) Validate

func (cs *CreateSpaceRequest) Validate() error

type CreateUserRequest

type CreateUserRequest struct {
	Username string `json:"username"`
	Email    string `json:"email"`
	// PublicKey is the public key of the ssh key
	PublicKey string `json:"public_key"`
}

==== User ====

func (*CreateUserRequest) Validate

func (cur *CreateUserRequest) Validate() error

type GetUserResponse

type GetUserResponse UserVO

type GrantCertRequest

type GrantCertRequest struct {
	UserID int64 `json:"-"`
	// Effect in seconds
	Effect int64 `json:"effect"`

	// StartDate is the start time of the certificate
	// If it is 0, it means the current time
	StartDate int64 `json:"start_date"`
}

func (*GrantCertRequest) Validate

func (scr *GrantCertRequest) Validate() error

type GrantCertResponse

type GrantCertResponse struct {
	// Cert is the certificate content
	Cert string `json:"cert"`
}

type Guard

type Guard interface {
	GetCA(ctx context.Context) []byte
	GetPrincipals(ctx context.Context, uniqueID string) (PrincipalList, error)
	GetNodeByUniqueID(ctx context.Context, uniqueID string) (*Node, error)
	GetKRL(ctx context.Context, uniqueID string) (string, error)
	GetAuthorizedKeys(ctx context.Context, uniqueID string) ([]string, error)

	CreateUser(ctx context.Context, in *CreateUserRequest) (int64, error)
	ListUser(ctx context.Context, in *ListUserRequest) (ListUserResponse, error)
	GetUser(ctx context.Context, id int64) (*GetUserResponse, error)
	GetUserByEmail(ctx context.Context, email string) (*GetUserResponse, error)
	BanUser(ctx context.Context, id int64) error
	UpdateUserPublicKey(ctx context.Context, in *UpdateUserPublicKeyRequest) error
	GrantCert(ctx context.Context, in *GrantCertRequest) (*GrantCertResponse, error)

	CreateSpace(ctx context.Context, in *CreateSpaceRequest) (int64, error)
	ListSpace(ctx context.Context) (ListSpaceResponse, error)

	CreateNode(ctx context.Context, in *CreateNodeRequest) (*CreateNodeResponse, error)
	ListNode(ctx context.Context, in *ListNodeRequest) (*ListNodeResponse, error)
	DeleteNode(ctx context.Context, id int64) error
	UpdateLastHeartbeat(ctx context.Context, uniqueID string) error

	CreateRole(ctx context.Context, in *CreateRoleRequest) (int64, error)
	ListRole(ctx context.Context, in *ListRoleRequest) (ListRoleResponse, error)
	DeleteRole(ctx context.Context, roleID int64) error
	AddNodeToRole(ctx context.Context, in *AddNodeToRoleRequest) error
	ListRoleNode(ctx context.Context, in *ListRoleNodeRequest) (ListRoleNodeResponse, error)
	RemoveNodeFromRole(ctx context.Context, in *RemoveNodeFromRoleRequest) error
	AddUserToRole(ctx context.Context, in *AddUserToRoleRequest) error
	ListRoleUser(ctx context.Context, in *ListRoleUserRequest) (ListRoleUserResponse, error)
	RemoveUserFromRole(ctx context.Context, in *RemoveUserFromRoleRequest) error
}

func New

func New(cfg Config, repo repo.Repo) (Guard, error)

type ListNodeRequest

type ListNodeRequest struct {
	PageRequest

	SpaceID int64 `json:"-"`
}

func (*ListNodeRequest) Validate

func (lnr *ListNodeRequest) Validate() error

type ListNodeResponse

type ListNodeResponse struct {
	Total int64         `json:"total"`
	Nodes []*ListNodeVO `json:"nodes"`
}

type ListNodeVO

type ListNodeVO struct {
	ID            int64    `json:"id"`
	UniqueID      string   `json:"unique_id"`
	Name          string   `json:"name"`
	Description   string   `json:"description"`
	IP            string   `json:"ip"`
	Accounts      []string `json:"accounts"`
	LastHeartbeat int64    `json:"last_heartbeat"`
	CreatedAt     int64    `json:"created_at"`
}

type ListRoleNodeRequest

type ListRoleNodeRequest struct {
	RoleID int64 `json:"role_id"`
}

ListRoleNodeRequest list role node request

func (*ListRoleNodeRequest) Validate

func (lrnr *ListRoleNodeRequest) Validate() error

type ListRoleNodeResponse

type ListRoleNodeResponse []*RoleNodeListVO

type ListRoleRequest

type ListRoleRequest struct {
	SpaceID int64 `json:"space_id"`
}

func (*ListRoleRequest) Validate

func (lrr *ListRoleRequest) Validate() error

type ListRoleResponse

type ListRoleResponse []*ListRoleVO

type ListRoleUserRequest

type ListRoleUserRequest struct {
	RoleID int64 `json:"role_id"`
}

func (*ListRoleUserRequest) Validate

func (lrur *ListRoleUserRequest) Validate() error

type ListRoleUserResponse

type ListRoleUserResponse []*RoleUserListVO

type ListRoleVO

type ListRoleVO struct {
	ID          int64  `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	CreatedAt   int64  `json:"created_at"`
}

type ListSpaceResponse

type ListSpaceResponse []*ListSpaceVO

type ListSpaceVO

type ListSpaceVO struct {
	ID          int64  `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	CreatedAt   int64  `json:"created_at"`
}

type ListUserRequest

type ListUserRequest struct {
	PageRequest
}

type ListUserResponse

type ListUserResponse []*UserListVO

type Node

type Node struct {
	ID            int64    `json:"id"`
	UniqueID      string   `json:"unique_id"`
	Secret        string   `json:"secret"`
	Name          string   `json:"name"`
	Description   string   `json:"description"`
	SpaceID       int64    `json:"space_id"`
	IP            string   `json:"ip"`
	LastHeartbeat int64    `json:"last_heartbeat"`
	Accounts      []string `json:"accounts"`
	CreatedAt     int64    `json:"created_at"`
	UpdatedAt     int64    `json:"updated_at"`
}

type PageRequest

type PageRequest struct {
	// Page is the page number, start from 1
	Page int64 `form:"page"`
	// Limit is the number of items per page,
	// must be less than or equal to 1000
	Limit int64 `form:"limit"`
}

func (*PageRequest) Offset

func (pr *PageRequest) Offset() int64

func (*PageRequest) Validate

func (pr *PageRequest) Validate() error

type PrincipalList

type PrincipalList = dto.PrincipalList

type Principals

type Principals = dto.Principals

type RemoveNodeFromRoleRequest

type RemoveNodeFromRoleRequest struct {
	RoleID  int64   `json:"-"`
	NodeIDs []int64 `json:"node_ids"`
}

func (*RemoveNodeFromRoleRequest) Validate

func (rnfr *RemoveNodeFromRoleRequest) Validate() error

type RemoveUserFromRoleRequest

type RemoveUserFromRoleRequest struct {
	RoleID  int64   `json:"-"`
	UserIDs []int64 `json:"user_ids"`
}

func (*RemoveUserFromRoleRequest) Validate

func (rur *RemoveUserFromRoleRequest) Validate() error

type RoleNodeListRequest

type RoleNodeListRequest []RoleNodeRequest

type RoleNodeListVO

type RoleNodeListVO struct {
	ID            int64  `json:"id"`
	UniqueID      string `json:"unique_id"`
	Name          string `json:"name"`
	Description   string `json:"description"`
	IP            string `json:"ip"`
	Account       string `json:"account"`
	LastHeartbeat int64  `json:"last_heartbeat"`
}

type RoleNodeRequest

type RoleNodeRequest struct {
	// NodeID is the node id, one of node id and unique id is required
	// If both are provided, the node id is used
	NodeID int64 `json:"node_id"`
	// UniqueID is the unique id of the node
	UniqueID string `json:"unique_id"`
	// Account is the account of the node, must from the node account list
	Account string `json:"account"`
}

type RoleUserListVO

type RoleUserListVO struct {
	ID       int64  `json:"id"`
	Username string `json:"username"`
	Email    string `json:"email"`
}

type UpdateUserPublicKeyRequest

type UpdateUserPublicKeyRequest struct {
	UserID    int64  `json:"user_id"`
	PublicKey string `json:"public_key"`
}

func (*UpdateUserPublicKeyRequest) Validate

func (uupr *UpdateUserPublicKeyRequest) Validate() error

type UserListVO

type UserListVO struct {
	ID       int64  `json:"id"`
	Username string `json:"username"`
	Email    string `json:"email"`
	// Ban is the status of the user
	// If it is true, the user is banned
	Ban       bool  `json:"ban"`
	CreatedAt int64 `json:"created_at"`
	UpdatedAt int64 `json:"updated_at"`
}

type UserVO

type UserVO struct {
	ID        int64  `json:"id"`
	Username  string `json:"username"`
	Email     string `json:"email"`
	PubKey    string `json:"public_key"`
	Ban       bool   `json:"ban"`
	CreatedAt int64  `json:"created_at"`
	UpdateAt  int64  `json:"updated_at"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL