That editorconfig file really butchered the formatting for go

This commit is contained in:
Dane Everitt 2019-03-24 18:00:21 -07:00
parent 4bdf373ab8
commit 29de97c857
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
8 changed files with 312 additions and 271 deletions

240
config.go
View File

@ -1,114 +1,114 @@
package wings package wings
import ( import (
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
"io/ioutil" "io/ioutil"
"os" "os"
) )
type Configuration struct { type Configuration struct {
// Determines if wings should be running in debug mode. This value is ignored // Determines if wings should be running in debug mode. This value is ignored
// if the debug flag is passed through the command line arguments. // if the debug flag is passed through the command line arguments.
Debug bool Debug bool
// Directory where the server data is stored at. // Directory where the server data is stored at.
Data string Data string
Api *ApiConfiguration Api *ApiConfiguration
Docker *DockerConfiguration Docker *DockerConfiguration
// Determines if permissions for a server should be set automatically on // Determines if permissions for a server should be set automatically on
// daemon boot. This can take a long time on systems with many servers, or on // daemon boot. This can take a long time on systems with many servers, or on
// systems with servers containing thousands of files. // systems with servers containing thousands of files.
SetPermissionsOnBoot bool `yaml:"set_permissions_on_boot"` SetPermissionsOnBoot bool `yaml:"set_permissions_on_boot"`
// The amount of time in seconds that should elapse between disk usage checks // The amount of time in seconds that should elapse between disk usage checks
// run by the daemon. Setting a higher number can result in better IO performance // run by the daemon. Setting a higher number can result in better IO performance
// at an increased risk of a malicious user creating a process that goes over // at an increased risk of a malicious user creating a process that goes over
// the assigned disk limits. // the assigned disk limits.
DiskCheckTimeout int `yaml:"disk_check_timeout"` DiskCheckTimeout int `yaml:"disk_check_timeout"`
// Defines internal throttling configurations for server processes to prevent // Defines internal throttling configurations for server processes to prevent
// someone from running an endless loop that spams data to logs. // someone from running an endless loop that spams data to logs.
Throttles struct { Throttles struct {
// The number of data overage warnings (inclusive) that can accumulate // The number of data overage warnings (inclusive) that can accumulate
// before a process is terminated. // before a process is terminated.
KillAtCount int `yaml:"kill_at_count"` KillAtCount int `yaml:"kill_at_count"`
// The number of seconds that must elapse before the internal counter // The number of seconds that must elapse before the internal counter
// begins decrementing warnings assigned to a process that is outputting // begins decrementing warnings assigned to a process that is outputting
// too much data. // too much data.
DecaySeconds int `yaml:"decay"` DecaySeconds int `yaml:"decay"`
// The total number of bytes allowed to be output by a server process // The total number of bytes allowed to be output by a server process
// per interval. // per interval.
BytesPerInterval int `yaml:"bytes"` BytesPerInterval int `yaml:"bytes"`
// The amount of time that should lapse between data output throttle // The amount of time that should lapse between data output throttle
// checks. This should be defined in milliseconds. // checks. This should be defined in milliseconds.
CheckInterval int `yaml:"check_interval"` CheckInterval int `yaml:"check_interval"`
} }
// The location where the panel is running that this daemon should connect to // The location where the panel is running that this daemon should connect to
// to collect data and send events. // to collect data and send events.
PanelLocation string `yaml:"remote"` PanelLocation string `yaml:"remote"`
// The token used when performing operations. Requests to this instance must // The token used when performing operations. Requests to this instance must
// validate aganist it. // validate aganist it.
AuthenticationToken string `yaml:"token"` AuthenticationToken string `yaml:"token"`
} }
// Defines the configuration for the internal API that is exposed by the // Defines the configuration for the internal API that is exposed by the
// daemon webserver. // daemon webserver.
type ApiConfiguration struct { type ApiConfiguration struct {
// The interface that the internal webserver should bind to. // The interface that the internal webserver should bind to.
Host string Host string
// The port that the internal webserver should bind to. // The port that the internal webserver should bind to.
Port int Port int
// SSL configuration for the daemon. // SSL configuration for the daemon.
Ssl struct { Ssl struct {
Enabled bool Enabled bool
CertificateFile string `yaml:"cert"` CertificateFile string `yaml:"cert"`
KeyFile string `yaml:"key"` KeyFile string `yaml:"key"`
} }
// The maximum size for files uploaded through the Panel in bytes. // The maximum size for files uploaded through the Panel in bytes.
UploadLimit int `yaml:"upload_limit"` UploadLimit int `yaml:"upload_limit"`
} }
// Defines the docker configuration used by the daemon when interacting with // Defines the docker configuration used by the daemon when interacting with
// containers and networks on the system. // containers and networks on the system.
type DockerConfiguration struct { type DockerConfiguration struct {
Container struct { Container struct {
User string User string
} }
// Network configuration that should be used when creating a new network // Network configuration that should be used when creating a new network
// for containers run through the daemon. // for containers run through the daemon.
Network struct { Network struct {
// The interface that should be used to create the network. Must not conflict // The interface that should be used to create the network. Must not conflict
// with any other interfaces in use by Docker or on the system. // with any other interfaces in use by Docker or on the system.
Interface string Interface string
// The name of the network to use. If this network already exists it will not // The name of the network to use. If this network already exists it will not
// be created. If it is not found, a new network will be created using the interface // be created. If it is not found, a new network will be created using the interface
// defined. // defined.
Name string Name string
} }
// If true, container images will be updated when a server starts if there // If true, container images will be updated when a server starts if there
// is an update available. If false the daemon will not attempt updates and will // is an update available. If false the daemon will not attempt updates and will
// defer to the host system to manage image updates. // defer to the host system to manage image updates.
UpdateImages bool `yaml:"update_images"` UpdateImages bool `yaml:"update_images"`
// The location of the Docker socket. // The location of the Docker socket.
Socket string Socket string
// Defines the location of the timezone file on the host system that should // Defines the location of the timezone file on the host system that should
// be mounted into the created containers so that they all use the same time. // be mounted into the created containers so that they all use the same time.
TimezonePath string `yaml:"timezone_path"` TimezonePath string `yaml:"timezone_path"`
} }
// Configures the default values for many of the configuration options present // Configures the default values for many of the configuration options present
@ -117,60 +117,60 @@ type DockerConfiguration struct {
// of the places in the code using them will need to be doing checks, which is // of the places in the code using them will need to be doing checks, which is
// a tedious thing to have to do. // a tedious thing to have to do.
func (c *Configuration) SetDefaults() { func (c *Configuration) SetDefaults() {
// Set the default data directory. // Set the default data directory.
c.Data = "/srv/daemon-data" c.Data = "/srv/daemon-data"
// By default the internal webserver should bind to all interfaces and // By default the internal webserver should bind to all interfaces and
// be served on port 8080. // be served on port 8080.
c.Api = &ApiConfiguration{ c.Api = &ApiConfiguration{
Host: "0.0.0.0", Host: "0.0.0.0",
Port: 8080, Port: 8080,
} }
// Setting this to true by default helps us avoid a lot of support requests // Setting this to true by default helps us avoid a lot of support requests
// from people that keep trying to move files around as a root user leading // from people that keep trying to move files around as a root user leading
// to server permission issues. // to server permission issues.
// //
// In production and heavy use environments where boot speed is essential, // In production and heavy use environments where boot speed is essential,
// this should be set to false as servers will self-correct permissions on // this should be set to false as servers will self-correct permissions on
// boot anyways. // boot anyways.
c.SetPermissionsOnBoot = true c.SetPermissionsOnBoot = true
// Configure the default throttler implementation. This should work fine // Configure the default throttler implementation. This should work fine
// for 99% of people running servers on the platform. The occasional host // for 99% of people running servers on the platform. The occasional host
// might need to tweak them to be less restrictive depending on their hardware // might need to tweak them to be less restrictive depending on their hardware
// and target audience. // and target audience.
c.Throttles.KillAtCount = 5 c.Throttles.KillAtCount = 5
c.Throttles.DecaySeconds = 10 c.Throttles.DecaySeconds = 10
c.Throttles.BytesPerInterval = 4096 c.Throttles.BytesPerInterval = 4096
c.Throttles.CheckInterval = 100 c.Throttles.CheckInterval = 100
// Configure the defaults for Docker connection and networks. // Configure the defaults for Docker connection and networks.
c.Docker = &DockerConfiguration{} c.Docker = &DockerConfiguration{}
c.Docker.UpdateImages = true c.Docker.UpdateImages = true
c.Docker.Socket = "/var/run/docker.sock" c.Docker.Socket = "/var/run/docker.sock"
c.Docker.Network.Name = "pterodactyl_nw" c.Docker.Network.Name = "pterodactyl_nw"
c.Docker.Network.Interface = "172.18.0.1" c.Docker.Network.Interface = "172.18.0.1"
} }
// Reads the configuration from the provided file and returns the configuration // Reads the configuration from the provided file and returns the configuration
// object that can then be used. // object that can then be used.
func ReadConfiguration(path string) (*Configuration, error) { func ReadConfiguration(path string) (*Configuration, error) {
b, err := ioutil.ReadFile(path) b, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
c := &Configuration{} c := &Configuration{}
c.SetDefaults() c.SetDefaults()
// Replace environment variables within the configuration file with their // Replace environment variables within the configuration file with their
// values from the host system. // values from the host system.
b = []byte(os.ExpandEnv(string(b))) b = []byte(os.ExpandEnv(string(b)))
if err := yaml.Unmarshal(b, c); err != nil { if err := yaml.Unmarshal(b, c); err != nil {
return nil, err return nil, err
} }
return c, nil return c, nil
} }

View File

@ -3,27 +3,27 @@ package wings
import "os" import "os"
const ( const (
Version = "0.0.1" Version = "0.0.1"
// DefaultFilePerms are the file perms used for created files. // DefaultFilePerms are the file perms used for created files.
DefaultFilePerms os.FileMode = 0644 DefaultFilePerms os.FileMode = 0644
// DefaultFolderPerms are the file perms used for created folders. // DefaultFolderPerms are the file perms used for created folders.
DefaultFolderPerms os.FileMode = 0755 DefaultFolderPerms os.FileMode = 0755
// ServersPath is the path of the servers within the configured DataPath. // ServersPath is the path of the servers within the configured DataPath.
ServersPath = "servers" ServersPath = "servers"
// ServerConfigFile is the filename of the server config file. // ServerConfigFile is the filename of the server config file.
ServerConfigFile = "server.json" ServerConfigFile = "server.json"
// ServerDataPath is the path of the data of a single server. // ServerDataPath is the path of the data of a single server.
ServerDataPath = "data" ServerDataPath = "data"
// DockerContainerPrefix is the prefix used for naming Docker containers. // DockerContainerPrefix is the prefix used for naming Docker containers.
// It's also used to prefix the hostnames of the docker containers. // It's also used to prefix the hostnames of the docker containers.
DockerContainerPrefix = "ptdl-" DockerContainerPrefix = "ptdl-"
// WSMaxMessages is the maximum number of messages that are sent in one transfer. // WSMaxMessages is the maximum number of messages that are sent in one transfer.
WSMaxMessages = 10 WSMaxMessages = 10
) )

View File

@ -1,16 +1,16 @@
package environment package environment
import ( import (
"github.com/pterodactyl/wings" "github.com/pterodactyl/wings"
"os" "os"
) )
type Docker struct { type Docker struct {
*Controller *Controller
// Defines the configuration for the Docker instance that will allow us to connect // Defines the configuration for the Docker instance that will allow us to connect
// and create and modify containers. // and create and modify containers.
Configuration wings.DockerConfiguration Configuration wings.DockerConfiguration
} }
// Ensure that the Docker environment is always implementing all of the methods // Ensure that the Docker environment is always implementing all of the methods
@ -18,17 +18,17 @@ type Docker struct {
var _ Environment = (*Docker)(nil) var _ Environment = (*Docker)(nil)
func (d *Docker) Exists() bool { func (d *Docker) Exists() bool {
return true return true
} }
func (d *Docker) Start() error { func (d *Docker) Start() error {
return nil return nil
} }
func (d *Docker) Stop() error { func (d *Docker) Stop() error {
return nil return nil
} }
func (d *Docker) Terminate(signal os.Signal) error { func (d *Docker) Terminate(signal os.Signal) error {
return nil return nil
} }

View File

@ -1,35 +1,35 @@
package environment package environment
import ( import (
"github.com/pterodactyl/wings/server" "github.com/pterodactyl/wings/server"
"os" "os"
) )
// Defines the basic interface that all environments need to implement so that // Defines the basic interface that all environments need to implement so that
// a server can be properly controlled. // a server can be properly controlled.
type Environment interface { type Environment interface {
// Starts a server instance. If the server instance is not in a state where it // Starts a server instance. If the server instance is not in a state where it
// can be started an error should be returned. // can be started an error should be returned.
Start() error Start() error
// Stops a server instance. If the server is already stopped an error should // Stops a server instance. If the server is already stopped an error should
// not be returned. // not be returned.
Stop() error Stop() error
// Determines if the server instance exists. For example, in a docker environment // Determines if the server instance exists. For example, in a docker environment
// this should confirm that the container is created and in a bootable state. In // this should confirm that the container is created and in a bootable state. In
// a basic CLI environment this can probably just return true right away. // a basic CLI environment this can probably just return true right away.
Exists() bool Exists() bool
// Terminates a running server instance using the provided signal. If the server // Terminates a running server instance using the provided signal. If the server
// is not running no error should be returned. // is not running no error should be returned.
Terminate(signal os.Signal) error Terminate(signal os.Signal) error
} }
// Defines an environment controller for a server instance. This can either be // Defines an environment controller for a server instance. This can either be
// a docker environment where the server is running in a container, or a host // a docker environment where the server is running in a container, or a host
// CLI environment where it is not running in a container at all (theoretically). // CLI environment where it is not running in a container at all (theoretically).
type Controller struct { type Controller struct {
// The server instance attached to this environment. // The server instance attached to this environment.
Server *server.Server Server *server.Server
} }

7
go.mod
View File

@ -20,7 +20,7 @@ require (
github.com/gorilla/websocket v1.2.0 github.com/gorilla/websocket v1.2.0
github.com/hashicorp/hcl v0.0.0-20180320202055-f40e974e75af // indirect github.com/hashicorp/hcl v0.0.0-20180320202055-f40e974e75af // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/lestrrat-go/file-rotatelogs v2.1.0+incompatible github.com/lestrrat-go/file-rotatelogs v2.1.0+incompatible // indirect
github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 // indirect github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 // indirect
github.com/magiconair/properties v1.7.6 // indirect github.com/magiconair/properties v1.7.6 // indirect
github.com/mattn/go-isatty v0.0.3 // indirect github.com/mattn/go-isatty v0.0.3 // indirect
@ -30,12 +30,13 @@ require (
github.com/pelletier/go-toml v1.1.0 // indirect github.com/pelletier/go-toml v1.1.0 // indirect
github.com/pkg/errors v0.8.0 // indirect github.com/pkg/errors v0.8.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rifflock/lfshook v0.0.0-20180227222202-bf539943797a github.com/remeh/sizedwaitgroup v0.0.0-20180822144253-5e7302b12cce // indirect
github.com/rifflock/lfshook v0.0.0-20180227222202-bf539943797a // indirect
github.com/shirou/gopsutil v0.0.0-20180227225847-5776ff9c7c5d github.com/shirou/gopsutil v0.0.0-20180227225847-5776ff9c7c5d
github.com/sirupsen/logrus v1.0.5 github.com/sirupsen/logrus v1.0.5
github.com/spf13/afero v1.0.2 // indirect github.com/spf13/afero v1.0.2 // indirect
github.com/spf13/cast v1.2.0 // indirect github.com/spf13/cast v1.2.0 // indirect
github.com/spf13/cobra v0.0.2 github.com/spf13/cobra v0.0.2 // indirect
github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec // indirect github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec // indirect
github.com/spf13/pflag v1.0.0 // indirect github.com/spf13/pflag v1.0.0 // indirect
github.com/spf13/viper v1.0.2 github.com/spf13/viper v1.0.2

2
go.sum
View File

@ -52,6 +52,8 @@ github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remeh/sizedwaitgroup v0.0.0-20180822144253-5e7302b12cce h1:aP+C+YbHZfOQlutA4p4soHi7rVUqHQdWEVMSkHfDTqY=
github.com/remeh/sizedwaitgroup v0.0.0-20180822144253-5e7302b12cce/go.mod h1:3j2R4OIe/SeS6YDhICBy22RWjJC5eNCJ1V+9+NVNYlo=
github.com/rifflock/lfshook v0.0.0-20180227222202-bf539943797a h1:zOAPcZGA4TZZv8zEI+uqbYXgyjmXtMcRVSnR0T0J2t0= github.com/rifflock/lfshook v0.0.0-20180227222202-bf539943797a h1:zOAPcZGA4TZZv8zEI+uqbYXgyjmXtMcRVSnR0T0J2t0=
github.com/rifflock/lfshook v0.0.0-20180227222202-bf539943797a/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM= github.com/rifflock/lfshook v0.0.0-20180227222202-bf539943797a/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM=
github.com/shirou/gopsutil v0.0.0-20180227225847-5776ff9c7c5d h1:TW8oufRzBs0qROjv16ll0N780gaBcgSu1TxKjwJMebM= github.com/shirou/gopsutil v0.0.0-20180227225847-5776ff9c7c5d h1:TW8oufRzBs0qROjv16ll0N780gaBcgSu1TxKjwJMebM=

View File

@ -1,99 +1,134 @@
package server package server
import ( import (
"github.com/pterodactyl/wings" "github.com/pterodactyl/wings"
"github.com/pterodactyl/wings/environment" "github.com/pterodactyl/wings/environment"
"gopkg.in/yaml.v2" "github.com/remeh/sizedwaitgroup"
"go.uber.org/zap"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"strings"
) )
// High level definition for a server instance being controlled by Wings. // High level definition for a server instance being controlled by Wings.
type Server struct { type Server struct {
// The unique identifier for the server that should be used when referencing // The unique identifier for the server that should be used when referencing
// it aganist the Panel API (and internally). This will be used when naming // it aganist the Panel API (and internally). This will be used when naming
// docker containers as well as in log output. // docker containers as well as in log output.
Uuid string Uuid string
// Wether or not the server is in a suspended state. Suspended servers cannot // Wether or not the server is in a suspended state. Suspended servers cannot
// be started or modified except in certain scenarios by an admin user. // be started or modified except in certain scenarios by an admin user.
Suspended bool Suspended bool
// The power state of the server. // The power state of the server.
State int State int
// The command that should be used when booting up the server instance. // The command that should be used when booting up the server instance.
Invocation string Invocation string
// An array of environment variables that should be passed along to the running // An array of environment variables that should be passed along to the running
// server process. // server process.
EnvVars map[string]string `yaml:"env"` EnvVars map[string]string `yaml:"env"`
Build *BuildSettings Build *BuildSettings
Allocations *Allocations Allocations *Allocations
environment *environment.Environment environment *environment.Environment
} }
// The build settings for a given server that impact docker container creation and // The build settings for a given server that impact docker container creation and
// resource limits for a server instance. // resource limits for a server instance.
type BuildSettings struct { type BuildSettings struct {
// The total amount of memory in megabytes that this server is allowed to // The total amount of memory in megabytes that this server is allowed to
// use on the host system. // use on the host system.
MemoryLimit int `yaml:"memory"` MemoryLimit int `yaml:"memory"`
// The amount of additional swap space to be provided to a container instance. // The amount of additional swap space to be provided to a container instance.
Swap int Swap int
// The relative weight for IO operations in a container. This is relative to other // The relative weight for IO operations in a container. This is relative to other
// containers on the system and should be a value between 10 and 1000. // containers on the system and should be a value between 10 and 1000.
IoWeight int `yaml:"io"` IoWeight int `yaml:"io"`
// The percentage of CPU that this instance is allowed to consume relative to // The percentage of CPU that this instance is allowed to consume relative to
// the host. A value of 200% represents complete utilization of two cores. This // the host. A value of 200% represents complete utilization of two cores. This
// should be a value between 1 and THREAD_COUNT * 100. // should be a value between 1 and THREAD_COUNT * 100.
CpuLimit int `yaml:"cpu"` CpuLimit int `yaml:"cpu"`
// The amount of disk space in megabytes that a server is allowed to use. // The amount of disk space in megabytes that a server is allowed to use.
DiskSpace int `yaml:"disk"` DiskSpace int `yaml:"disk"`
} }
// Defines the allocations available for a given server. When using the Docker environment // Defines the allocations available for a given server. When using the Docker environment
// driver these correspond to mappings for the container that allow external connections. // driver these correspond to mappings for the container that allow external connections.
type Allocations struct { type Allocations struct {
// Defines the default allocation that should be used for this server. This is // Defines the default allocation that should be used for this server. This is
// what will be used for {SERVER_IP} and {SERVER_PORT} when modifying configuration // what will be used for {SERVER_IP} and {SERVER_PORT} when modifying configuration
// files or the startup arguments for a server. // files or the startup arguments for a server.
DefaultMapping struct { DefaultMapping struct {
Ip string Ip string
Port int Port int
} `yaml:"default"` } `yaml:"default"`
// Mappings contains all of the ports that should be assigned to a given server // Mappings contains all of the ports that should be assigned to a given server
// attached to the IP they correspond to. // attached to the IP they correspond to.
Mappings map[string][]int Mappings map[string][]int
}
// Iterates over a given directory and loads all of the servers listed before returning
// them to the calling function.
func LoadDirectory(dir string) (*[]Server, error) {
wg := sizedwaitgroup.New(5)
f, err := ioutil.ReadDir(dir)
if err != nil {
return nil, err
}
zap.S().Debug("starting loop")
for _, file := range f {
if !strings.HasSuffix(file.Name(), ".yml") {
continue
}
wg.Add()
go func(file os.FileInfo) {
zap.S().Debugw("processing in parallel", zap.String("name", file.Name()))
wg.Done()
}(file)
}
wg.Wait()
zap.S().Debug("done processing files")
return nil, nil
} }
// Initalizes a server using a data byte array. This will be marshaled into the // Initalizes a server using a data byte array. This will be marshaled into the
// given struct using a YAML marshaler. This will also configure the given environment // given struct using a YAML marshaler. This will also configure the given environment
// for a server. // for a server.
func FromConfiguration(data []byte, cfg wings.DockerConfiguration) (*Server, error) { func FromConfiguration(data []byte, cfg wings.DockerConfiguration) (*Server, error) {
s := &Server{} s := &Server{}
if err := yaml.Unmarshal(data, s); err != nil { if err := yaml.Unmarshal(data, s); err != nil {
return nil, err return nil, err
} }
// Right now we only support a Docker based environment, so I'm going to hard code // Right now we only support a Docker based environment, so I'm going to hard code
// this logic in. When we're ready to support other environment we'll need to make // this logic in. When we're ready to support other environment we'll need to make
// some modifications here obviously. // some modifications here obviously.
var env environment.Environment var env environment.Environment
env = &environment.Docker{ env = &environment.Docker{
Controller: &environment.Controller{ Controller: &environment.Controller{
Server: s, Server: s,
}, },
Configuration: cfg, Configuration: cfg,
} }
s.environment = &env s.environment = &env
return s, nil return s, nil
} }

View File

@ -1,74 +1,77 @@
package wings package wings
import ( import (
"flag" "flag"
"fmt" "fmt"
"go.uber.org/zap" "github.com/pterodactyl/wings/server"
"go.uber.org/zap"
) )
// Entrypoint for the Wings application. Configures the logger and checks any // Entrypoint for the Wings application. Configures the logger and checks any
// flags that were passed through in the boot arguments. // flags that were passed through in the boot arguments.
func main() { func main() {
var configPath = *flag.String("config", "config.yml", "set the location for the configuration file") var configPath = *flag.String("config", "config.yml", "set the location for the configuration file")
var debug = *flag.Bool("debug", false, "pass in order to run wings in debug mode") var debug = *flag.Bool("debug", false, "pass in order to run wings in debug mode")
flag.Parse() flag.Parse()
zap.S().Infof("using configuration file: %s", configPath) zap.S().Infof("using configuration file: %s", configPath)
c, err := ReadConfiguration(configPath) c, err := ReadConfiguration(configPath)
if err != nil { if err != nil {
panic(err) panic(err)
return return
} }
if debug { if debug {
c.Debug = true c.Debug = true
} }
printLogo() printLogo()
if err := configureLogging(c.Debug); err != nil { if err := configureLogging(c.Debug); err != nil {
panic(err) panic(err)
} }
if c.Debug { if c.Debug {
zap.S().Debugw("running in debug mode") zap.S().Debugw("running in debug mode")
} }
zap.S().Infow("configuration initalized", zap.Any("config", c)) zap.S().Infow("configuration initalized", zap.Any("config", c))
server.LoadDirectory("config/servers")
} }
// Configures the global logger for Zap so that we can call it from any location // Configures the global logger for Zap so that we can call it from any location
// in the code without having to pass around a logger instance. // in the code without having to pass around a logger instance.
func configureLogging(debug bool) error { func configureLogging(debug bool) error {
cfg := zap.NewProductionConfig() cfg := zap.NewProductionConfig()
if debug { if debug {
cfg = zap.NewDevelopmentConfig() cfg = zap.NewDevelopmentConfig()
} }
cfg.Encoding = "console" cfg.Encoding = "console"
cfg.OutputPaths = []string{ cfg.OutputPaths = []string{
"stdout", "stdout",
} }
logger, err := cfg.Build() logger, err := cfg.Build()
if err != nil { if err != nil {
return err return err
} }
zap.ReplaceGlobals(logger) zap.ReplaceGlobals(logger)
return nil return nil
} }
// Prints the wings logo, nothing special here! // Prints the wings logo, nothing special here!
func printLogo() { func printLogo() {
fmt.Println() fmt.Println()
fmt.Println(` ____`) fmt.Println(` ____`)
fmt.Println(`__ Pterodactyl _____/___/_______ _______ ______`) fmt.Println(`__ Pterodactyl _____/___/_______ _______ ______`)
fmt.Println(`\_____\ \/\/ / / / __ / ___/`) fmt.Println(`\_____\ \/\/ / / / __ / ___/`)
fmt.Println(` \___\ / / / / /_/ /___ /`) fmt.Println(` \___\ / / / / /_/ /___ /`)
fmt.Println(` \___/\___/___/___/___/___ /______/`) fmt.Println(` \___/\___/___/___/___/___ /______/`)
fmt.Println(` /_______/ v` + Version) fmt.Println(` /_______/ v` + Version)
fmt.Println() fmt.Println()
} }