competition

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2017 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LF_HOME is the base directory for competition development
	LF_HOME = "LF_HOME"

	LF_HOME_FILE = ".lf_home"

	// LF_ENV is the currently assigned LF environment
	LF_ENV = "LF_ENV"

	LF_ENV_FILE   = ".lf_env"
	SPECIAL_CHARS = "!@#$%^"
)

Variables

View Source
var (
	AMIMap map[string]*AMI
)

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func Contains

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

func CreateHome

func CreateHome()

func CreateHomeConfig

func CreateHomeConfig()

func CurrentEnvDir

func CurrentEnvDir() string

func CustomExternalCNAME

func CustomExternalCNAME(e *Environment, c string) string

func CustomIP

func CustomIP(cidr string, offset, id int) string

func CustomInternalCNAME

func CustomInternalCNAME(e *Environment, n *Network, c string) string

func DScript

func DScript(name string, c *Competition, e *Environment, i int, n *Network, h *Host, hn string) string

func DeterminedPassword

func DeterminedPassword(seed string) string

func DictionaryWords

func DictionaryWords() (words []string)

func Ds_store added in v1.0.1

func Ds_store() (*asset, error)

func Ds_storeBytes added in v1.0.1

func Ds_storeBytes() ([]byte, error)

func EmbedRender

func EmbedRender(t string, c *Competition, e *Environment, i int, n *Network, h *Host, hn string) string

func EnvDirByName

func EnvDirByName(name string) string

func EnvDirExistsByName

func EnvDirExistsByName(name string) bool

func EnvExists

func EnvExists() bool

func EnvSet

func EnvSet() bool

func EnvValid

func EnvValid() bool

func ExecInteractiveCommand

func ExecInteractiveCommand(command string, args []string)

func FileToName

func FileToName(path string) string

func GetEnv

func GetEnv() string

func GetHome

func GetHome() string

func GetPublicIP

func GetPublicIP() string

func HomeExists

func HomeExists() bool

func HomeSet

func HomeSet() bool

func HomeValid

func HomeValid() bool

func Incr added in v1.0.13

func Incr(val int) error

func LoadAMIs

func LoadAMIs()

func LoadUsersFromDB

func LoadUsersFromDB(path string) map[string][]User

func Log

func Log(msg string)

func LogEnvs

func LogEnvs(envs map[*Environment]bool)

func LogError

func LogError(msg string)

func LogFatal

func LogFatal(msg string)

func LogPlain

func LogPlain(msg string)

func MakeSSHKeyPair

func MakeSSHKeyPair(pubKeyPath, privateKeyPath string) error

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func NewTemplate

func NewTemplate(tmpl string, includeScripts bool) *template.Template

func NewTermScanner

func NewTermScanner(data []byte, atEOF bool) (advance int, token []byte, err error)

Ugly hack, this is bufio.ScanLines with ? added as an other delimiter :D

func PathExists

func PathExists(path string) bool

func RandomPasswordFromSeed

func RandomPasswordFromSeed(seed int64) string

func RandomString

func RandomString(length int) string

func Render

func Render(tmpName string, c *Competition, e *Environment, t int, n *Network, h *Host) []byte

func RenderTB

func RenderTB(tmpName string, tb *TemplateBuilder) []byte

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func ScriptRender

func ScriptRender(t string, c *Competition, e *Environment, i int, n *Network, h *Host, hn string) string

func SetEnv

func SetEnv(val string)

func SetHome

func SetHome(val string)

func SetZero added in v1.0.13

func SetZero(val int) error

func StringRender added in v1.0.3

func StringRender(t string, c *Competition, e *Environment, i int, n *Network, h *Host) string

func StringWithCharset

func StringWithCharset(length int, charset string) string

func TFRender

func TFRender(tfobj interface{}) (string, error)

func TouchFile

func TouchFile(path string)

func ValidName

func ValidName(name string) bool

func ValidPrefix

func ValidPrefix(prefix string) bool

func ValidateEnv

