data

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

README

This package includes data containers that are shared between the Gort server and the relay or API service.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCryptoHash is returned by HashPassword and will wrap its
	// underlying error.
	ErrCryptoHash = errors.New("failed to generate password hash")

	// ErrCryptoIO is returned by GenerateRandomToken if it can't retrieve
	// random bytes from rand.Read()
	ErrCryptoIO = errors.New("failed to retrieve randomness")
)

Functions

func CompareHashAndPassword

func CompareHashAndPassword(hashedPassword string, password string) bool

CompareHashAndPassword receives a plaintext password and its hash, and returns true if they match.

func GenerateRandomToken

func GenerateRandomToken(length int) (string, error)

GenerateRandomToken generates a random character token.

func HashPassword

func HashPassword(pwd string) (string, error)

HashPassword receives a plaintext password and returns its hashed equivalent.

Types

type AbstractProvider

type AbstractProvider struct {
	BotName string `yaml:"bot_name,omitempty"`
	Name    string `yaml:"name,omitempty"`
}

AbstractProvider is used to contain the general properties shared by all providers.

type Bundle

type Bundle struct {
	GortBundleVersion int                       `yaml:"gort_bundle_version,omitempty" json:"gort_bundle_version,omitempty"`
	Name              string                    `yaml:",omitempty" json:"name,omitempty"`
	Version           string                    `yaml:",omitempty" json:"version,omitempty"`
	Enabled           bool                      `yaml:",omitempty" json:"enabled"`
	Author            string                    `yaml:",omitempty" json:"author,omitempty"`
	Homepage          string                    `yaml:",omitempty" json:"homepage,omitempty"`
	Description       string                    `yaml:",omitempty" json:"description,omitempty"`
	InstalledOn       time.Time                 `yaml:"-" json:"installed_on,omitempty"`
	InstalledBy       string                    `yaml:",omitempty" json:"installed_by,omitempty"`
	LongDescription   string                    `yaml:"long_description,omitempty" json:"long_description,omitempty"`
	Docker            BundleDocker              `yaml:",omitempty" json:"docker,omitempty"`
	Permissions       []string                  `yaml:",omitempty" json:"permissions,omitempty"`
	Commands          map[string]*BundleCommand `yaml:",omitempty" json:"commands,omitempty"`
	Default           bool                      `yaml:"-" json:"default,omitempty"`
}

Bundle represents a bundle as defined in the "bundles" section of the config.

type BundleCommand

type BundleCommand struct {
	Description     string   `yaml:",omitempty" json:"description,omitempty"`
	Executable      []string `yaml:",omitempty,flow" json:"executable,omitempty"`
	LongDescription string   `yaml:"long_description,omitempty" json:"long_description,omitempty"`
	Name            string   `yaml:"-" json:"-"`
	Rules           []string `yaml:",omitempty" json:"rules,omitempty"`
}

BundleCommand represents a bundle command, as defined in the "bundles/commands" section of the config.

type BundleDocker

type BundleDocker struct {
	Image string `yaml:",omitempty" json:"image,omitempty"`
	Tag   string `yaml:",omitempty" json:"tag,omitempty"`
}

BundleDocker represents the "bundles/docker" subsection of the config doc

type BundleInfo

type BundleInfo struct {
	Name           string
	Versions       []string
	Enabled        bool
	EnabledVersion Bundle
}

BundleInfo wraps a minimal amount of data about a bundle.

type CommandEntry

type CommandEntry struct {
	Bundle  Bundle
	Command BundleCommand
}

CommandEntry conveniently wraps a bundle and one command within that bundle.

type CommandRequest

type CommandRequest struct {
	CommandEntry
	Adapter    string          // The name of the adapter this request originated from.
	ChannelID  string          // The provider ID of the channel that the request originated in.
	Context    context.Context // The request context
	Parameters []string        // Tokenized command parameters
	RequestID  int64           // A unique requestID
	Timestamp  time.Time       // The time this request was triggered
	UserID     string          // The provider ID of user making this request.
	UserEmail  string          // The email address associated with the user making the request
	UserName   string          // The gort username of the user making the request
}

CommandRequest represents a user command request as triggered in (probably) a chat provider.

func (CommandRequest) CommandString

