config

package
v0.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrWrongServerSection is the error message for wrong server section.
	ErrWrongServerSection = "Wrong server section."
	// ErrWrongGitHubSection is the error message for wrong github section.
	ErrWrongGitHubSection = "Wrong github section."
	// ErrWrongUsersSection is the error message for wrong users section.
	ErrWrongUsersSection = "Wrong users section."
	// ErrWrongTokensSection is the error message for wrong tokens section.
	ErrWrongTokensSection = "Wrong tokens section."
	// ErrWrongServicesSection is the error message for wrong services section.
	ErrWrongServicesSection = "Wrong services section."

	// ErrOpeningConfigFile is the error message for opening config file.
	ErrOpeningConfigFile = "Error opening config file."
	// ErrDecodingConfigFile is the error message for decoding config file.
	ErrDecodingConfigFile = "Error decoding config file."
	// ErrCleaningConfigData is the error message for cleaning config data.
	ErrCleaningConfigData = "Error cleaning config data."
)
View Source
const (
	ErrEmptyServerTelegramToken = "Telegram token cannot be empty."
	ErrEmptySsoHost             = "SSO host cannot be empty."

	DEFAULT_KEY_SIZE = 32
)
View Source
const (
	// ErrEmptyServiceName is the error message for empty service name.
	ErrEmptyServiceName = "Service name cannot be empty."
	// ErrEmptyServiceHost is the error message for empty service host.
	ErrEmptyServiceHost = "Service host cannot be empty."
)
View Source
const (
	// ErrEmptyTokenName is the error message for empty token name.
	ErrEmptyTokenName = "Token name cannot be empty."

	// ErrEmptyToken is the error message for empty token.
	ErrEmptyToken = "Token cannot be empty."
)
View Source
const (
	// ErrEmptyName is the error message for empty name.
	ErrEmptyUserName = "User name cannot be empty."

	// ErrEmptyEmail is the error message for empty email.
	ErrEmptyUserEmail = "User email cannot be empty."

	// ErrEmptyTelegramId is the error message for empty telegram id.
	ErrEmptyUserTelegramId = "User telegram id cannot be empty (0)."
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Server   Server    `toml:"server"`
	GitHub   GitHub    `toml:"github"`
	Users    []User    `toml:"users"`
	Tokens   []Token   `toml:"tokens"`
	Services []Service `toml:"services"`
	// contains filtered or unexported fields
}

func FromFile

func FromFile(path string) (*Config, errors.TraceableError)

Parse config from toml file.

func (*Config) Clean

func (c *Config) Clean() errors.TraceableError

Clean and validate config data.

func (*Config) FindService

func (c *Config) FindService(host string) *Service

func (*Config) FindUser

func (c *Config) FindUser(name string) *User

func (*Config) FindUserByGitHub

func (c *Config) FindUserByGitHub(name string) *User

type GitHub

type GitHub struct {
	ClientID     string `toml:"client_id"`
	ClientSecret string `toml:"client_secret"`
}

func (*GitHub) Clean

func (g *GitHub) Clean() errors.TraceableError

type Server

type Server struct {
	ListenAddress string `toml:"listen_address"`
	SsoHost       string `toml:"sso_host"`
	SsoJwtSecret  string `toml:"sso_jwt_secret"`
	ServicesJwt   string `toml:"services_jwt_secret"`
	TelegramToken string `toml:"telegram_token"`
	// contains filtered or unexported fields
}

Struct Server for [server] section in config file. example: ============================== listen_address = "localhost:5000" sso_host = "auth.example.com" sso_jwt_secret = "example_sso_jwt_secret" services_jwt_secret = "example_services_jwt_secret" telegram_token = "example_telegram_token"

func (*Server) Clean

func (s *Server) Clean() errors.TraceableError

Clean and validate server data.

func (*Server) GetServicesSecretBytes

func (s *Server) GetServicesSecretBytes() []byte

GetServicesSecretBytes returns the secret bytes for the services JWT.

func (*Server) GetSsoSecretBytes

func (s *Server) GetSsoSecretBytes() []byte

GetSsoSecretBytes returns the secret bytes for the SSO JWT.

type Service

type Service struct {
	Name  string   `toml:"name"`
	Host  string   `toml:"host"`
	Users []string `toml:"users"`

	Tokens []string `toml:"tokens"`

	Bypass []string `toml:"bypass"`
	// contains filtered or unexported fields
}

Struct Service for [[services]] section in config file. example: ============================== name = "code-server" host = "code.example.com" users = [ "john" ] tokens = [ "local-pc", "my-server" ] bypass = [ "/static/", "/some-path/" ]

func (*Service) Clean

func (s *Service) Clean() errors.TraceableError

Clean and validate service data.

func (*Service) IsBypass

func (s *Service) IsBypass(path string) bool

func (*Service) IsPathAllowed

func (s *Service) IsPathAllowed(path string) bool

Check if path is allowed to bypass the service.

func (*Service) IsTokenAllowed

func (s *Service) IsTokenAllowed(token string) bool

Check if token is allowed to access the service.

func (*Service) IsUserAllowed

func (s *Service) IsUserAllowed(user string) bool

Check if user is allowed to access the service.

type Token

type Token struct {
	Name  string `toml:"name"`
	Token string `toml:"token"`
}

Struct Token for [[tokens]] section in config file. example: ============================== name = "example_token_name" token = "example_token"

func (*Token) Clean

func (t *Token) Clean() errors.TraceableError

type User

type User struct {
	Name       string `toml:"name"`
	GitHub     string `toml:"github"`
	TelegramId int64  `toml:"telegram_id"`
}

Struct User for [[users]] section in config file. example: ============================== name = "your_name" github = "your_github_username" telegram_id = 123456789

func (*User) Clean

func (u *User) Clean() errors.TraceableError

Clean and validate user data.

Jump to

Keyboard shortcuts

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