hossted

package
v0.0.0-...-d2ba4ac Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AUTHORIZED_KEY_PATH = "/root/.ssh/authorized_keys"
View Source
var AVAILABLE = `
apps:
  - app: demo
    group:
    commands: [abc, def]
    values: [abc, def]
`

Available commands in yaml format. If a new set of apps/commands needs to be supported, need to append the values here TODO: Handle logic for command group

View Source
var GAVAILABLE = `` /* 265-byte string literal not displayed */

Generall available commands, for all apps

Functions

func ChangeMOTD

func ChangeMOTD(domain string) error

ChangeMOTD changes the content of the MOTD file, to match the set domain changes TODO: print status TODO: Allow domain to be something other than .com by changing the regex patten

func CheckCommands

func CheckCommands(app, command string) error

CheckCommands check whether the app, and corresponding commands/subcommands are supported. Return error if the provided values are not in the pre-defined list

func ConvertBool

func ConvertBool(in string) (bool, error)

ConvertBool converts the string input to boolean, return error if the input is not true/false

func Dev

func Dev() error

func EmailPrompt

func EmailPrompt() (string, error)

emailPrompt prompts the user for email

func GetAppLogs

func GetAppLogs(input string, followFlag bool) error

GetAppLogs goes to the app directory, then calls docker-compose logs Similar to ListAppPS func

func GetConfigPath

func GetConfigPath() (string, error)

GetConfigPath gets the pre-defined config path. ~/.hossted/config.yaml

func GetCurrentDirectory

func GetCurrentDirectory() string

Wrapper for getting current directory

func GetDockerComposeDir

func GetDockerComposeDir() (string, error)

GetDockerComposeDir gets the docker compose directory

func GetDockersInfo

func GetDockersInfo() (string, error)

func GetHosstedEnv

func GetHosstedEnv(env string) string

GetHosstedEnv determines which env. Support dev/prod only. If it is not set, default as dev

func GetHosstedUUID

func GetHosstedUUID(path string) (string, error)

GetHosstedUUID gets the uuid from the file /opt/linnovate/run/uuid.txt Return error if it's empty or file not exists TODO: Ask whether it's a request to get the uuid or somewhat being saved to the VM during creation

func GetSoftwarePath

func GetSoftwarePath() (string, error)

GetSoftwarePath gets the software related path, it could either be /opt/hossted/run/software.txt (Preferred) or /opt/linnovate/run/software.txt If neither of that exists, return error

func GetUUIDPath

func GetUUIDPath() (string, error)

GetUUIDPath is similar to GetSoftwarePath

func HasContainerRunning

func HasContainerRunning() bool

HasContainerRunning checks if there is a container with the name "trafik" in the list of containers

func Import

func Import(env string, authorization string, kluster KCluster) error

hossted ping - send docker ,sbom and security infor to hossted API

func ImportRequest

func ImportRequest(env, authorization, kluster, klusterJson string) (importResponse, error)

func Init

func Init(env, authorization, image string, instance Instance) error

hossted init - Send instance hossted API

func InitRequest

func InitRequest(env, authorization, image, instancejson string) (initResponse, error)

PingRequest sends dockers request

func ListAppPS

func ListAppPS(input string) error

ListAppPS goes to the app directory, then calls docker-compose ps if input is "", call prompt to get user input, otherwise look up the application in the config

func ListCommands

func ListCommands() error

ListCommands lists the available services and general commands on the virtual machine. The available application is defined under the file /opt/linoovate/run/uuid.txt. Also it would depends on whether the "action" is predefined as available of the certain app.

func Ping

func Ping(env string) error

hossted ping - send docker ,sbom and security infor to hossted API

func PingRequest

func PingRequest(dockers, uuid, env string) (pingResponse, error)

PingRequest sends dockers request

func PrettyPrint

func PrettyPrint(i interface{}) string

PrettyPrint to print struct in a readable way

func RegisterUsers

func RegisterUsers(env string) error

RegisterUsers updates email, organization in the yaml file, if successful. Also it will get the uuid of the machine, and environment from $HOSSTED_ENV. It will then send an request to the API server, to get the JWT sessin token. TODO: Use the original values as default.

func Scan

func Scan(env string) error

func ScanRequest

func ScanRequest(imageName, fileName, containerId, imageID, env string) (scanResponse, error)

ScanRequest sends security request

func Schedule

func Schedule(env string) error

func SetAuth

func SetAuth(env, app string, flag bool) error

SetAuth sets the authorization of the application

func SetDomain

func SetDomain(env, app, domain string) error

SetDomain set the domain for different apps TODO: check whether the function is generic for different apps. Divide to different cases if not. TODO: check error for sed command

func SetMonitoring

func SetMonitoring(env string, flag bool) error

func SetRemoteAccess

func SetRemoteAccess(env string, flag bool) error

SetRemoteAccess set the remote access by comment/uncomment the hossted public key in the ~/.ssh/authorized_keys file

func SetUpdates

func SetUpdates(env string, flag bool) error

func Shell

func Shell(appDir string, commands []string) (error, string, string)

Shell calls the bash shell command in a particular directory

func Update

func Update(env string) error

func WriteConfig

func WriteConfig(w io.Writer, config Config) error

WriteConfig writes the config to the config file (~/.hossted/config.yaml)

func WriteConfigWrapper

func WriteConfigWrapper(config Config) error

WriteConfigWrapper is a wrapper function to call the underlying io.Writer function

Types

type App

