mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
removing some dependencies from glide (#493)
This commit is contained in:
parent
bf4ee40c41
commit
eb3f3cd765
35
glide.lock
generated
35
glide.lock
generated
@ -1,5 +1,5 @@
|
|||||||
hash: 3519c1da46244ec37972b542173f088df94422080bc99652f88f960d70a7005a
|
hash: ceffc2eea38197f3398b8abd70fae1c04852ffc5c307515d2275f1955be6f423
|
||||||
updated: 2016-11-02T22:14:07.180331599+08:00
|
updated: 2016-11-16T10:18:48.9588602-08:00
|
||||||
imports:
|
imports:
|
||||||
- name: github.com/alecthomas/template
|
- name: github.com/alecthomas/template
|
||||||
version: a0175ee3bccc567396460bf5acd36800cb10c49c
|
version: a0175ee3bccc567396460bf5acd36800cb10c49c
|
||||||
@ -11,10 +11,6 @@ imports:
|
|||||||
version: 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9
|
version: 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9
|
||||||
subpackages:
|
subpackages:
|
||||||
- quantile
|
- quantile
|
||||||
- name: github.com/davecgh/go-spew
|
|
||||||
version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d
|
|
||||||
subpackages:
|
|
||||||
- spew
|
|
||||||
- name: github.com/dgrijalva/jwt-go
|
- name: github.com/dgrijalva/jwt-go
|
||||||
version: 01aeca54ebda6e0fbfafd0a524d234159c05ec20
|
version: 01aeca54ebda6e0fbfafd0a524d234159c05ec20
|
||||||
- name: github.com/elazarl/go-bindata-assetfs
|
- name: github.com/elazarl/go-bindata-assetfs
|
||||||
@ -26,17 +22,6 @@ imports:
|
|||||||
subpackages:
|
subpackages:
|
||||||
- internal
|
- internal
|
||||||
- redis
|
- redis
|
||||||
- name: github.com/gin-gonic/contrib
|
|
||||||
version: 547e518040cfb96576b507d2f26779ab9c6fc829
|
|
||||||
subpackages:
|
|
||||||
- ginrus
|
|
||||||
- renders/multitemplate
|
|
||||||
- static
|
|
||||||
- name: github.com/gin-gonic/gin
|
|
||||||
version: f931d1ea80ae95a6fc739213cdd9399bd2967fb6
|
|
||||||
subpackages:
|
|
||||||
- binding
|
|
||||||
- render
|
|
||||||
- name: github.com/go-kit/kit
|
- name: github.com/go-kit/kit
|
||||||
version: dd9236608629b98d33d4c6681dc3740400c01243
|
version: dd9236608629b98d33d4c6681dc3740400c01243
|
||||||
subpackages:
|
subpackages:
|
||||||
@ -75,10 +60,10 @@ imports:
|
|||||||
- json/token
|
- json/token
|
||||||
- name: github.com/inconshreveable/mousetrap
|
- name: github.com/inconshreveable/mousetrap
|
||||||
version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
|
version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
|
||||||
- name: github.com/jinzhu/inflection
|
|
||||||
version: 8f4d3a0d04ce0b7c0cf3126fb98524246d00d102
|
|
||||||
- name: github.com/jmoiron/sqlx
|
- name: github.com/jmoiron/sqlx
|
||||||
version: 5f97679e23f75f42b265fec8d3bdb1c8de90b79d
|
version: 5f97679e23f75f42b265fec8d3bdb1c8de90b79d
|
||||||
|
subpackages:
|
||||||
|
- reflectx
|
||||||
- name: github.com/jordan-wright/email
|
- name: github.com/jordan-wright/email
|
||||||
version: fd703108daeb23d77c124d12978e9b6c4f28f034
|
version: fd703108daeb23d77c124d12978e9b6c4f28f034
|
||||||
- name: github.com/kr/fs
|
- name: github.com/kr/fs
|
||||||
@ -87,8 +72,6 @@ imports:
|
|||||||
version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0
|
version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0
|
||||||
- name: github.com/magiconair/properties
|
- name: github.com/magiconair/properties
|
||||||
version: 61b492c03cf472e0c6419be5899b8e0dc28b1b88
|
version: 61b492c03cf472e0c6419be5899b8e0dc28b1b88
|
||||||
- name: github.com/manucorporat/sse
|
|
||||||
version: ee05b128a739a0fb76c7ebd3ae4810c1de808d6d
|
|
||||||
- name: github.com/matttproud/golang_protobuf_extensions
|
- name: github.com/matttproud/golang_protobuf_extensions
|
||||||
version: c12348ce28de40eed0136aa2b644d0ee0650e56c
|
version: c12348ce28de40eed0136aa2b644d0ee0650e56c
|
||||||
subpackages:
|
subpackages:
|
||||||
@ -125,8 +108,6 @@ imports:
|
|||||||
- model
|
- model
|
||||||
- name: github.com/prometheus/procfs
|
- name: github.com/prometheus/procfs
|
||||||
version: abf152e5f3e97f2fafac028d2cc06c1feb87ffa5
|
version: abf152e5f3e97f2fafac028d2cc06c1feb87ffa5
|
||||||
- name: github.com/Sirupsen/logrus
|
|
||||||
version: a283a10442df8dc09befd873fab202bf8a253d6a
|
|
||||||
- name: github.com/spf13/afero
|
- name: github.com/spf13/afero
|
||||||
version: 20500e2abd0d1f4564a499e83d11d6c73cd58c27
|
version: 20500e2abd0d1f4564a499e83d11d6c73cd58c27
|
||||||
subpackages:
|
subpackages:
|
||||||
@ -177,7 +158,11 @@ imports:
|
|||||||
- name: gopkg.in/go-playground/validator.v8
|
- name: gopkg.in/go-playground/validator.v8
|
||||||
version: 5f57d2222ad794d0dffb07e664ea05e2ee07d60c
|
version: 5f57d2222ad794d0dffb07e664ea05e2ee07d60c
|
||||||
- name: gopkg.in/natefinch/lumberjack.v2
|
- name: gopkg.in/natefinch/lumberjack.v2
|
||||||
version: e21e5cbec0cd0861b9dc302736ad5666c529d93f
|
version: 514cbda263a734ae8caac038dadf05f8f3f9f738
|
||||||
- name: gopkg.in/yaml.v2
|
- name: gopkg.in/yaml.v2
|
||||||
version: e4d366fc3c7938e2958e662b4258c7a89e1f0e3e
|
version: e4d366fc3c7938e2958e662b4258c7a89e1f0e3e
|
||||||
testImports: []
|
testImports:
|
||||||
|
- name: github.com/davecgh/go-spew
|
||||||
|
version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9
|
||||||
|
subpackages:
|
||||||
|
- spew
|
||||||
|
21
glide.yaml
21
glide.yaml
@ -1,40 +1,19 @@
|
|||||||
package: github.com/kolide/kolide-ose
|
package: github.com/kolide/kolide-ose
|
||||||
import:
|
import:
|
||||||
- package: github.com/Sirupsen/logrus
|
|
||||||
version: a283a10442df8dc09befd873fab202bf8a253d6a
|
|
||||||
- package: github.com/alecthomas/template
|
- package: github.com/alecthomas/template
|
||||||
version: a0175ee3bccc567396460bf5acd36800cb10c49c
|
version: a0175ee3bccc567396460bf5acd36800cb10c49c
|
||||||
subpackages:
|
subpackages:
|
||||||
- parse
|
- parse
|
||||||
- package: github.com/alecthomas/units
|
- package: github.com/alecthomas/units
|
||||||
version: 2efee857e7cfd4f3d0138cc3cbb1b4966962b93a
|
version: 2efee857e7cfd4f3d0138cc3cbb1b4966962b93a
|
||||||
- package: github.com/davecgh/go-spew
|
|
||||||
version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d
|
|
||||||
subpackages:
|
|
||||||
- spew
|
|
||||||
- package: github.com/dgrijalva/jwt-go
|
- package: github.com/dgrijalva/jwt-go
|
||||||
version: 01aeca54ebda6e0fbfafd0a524d234159c05ec20
|
version: 01aeca54ebda6e0fbfafd0a524d234159c05ec20
|
||||||
- package: github.com/gin-gonic/contrib
|
|
||||||
version: 547e518040cfb96576b507d2f26779ab9c6fc829
|
|
||||||
subpackages:
|
|
||||||
- ginrus
|
|
||||||
- renders/multitemplate
|
|
||||||
- static
|
|
||||||
- package: github.com/gin-gonic/gin
|
|
||||||
version: f931d1ea80ae95a6fc739213cdd9399bd2967fb6
|
|
||||||
subpackages:
|
|
||||||
- binding
|
|
||||||
- render
|
|
||||||
- package: github.com/go-sql-driver/mysql
|
- package: github.com/go-sql-driver/mysql
|
||||||
version: 3654d25ec346ee8ce71a68431025458d52a38ac0
|
version: 3654d25ec346ee8ce71a68431025458d52a38ac0
|
||||||
- package: github.com/golang/protobuf
|
- package: github.com/golang/protobuf
|
||||||
version: c3cefd437628a0b7d31b34fe44b3a7a540e98527
|
version: c3cefd437628a0b7d31b34fe44b3a7a540e98527
|
||||||
subpackages:
|
subpackages:
|
||||||
- proto
|
- proto
|
||||||
- package: github.com/jinzhu/inflection
|
|
||||||
version: 8f4d3a0d04ce0b7c0cf3126fb98524246d00d102
|
|
||||||
- package: github.com/manucorporat/sse
|
|
||||||
version: ee05b128a739a0fb76c7ebd3ae4810c1de808d6d
|
|
||||||
- package: github.com/pmezard/go-difflib
|
- package: github.com/pmezard/go-difflib
|
||||||
version: ~1.0.0
|
version: ~1.0.0
|
||||||
subpackages:
|
subpackages:
|
||||||
|
@ -3,10 +3,6 @@ package errors
|
|||||||
import (
|
import (
|
||||||
goerrs "errors"
|
goerrs "errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"gopkg.in/go-playground/validator.v8"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -80,50 +76,3 @@ func InternalServerError(err error) *KolideError {
|
|||||||
|
|
||||||
// The status code returned for validation errors. Inspired by the Github API.
|
// The status code returned for validation errors. Inspired by the Github API.
|
||||||
const StatusUnprocessableEntity = 422
|
const StatusUnprocessableEntity = 422
|
||||||
|
|
||||||
// Handle an error, printing debug information, writing to the HTTP response as
|
|
||||||
// appropriate for the dynamic error type.
|
|
||||||
func ReturnError(c *gin.Context, err error) {
|
|
||||||
baseReturnError(c, err, "message")
|
|
||||||
}
|
|
||||||
|
|
||||||
// osqueryd does not check the HTTP status code, and only looks for a
|
|
||||||
func ReturnOsqueryError(c *gin.Context, err error) {
|
|
||||||
baseReturnError(c, err, "error")
|
|
||||||
}
|
|
||||||
|
|
||||||
func baseReturnError(c *gin.Context, err error, messageKey string) {
|
|
||||||
switch typedErr := err.(type) {
|
|
||||||
|
|
||||||
case *KolideError:
|
|
||||||
errJSON := map[string]interface{}{}
|
|
||||||
for key, val := range typedErr.Extra {
|
|
||||||
errJSON[key] = val
|
|
||||||
}
|
|
||||||
errJSON[messageKey] = typedErr.PublicMessage
|
|
||||||
|
|
||||||
c.JSON(typedErr.StatusCode, errJSON)
|
|
||||||
logrus.WithError(typedErr.Err).Debug(typedErr.PrivateMessage)
|
|
||||||
|
|
||||||
case validator.ValidationErrors:
|
|
||||||
errors := make([](map[string]string), 0, len(typedErr))
|
|
||||||
for _, fieldErr := range typedErr {
|
|
||||||
m := make(map[string]string)
|
|
||||||
m["field"] = fieldErr.Name
|
|
||||||
m["code"] = "invalid"
|
|
||||||
m["message"] = fieldErr.Tag
|
|
||||||
errors = append(errors, m)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(StatusUnprocessableEntity,
|
|
||||||
gin.H{messageKey: "Validation error",
|
|
||||||
"errors": errors,
|
|
||||||
})
|
|
||||||
logrus.WithError(typedErr).Debug("Validation error")
|
|
||||||
|
|
||||||
default:
|
|
||||||
c.JSON(http.StatusInternalServerError,
|
|
||||||
gin.H{messageKey: "Unspecified error"})
|
|
||||||
logrus.WithError(typedErr).Debug("Unspecified error")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,17 +1,11 @@
|
|||||||
package errors
|
package errors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
|
||||||
"sort"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"gopkg.in/go-playground/validator.v8"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNew(t *testing.T) {
|
func TestNew(t *testing.T) {
|
||||||
@ -66,41 +60,6 @@ func TestDatabaseError(t *testing.T) {
|
|||||||
assert.Equal(t, expect, kolideErr)
|
assert.Equal(t, expect, kolideErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReturnErrorUnspecified(t *testing.T) {
|
|
||||||
r := gin.New()
|
|
||||||
r.POST("/foo", func(c *gin.Context) {
|
|
||||||
ReturnError(c, errors.New("foo"))
|
|
||||||
})
|
|
||||||
|
|
||||||
req, _ := http.NewRequest("POST", "/foo", nil)
|
|
||||||
resp := httptest.NewRecorder()
|
|
||||||
|
|
||||||
r.ServeHTTP(resp, req)
|
|
||||||
assert.Equal(t, http.StatusInternalServerError, resp.Code)
|
|
||||||
|
|
||||||
expect := `{"message": "Unspecified error"}`
|
|
||||||
assert.JSONEq(t, expect, resp.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestReturnErrorKolideError(t *testing.T) {
|
|
||||||
r := gin.New()
|
|
||||||
r.POST("/foo", func(c *gin.Context) {
|
|
||||||
ReturnError(c, &KolideError{
|
|
||||||
StatusCode: http.StatusUnauthorized,
|
|
||||||
PublicMessage: "Some error",
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
req, _ := http.NewRequest("POST", "/foo", nil)
|
|
||||||
resp := httptest.NewRecorder()
|
|
||||||
|
|
||||||
r.ServeHTTP(resp, req)
|
|
||||||
assert.Equal(t, http.StatusUnauthorized, resp.Code)
|
|
||||||
|
|
||||||
expect := `{"message": "Some error"}`
|
|
||||||
assert.JSONEq(t, expect, resp.Body.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// These types and functions for performing an unordered comparison on a
|
// These types and functions for performing an unordered comparison on a
|
||||||
// []map[string]string] as parsed from the error JSON
|
// []map[string]string] as parsed from the error JSON
|
||||||
type errorField map[string]string
|
type errorField map[string]string
|
||||||
@ -119,57 +78,3 @@ func (e errorFields) Less(i, j int) bool {
|
|||||||
func (e errorFields) Swap(i, j int) {
|
func (e errorFields) Swap(i, j int) {
|
||||||
e[i], e[j] = e[j], e[i]
|
e[i], e[j] = e[j], e[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReturnErrorValidationError(t *testing.T) {
|
|
||||||
r := gin.New()
|
|
||||||
|
|
||||||
type Foo struct {
|
|
||||||
Email string `json:"email_foo" validate:"required,email"`
|
|
||||||
Password string `json:"password" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
validate := validator.New(&validator.Config{TagName: "validate", FieldNameTag: "json"})
|
|
||||||
|
|
||||||
r.POST("/foo", func(c *gin.Context) {
|
|
||||||
ReturnError(c, validate.Struct(&Foo{Email: "foo", Password: ""}))
|
|
||||||
})
|
|
||||||
|
|
||||||
req, _ := http.NewRequest("POST", "/foo", nil)
|
|
||||||
resp := httptest.NewRecorder()
|
|
||||||
|
|
||||||
r.ServeHTTP(resp, req)
|
|
||||||
assert.Equal(t, StatusUnprocessableEntity, resp.Code)
|
|
||||||
|
|
||||||
var bodyJson map[string]interface{}
|
|
||||||
err := json.Unmarshal(resp.Body.Bytes(), &bodyJson)
|
|
||||||
assert.Nil(t, err)
|
|
||||||
assert.Equal(t, "Validation error", bodyJson["message"])
|
|
||||||
|
|
||||||
fields, ok := bodyJson["errors"].([]interface{})
|
|
||||||
assert.True(t, ok)
|
|
||||||
|
|
||||||
// The error fields must be copied from []interface{} to
|
|
||||||
// []map[string][string] before we can sort
|
|
||||||
compFields := make(errorFields, 0, 0)
|
|
||||||
for _, field := range fields {
|
|
||||||
field := field.(map[string]interface{})
|
|
||||||
compFields = append(
|
|
||||||
compFields,
|
|
||||||
errorField{
|
|
||||||
"code": field["code"].(string),
|
|
||||||
"field": field["field"].(string),
|
|
||||||
"message": field["message"].(string),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
expect := errorFields{
|
|
||||||
{"code": "invalid", "field": "email_foo", "message": "email"},
|
|
||||||
{"code": "invalid", "field": "password", "message": "required"},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort to standardize ordering before comparison
|
|
||||||
sort.Sort(compFields)
|
|
||||||
sort.Sort(expect)
|
|
||||||
|
|
||||||
assert.Equal(t, expect, compFields)
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user