Merge pull request #757 from iamken1204/improve/totp-user

totp-user: add default user 'bbgo'
This commit is contained in:
Yo-An Lin 2022-06-22 18:35:12 +08:00 committed by GitHub
commit d1abfcf80b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View File

@ -1,5 +1,5 @@
# First stage container # First stage container
FROM golang:1.17.6-alpine3.15 AS builder FROM golang:1.17.11-alpine3.16 AS builder
RUN apk add --no-cache git ca-certificates gcc libc-dev pkgconfig RUN apk add --no-cache git ca-certificates gcc libc-dev pkgconfig
# gcc is for github.com/mattn/go-sqlite3 # gcc is for github.com/mattn/go-sqlite3
# ADD . $GOPATH/src/github.com/c9s/bbgo # ADD . $GOPATH/src/github.com/c9s/bbgo
@ -16,14 +16,16 @@ ADD . .
RUN go build -o $GOPATH_ORIG/bin/bbgo ./cmd/bbgo RUN go build -o $GOPATH_ORIG/bin/bbgo ./cmd/bbgo
# Second stage container # Second stage container
FROM alpine:3.15 FROM alpine:3.16
# RUN apk add --no-cache ca-certificates # Create the default user 'bbgo' and assign to env 'USER'
RUN mkdir /app ENV USER=bbgo
RUN adduser -D -G wheel "$USER"
USER ${USER}
WORKDIR /app
COPY --from=builder /go/bin/bbgo /usr/local/bin COPY --from=builder /go/bin/bbgo /usr/local/bin
WORKDIR /home/${USER}
ENTRYPOINT ["/usr/local/bin/bbgo"] ENTRYPOINT ["/usr/local/bin/bbgo"]
CMD ["run", "--config", "/config/bbgo.yaml", "--no-compile"] CMD ["run", "--config", "/config/bbgo.yaml", "--no-compile"]
# vim:filetype=dockerfile: # vim:filetype=dockerfile:

View File

@ -1,12 +1,12 @@
package service package service
import ( import (
"fmt"
"os" "os"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/pquerna/otp" "github.com/pquerna/otp"
"github.com/pquerna/otp/totp" "github.com/pquerna/otp/totp"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -39,7 +39,8 @@ func NewDefaultTotpKey() (*otp.Key, error) {
} }
if !ok { if !ok {
return nil, fmt.Errorf("can not get USER or USERNAME env var for totp account name") log.Warnf("can not get USER or USERNAME env var, use default name 'bbgo' for totp account name")
user = "bbgo"
} }
totpAccountName = user totpAccountName = user