use env vars instead of files for vars

This commit is contained in:
Artem Titoulenko 2021-12-27 16:15:47 -05:00
parent 9a28132dae
commit 4f345b30da
2 changed files with 8 additions and 26 deletions

View file

@ -16,7 +16,7 @@ RUN adduser \
"${USER}" "${USER}"
WORKDIR /app WORKDIR /app
COPY go.mod go.sum /app COPY go.mod go.sum /app/
RUN go mod download RUN go mod download
COPY . /app COPY . /app
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o /app/aim RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o /app/aim

32
main.go
View file

@ -11,7 +11,6 @@ import (
"database/sql" "database/sql"
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"net" "net"
"os" "os"
@ -37,9 +36,7 @@ var (
OSCAR_BOS_ADDRESS = OSCAR_BOS_HOST + ":" + OSCAR_BOS_PORT OSCAR_BOS_ADDRESS = OSCAR_BOS_HOST + ":" + OSCAR_BOS_PORT
DB_URL = "" DB_URL = ""
DB_USER = "" DB_USER = ""
DB_USER_FILE = ""
DB_PASSWORD = "" DB_PASSWORD = ""
DB_PASSWORD_FILE = ""
) )
func init() { func init() {
@ -68,15 +65,15 @@ func init() {
flag.StringVar(&oscarBOSPort, "bosport", OSCAR_BOS_PORT, "BOS port") flag.StringVar(&oscarBOSPort, "bosport", OSCAR_BOS_PORT, "BOS port")
if dbUrl, ok := os.LookupEnv("DB_URL"); ok { if dbUrl, ok := os.LookupEnv("DB_URL"); ok {
DB_URL = dbUrl DB_URL = strings.TrimSpace(dbUrl)
} }
if dbUserFile, ok := os.LookupEnv("DB_USER_FILE"); ok { if dbUser, ok := os.LookupEnv("DB_USER"); ok {
DB_USER_FILE = dbUserFile DB_USER = strings.TrimSpace(dbUser)
} }
if dbPasswordFile, ok := os.LookupEnv("DB_PASSWORD_FILE"); ok { if dbPassword, ok := os.LookupEnv("DB_PASSWORD"); ok {
DB_PASSWORD_FILE = dbPasswordFile DB_PASSWORD = strings.TrimSpace(dbPassword)
} }
flag.Parse() flag.Parse()
@ -89,26 +86,14 @@ func init() {
OSCAR_BOS_PORT = oscarBOSPort OSCAR_BOS_PORT = oscarBOSPort
OSCAR_BOS_ADDRESS = OSCAR_BOS_HOST + ":" + OSCAR_BOS_PORT OSCAR_BOS_ADDRESS = OSCAR_BOS_HOST + ":" + OSCAR_BOS_PORT
log.Println(os.Environ())
if DB_URL == "" { if DB_URL == "" {
log.Fatalln("DB Url not specified") log.Fatalln("DB Url not specified")
} }
dbUser, err := ioutil.ReadFile(DB_USER_FILE)
if err != nil {
panic(err)
}
DB_USER = strings.TrimSpace(string(dbUser))
if DB_USER == "" { if DB_USER == "" {
log.Fatalln("DB User not specified") log.Fatalln("DB User not specified")
} }
dbPassword, err := ioutil.ReadFile(DB_PASSWORD_FILE)
if err != nil {
panic(err)
}
DB_PASSWORD = strings.TrimSpace(string(dbPassword))
if DB_PASSWORD == "" { if DB_PASSWORD == "" {
log.Fatalln("DB password not specified") log.Fatalln("DB password not specified")
} }
@ -177,16 +162,13 @@ func main() {
user := models.UserFromContext(ctx) user := models.UserFromContext(ctx)
if user != nil { if user != nil {
// tellBuddies := user.Status != models.UserStatusAway
user.Status = models.UserStatusAway user.Status = models.UserStatusAway
user.Cipher = ""
if err := user.Update(ctx, db); err != nil { if err := user.Update(ctx, db); err != nil {
log.Print(errors.Wrap(err, "could not set user as inactive")) log.Print(errors.Wrap(err, "could not set user as inactive"))
} }
if true { onlineCh <- user
onlineCh <- user
}
sessionManager.RemoveSession(user.Username) sessionManager.RemoveSession(user.Username)
} }
} }