Compare commits

..

No commits in common. "27150e9502d5452197608f9250cf5ed03fb6a503" and "7f8165e72bd3657d6ef1247cc8ec024c1abc5e17" have entirely different histories.

8 changed files with 35 additions and 105 deletions

View File

@ -1,51 +0,0 @@
---
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 ./...
- 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: 0f5318785e361ab48470f37a93f15cb218f6f2a22dbdd2ec2f16298dd7577ada
...

30
Gopkg.toml Normal file
View File

@ -0,0 +1,30 @@
# 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"

View File

@ -493,7 +493,6 @@ func (app *Bouquins) IndexPage(res http.ResponseWriter, req *http.Request) error
return app.render(res, tplIndex, model) return app.render(res, tplIndex, model)
} }
// CalibreFileServer serves files from calibre path
func (app *Bouquins) CalibreFileServer() http.Handler { func (app *Bouquins) CalibreFileServer() http.Handler {
calibre := app.Conf.CalibrePath calibre := app.Conf.CalibrePath
handler := http.StripPrefix(URLCalibre, http.FileServer(http.Dir(calibre))) handler := http.StripPrefix(URLCalibre, http.FileServer(http.Dir(calibre)))

View File

@ -9,7 +9,7 @@ import (
"golang.org/x/oauth2" "golang.org/x/oauth2"
) )
// GiteaProvider implements OAuth2 client with custom gitea server // GithubProvider implements OAuth2 client with github.com
type GiteaProvider string type GiteaProvider string
type giteaProfile struct { type giteaProfile struct {
@ -61,11 +61,7 @@ func (p GiteaProvider) Config(conf *Conf) *oauth2.Config {
ClientID: c.ClientID, ClientID: c.ClientID,
ClientSecret: c.ClientSecret, ClientSecret: c.ClientSecret,
RedirectURL: conf.ExternalURL + "/callback", RedirectURL: conf.ExternalURL + "/callback",
Endpoint: oauth2.Endpoint{ Endpoint: oauth2.Endpoint{c.AuthURL, c.TokenURL, oauth2.AuthStyleAutoDetect},
AuthURL: c.AuthURL,
TokenURL: c.TokenURL,
AuthStyle: oauth2.AuthStyleAutoDetect,
},
} }
} }
} }
@ -79,11 +75,11 @@ func (p GiteaProvider) GetUser(app *Bouquins, token *oauth2.Token) (string, erro
apiReq.Header.Add("Authorization", "token "+token.AccessToken) apiReq.Header.Add("Authorization", "token "+token.AccessToken)
client := &http.Client{} client := &http.Client{}
response, err := client.Do(apiReq) response, err := client.Do(apiReq)
defer response.Body.Close()
if err != nil { if err != nil {
log.Println("Auth error", err) log.Println("Auth error", err)
return "", fmt.Errorf("Authentification error") return "", fmt.Errorf("Authentification error")
} }
defer response.Body.Close()
dec := json.NewDecoder(response.Body) dec := json.NewDecoder(response.Body)
var profile giteaProfile var profile giteaProfile

View File

@ -61,11 +61,11 @@ func (p GithubProvider) GetUser(app *Bouquins, token *oauth2.Token) (string, err
apiReq.Header.Add("Authorization", "token "+token.AccessToken) apiReq.Header.Add("Authorization", "token "+token.AccessToken)
client := &http.Client{} client := &http.Client{}
response, err := client.Do(apiReq) response, err := client.Do(apiReq)
defer response.Body.Close()
if err != nil { if err != nil {
log.Println("Auth error", err) log.Println("Auth error", err)
return "", fmt.Errorf("Authentification error") return "", fmt.Errorf("Authentification error")
} }
defer response.Body.Close()
dec := json.NewDecoder(response.Body) dec := json.NewDecoder(response.Body)
var emails []githubEmail var emails []githubEmail

View File

@ -62,11 +62,11 @@ func (p GoogleProvider) Config(conf *Conf) *oauth2.Config {
// GetUser returns github primary email // GetUser returns github primary email
func (p GoogleProvider) GetUser(app *Bouquins, token *oauth2.Token) (string, error) { 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) 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 { if err != nil {
log.Println("Auth error", err) log.Println("Auth error", err)
return "", fmt.Errorf("Authentification error") return "", fmt.Errorf("Authentification error")
} }
defer apiRes.Body.Close()
dec := json.NewDecoder(apiRes.Body) dec := json.NewDecoder(apiRes.Body)
var tokenInfo googleTokenInfo var tokenInfo googleTokenInfo
err = dec.Decode(&tokenInfo) err = dec.Decode(&tokenInfo)

12
go.mod
View File

@ -1,12 +0,0 @@
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/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
)

32
go.sum
View File

@ -1,32 +0,0 @@
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/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 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=
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=