utils

package
v0.5.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: AGPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ArchiveTar = iota
	ArchiveTarBz2
	ArchiveTarGz
	ArchiveTarLz4
	ArchiveTarSz
	ArchiveTarXz
	ArchiveZip
	ArchiveRar
)

Type of archive

View Source
const (
	JobTypeTLSCertificate = "tlscert"
	JobTypeACME           = "acme"
)

Job type identifiers

Variables

View Source
var ArchiveExtensions = []string{".zip", ".tar", ".tar.bz2", ".tbz2", ".tar.gz", ".tgz", ".tar.lz4", ".tlz4", ".tar.sz", ".tsz", ".tar.xz", ".txz", ".rar"}

Valid extensions

Functions

func ArchiveTypeByExtension

func ArchiveTypeByExtension(name string) int

ArchiveTypeByExtension returns the type of the archive by the file's extension Note: this function assumes that the file was already validated to contain one of the valid extensions Ensure to use the SiteApp.Validate() method first

func CertificateExists

func CertificateExists(cert string, key string) (exists bool, err error)

CertificateExists checks if the certificate and key exist on disk

func CopyFile

func CopyFile(src string, dst string) error

CopyFile copies the src file to dst. Any existing file will be overwritten and will not copy file attributes. Source: https://stackoverflow.com/a/21061062/192024

func CreateJobID

func CreateJobID(job JobData) (jobID string)

Build job ID

func EnsureFolder

func EnsureFolder(path string) error

EnsureFolder creates a folder if it doesn't exist already

func ExtractArchive

func ExtractArchive(dst string, in io.Reader, size int64, format int) error

ExtractArchive extracts a compressed archive Reads input from a stream in, and extracts all files into dst This supports all archive formats supported by archiver, including zip, tar.gz, tar.bz2, rar

func FileExists

func FileExists(path string) (bool, error)

FileExists returns true if the path exists on disk and it's not a folder

func FolderExists

func FolderExists(path string) (bool, error)

FolderExists returns true if the path exists on disk and it's a folder

func GetAzureAuthorizer

func GetAzureAuthorizer(service string) (autorest.Authorizer, error)

GetAzureAuthorizer returns the autorest.Authorizer object for the Azure SDK, for a given service See GetAzureEndpoint for the list of services

func GetAzureEndpoint

func GetAzureEndpoint(service string) (endpoint string, err error)

GetAzureEndpoint returns the endpoint for the Azure service Service can be one of: - "azure" for Azure Resource Manager - "keyvault" for Azure Key Vault - "storage" for Azure Storage

func GetAzureOAuthConfig

func GetAzureOAuthConfig() (*adal.OAuthConfig, error)

GetAzureOAuthConfig returns the adal.OAuthConfig object that can be used to authenticate against Azure resources

func GetAzureServicePrincipalToken

func GetAzureServicePrincipalToken(service string) (*adal.ServicePrincipalToken, error)

GetAzureServicePrincipalToken returns a Service Principal token inside an adal.ServicePrincipalToken object, for a given service Note that the returned token needs to be refreshed with the `Refresh()` method right away before it can be used See GetAzureEndpoint for the list of services

func GetAzureStorageCredentials

func GetAzureStorageCredentials() (azblob.Credential, error)

GetAzureStorageCredentials returns a azblob.Credential object that can be used to authenticate an Azure Blob Storage SDK pipeline

func GetAzureStorageEndpointSuffix

func GetAzureStorageEndpointSuffix() (string, error)

GetAzureStorageEndpointSuffix returns the endpoint suffix for Azure Storage in this environment

func HeaderIsAllowed

func HeaderIsAllowed(name string) bool

HeaderIsAllowed returns true if a header is allowed as response header

func IsTruthy

func IsTruthy(val string) bool

IsTruthy returns true if a string (e.g. a querystring parameter) is a truthy value, as a string

func NodeAddress

func NodeAddress() string

NodeAddress returns the address of the node

func ParseRSAPublicKey

func ParseRSAPublicKey(nStr string, eStr string) (*rsa.PublicKey, error)

ParseRSAPublicKey converts a public RSA key represented by base64-encoded modulus and exponent into a rsa.PublicKey object

func PathExists

func PathExists(path string) (bool, error)

PathExists returns true if the path exists on disk

func ReaderFuncWithContext

func ReaderFuncWithContext(ctx context.Context, in io.Reader) ioctx

func RemoveContents

func RemoveContents(dir string) error

RemoveContents remove all contents within a directory Source: https://stackoverflow.com/a/33451503/192024