type App struct {
	App          string   `yaml:"app"`
	CommandGroup string   `yaml:"group"`
	Commands     []string `yaml:"commands"`
	Values       []string `yaml:"values"`
}

App is a struct to save the available commands for a particular application The length of Commands and Values is expected to be the same, to give additional information or examples to users, on to call the command

type AvailableCommand

type AvailableCommand struct {
	Apps []App `yaml:"apps"`
}

AvailableCommand is the predefined app/command mapping. Maintained with the command.go file

type AvailableCommandMap

type AvailableCommandMap map[string]Command

AvailableCommandMap saves the map for available commands e.g. map["app.command"] -> [{app command value} {prometheus url example.com} ]

type Command

type Command struct {
	App          string
	CommandGroup string
	Command      string
	Value        string
}

Command is the individual command, with the app and example values information

type Config

type Config struct {
	Email        string              `yaml:"email"`
	UserToken    string              `yaml:"userToken"`
	SessionToken string              `yaml:"sessionToken"`
	EndPoint     string              `yaml:"endPoint"`
	UUIDPath     string              `yaml:"uuidPath"`
	HostUUID     string              `yaml:"hostUuid"`
	Update       bool                `yaml:"update"`
	Monitoring   bool                `yaml:"monitoring"`
	Applications []ConfigApplication `yaml:"applications"`
}

Config is a struct to parse config.yaml file

func GetConfig

func GetConfig() (Config, error)

GetConfigPath gets the config object TODO: Check which field is missing

func (*Config) GetAppConfig

func (c *Config) GetAppConfig(in string) (ConfigApplication, error)

GetAppConfig finds the specific Application Config with the application name e.g. Find the config for prometheus -> ConfigApplication{prometheus /opt/prometheus}

func (*Config) GetDefaultApp

func (c *Config) GetDefaultApp(pwd string) (string, error)

GetDefaultApp gets the default app from the config file. If there is only an single app from the config, return it as default app. otherwise return error

type ConfigApplication

type ConfigApplication struct {
	AppName string `yaml:"appName"`
	AppPath string `yaml:"appPath"`
}

ConfigApplication is the applications installled in the vm. Currently it will look up the values from /opt/hossted/run/software.txt (Preferred) or /opt/linnovate/run/software.txt Supporting multiple values for future enhancement.

func GetAppInfo

func GetAppInfo() ([]ConfigApplication, error)

GetAppInfo gets the application related information from predefined path /opt/hossted/run/software.txt or /opt/linnovate/run/software.txt Returns the App name, and the corresponding path. e.g. Linnovate-AWS-wikijs -> wikijs TODO Assume single application for now TODO Remove dummy app (for dropdown select demo)

type Docker

type Docker struct {
	ID        string             `json:"docker_id"`
	Image     string             `json:"image"`
	ImageID   string             `json:"image_id"`
	CreatedAt int64              `json:"created_at"`
	Ports     []types.Port       `json:"ports"`
	Status    string             `json:"status"`
	Size      int64              `json:"size"`
	Names     []string           `json:"names"`
	Mounts    []types.MountPoint `json:"mounts"`
	Networks  string             `json:"networks"`
	Tag       string             `json:"tag"`
}

type HosstedRequest

type HosstedRequest struct {
	EndPoint     string            // Request end point
	Environment  string            // environment, dev or prod
	Params       map[string]string // kv pairs for param
	BearToken    string            // Authorization token
	SessionToken string            // Session token. JWT
	TypeRequest  string            // Request type, GET, POST, PUT, DELETE
	ContentType  string            // Content type, application/json, multipart/form-data
	Body         io.Reader         // Request body
}

HosstedRequest is a struct to construct neccessary information to send the request to hossted backend

func (*HosstedRequest) SendRequest

func (h *HosstedRequest) SendRequest() (string, error)

SendRequest sends a request to hossted API server with parameters TODO: This is insecure; use only in dev environments. TODO: Add timeout context TODO: Check all params is not null TODO: Check response status

type Instance

type Instance struct {
	Uuid      string `json:"uuid,omitempty"`
	Ip        string `json:"ip,omitempty"`
	User      string `json:"user,omitempty"`
	Url       string `json:"url,omitempty"`
	Product   string `json:"product,omitempty"`
	Cpunum    string `json:"cpunum,omitempty"`
	Mem       string `json:"mem,omitempty"`
	Rootsize  string `json:"rootsize,omitempty"`
	Cloud     string `json:"cloud,omitempty"`
	Status    string `json:"status,omitempty"`
	Test_mode string `json:"test_mode,omitempty"`
	Comment   string `json:"comment,omitempty"`
}

type KCluster

type KCluster struct {
	Uuid       string   `json:"uuid,omitempty"`
	Namespaces []string `json:"namespaces"`
	Name       string   `json:"name,omitempty"`
	User       string   `json:"user,omitempty"`
	Cloud      string   `json:"cloud,omitempty"`
	Status     string   `json:"status,omitempty"`
	Test_mode  string   `json:"test_mode,omitempty"`
	Comment    string   `json:"comment,omitempty"`
}

type NameSpace

type NameSpace struct {
	Name string `json:"namespace"`
}

type RegisterResponse

type RegisterResponse struct {
	StatusCode int    `json:"status"`
	Message    string `json:"msg"`
	JWT        string `json:"jwt"`
	URL        string `json:"url"`
}

RegisterResponse is the return response from the register api

type YamlSetting

type YamlSetting struct {
	Pattern  string // regex
	NewValue string // value of the new input, should be matching the number of match groups in regex
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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