update conf var names

This commit is contained in:
Matthieu Lamalle 2020-07-22 10:14:13 +02:00
parent 7927fe6483
commit 3f03090762
4 changed files with 26 additions and 21 deletions

View File

@ -1,11 +1,16 @@
## Server ## Server
web_adress=":3001" jwt_web_adress=":3001"
## Postgres ## Postgres
db_user="jwtserver" jwt_db_user="jwtserver"
db_pass="jwtserver" jwt_db_pass="jwtserver"
db_name="jwtserver" jwt_db_name="jwtserver"
db_host="localhost" jwt_db_host="localhost"
## JWT ## JWT
token_password="NotSoSecretJwtSecretPassword" jwt_subject="factory"
jwt_audience="risotto"
jwt_access_token_password="NotSoSecretJwtAccessSecretPassword"
jwt_refresh_token_password="NotSoSecretJwtRefreshSecretPassword"
jwt_access_expiration=30 ## in seconds
jwt_refresh_expiration=2 ## in minutes

View File

@ -23,7 +23,7 @@ func init() {
if e != nil { if e != nil {
fmt.Print(e) fmt.Print(e)
} }
confWebadress = os.Getenv("web_adress") confWebadress = os.Getenv("jwt_web_adress")
} }
func main() { func main() {

View File

@ -34,16 +34,16 @@ func init() {
fmt.Print(e) fmt.Print(e)
} }
var err error var err error
accessExpires, err = strconv.Atoi(os.Getenv("access_expiration")) accessExpires, err = strconv.Atoi(os.Getenv("jwt_access_expiration"))
if err != nil { if err != nil {
panic(err) panic(err)
} }
refreshExpiration, err = strconv.Atoi(os.Getenv("access_expiration")) refreshExpiration, err = strconv.Atoi(os.Getenv("jwt_access_expiration"))
if err != nil { if err != nil {
panic(err) panic(err)
} }
audience = os.Getenv("audience") audience = os.Getenv("jwt_audience")
subject = os.Getenv("subject") subject = os.Getenv("jwt_subject")
} }
// TokenDetails struct // TokenDetails struct
@ -151,7 +151,7 @@ func (account *Account) GenerateTokenPair() (*TokenDetails, error) {
}, },
} }
token := jwt.NewWithClaims(jwt.GetSigningMethod("HS256"), tk) token := jwt.NewWithClaims(jwt.GetSigningMethod("HS256"), tk)
tokenString, err := token.SignedString([]byte(os.Getenv("access_token_password"))) tokenString, err := token.SignedString([]byte(os.Getenv("jwt_access_token_password")))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -164,7 +164,7 @@ func (account *Account) GenerateTokenPair() (*TokenDetails, error) {
}, },
} }
refreshtoken := jwt.NewWithClaims(jwt.GetSigningMethod("HS256"), reftk) refreshtoken := jwt.NewWithClaims(jwt.GetSigningMethod("HS256"), reftk)
refreshtokenString, err := refreshtoken.SignedString([]byte(os.Getenv("refresh_token_password"))) refreshtokenString, err := refreshtoken.SignedString([]byte(os.Getenv("jwt_refresh_token_password")))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -19,15 +19,15 @@ func init() {
fmt.Print(e) fmt.Print(e)
} }
username := os.Getenv("db_user") username := os.Getenv("jwt_db_user")
password := os.Getenv("db_pass") password := os.Getenv("jwt_db_pass")
dbName := os.Getenv("db_name") dbName := os.Getenv("jwt_db_name")
dbHost := os.Getenv("db_host") dbHost := os.Getenv("jwt_db_host")
dbUri := fmt.Sprintf("host=%s user=%s dbname=%s sslmode=disable password=%s", dbHost, username, dbName, password) //Build connection string dbURI := fmt.Sprintf("host=%s user=%s dbname=%s sslmode=disable password=%s", dbHost, username, dbName, password) //Build connection string
fmt.Println(dbUri) fmt.Println(dbURI)
conn, err := gorm.Open("postgres", dbUri) conn, err := gorm.Open("postgres", dbURI)
if err != nil { if err != nil {
fmt.Print(err) fmt.Print(err)
} }
@ -36,7 +36,7 @@ func init() {
db.Debug().AutoMigrate(&Account{}) //Database migration db.Debug().AutoMigrate(&Account{}) //Database migration
} }
//returns a handle to the DB object //GetDB returns a handle to the DB object
func GetDB() *gorm.DB { func GetDB() *gorm.DB {
return db return db
} }