Skip to content
Permalink
Browse files

Merge pull request #217 from netlify/chore/rip-commons

Remove uses of netlify-commons
  • Loading branch information...
mraerino committed Sep 11, 2019
2 parents 738272d + 58dc353 commit 4249f22afb8b2822174264ade7a7fe3e48277b37
Showing with 112 additions and 328 deletions.
  1. +2 −2 .travis.yml
  2. +2 −2 Dockerfile
  3. +30 −6 api/api.go
  4. +3 −4 conf/configuration.go
  5. +60 −0 conf/logging.go
  6. +8 −50 go.mod
  7. +7 −264 go.sum
@@ -2,7 +2,7 @@
language: go

go:
- 1.11.4
- 1.13

env:
- GO111MODULE=on
@@ -17,4 +17,4 @@ install: make deps
script: make migrate_test all

notifications:
email: false
email: false
@@ -1,4 +1,4 @@
FROM golang:1.11.4-alpine as build
FROM golang:1.13-alpine as build
ENV GO111MODULE=on
ENV CGO_ENABLED=0
ENV GOOS=linux
@@ -22,4 +22,4 @@ COPY --from=build /go/src/github.com/netlify/gotrue/migrations /usr/local/etc/go
ENV GOTRUE_DB_MIGRATIONS_PATH /usr/local/etc/gotrue/migrations