func (r CommandRequest) CommandString() string

CommandString is a convenience method that outputs the normalized command string, more or less as the user typed it.

type CommandResponse

type CommandResponse struct {
	Command  CommandRequest
	Duration time.Duration
	Status   int64
	Title    string   // Command Error
	Output   []string // Contents of the commands stdout.
	Error    error
}

CommandResponse is returned by a relay to indicate that a command has been executed. It includes the original CommandRequest, the command's exit status code, and the commands entire stdout as a slice of lines. Title can be used to build a user output message, and generally contains a short description of the result.

TODO Add a request ID that correcponds with the request, so that we can more directly link it back to its user and adapter of origin.

type DatabaseConfigs

type DatabaseConfigs struct {
	Host                  string        `yaml:"host,omitempty"`
	Port                  int           `yaml:"port,omitempty"`
	User                  string        `yaml:"user,omitempty"`
	Password              string        `yaml:"password,omitempty"`
	SSLEnabled            bool          `yaml:"ssl_enabled,omitempty"`
	ConnectionMaxIdleTime time.Duration `yaml:"connection_max_idle_time,omitempty"`
	ConnectionMaxLifetime time.Duration `yaml:"connection_max_life_time,omitempty"`
	MaxIdleConnections    int           `yaml:"max_idle_connections,omitempty"`
	MaxOpenConnections    int           `yaml:"max_open_connections,omitempty"`
	QueryTimeout          time.Duration `yaml:"query_timeout,omitempty"`
}

DatabaseConfigs is the data wrapper for the "database" section.

type DockerConfigs

type DockerConfigs struct {
	DockerHost string `yaml:"host,omitempty"`
	Network    string `yaml:"network,omitempty"`
}

DockerConfigs is the data wrapper for the "docker" section. This will move into the relay config(s) eventually.

type GlobalConfigs

type GlobalConfigs struct {
	CommandTimeout time.Duration `yaml:"command_timeout,omitempty"`
}

GlobalConfigs is the data wrapper for the "global" section

type GortConfig

type GortConfig struct {
	GortServerConfigs GortServerConfigs `yaml:"gort,omitempty"`
	GlobalConfigs     GlobalConfigs     `yaml:"global,omitempty"`
	DatabaseConfigs   DatabaseConfigs   `yaml:"database,omitempty"`
	DockerConfigs     DockerConfigs     `yaml:"docker,omitempty"`
	JaegerConfigs     JaegerConfigs     `yaml:"jaeger,omitempty"`
	SlackProviders    []SlackProvider   `yaml:"slack,omitempty"`
}

GortConfig is the top-level configuration object

type GortServerConfigs

type GortServerConfigs struct {
	AllowSelfRegistration bool   `yaml:"allow_self_registration,omitempty"`
	APIAddress            string `yaml:"api_address,omitempty"`
	APIURLBase            string `yaml:"api_url_base,omitempty"`
	DevelopmentMode       bool   `yaml:"development_mode,omitempty"`
	EnableSpokenCommands  bool   `yaml:"enable_spoken_commands,omitempty"`
	TLSCertFile           string `yaml:"tls_cert_file,omitempty"`
	TLSKeyFile            string `yaml:"tls_key_file,omitempty"`
}

GortServerConfigs is the data wrapper for the "gort" section.

type JaegerConfigs

type JaegerConfigs struct {
	Endpoint string `yaml:"endpoint,omitempty"`
	Password string `yaml:"password,omitempty"`
	Username string `yaml:"username,omitempty"`
}

JaegerConfigs is the data wrapper for the "jaeger" section.

type Provider

type Provider interface{}

Provider is the general interface for all providers. Currently only Slack is supported, with HipChat coming in time.

type SlackProvider

type SlackProvider struct {
	AbstractProvider `yaml:",inline"`
	IconURL          string `yaml:"icon_url,omitempty"`

	// App and Bot tokens, used for Socket mode.
	AppToken string `yaml:"app_token,omitempty"`
	BotToken string `yaml:"bot_token,omitempty"`

	// Deprecated, used for Classic Slack apps
	APIToken string `yaml:"api_token,omitempty"`
}

SlackProvider is the data wrapper for a Slack App provider.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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