internal

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2025 License: BSD-3-Clause Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowHost

func AllowHost(host string)

AllowHost appends a host to the allowed hosts list in the .env file.

func AskForConfirmation added in v0.2.12

func AskForConfirmation(s string) bool

AskForConfirmation asks the user for confirmation. A user must type in "yes" or "no" and then press enter. It has fuzzy matching, so "y", "Y", "yes", "YES", and "Yes" all count as confirmations. If the input is not recognized, it will ask again. The function does not return until it gets a valid response from the user. Original source: https://gist.github.com/r0l1/3dcbb0c8f6cfe9c66ab8008f55f8f28b

func CheckPath

func CheckPath(cmd string) bool

CheckPath checks the $PATH environment variable for a given “cmd“ and return a “bool“ indicating if it exists.

func Contains

func Contains(slice []string, target string) bool

Contains checks if a slice of strings (“slice“ parameter) contains a given string (“search“ parameter).

func DirExists

func DirExists(path string) bool

DirExists determines if a given string is a valid directory. Reference: https://golangcode.com/check-if-a-file-exists/

func DisallowHost

func DisallowHost(host string)

DisallowHost removes a host to the allowed hosts list in the .env file.

func DistrustOrigin added in v0.2.2

func DistrustOrigin(host string)

DistrustOrigin removes an origin to the trusted origins list in the .env file.

func EvaluateDockerComposeStatus added in v0.2.8

func EvaluateDockerComposeStatus() error

EvaluateDockerComposeStatus determines if the host has the “docker compose“ plugin or the “docker compose“ script installed and set the global `dockerCmd` variable.

func FetchLogs

func FetchLogs(containerName string, lines string) []string

FetchLogs fetches logs from the container with the specified “name“ label (“containerName“ parameter).

func FileExists

func FileExists(path string) bool

FileExists determines if a given string is a valid filepath. Reference: https://golangcode.com/check-if-a-file-exists/

func GenerateCertificatePackage

func GenerateCertificatePackage() error

GenerateCertificatePackage generate TLS certificates and Diffie-Helman parameters file using Go.

func GenerateRandomPassword

func GenerateRandomPassword(pwLength int, safe bool) string

GenerateRandomPassword generates a random password of the given length The password will be comprised of a-zA-Z0-9 and !@#$%^&*()_-+=/?<>., Special characters exclude the following: '";:`~\/| Exclusions are to help avoid issues with escaping and breaking quotes in env files

func GetCwdFromExe

func GetCwdFromExe() string

GetCwdFromExe gets the current working directory based on “ghostwriter-cli“ location.

func GetLocalGhostwriterVersion

func GetLocalGhostwriterVersion() (string, error)

GetLocalGhostwriterVersion fetches the local Ghostwriter version from the “VERSION“ file.

func GetRemoteGhostwriterVersion

func GetRemoteGhostwriterVersion() (string, error)

GetRemoteGhostwriterVersion fetches the latest Ghostwriter version from GitHub's API.

func ParseGhostwriterEnvironmentVariables

func ParseGhostwriterEnvironmentVariables()

ParseGhostwriterEnvironmentVariables attempts to find and open an existing .env file or create a new one. If an .env file is found, load it into the Viper configuration. If an .env file is not found, create a new one with default values. Then write the final file with “WriteGhostwriterEnvironmentVariables()“.

func PostgresVersionForData added in v0.2.21

func PostgresVersionForData(
	yaml string,
) int

Gets the major version number of the PostgreSQL data. If different from the installation version, an upgrade is needed.

func PostgresVersionInstalled added in v0.2.21

func PostgresVersionInstalled(
	yaml string,
) int

Gets the major version number of the PostgreSQL installation

func RunBasicCmd

func RunBasicCmd(name string, args []string) (string, error)

RunBasicCmd executes a given command (“name“) with a list of arguments (“args“) and return a “string“ with the output.

func RunCmd

func RunCmd(name string, args []string) error

RunCmd executes a given command (“name“) with a list of arguments (“args“)

func RunDockerComposeBackup added in v0.2.12

func RunDockerComposeBackup(yaml string)

RunDockerComposeBackup executes the “docker compose“ command to back up the PostgreSQL database in the environment from the specified YAML file (“yaml“ parameter).

func RunDockerComposeBackups added in v0.2.12

func RunDockerComposeBackups(yaml string)

RunDockerComposeBackups executes the “docker compose“ command to list available PostgreSQL database backups in the environment from the specified YAML file (“yaml“ parameter).

func RunDockerComposeDown

func RunDockerComposeDown(yaml string)

RunDockerComposeDown executes the “docker compose“ commands to bring down the environment with the specified YAML file (“yaml“ parameter).

func RunDockerComposeInstall

func RunDockerComposeInstall(yaml string)

RunDockerComposeInstall executes the “docker compose“ commands for a first-time installation with the specified YAML file (“yaml“ parameter).

func RunDockerComposeRestart