func ValidateEnv()

func ValidateHome

func ValidateHome()

Types

type AMI

type AMI struct {
	OS       string            `json:"os"`
	Regions  map[string]string `json:"regions"`
	Username string            `json:"username"`
}

type AWSConfig

type AWSConfig struct {
	CIDR   string `yaml:"cidr"`
	Region string `yaml:"region"`
	Zone   string `yaml:"zone"`
}

type AWSCred

type AWSCred struct {
	APIKey    string `yaml:"api_key"`
	APISecret string `yaml:"api_secret"`
	Region    string `yaml:"region"`
	Zone      string `yaml:"zone"`
}

type App

type App struct {
	Name string
}

type AppMap

type AppMap map[string]*App

func GetApps

func GetApps() AppMap

type Competition

type Competition struct {
	R53ZoneID    string `yaml:"external_r53_zone_id"`
	AWSCred      `yaml:"aws_creds"`
	S3Config     `yaml:"s3_config"`
	AdminIPs     []string `yaml:"admin_ips"`
	RootPassword string   `yaml:"root_password"`
	UserList     map[string][]User
}

func LoadCompetition

func LoadCompetition() (*Competition, error)

func (*Competition) ChangeEnv

func (c *Competition) ChangeEnv(name string)

func (*Competition) CreateEnv

func (c *Competition) CreateEnv(name, prefix string)

func (*Competition) CurrentEnv

func (c *Competition) CurrentEnv() *Environment

func (*Competition) EmployeeDBPath

func (c *Competition) EmployeeDBPath() string

func (*Competition) EnvMap

func (c *Competition) EnvMap() map[string]*Environment

func (*Competition) GetEnvByName

func (c *Competition) GetEnvByName(name string) *Environment

func (*Competition) GetEnvs

func (c *Competition) GetEnvs() map[*Environment]bool

func (*Competition) ParseScripts

func (c *Competition) ParseScripts() map[string]*Script

func (*Competition) SSHPrivateKey

func (c *Competition) SSHPrivateKey() string

func (*Competition) SSHPrivateKeyPath

func (c *Competition) SSHPrivateKeyPath() string

func (*Competition) SSHPublicKey

func (c *Competition) SSHPublicKey() string

func (*Competition) SSHPublicKeyPath

func (c *Competition) SSHPublicKeyPath() string

type DNSEntry added in v1.0.3

type DNSEntry struct {
	Name  string `yaml:"name"`
	Value string `yaml:"value"`
	Type  string `yaml:"type"`
}

type Dependency added in v1.0.3

type Dependency struct {
	Host    string `yaml:"host"`
	Network string `yaml:"network"`
}

type Environment

type Environment struct {
	Name             string   `yaml:"name"`
	Prefix           string   `yaml:"prefix"`
	WhitelistIPs     []string `yaml:"ip_whitelist"`
	Vars             `yaml:"variables"`
	AWSConfig        `yaml:"aws_config"`
	PodCount         int                 `yaml:"pod_count"`
	Domain           string              `yaml:"domain"`
	IncludedNetworks []string            `yaml:"included_networks"`
	ResolvedNetworks map[string]*Network `yaml:"-"`
	Competition      `yaml:"-"`
	Users            []*User    `yaml:"-"`
	Networks         []*Network `yaml:"-"`
	Hosts            []*Host    `yaml:"-"`
	JumpHosts        `yaml:"jump_hosts"`
}

func LoadEnvironment

func LoadEnvironment(name string) (*Environment, error)

func (*Environment) CreateHost

func (e *Environment) CreateHost(h *Host)

func (*Environment) CreateNetwork

func (e *Environment) CreateNetwork(n *Network)

func (*Environment) DefaultCIDR

func (e *Environment) DefaultCIDR() string

func (*Environment) EnvRoot

func (e *Environment) EnvRoot() string

func (*Environment) GenerateSSHConfig added in v1.0.10

func (e *Environment) GenerateSSHConfig()

func (*Environment) HostsDir

func (e *Environment) HostsDir() string

func (*Environment) KaliJumpAMI

func (e *Environment) KaliJumpAMI() string

func (*Environment) NetworksDir

func (e *Environment) NetworksDir() string

func (*Environment) ParseHosts

func (e *Environment) ParseHosts() map[string]*Host

func (*Environment) ParseNetworks

func (e *Environment) ParseNetworks() map[string]*Network

func (*Environment) PodPassword

func (e *Environment) PodPassword(podID int) string

func (*Environment) ResolveIncludedNetworks

func (e *Environment) ResolveIncludedNetworks() map[string]*Network

func (*Environment) ResolvePublicTCP

func (e *Environment) ResolvePublicTCP() map[string]SecurityGroup

func (*Environment) ResolvePublicUDP

func (e *Environment) ResolvePublicUDP() map[string]SecurityGroup

func (*Environment) SSHConfigPath added in v1.0.10

func (e *Environment) SSHConfigPath() string

func (*Environment) Suffix

func (e *Environment) Suffix(podOffset int) string

func (*Environment) TFName

func (e *Environment) TFName(name string, offset int) string

func (*Environment) TfDir

func (e *Environment) TfDir() string

func (*Environment) TfFile

func (e *Environment) TfFile() string

func (*Environment) TfScriptsDir

func (e *Environment) TfScriptsDir() string

func (*Environment) TfStateFile added in v1.0.10

func (e *Environment) TfStateFile() string

func (*Environment) WindowsJumpAMI

func (e *Environment) WindowsJumpAMI() string

type File

type File struct {
	Name string
}

type FileMap

type FileMap map[string]*File

func GetFiles

func GetFiles() FileMap

type Host

type Host struct {
	Hostname       string       `yaml:"hostname"`
	OS             string       `yaml:"os"`
	AMI            string       `yaml:"ami"`
	InstanceSize   string       `yaml:"instance_size"`
	LastOctet      int          `yaml:"last_octet"`
	InternalCNAMEs []string     `yaml:"internal_cnames"`
	ExternalCNAMEs []string     `yaml:"external_cnames"`
	TCPPorts       []string     `yaml:"public_tcp"`
	UDPPorts       []string     `yaml:"public_udp"`
	Scripts        []string     `yaml:"scripts"`
	UserGroups     []string     `yaml:"user_groups"`
	DNSEntries     []DNSEntry   `yaml:"dns_entries"`
	Dependencies   []Dependency `yaml:"dependencies"`
	Vars           `yaml:"variables"`
	Network        `yaml:"-"`
}

func LoadHostFromFile

func LoadHostFromFile(file string) (*Host, error)

func (*Host) GetAMI

func (h *Host) GetAMI() string

func (*Host) RenderIP added in v1.0.3

func (h *Host) RenderIP() string

func (*Host) RenderedDNSEntries added in v1.0.3

func (h *Host) RenderedDNSEntries(podOffset int) []DNSEntry

func (*Host) ToYAML

func (h *Host) ToYAML() string

func (*Host) ValidTCPPorts added in v1.0.10

func (h *Host) ValidTCPPorts() []string

func (*Host) ValidUDPPorts added in v1.0.10

func (h *Host) ValidUDPPorts() []string

type JumpHosts

type JumpHosts struct {
	CIDR    string `yaml:"cidr"`
	Windows struct {
		AMI     string   `yaml:"ami"`
		Count   int      `yaml:"count"`
		Size    string   `yaml:"size"`
		Scripts []string `yaml:"scripts"`
	} `yaml:"windows"`
	Kali struct {
		AMI     string   `yaml:"ami"`
		Count   int      `yaml:"count"`
		Size    string   `yaml:"size"`
		Scripts []string `yaml:"scripts"`
	} `yaml:"kali"`
}

type Network

