added settings

This commit is contained in:
Brad Rydzewski 2015-04-08 14:20:06 -07:00
parent 914807c67f
commit 42f2ac392a

167
settings/settings.go Normal file
View file

@ -0,0 +1,167 @@
package settings
import (
"github.com/BurntSushi/toml"
)
// Service represents the configuration details required
// to connect to the revision control system (ie GitHub, Bitbucket)
type Service struct {
// Name defines the name of the plugin. Possible values
// may be github, gitlab, bitbucket, or gogs.
Name string `toml:"name"`
// Base defines the base URL for the service. For example:
// https://github.com
// https://bitbucket.org
// https://gitlab.drone.io
Base string `toml:"base"`
// Indicates registration is open. If true any user
// will be able to setup an account. If false, the
// system administrator will need to provision accounts.
Open bool `toml:"open"`
// Orgs defines a list of organizations the user
// must belong to in order to register. This will
// take precedence over the `Open` paramter.
Orgs []string `toml:"orgs"`
// PrivateMode should be set to true if the
// remote system requires authentication for
// cloning public (open source) repositories.
PrivateMode bool `toml:"private_mode"`
// SkipVerify instructs the client to skip SSL verification.
// This may be used with self-signed certificates, however,
// is not recommended for security reasons.
SkipVerify bool `toml:"skip_verify"`
// OAuth configuration data. If nil or empty, Drone may
// assume basic authentication via username and password.
OAuth *OAuth `toml:"oauth"`
}
// OAuth defines how a user should autheticate with the service.
// This supports OAuth2 and OAuth1 protocols.
type OAuth struct {
Client string `toml:"client"`
Secret string `toml:"secret"`
Authorize string `toml:"authorize"`
AccessToken string `toml:"access_token"`
RequestToken string `toml:"request_token"`
Scope []string `toml:"scope"`
}
// Server represents the web server configuration details
// used to server HTTP requests.
type Server struct {
Base string `toml:"base"`
Addr string `toml:"addr"`
Cert string `toml:"cert"`
Key string `toml:"key"`
Scheme string `toml:"scheme"`
Hostname string `toml:"hostname"`
}
// Session represents the session configuration details
// used to generate, validate and expire authentication
// sessions.
type Session struct {
Secret string `toml:"secret"`
Expires int64 `toml:"expires"`
}
// Docker represents the configuration details used
// to connect to the Docker daemon when scheduling
// and executing builds in containers.
type Docker struct {
Cert string `toml:"cert"`
Key string `toml:"key"`
Nodes []string `toml:"nodes"`
}
// Database represents the configuration details used
// to connect to the embedded Bolt database.
type Database struct {
Path string `toml:"path"`
}
// Settings defines global settings for the Drone system.
type Settings struct {
Database *Database `toml:"database"`
Docker *Docker `toml:"docker"`
Service *Service `toml:"service"`
Server *Server `toml:"server"`
Session *Session `toml:"session"`
Plugins map[string]interface{} `toml:"plugins"`
}
// Parse parses the Drone settings file at the specified path
// and unmarshals to a Settings structure.
func Parse(path string) (*Settings, error) {
s := &Settings{}
_, err := toml.DecodeFile(path, s)
return s, err
}
// ParseString parses the Drone settings string and unmarshals
// to a Settings structure.
func ParseString(data string) (*Settings, error) {
s := &Settings{}
_, err := toml.Decode(data, s)
return s, err
}
/* SAMPLE. REMOVE ME
[server]
addr=":80"
cert=""
key=""
[session]
secret=""
expires=""
[database]
path=""
[docker]
cert=""
key=""
nodes=[
"unix:///var/run/docker.sock",
"unix:///var/run/docker.sock"
]
[service]
name = "gitlab"
base = "https://github.com"
orgs = []
open = true
private_mode = false
skip_verify = true
[service.oauth]
client = ""
secret = ""
authorize_url=""
access_token_url=""
request_token_url=""
[plugins.npm]
[plugins.email]
[plugins.smtp]
host=""
port=""
from=""
user=""
pass=""
*/