lint: minor warn

This commit is contained in:
Umputun
2018-06-08 14:18:09 -05:00
parent 424e0cf73c
commit 67baf50b6e
10 changed files with 36 additions and 41 deletions
+1
View File
@@ -27,6 +27,7 @@ import (
)
// Opts with command line flags and env
// nolint:maligned
type Opts struct {
BoltPath string `long:"bolt" env:"BOLTDB_PATH" default:"./var" description:"parent dir for bolt files"`
Sites []string `long:"site" env:"SITE" default:"remark" description:"site names" env-delim:","`
+1 -1
View File
@@ -19,7 +19,7 @@ import (
func TestApplication(t *testing.T) {
app, ctx := prepApp(t, 18080, 500*time.Millisecond)
go app.Run(ctx)
go func() { _ = app.Run(ctx) }()
time.Sleep(100 * time.Millisecond) // let server start
// send ping
+2 -2
View File
@@ -26,8 +26,8 @@ type disqusThread struct {
CreateAt time.Time `xml:"createdAt"`
AuthorName string `xml:"author>name"`
AuthorEmail string `xml:"author>email"`
Anonymous bool `xml:"author>isAnonymous"`
IP string `xml:"ipAddress"`
Anonymous bool `xml:"author>isAnonymous"`
Closed bool `xml:"isClosed"`
Deleted bool `xml:"isDeleted"`
}
@@ -37,13 +37,13 @@ type disqusComment struct {
ID string `xml:"id"`
Message string `xml:"message"`
CreatedAt time.Time `xml:"createdAt"`
IsSpam bool `xml:"isSpam"`
AuthorEmail string `xml:"author>email"`
AuthorName string `xml:"author>name"`
AuthorUserName string `xml:"author>username"`
IP string `xml:"ipAddress"`
Tid uid `xml:"thread"`
Pid uid `xml:"parent"`
IsSpam bool `xml:"isSpam"`
}
type uid struct {
-1
View File
@@ -24,7 +24,6 @@ type admin struct {
dataService service.DataStore
exporter migrator.Exporter
cache cache.LoadingCache
defAvatarURL string
authenticator auth.Authenticator
}
+17 -12
View File
@@ -163,18 +163,7 @@ func (p Provider) authHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("[DEBUG] got raw user info %+v", jData)
u := p.MapUser(jData, data)
if p.AvatarProxy != nil {
if avatarURL, e := p.AvatarProxy.Put(u); e == nil {
u.Picture = avatarURL
} else {
log.Printf("[WARN] failed to proxy avatar, %s", e)
}
}
u.Admin = isAdmin(u.ID, p.Admins)
if p.IsVerifiedFn != nil {
u.Verified = p.IsVerifiedFn(oauthClaims.SiteID, u.ID)
}
u = p.alterUser(u, oauthClaims)
authClaims := &CustomClaims{
User: &u,
@@ -200,6 +189,22 @@ func (p Provider) authHandler(w http.ResponseWriter, r *http.Request) {
render.JSON(w, r, &u)
}
// alterUser sets fileds not handled by provider's MapUser, things like avatar, admin, verified
func (p Provider) alterUser(u store.User, oauthClaims *CustomClaims) store.User {
if p.AvatarProxy != nil {
if avatarURL, e := p.AvatarProxy.Put(u); e == nil {
u.Picture = avatarURL
} else {
log.Printf("[WARN] failed to proxy avatar, %s", e)
}
}
u.Admin = isAdmin(u.ID, p.Admins)
if p.IsVerifiedFn != nil {
u.Verified = p.IsVerifiedFn(oauthClaims.SiteID, u.ID)
}
return u
}
// LogoutHandler - GET /logout
func (p Provider) LogoutHandler(w http.ResponseWriter, r *http.Request) {
p.JwtService.Reset(w)
+13
View File
@@ -2,11 +2,13 @@ package cache
import (
"log"
"net/http"
"strings"
"sync/atomic"
"github.com/hashicorp/golang-lru"
"github.com/pkg/errors"
"github.com/umputun/remark/app/rest"
)
// LoadingCache defines interface for caching
@@ -142,3 +144,14 @@ func (lc *loadingCache) allowed(data []byte) bool {
}
return true
}
// URLKey gets url from request to use it as cache key
// admins will have different keys in order to prevent leak of admin-only data to regular users
func URLKey(r *http.Request) string {
adminPrefix := "admin!!"
key := strings.TrimPrefix(r.URL.String(), adminPrefix) // prevents attach with fake url to get admin view
if user, err := rest.GetUserInfo(r); err == nil && user.Admin { // make separate cache key for admins
key = adminPrefix + key
}
return key
}
-18
View File
@@ -1,12 +1,5 @@
package cache
import (
"net/http"
"strings"
"github.com/umputun/remark/app/rest"
)
// Option func type
type Option func(lc *loadingCache) error
@@ -44,14 +37,3 @@ func PostFlushFn(postFlushFn func()) Option {
return nil
}
}
// URLKey gets url from request to use it as cache key
// admins will have different keys in order to prevent leak of admin-only data to regular users
func URLKey(r *http.Request) string {
adminPrefix := "admin!!"
key := strings.TrimPrefix(r.URL.String(), adminPrefix) // prevents attach with fake url to get admin view
if user, err := rest.GetUserInfo(r); err == nil && user.Admin { // make separate cache key for admins
key = adminPrefix + key
}
return key
}
-5
View File
@@ -1,13 +1,11 @@
package proxy
import (
"hash/crc64"
"io"
"log"
"net/http"
"strconv"
"strings"
"sync"
"time"
"github.com/go-chi/chi"
@@ -23,9 +21,6 @@ type Avatar struct {
Store AvatarStore
RoutePath string
RemarkURL string
once sync.Once
ctcTable *crc64.Table
}
const imgSfx = ".image"
+1 -1
View File
@@ -19,8 +19,8 @@ type Comment struct {
Score int `json:"score"`
Votes map[string]bool `json:"votes"`
Timestamp time.Time `json:"time"`
Pin bool `json:"pin,omitempty"`
Edit *Edit `json:"edit,omitempty"` // pointer to have empty default in json response
Pin bool `json:"pin,omitempty"`
Deleted bool `json:"delete,omitempty"`
}
+1 -1
View File
@@ -16,9 +16,9 @@ type User struct {
Name string `json:"name"`
ID string `json:"id"`
Picture string `json:"picture"`
IP string `json:"ip,omitempty"`
Admin bool `json:"admin"`
Blocked bool `json:"block,omitempty"`
IP string `json:"ip,omitempty"`
Verified bool `json:"verified,omitempty"`
}