util

package
v0.0.0-...-1927dbb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JWTSecret defines default JWT secret
	JWTSecret = "istioIsAwesome"
)

Variables

View Source
var Authentication = func(r *http.Request) (model.User, error) {
	t, e := request.ParseFromRequest(r, request.OAuth2Extractor, func(token *jwt.Token) (interface{}, error) {
		b := []byte(JWTSecret)
		return b, nil
	})
	if e != nil {
		return model.User{}, ErrJWTUnauthorized
	}

	username := t.Claims.(jwt.MapClaims)["username"].(string)
	u, ok := model.MockUsers[username]
	if !ok {
		return model.User{}, ErrJWTUnauthorized
	}
	return u, nil
}

Authentication authenticates incoming request.

View Source
var BindFailFn = func(c *gin.Context, e error) {
	log.Info("[BindFailFn]", "err", e)
	c.JSON(http.StatusBadRequest, gin.H{
		"code": 1,
		"data": e.Error(),
	})
}

BindFailFn defines function that handle payload-binding failure.

View Source
var (
	// ErrJWTUnauthorized is returned when the token isn't authorized.
	ErrJWTUnauthorized = errors.New("unauthorized")
)
View Source
var OpFailFn = func(c *gin.Context, e error) {
	log.Info("[OpFailFn]", "err", e)
	c.JSON(http.StatusInternalServerError, gin.H{
		"code": 2,
		"data": e.Error(),
	})
}

OpFailFn defines function that handle internal error.

View Source
var RetOK = map[string]interface{}{"code": 0, "data": struct{}{}}

RetOK defines JSON response of successful HTTP response.

Functions

func Home

func Home() string

Home returns home path.

func Kubeconfig

func Kubeconfig() string

Kubeconfig returns kube config path.

func User

func User(c *gin.Context) model.User

User returns current login user.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL