Skip to content

Templating Library

Fred Rybin edited this page Oct 22, 2021 · 6 revisions

Templating Library

Laforge Uses GoLang's Laforge Has some custom Template Variables and Functions available to be used in creating scripts in addition to what you can normally do with the library.

Fuctions

"hclstring"

Parameter: s String It is a template function that renders a safe HCLv2 string from s

"N"

Parameter: n Integer N returns a slice of n 0-sized elements, suitable for ranging over.

"UnsafeAtoi"

Parameter: s String UnsafeAtoi will convert the string s to an integer and return -1 if it cannot convert the string to an integer.

"Decr"

Parameter: n Integer Decreases n by 1 non-destructively and returns the result

"ToUpper"

Parameter: s String Converts s to an all Upper Case string

"Contains"

Parameter: s String, substring String Returns True or False if substring is in s

"HasPrefix"

Parameter: s String, prefix String Returns True or False if s has the defined prefix

"HasSuffix"

Parameter: s String, suffix String Returns True or False if s has the defined suffix

"Join"

Parameter: elems Takes elems which is an array of strings and combines it into 1 string with the elements separated with sep

"Replace"

Parameter: s string, old_string string, new_string string, n int Replaces instances of old_string in s with new_string n number of times. If n is < 0 then all occurrences will be replaced

"Repeat"

Parameter: s string, n int Returns a string with s repeated n times

"Split"

Parameter: s string, sep string Returns an array of strings from s with the elements separated by sep

"Title"

Parameter: s String Converts s to a Title cased string

"ToLower"

Parameter: s String Converts s to an all Lower Case string

"ToSnake"

Parameter: s String Converts s to Snake cased string

"ToScreamingSnake"

Parameter: s String Converts s to an all Upper Case Snake cased string

"ToKebab"

Parameter: s String Converts s to a Kebab cased string

"ToScreamingKebab"

Parameter: s String Converts s to an all Upper Case Kebab cased string

"ToDelimited"

Parameter: s string, delimiter uint8 Converts s to a string delimited by delimiter

"ToScreamingDelimited"

Parameter: s string, delimiter uint8, ignore uint8, screaming bool Converts s to a string delimited by delimiter that does not modify the ignore character and is converted to all uppercase if screaming is true

"ToCamel"

Parameter: s String Converts s to a Camel cased string

"ToLowerCamel"

Parameter: s String Converts s to a Lower Case, Camel cased string

"Incr"

Parameter: n Integer Increases n by 1 non-destructively and returns the result

"CalcIP"

Parameter: subnet string, lastOctect int Returns the IP of a subnet plus the lastOctect as a string

"TagEquals"

Parameter: h Takes a host object h and returns True or False if it contains the tag tag and if the value of that tag is value

"Octet"

Parameter: n Returns the Last Octect of the CIDR defined for the n network

"Base"

Parameter: path string Returns the Base of the specified path

Variables

Build

revision

  • Type: Int
  • Description: The version number of this Build for the Environment

environment_revision

  • Type: Int
  • Description: The Environment Revision this build is built off of

Competition

hcl_id

  • Type: String
  • Description: The HCL ID of the Competition Object in the LaForge Config

root_password

  • Type: String
  • Description: The Default Password for Boxes in the Competition

config

  • Type: map[string]string
  • Description: A map of configuration Key-Value Pairs
  • Optional

tags

  • Type: map[string]string
  • Description: A map of tag Key-Value Pairs
  • Optional

Environment

hcl_id

  • Type: String
  • Description: The HCL ID of the Enviroment Object in the LaForge Config

competition_id

  • Type: String
  • Description: The HCL ID of the Competition Object for this Enviroment

name

  • Type: String
  • Description: The Name of the Enviroment

description

  • Type: String
  • Description: The Description of the Enviroment

builder

  • Type: String
  • Description: The Builder that will be Used for this Enviroment

team_count

  • Type: Int
  • Description: The amount of teams to build this envrioment

revision

  • Type: Int
  • Description: The version number of this Enviroment. Basically the amount of times this enviroment was loaded.

admin_cidrs

  • Type: []string
  • Description: The CIDRs that have full port access to VDI Boxes

exposed_vdi_ports

  • Type: []string
  • Description: The ports that are accessable by everyone for the VDI Boxes

config

  • Type: map[string]string
  • Description: A map of configuration Key-Value Pairs
  • Optional

tags

  • Type: map[string]string
  • Description: A map of tag Key-Value Pairs
  • Optional

DNS

hcl_id

  • Type: String
  • Description: The HCL ID of the DNS Object in the LaForge Config

type

  • Type: String
  • Description: The type of DNS server, EX: "bind"

root_domain

  • Type: String
  • Description: The root domain of the DNS server

dns_servers

  • Type: []string
  • Description: A List of DNS Servers for this DNS Object

ntp_servers

  • Type: []string
  • Description: A List of NTP Servers for this DNS Object
  • Optional

config

  • Type: map[string]string
  • Description: A map of configuration Key-Value Pairs
  • Optional

DNSRecords (List of DNSRecords)