type Network struct {
	CIDR          string `yaml:"cidr"`
	Name          string `yaml:"name"`
	Subdomain     string `yaml:"subdomain"`
	VDIVisible    bool   `yaml:"vdi_visible"`
	Vars          `yaml:"variables"`
	IncludedHosts []string         `yaml:"included_hosts"`
	ResolvedHosts map[string]*Host `yaml:"-"`
	Environment   `yaml:"-"`
}

func LoadNetworkFromFile

func LoadNetworkFromFile(file string) (*Network, error)

func (*Network) ResolveIncludedHosts

func (n *Network) ResolveIncludedHosts() map[string]*Host

func (*Network) ToYAML

func (n *Network) ToYAML() string

type S3Config

type S3Config struct {
	Region string `yaml:"region"`
	Bucket string `yaml:"bucket"`
}

type SSHConfig added in v1.0.10

type SSHConfig struct {
	SSHKey string
	Hosts  map[string]string
}

type Script

type Script struct {
	Contents []byte
}

func LoadScript

func LoadScript(path string) (*Script, error)

func (*Script) RenderFile

func (s *Script) RenderFile(path string, t TemplateBuilder) error

func (*Script) RenderString

func (s *Script) RenderString(t TemplateBuilder) string

type ScriptMap

type ScriptMap map[string]*Script

func GetScripts

func GetScripts() ScriptMap

type SecurityGroup added in v1.0.8

type SecurityGroup struct {
	Protocol string
	FromPort int
	ToPort   int
}

type TFAWSDHCPOptions

type TFAWSDHCPOptions struct {
	Name       string
	DomainName string
	DNSServers []string
	Tags       []string
}

func (*TFAWSDHCPOptions) Mix

func (t *TFAWSDHCPOptions) Mix(tpl *TemplateBuilder)

type TFAWSDHCPOptionsAssociation

type TFAWSDHCPOptionsAssociation struct {
	Name        string
	VPC         TFAWSVirtualPrivateCloud
	DHCPOptions TFAWSDHCPOptions
}

func (*TFAWSDHCPOptionsAssociation) Mix

type TFAWSEgressRule

type TFAWSEgressRule struct {
	FromPort string
	ToPort   string
	Protocol string
	CIDRs    []string
}

func (*TFAWSEgressRule) Mix

func (t *TFAWSEgressRule) Mix(tpl *TemplateBuilder)

type TFAWSElasticIP

type TFAWSElasticIP struct {
	Name     string
	VPC      bool
	Attach   bool
	Instance TFAWSInstance
}

func (*TFAWSElasticIP) Mix

func (t *TFAWSElasticIP) Mix(tpl *TemplateBuilder)

type TFAWSIngressRule

type TFAWSIngressRule struct {
	FromPort string
	ToPort   string
	Protocol string
	CIDRs    []string
}

func (*TFAWSIngressRule) Mix

func (t *TFAWSIngressRule) Mix(tpl *TemplateBuilder)

type TFAWSInstance

type TFAWSInstance struct {
	Name                     string
	AMI                      string
	InstanceType             string
	Subnet                   TFAWSSubnet
	KeyPair                  TFAWSKeyPair
	PrivateIP                string
	AssociatePublicIPAddress bool
	SecurityGroups           []TFAWSSecurityGroup
	UserDataScript           TFUserDataScript
	Connection               TFInstanceConnection
	FileProvisioners         []TFFileProvisioner
	InlineProvisioners       []TFInlineProvisioner
	ScriptProvisioners       []TFScriptProvisioner
	Tags                     []string
}

func (*TFAWSInstance) Mix

func (t *TFAWSInstance) Mix(tpl *TemplateBuilder)

type TFAWSKeyPair

type TFAWSKeyPair struct {
	Name       string
	KeyName    string
	PublicKey  string
	PrivateKey string
}

func (*TFAWSKeyPair) Mix

func (t *TFAWSKeyPair) Mix(tpl *TemplateBuilder)

type TFAWSNATGateway

type TFAWSNATGateway struct {
	Name      string
	VPC       TFAWSVirtualPrivateCloud
	ElasticIP TFAWSElasticIP
	Subnet    TFAWSSubnet
}

