Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Milestone 0.5.0 #139

Merged
merged 9 commits into from
Jun 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Et voilà, you have a copy of notorious running,.
This will build the docker image which you can then run it either on local bare-metal, or if you're interested in the Docker Cloud route (which I highly recommend) head over to their [Documentation](https://docs.docker.com/docker-cloud/getting-started/) They'll explain deployment 1 000% better than I can.

## Please note:
I have not yet included instructions for running everything on bare-metal and I'm using docker because it just works (sorry, I try to keep the buzzwordiness down [despite deploying notorious with mariadb, redis, docker, go...]), but those are soon to come. I just honestly thing the docker way is 10x (just like me, heh) easier to deploy with at this particular moment.
I have not yet included instructions for running everything on bare-metal and I'm using docker because it just works (sorry, I try to keep the buzzwordiness down [despite deploying notorious with redis, docker, go...]), but those are soon to come. I just honestly thing the docker way is 10x (just like me, heh) easier to deploy with at this particular moment.

# Test it out?

Expand Down
4 changes: 0 additions & 4 deletions build/install_dependencies.sh

This file was deleted.

2 changes: 1 addition & 1 deletion build/install_deps.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

go get github.com/NotoriousTracker/viper
go get github.com/spf13/viper
go get github.com/jinzhu/gorm
go get gopkg.in/redis.v3
go get github.com/go-sql-driver/mysql
Expand Down
8 changes: 7 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
MySQLHost: localhost
MySQLPort: 3306
MySQLPort: "3306"
MySQLUser: testuser
MySQLPass: testuser
MySQLDB: testdb
RedisServer: localhost
RedisPort: 6379
# Whitelist indicates that torrent whitelisting is activated. When torrent
# whitelisting is activated, only pre-approved torrents can be served by
# Notorious
Whitelist: false
# UseEnvVariables allows environmental variables to be used instead of
# expliclitly defined config variables.
UseEnvVariables: true
41 changes: 24 additions & 17 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,51 @@ import (
// ConfigStruct holds the values that our config file holds
type ConfigStruct struct {
MySQLHost string
MySQLPort int
MySQLPort string
MySQLUser string
MySQLPass string
MySQLDB string
Whitelist bool
}

// LoadConfig loads the config into the Config Struct and returns the
// ConfigStruct object
// ConfigStruct object. Will load from environmental variables (all caps) if we
// set a flag to true.
func LoadConfig() ConfigStruct {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("../")
viper.AddConfigPath("/etc/")

err := viper.ReadInConfig()
if err != nil {
panic("Failed to open config file")
}
err := viper.ReadInConfig()
if err != nil {
panic("Failed to open config file")
}

if viper.GetBool("UseEnvVariables") == true {
viper.AutomaticEnv()
viper.BindEnv("mysqluser")
}


if viper.Get("MySQLPass").(string) != "" {
return ConfigStruct{
viper.Get("MySQLHost").(string),
viper.Get("MySQLPort").(int),
viper.Get("MySQLUser").(string),
viper.Get("MySQLPass").(string),
viper.Get("MySQLDB").(string),
viper.Get("Whitelist").(bool),
viper.Get("mysqlhost").(string),
viper.Get("mysqlport").(string),
viper.Get("mysqluser").(string),
viper.Get("mysqlpass").(string),
viper.Get("mysqldb").(string),
viper.Get("whitelist").(bool),
}
} else {
return ConfigStruct{
viper.Get("MySQLHost").(string),
viper.Get("MySQLPort").(int),
viper.Get("MySQLUser").(string),
viper.Get("mysqlhost").(string),
viper.Get("mysqlport").(string),
viper.Get("mysqluser").(string),
"",
viper.Get("MySQLDB").(string),
viper.GetBool("Whitelist"),
viper.Get("mysqldb").(string),
viper.Get("whitelist").(bool),
}
}

Expand Down
2 changes: 1 addition & 1 deletion database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// formatConnectStrings concatenates the data from the config file into a
// usable MySQL connection string.
func formatConnectString(c config.ConfigStruct) string {
return fmt.Sprintf("%s:%s@tcp(%s:%v)/%s?parseTime=true",
return fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?parseTime=true",
c.MySQLUser,
c.MySQLPass,
c.MySQLHost,
Expand Down