hcl_id

  • Type: String
  • Description: The HCL ID of the DNSRecords Object in the LaForge Config

name

  • Type: String
  • Description:

values

  • Type: []string
  • Description:
  • Optional

type

  • Type: string
  • Description:

zone

  • Type: string
  • Description:

vars

  • Type: map[string]string
  • Description: A map of vars Key-Value Pairs
  • Optional

disabled

  • Type: bool
  • Description:

tags

  • Type: map[string]string
  • Description: A Tag of configuration Key-Value Pairs
  • Optional

Host

hcl_id

  • Type: String
  • Description: The HCL ID of the Enviroment Object in the LaForge Config

hostname

  • Type: String
  • Description: The first part if the Hostname for this host

description

  • Type: String
  • Description: The Description of the Host
  • Optional

OS

  • Type: String
  • Description: The OS of the Host

last_octet

  • Type: Int
  • Description: The last octet of the host in the network it's apart of

instance_size

  • Type: String
  • Description: The size of the Host

allow_mac_changes

  • Type: Bool
  • Description: Needed for VM Stuff
  • Optional

exposed_tcp_ports

  • Type: []string
  • Description: The TCP Ports that the Host will expose
  • Optional

exposed_udp_ports

  • Type: []string
  • Description: The UDP Port that the Host will expose
  • Optional

override_password

  • Type: String
  • Description: The Defult Password for the Host if set
  • Optional

vars

  • Type: map[string]string
  • Description: A map of vars Key-Value Pairs
  • Optional

user_groups

  • Type: []string
  • Description: A list of user groups for the host
  • Optional

provision_steps

  • Type: []string
  • Description: A list of Provision Steps using their HCL IDs
  • Optional

tags

  • Type: map[string]string
  • Description: A Tag of configuration Key-Value Pairs
  • Optional

IncludedNetworks (List of IncludedNetworks)

name

  • Type: String
  • Description: Network HCL ID

hosts

  • Type: []String
  • Description: List of Host HCL IDs

Edges.IncludedNetworkToHost

  • Type: Host
  • Description: See Above

Edges.IncludedNetworkToNetwork

  • Type: Network
  • Description: See Below

Network

hcl_id

  • Type: String
  • Description: The HCL ID of the Network Object in the LaForge Config

name

  • Type: String
  • Description: Network Name

cidr

  • Type: String
  • Description: Network Name

vdi_visible

  • Type: bool
  • Description: If the network is visable for the VDI
  • Optional

vars

  • Type: map[string]string
  • Description: A map of vars Key-Value Pairs
  • Optional

tags

  • Type: map[string]string
  • Description: A Tag of configuration Key-Value Pairs
  • Optional

Script

hcl_id

  • Type: String
  • Description: The HCL ID of the Script Object in the LaForge Config

name

  • Type: String
  • Description: Script Name

language

  • Type: String
  • Description: either something like shell or powershell

description

  • Type: String
  • Description: Description of the script
  • Optional

source_type

  • Type: string
  • Description: Should be local probably

source

  • Type: string
  • Description: Path to the script in the repo according to where this config file is

cooldown

  • Type: Int
  • Description:
  • Optional

timeout

  • Type: Int
  • Description:
  • Optional

ignore_errors

  • Type: bool
  • Description:
  • Optional

args

  • Type: []string
  • Description: Args for script
  • Optional

disabled

  • Type: bool
  • Description:
  • Optional

vars

  • Type: map[string]string
  • Description: A map of vars Key-Value Pairs
  • Optional

abs_path

  • Type: string
  • Description: Absolute path for script on the build box
  • Optional

tags

  • Type: map[string]string
  • Description: A Tag of configuration Key-Value Pairs
  • Optional

Team

cooldown

  • Type: Int
  • Description: Team Number

vars

  • Type: map[string]string
  • Description: A map of vars Key-Value Pairs
  • gateway_public_ip is the key to get the public IP for the team, if it exists

Identities (List of Identity)

hcl_id

  • Type: String
  • Description: The HCL ID of the Identity Object in the LaForge Config

first_name

  • Type: String
  • Description:

last_name

  • Type: String
  • Description:

email

  • Type: String
  • Description:

password

  • Type: String
  • Description:

description

  • Type: String
  • Description:
  • Optional

avatar_file

  • Type: String
  • Description:
  • Optional

vars

  • Type: map[string]string
  • Description: A map of vars Key-Value Pairs
  • Optional

tags

  • Type: map[string]string
  • Description: A Tag of configuration Key-Value Pairs
  • Optional

ProvisionedNetwork

name

  • Type: String
  • Description: Provisioned Network Name

cidr

  • Type: String
  • Description: Provisioned Network Name

ProvisionedHost

subnet_ip

  • Type: String
  • Description: IP of the Deployed Host

addon_type

  • Type: Enum
  • Values: DNS

ProvisioningStep

type

  • Type: Enum
  • Values:
    • Script
    • Command
    • DNSRecord
    • FileDelete
    • FileDownload
    • FileExtract

step_number

  • Type: Int
  • Description: The order in which the ProvisioningStep is sent

AgentSlug

  • Type: String
  • Description: The Slug to get the Agent