func (*TFAWSNATGateway) Mix

func (t *TFAWSNATGateway) Mix(tpl *TemplateBuilder)

type TFAWSProvider

type TFAWSProvider struct {
	Name      string
	AccessKey string
	SecretKey string
	Region    string
	Profile   string
}

func (*TFAWSProvider) Mix

func (t *TFAWSProvider) Mix(tpl *TemplateBuilder)

type TFAWSRoute

type TFAWSRoute struct {
	Name       string
	CIDR       string
	NATGateway TFAWSNATGateway
}

func (*TFAWSRoute) Mix

func (t *TFAWSRoute) Mix(tpl *TemplateBuilder)

type TFAWSRoute53ARecord

type TFAWSRoute53ARecord struct {
	Name     string
	ZoneID   string
	Hostname string
	TTL      int
	Records  []string
}

func (*TFAWSRoute53ARecord) Mix

func (t *TFAWSRoute53ARecord) Mix(tpl *TemplateBuilder)

type TFAWSRouteTable

type TFAWSRouteTable struct {
	Name   string
	VPC    TFAWSVirtualPrivateCloud
	Routes []TFAWSRoute
	Tags   []string
}

func (*TFAWSRouteTable) Mix

func (t *TFAWSRouteTable) Mix(tpl *TemplateBuilder)

type TFAWSRouteTableAssociation

type TFAWSRouteTableAssociation struct {
	Name       string
	Subnet     TFAWSSubnet
	RouteTable TFAWSRouteTable
	Tags       []string
}

func (*TFAWSRouteTableAssociation) Mix

type TFAWSSecurityGroup

type TFAWSSecurityGroup struct {
	Name         string
	Description  string
	VPC          TFAWSVirtualPrivateCloud
	IngressRules []TFAWSIngressRule
	EgressRules  []TFAWSEgressRule
	Tags         []string
}

func (*TFAWSSecurityGroup) Mix

func (t *TFAWSSecurityGroup) Mix(tpl *TemplateBuilder)

type TFAWSSubnet

type TFAWSSubnet struct {
	Name                string
	VPC                 TFAWSVirtualPrivateCloud
	CIDR                string
	AvailabilityZone    string
	MapPublicIPOnLaunch bool
	DependsOn           []string
	Tags                []string
}

func (*TFAWSSubnet) Mix

func (t *TFAWSSubnet) Mix(tpl *TemplateBuilder)

type TFAWSVirtualPrivateCloud

type TFAWSVirtualPrivateCloud struct {
	Name               string
	CIDR               string
	EnableDNSHostnames bool
	Tags               []string
}

func (*TFAWSVirtualPrivateCloud) Mix

type TFFileProvisioner

type TFFileProvisioner struct {
	Name        string
	Source      string
	Content     string
	Destination string
}

func (*TFFileProvisioner) Mix

func (t *TFFileProvisioner) Mix(tpl *TemplateBuilder)

type TFGCPElasticIP

type TFGCPElasticIP struct {
	Name string
}

func (*TFGCPElasticIP) Mix

func (t *TFGCPElasticIP) Mix(tpl *TemplateBuilder)

type TFGCPFirewall

type TFGCPFirewall struct {
	Name         string
	Network      TFGCPNetwork
	SourceRanges []string
	SourceTags   []string
	TargetTags   []string
	Rules        []TFGCPFirewallAllowRule
}

func (*TFGCPFirewall) Mix

func (t *TFGCPFirewall) Mix(tpl *TemplateBuilder)

type TFGCPFirewallAllowRule

type TFGCPFirewallAllowRule struct {
	Protocol string
	Ports    []int
}

func (*TFGCPFirewallAllowRule) Mix

type TFGCPInstance

