From eceb0a8946bf5a29b475ac0b1ecc52902bcd06af Mon Sep 17 00:00:00 2001 From: Meutel Date: Wed, 11 Sep 2019 15:38:57 +0200 Subject: [PATCH 1/4] go.mod --- Gopkg.toml | 30 ------------------------------ go.mod | 10 ++++++++++ go.sum | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 30 deletions(-) delete mode 100644 Gopkg.toml create mode 100644 go.mod create mode 100644 go.sum diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index 817442a..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,30 +0,0 @@ - -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" - - -[[constraint]] - branch = "master" - name = "github.com/c2h5oh/datasize" - -[[constraint]] - name = "github.com/mattn/go-sqlite3" - version = "1.2.0" diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5207271 --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module meutel.net/meutel/go-bouquins + +go 1.13 + +require ( + github.com/c2h5oh/datasize v0.0.0-20171227191756-4eba002a5eae + github.com/gorilla/sessions v1.2.0 + github.com/mattn/go-sqlite3 v1.11.0 + golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..fc119a6 --- /dev/null +++ b/go.sum @@ -0,0 +1,19 @@ +cloud.google.com/go v0.34.0 h1:eOI3/cP2VTU6uZLDYAoic+eyzzB9YyGmJ7eIjl8rOPg= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/c2h5oh/datasize v0.0.0-20171227191756-4eba002a5eae h1:2Zmk+8cNvAGuY8AyvZuWpUdpQUAXwfom4ReVMe/CTIo= +github.com/c2h5oh/datasize v0.0.0-20171227191756-4eba002a5eae/go.mod h1:S/7n9copUssQ56c7aAgHqftWO4LTf4xY6CGWt8Bc+3M= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= +github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= +github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ= +github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= +github.com/mattn/go-sqlite3 v1.11.0 h1:LDdKkqtYlom37fkvqs8rMPFKAMe8+SgjbwZ6ex1/A/Q= +github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= From 641e4e2093879aa3a446a837faa704297bdb2aea Mon Sep 17 00:00:00 2001 From: Meutel Date: Wed, 11 Sep 2019 15:03:12 +0200 Subject: [PATCH 2/4] Drone build --- .drone.yml | 36 ++++++++++++++++++++++++++++++++++++ go.mod | 2 ++ go.sum | 12 ++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..3c84e92 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,36 @@ +--- +kind: pipeline +type: docker +name: default + +steps: + + - name: build + image: golang + environment: + CGO_ENABLED: 1 + GOOS: linux + commands: + - go test ./... + - go build -a -installsuffix cgo . + + - name: lint + image: golang + commands: + - go get -u golang.org/x/lint/golint + - golint -set_exit_status ./... + + - name: vet + image: golang + commands: + - go vet ./... + +trigger: + event: + - push + +--- +kind: signature +hmac: 663682f7b45c7f2629991785fc04170d60a0232719bac11d29620882ad857277 + +... diff --git a/go.mod b/go.mod index 5207271..6fa142a 100644 --- a/go.mod +++ b/go.mod @@ -6,5 +6,7 @@ require ( github.com/c2h5oh/datasize v0.0.0-20171227191756-4eba002a5eae github.com/gorilla/sessions v1.2.0 github.com/mattn/go-sqlite3 v1.11.0 + golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac // indirect golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 + golang.org/x/tools v0.0.0-20190911022129-16c5e0f7d110 // indirect ) diff --git a/go.sum b/go.sum index fc119a6..2dbdc20 100644 --- a/go.sum +++ b/go.sum @@ -9,11 +9,23 @@ github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYb github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/mattn/go-sqlite3 v1.11.0 h1:LDdKkqtYlom37fkvqs8rMPFKAMe8+SgjbwZ6ex1/A/Q= github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac h1:8R1esu+8QioDxo4E4mX6bFztO+dMTM49DNAaWfO5OeY= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd h1:/e+gpKk9r3dJobndpTytxS2gOy6m5uvpg+ISQoEcusQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190911022129-16c5e0f7d110 h1:6S6bidS7O4yAwA5ORRbRIjvNQ9tGbLd5e+LRIaTeVDQ= +golang.org/x/tools v0.0.0-20190911022129-16c5e0f7d110/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= From 1b9a4a66143e8ea406af3404cd7367a0561257c1 Mon Sep 17 00:00:00 2001 From: Meutel Date: Wed, 11 Sep 2019 17:11:43 +0200 Subject: [PATCH 3/4] fix lint, vet --- bouquins/bouquins.go | 1 + bouquins/gitea.go | 10 +++++++--- bouquins/github.go | 2 +- bouquins/google.go | 2 +- go.sum | 1 + 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bouquins/bouquins.go b/bouquins/bouquins.go index 79faefa..2cd908a 100644 --- a/bouquins/bouquins.go +++ b/bouquins/bouquins.go @@ -493,6 +493,7 @@ func (app *Bouquins) IndexPage(res http.ResponseWriter, req *http.Request) error return app.render(res, tplIndex, model) } +// CalibreFileServer serves files from calibre path func (app *Bouquins) CalibreFileServer() http.Handler { calibre := app.Conf.CalibrePath handler := http.StripPrefix(URLCalibre, http.FileServer(http.Dir(calibre))) diff --git a/bouquins/gitea.go b/bouquins/gitea.go index 98dea22..37a34cc 100644 --- a/bouquins/gitea.go +++ b/bouquins/gitea.go @@ -9,7 +9,7 @@ import ( "golang.org/x/oauth2" ) -// GithubProvider implements OAuth2 client with github.com +// GiteaProvider implements OAuth2 client with custom gitea server type GiteaProvider string type giteaProfile struct { @@ -61,7 +61,11 @@ func (p GiteaProvider) Config(conf *Conf) *oauth2.Config { ClientID: c.ClientID, ClientSecret: c.ClientSecret, RedirectURL: conf.ExternalURL + "/callback", - Endpoint: oauth2.Endpoint{c.AuthURL, c.TokenURL, oauth2.AuthStyleAutoDetect}, + Endpoint: oauth2.Endpoint{ + AuthURL: c.AuthURL, + TokenURL: c.TokenURL, + AuthStyle: oauth2.AuthStyleAutoDetect, + }, } } } @@ -75,11 +79,11 @@ func (p GiteaProvider) GetUser(app *Bouquins, token *oauth2.Token) (string, erro apiReq.Header.Add("Authorization", "token "+token.AccessToken) client := &http.Client{} response, err := client.Do(apiReq) - defer response.Body.Close() if err != nil { log.Println("Auth error", err) return "", fmt.Errorf("Authentification error") } + defer response.Body.Close() dec := json.NewDecoder(response.Body) var profile giteaProfile diff --git a/bouquins/github.go b/bouquins/github.go index 0a6d6ed..c7b87a7 100644 --- a/bouquins/github.go +++ b/bouquins/github.go @@ -61,11 +61,11 @@ func (p GithubProvider) GetUser(app *Bouquins, token *oauth2.Token) (string, err apiReq.Header.Add("Authorization", "token "+token.AccessToken) client := &http.Client{} response, err := client.Do(apiReq) - defer response.Body.Close() if err != nil { log.Println("Auth error", err) return "", fmt.Errorf("Authentification error") } + defer response.Body.Close() dec := json.NewDecoder(response.Body) var emails []githubEmail diff --git a/bouquins/google.go b/bouquins/google.go index cebd669..8c1124e 100644 --- a/bouquins/google.go +++ b/bouquins/google.go @@ -62,11 +62,11 @@ func (p GoogleProvider) Config(conf *Conf) *oauth2.Config { // GetUser returns github primary email func (p GoogleProvider) GetUser(app *Bouquins, token *oauth2.Token) (string, error) { apiRes, err := http.Post("https://www.googleapis.com/oauth2/v2/tokeninfo?access_token="+token.AccessToken, "application/json", nil) - defer apiRes.Body.Close() if err != nil { log.Println("Auth error", err) return "", fmt.Errorf("Authentification error") } + defer apiRes.Body.Close() dec := json.NewDecoder(apiRes.Body) var tokenInfo googleTokenInfo err = dec.Decode(&tokenInfo) diff --git a/go.sum b/go.sum index 2dbdc20..4b63630 100644 --- a/go.sum +++ b/go.sum @@ -16,6 +16,7 @@ golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= From 1db12a61b145a5567d46615f6ebf075c95ebb4db Mon Sep 17 00:00:00 2001 From: Meutel Date: Wed, 11 Sep 2019 17:42:26 +0200 Subject: [PATCH 4/4] Docker build --- .drone.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 3c84e92..8491d28 100644 --- a/.drone.yml +++ b/.drone.yml @@ -25,12 +25,27 @@ steps: commands: - go vet ./... + - name: docker + image: plugins/docker + settings: + registry: reg.meutel.net + repo: reg.meutel.net/go-bouquins + username: + from_secret: registry_login + password: + from_secret: registry_password + auto_tag: true + when: + event: + - tag + trigger: event: - push + - tag --- kind: signature -hmac: 663682f7b45c7f2629991785fc04170d60a0232719bac11d29620882ad857277 +hmac: 0f5318785e361ab48470f37a93f15cb218f6f2a22dbdd2ec2f16298dd7577ada ...