USER netlify
CMD ["gotrue"]
CMD ["gotrue"]
@@ -3,16 +3,19 @@ package api
import (
"context"
"net/http"
"os"
"os/signal"
"regexp"
"syscall"
"time"

"github.com/go-chi/chi"
"github.com/gobuffalo/uuid"
"github.com/imdario/mergo"
"github.com/netlify/gotrue/conf"
"github.com/netlify/gotrue/mailer"
"github.com/netlify/gotrue/storage"
"github.com/netlify/netlify-commons/graceful"
"github.com/rs/cors"
"github.com/gobuffalo/uuid"
"github.com/sebest/xff"
"github.com/sirupsen/logrus"
)
@@ -35,16 +38,37 @@ type API struct {
// ListenAndServe starts the REST API
func (a *API) ListenAndServe(hostAndPort string) {
log := logrus.WithField("component", "api")
server := graceful.NewGracefulServer(a.handler, log)
if err := server.Bind(hostAndPort); err != nil {
log.WithError(err).Fatal("http server bind failed")
server := &http.Server{
Addr: hostAndPort,
Handler: a.handler,
}

if err := server.Listen(); err != nil {
done := make(chan struct{})
defer close(done)
go func() {
waitForTermination(log, done)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
server.Shutdown(ctx)
}()

if err := server.ListenAndServe(); err != http.ErrServerClosed {
log.WithError(err).Fatal("http server listen failed")
}
}

// WaitForShutdown blocks until the system signals termination or done has a value
func waitForTermination(log logrus.FieldLogger, done <-chan struct{}) {
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
select {
case sig := <-signals:
log.Infof("Triggering shutdown from signal %s", sig)
case <-done:
log.Infof("Shutting down...")
}
}

// NewAPI instantiates a new REST API
func NewAPI(globalConfig *conf.GlobalConfiguration, db *storage.Connection) *API {
return NewAPIWithVersion(context.Background(), globalConfig, db, defaultVersion)
@@ -9,7 +9,6 @@ import (

"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
"github.com/netlify/netlify-commons/nconf"
)

// OAuthProviderConfiguration holds all config related to external account providers.
@@ -61,8 +60,8 @@ type GlobalConfiguration struct {
}
DB DBConfiguration
External ProviderConfiguration
Logging nconf.LoggingConfig `envconfig:"LOG"`
OperatorToken string `split_words:"true" required:"true"`
Logging LoggingConfig `envconfig:"LOG"`
OperatorToken string `split_words:"true" required:"true"`
MultiInstanceMode bool
SMTP SMTPConfiguration
}
@@ -157,7 +156,7 @@ func LoadGlobal(filename string) (*GlobalConfiguration, error) {
return nil, err
}

if _, err := nconf.ConfigureLogging(&config.Logging); err != nil {
if _, err := ConfigureLogging(&config.Logging); err != nil {
return nil, err
}

@@ -0,0 +1,60 @@
package conf

import (
"os"
"time"

"github.com/sirupsen/logrus"
)

type LoggingConfig struct {
Level string `mapstructure:"log_level" json:"log_level"`
File string `mapstructure:"log_file" json:"log_file"`
DisableColors bool `mapstructure:"disable_colors" split_words:"true" json:"disable_colors"`
QuoteEmptyFields bool `mapstructure:"quote_empty_fields" split_words:"true" json:"quote_empty_fields"`
TSFormat string `mapstructure:"ts_format" json:"ts_format"`
Fields map[string]interface{} `mapstructure:"fields" json:"fields"`
}

func ConfigureLogging(config *LoggingConfig) (*logrus.Entry, error) {
logger := logrus.New()

tsFormat := time.RFC3339Nano
if config.TSFormat != "" {
tsFormat = config.TSFormat
}
// always use the full timestamp
logger.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
DisableTimestamp: false,
TimestampFormat: tsFormat,
DisableColors: config.DisableColors,
QuoteEmptyFields: config.QuoteEmptyFields,
})

// use a file if you want
if config.File != "" {
f, errOpen := os.OpenFile(config.File, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0664)
if errOpen != nil {
return nil, errOpen
}
logger.SetOutput(f)
logger.Infof("Set output file to %s", config.File)
}

if config.Level != "" {
level, err := logrus.ParseLevel(config.Level)
if err != nil {
return nil, err
}
logger.SetLevel(level)
logger.Debug("Set log level to: " + logger.GetLevel().String())
}

f := logrus.Fields{}
for k, v := range config.Fields {
f[k] = v
}

return logger.WithFields(f), nil
}
58 go.mod 100755 → 100644
@@ -3,85 +3,43 @@ module github.com/netlify/gotrue
require (
cloud.google.com/go v0.0.0-20170822200954-98f5696b1026 // indirect
github.com/GoogleCloudPlatform/cloudsql-proxy v0.0.0-20170623214735-571947b0f240
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect
github.com/badoux/checkmail v0.0.0-20170203135005-d0a759655d62
github.com/beevik/etree v0.0.0-20180609182452-90dafc1e1f11
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/boltdb/bolt v1.3.1 // indirect
github.com/bugsnag/bugsnag-go v1.3.0 // indirect
github.com/bugsnag/panicwrap v0.0.0-20170829152406-dd8df9a3778a // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/dropbox/godropbox v0.0.0-20180512210157-31879d3884b9 // indirect
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
github.com/facebookgo/stackerr v0.0.0-20150612192056-c2fcf88613f4 // indirect
github.com/go-chi/chi v3.1.4+incompatible
github.com/go-kit/kit v0.8.0 // indirect
github.com/go-logfmt/logfmt v0.4.0 // indirect
github.com/go-sql-driver/mysql v1.4.1
github.com/go-stack/stack v1.8.0 // indirect
github.com/gobuffalo/buffalo-plugins v1.9.4 // indirect
github.com/gobuffalo/gogen v0.1.1 // indirect
github.com/gobuffalo/nulls v0.0.0-20190305142546-85f3c9250d87 // indirect
github.com/gobuffalo/plushgen v0.0.0-20190104222512-177cd2b872b3 // indirect
github.com/gobuffalo/plush v3.7.32+incompatible // indirect
github.com/gobuffalo/pop v4.11.0+incompatible
github.com/gobuffalo/tags v2.0.15+incompatible // indirect
github.com/gobuffalo/uuid v2.0.5+incompatible
github.com/gobuffalo/x v0.0.0-20181110221217-14085ca3e1a9 // indirect
github.com/gogo/protobuf v0.0.0-20171109181519-616a82ed12d7 // indirect
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
github.com/hashicorp/go-msgpack v0.0.0-20150518234257-fa3f63826f7c // indirect
github.com/hashicorp/raft v1.0.0 // indirect
github.com/imdario/mergo v0.0.0-20160216103600-3e95a51e0639
github.com/joho/godotenv v1.3.0
github.com/jonboulle/clockwork v0.0.0-20180716110948-e7c6d408fd5c // indirect
github.com/jtolds/gls v4.2.1+incompatible // indirect
github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5 // indirect
github.com/juju/loggo v0.0.0-20180524022052-584905176618 // indirect
github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073 // indirect
github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1 // indirect
github.com/kelseyhightower/envconfig v1.3.0
github.com/kr/fs v0.0.0-20131111012553-2788f0dbd169 // indirect
github.com/nats-io/gnatsd v1.3.0 // indirect
github.com/nats-io/go-nats v1.3.0 // indirect
github.com/nats-io/go-nats-streaming v0.3.4 // indirect
github.com/nats-io/nats-streaming-server v0.11.2 // indirect
github.com/nats-io/nuid v0.0.0-20170303150224-3cf34f9fca4e // indirect
github.com/microcosm-cc/bluemonday v1.0.2 // indirect
github.com/netlify/mailme v0.0.0-20170821082834-c4a76ce443c1
github.com/netlify/netlify-commons v0.7.7
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c // indirect
github.com/pelletier/go-buffruneio v0.1.0 // indirect
github.com/onsi/ginkgo v1.7.0 // indirect
github.com/onsi/gomega v1.4.3 // indirect
github.com/pkg/errors v0.8.1
github.com/pkg/sftp v0.0.0-20160908100035-8197a2e58073 // indirect
github.com/rs/cors v0.0.0-20170608165155-8dd4211afb5d
github.com/russellhaering/gosaml2 v0.3.1
github.com/russellhaering/goxmldsig v0.0.0-20180430223755-7acd5e4a6ef7
github.com/sebest/xff v0.0.0-20160910043805-6c115e0ffa35
github.com/shopify/logrus-bugsnag v0.0.0-20170309145241-6dbc35f2c30d // indirect
github.com/signalfx/com_signalfx_metrics_protobuf v0.0.0-20170330202426-93e507b42f43 // indirect
github.com/signalfx/gohistogram v0.0.0-20160107210732-1ccfd2ff5083 // indirect
github.com/signalfx/golib v1.0.0 // indirect
github.com/sirupsen/logrus v1.4.1
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c // indirect
github.com/spf13/cobra v0.0.3
github.com/streadway/amqp v0.0.0-20170707203015-2cbfe40c9341 // indirect
github.com/stretchr/testify v1.3.0
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f
golang.org/x/lint v0.0.0-20190409202823-959b441ac422 // indirect
golang.org/x/net v0.0.0-20190514140710-3ec191127204 // indirect
golang.org/x/oauth2 v0.0.0-20170807180024-9a379c6b3e95
golang.org/x/sys v0.0.0-20190515190549-87c872767d25 // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/tools v0.0.0-20190515235946-4f9510c6a12d // indirect
google.golang.org/api v0.0.0-20170821230356-dd6bdadc5852 // indirect
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
gopkg.in/logfmt.v0 v0.3.0 // indirect
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
gopkg.in/stack.v1 v1.6.0 // indirect
gopkg.in/vmihailenco/msgpack.v2 v2.9.1 // indirect
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
)

go 1.13

0 comments on commit 4249f22

Please sign in to comment.
You can’t perform that action at this time.