type TFGCPInstance struct {
	Name               string
	HostName           string
	InstanceType       string
	AvailabilityZone   string
	Tags               []string
	AMI                string
	Subnet             TFGCPSubnet
	PrivateIP          string
	ElasticIP          TFGCPElasticIP
	SSHPublicKey       string
	UserDataScript     TFUserDataScript
	Connection         TFInstanceConnection
	FileProvisioners   []TFFileProvisioner
	InlineProvisioners []TFInlineProvisioner
	ScriptProvisioners []TFScriptProvisioner
}

func (*TFGCPInstance) Mix

func (t *TFGCPInstance) Mix(tpl *TemplateBuilder)

type TFGCPNetwork

type TFGCPNetwork struct {
	Name              string
	AutoCreateSubnets bool
}

func (*TFGCPNetwork) Mix

func (t *TFGCPNetwork) Mix(tpl *TemplateBuilder)

type TFGCPProvider

type TFGCPProvider struct {
	Name           string
	CredentialFile string
	Project        string
	Region         string
}

func (*TFGCPProvider) Mix

func (t *TFGCPProvider) Mix(tpl *TemplateBuilder)

type TFGCPSubnet

type TFGCPSubnet struct {
	Name    string
	CIDR    string
	Network TFGCPNetwork
}

func (*TFGCPSubnet) Mix

func (t *TFGCPSubnet) Mix(tpl *TemplateBuilder)

type TFInlineProvisioner

type TFInlineProvisioner struct {
	Name     string
	Commands []string
}

func (*TFInlineProvisioner) Mix

func (t *TFInlineProvisioner) Mix(tpl *TemplateBuilder)

type TFInstanceConnection

type TFInstanceConnection struct {
	ConnType          string
	User              string
	Password          string
	PrivateKey        string
	BastionHost       string
	BastionUser       string
	BastionPrivateKey string
	WinRMInsecure     bool
}

func (*TFInstanceConnection) Mix

type TFObject

type TFObject interface {
	Mix(tpl *TemplateBuilder)
}

type TFOutput

type TFOutput struct {
	Name  string
	Value string
}

func (*TFOutput) Mix

func (t *TFOutput) Mix(tpl *TemplateBuilder)

type TFScriptProvisioner

type TFScriptProvisioner struct {
	Scripts []TFTemplate
}

func (*TFScriptProvisioner) Mix

func (t *TFScriptProvisioner) Mix(tpl *TemplateBuilder)

type TFTemplate

type TFTemplate struct {
	Name     string
	Builder  TemplateBuilder
	Template string
	Rendered string
}

type TFUserDataScript

type TFUserDataScript struct {
	Name string
}

func (*TFUserDataScript) Mix

func (t *TFUserDataScript) Mix(tpl *TemplateBuilder)

type TFVar

type TFVar struct {
	Name        string
	Description string
	Value       string
}

func (*TFVar) Mix

func (t *TFVar) Mix(tpl *TemplateBuilder)

type TemplateBuilder

type TemplateBuilder struct {
	Competition      *Competition
	Environment      *Environment
	PodID            int
	Network          *Network
	Host             *Host
	HostIndex        int
	ScriptErrorCount int
}

func NewTemplateContext

func NewTemplateContext(c *Competition, e *Environment, pid int, n *Network, h *Host) *TemplateBuilder

func (*TemplateBuilder) EnvItemName

func (t *TemplateBuilder) EnvItemName(i interface{}, opts ...string) string

func (*TemplateBuilder) NetItemName

func (t *TemplateBuilder) NetItemName(i interface{}, opts ...string) string

type User

type User struct {
	Firstname  string `json:"first_name"`
	Lastname   string `json:"last_name"`
	Username   string `json:"username"`
	Email      string `json:"email"`
	Department string `json:"department"`
	Title      string `json:"title"`
	Password   string `json:"password"`
	OU         string `json:"ou"`
}

func GetUsersByOU

func GetUsersByOU(c *Competition, ou string) []User

func GetUsersForHost

func GetUsersForHost(c *Competition, h *Host) []User

type UserList

type UserList map[string][]User

type Vars

type Vars map[string]string

Jump to

Keyboard shortcuts

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