func RequestJSON

func RequestJSON(client *http.Client, url string, target interface{}) error

RequestJSON fetches a JSON document from the web

func SHA256String

func SHA256String(str string) string

SHA256String returns the SHA256 of a string, as a hex-encoded string

func SanitizeAppName

func SanitizeAppName(name string) string

SanitizeAppName validates and sanitizes the name of an app's bundle App bundles must be lowercase strings containing letters, numbers, dashes and dots; the first character must be a letter

func SerializeECDSAKey

func SerializeECDSAKey(privateKey *ecdsa.PrivateKey) ([]byte, error)

SerializeECDSAKey serializes an ecdsa private key Source https://stackoverflow.com/a/41315404/192024

func StringInSlice

func StringInSlice(list []string, a string) bool

StringInSlice checks if a string is contained inside a slice of strings

func UnserializeECDSAKey

func UnserializeECDSAKey(pemEncoded []byte) (*ecdsa.PrivateKey, error)

UnserializeECDSAKey unserializes an ecdsa private key Source https://stackoverflow.com/a/41315404/192024

func WriterFuncWithContext

func WriterFuncWithContext(ctx context.Context, in io.Writer) ioctx

Types

type AppManifest

type AppManifest struct {
	Rules   ManifestRules     `yaml:"rules"`
	Rewrite map[string]string `yaml:"rewrite"`
	Page403 string            `yaml:"page403"`
	Page404 string            `yaml:"page404"`

	// Internal
	Locations map[string]ManifestRuleOptions `yaml:"-"`
}

AppManifest represents the manifest of an app

type JobData

type JobData struct {
	Type string
	Data string
}

JobData is the struct of the

type ManifestRule

type ManifestRule struct {
	// An "exact" match equals to a = modifier in the nginx location block
	Exact string `yaml:"exact"`
	// A "prefix" match equals to a ^~ modifier in the nginx location block
	// Exception is the prefix "/", which doesn't use any modifier
	Prefix string `yaml:"prefix"`
	// A "match" match equals to ~* modifier (or ~ modifier if "caseSensitive" is true) in the nginx location block
	Match         string `yaml:"match"`
	CaseSensitive bool   `yaml:"caseSensitive"`
	// Using "file" lets user list file extensions or extension groups (such as "_images")
	File string `yaml:"file"`

	// Options to apply
	Options ManifestRuleOptions `yaml:"options"`
}

ManifestRule is the dictionary with rules

type ManifestRuleOptions

type ManifestRuleOptions struct {
	Deny          bool              `yaml:"deny"`
	ClientCaching string            `yaml:"clientCaching"`
	Headers       map[string]string `yaml:"headers"`
	CleanHeaders  map[string]string `yaml:"-"`
	Proxy         string            `yaml:"proxy"`
}

ManifestRuleOptions is used by the AppManifest struct to represent options for a specific location or file type

type ManifestRules

type ManifestRules []ManifestRule

ManifestRules is a slice of ManifestRule structs

type NginxStatus

type NginxStatus struct {
	Running bool `json:"running"`
}

NginxStatus contains information on the status of the Nginx server

type NodeStatus

type NodeStatus struct {
	NodeName string       `json:"name"`
	Nginx    NginxStatus  `json:"nginx"`
	Sync     NodeSync     `json:"sync"`
	Store    NodeStore    `json:"store"`
	Health   []SiteHealth `json:"health"`
}

NodeStatus contains the current status of the node

type NodeStore

type NodeStore struct {
	Healthy bool `json:"healthy"`
}

NodeStore contains information on the status of the store Particularly useful if using etcd as store

type NodeSync

type NodeSync struct {
	Running   bool       `json:"running"`
	LastSync  *time.Time `json:"lastSync"`
	SyncError string     `json:"syncError,omitempty"`
}

NodeSync contains information on the sync status

type SiteHealth

type SiteHealth struct {
	Domain       string     `json:"domain"`
	App          *string    `json:"app"`
	StatusCode   *int       `json:"-"`
	ResponseSize *int       `json:"-"`
	Error        string     `json:"error,omitempty"`
	Time         *time.Time `json:"time,omitempty"`
}

SiteHealth contains the results of the health checks for each individual app

func (*SiteHealth) IsHealthy

func (h *SiteHealth) IsHealthy() bool

IsHealthy returns true if the site is in a healthy state

func (*SiteHealth) MarshalJSON

func (h *SiteHealth) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom JSON serializer for the SiteHealth object

Jump to

Keyboard shortcuts

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