func RunDockerComposeRestart(yaml string)

RunDockerComposeRestart executes the “docker compose“ commands to restart the environment with the specified YAML file (“yaml“ parameter).

func RunDockerComposeRestore added in v0.2.12

func RunDockerComposeRestore(yaml string, restore string)

RunDockerComposeRestore executes the “docker compose“ command to restore a PostgreSQL database backup in the environment from the specified YAML file (“yaml“ parameter).

func RunDockerComposeStart

func RunDockerComposeStart(yaml string)

RunDockerComposeStart executes the “docker compose“ commands to start the environment with the specified YAML file (“yaml“ parameter).

func RunDockerComposeStop

func RunDockerComposeStop(yaml string)

RunDockerComposeStop executes the “docker compose“ commands to stop all services in the environment with the specified YAML file (“yaml“ parameter).

func RunDockerComposeUp

func RunDockerComposeUp(yaml string)

RunDockerComposeUp executes the “docker compose“ commands to bring up the environment with the specified YAML file (“yaml“ parameter).

func RunDockerComposeUpgrade

func RunDockerComposeUpgrade(yaml string, skipseed bool)

RunDockerComposeUpgrade executes the “docker compose“ commands for re-building or upgrading an installation with the specified YAML file (“yaml“ parameter).

func RunGhostwriterTests

func RunGhostwriterTests()

RunGhostwriterTests runs Ghostwriter's unit and integration tests via “docker compose“. The tests are run in the development environment and assume certain values will be set for test conditions, so the .env file is temporarily adjusted during the test run.

func RunRawCmd added in v0.2.21

func RunRawCmd(name string, args ...string) error

RunRawCmd executes a given command (“name“) with a list of arguments (“args“) Does not convert docker to docker compose like `RunCmd` does.

func SetConfig

func SetConfig(key string, value string)

SetConfig sets the value of the specified key in the .env file.

func SetDevMode

func SetDevMode()

SetDevMode updates the environment variables to switch to development mode.

func SetProductionMode

func SetProductionMode()

SetProductionMode updates the environment variables to switch to production mode.

func TrustOrigin added in v0.2.2

func TrustOrigin(host string)

TrustOrigin appends an origin to the trusted origins list in the .env file.

func WriteGhostwriterEnvironmentVariables

func WriteGhostwriterEnvironmentVariables()

WriteGhostwriterEnvironmentVariables writes the environment variables to the “.env“ file.

Types

type Configuration

type Configuration struct {
	Key string
	Val string
}

Configuration is a custom type for storing configuration values as Key:Val pairs.

type Configurations

type Configurations []Configuration

Configurations is a custom type for storing `Configuration` values

func GetConfig

func GetConfig(args []string) Configurations

GetConfig retrieves the specified values from the .env file.

func GetConfigAll

func GetConfigAll() Configurations

GetConfigAll retrieves all values from the .env configuration file.

func (Configurations) Len

func (c Configurations) Len() int

Len returns the length of a Configurations struct

func (Configurations) Less

func (c Configurations) Less(i, j int) bool

Less determines if one Configuration is less than another Configuration

func (Configurations) Swap

func (c Configurations) Swap(i, j int)

Swap exchanges the position of two Configuration values in a Configurations struct

type Container

type Container struct {
	ID     string
	Image  string
	Status string
	Ports  []types.Port
	Name   string
}

Container is a custom type for storing container information similar to output from “docker containers ls“.

type Containers

type Containers []Container

Containers is a collection of Container structs

func GetRunning

func GetRunning() Containers

GetRunning determines if the container with the specified “name“ label (“containerName“ parameter) is running.

func (Containers) Len

func (c Containers) Len() int

Len returns the length of a Containers struct

func (Containers) Less

func (c Containers) Less(i, j int) bool

Less determines if one Container is less than another Container

func (Containers) Swap

func (c Containers) Swap(i, j int)

Swap exchanges the position of two Container values in a Containers struct

type HealthIssue added in v0.2.8

type HealthIssue struct {
	Type    string
	Service string
	Message string
}

HealthIssue is a custom type for storing healthcheck output.

type HealthIssues added in v0.2.8

type HealthIssues []HealthIssue

func CheckDockerHealth added in v0.2.8

func CheckDockerHealth(dev bool) (HealthIssues, error)

CheckDockerHealth determines if all containers are running and passing their respective health checks.

func CheckGhostwriterHealth added in v0.2.8

func CheckGhostwriterHealth(dev bool) (HealthIssues, error)

CheckGhostwriterHealth fetches the latest health reports from Ghostwriter's status API endpoint.

func (HealthIssues) Len added in v0.2.8

func (c HealthIssues) Len() int

func (HealthIssues) Less added in v0.2.8

func (c HealthIssues) Less(i, j int) bool

func (HealthIssues) Swap added in v0.2.8

func (c HealthIssues) Swap(i, j int)

Jump to

Keyboard shortcuts

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