service

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2019 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAccess = errors.New("access denied")

ErrNoAccess means user doesn't have necessary permissions for a resource

Functions

func GetUserID

func GetUserID(ctx context.Context) (int, error)

GetUserID gets the user ID set by the JWT middleware in the Context

func NewLogger

func NewLogger(env string) *logrus.Logger

NewLogger returns a logrus Logger

func ReplaceInvisible added in v0.0.6

func ReplaceInvisible(content string) string

ReplaceInvisible preprocessor function that replace invisible character with visible onces

func SetUserID added in v0.0.4

func SetUserID(ctx context.Context, userID int) context.Context

SetUserID sets the user ID to the context

Types

type ACL

type ACL struct {
	// contains filtered or unexported fields
}

ACL allows to manage permissions for user role

func NewACL

func NewACL(usersRepo *repository.Users, role model.Role) *ACL

NewACL creates new ACL service

func (*ACL) Middleware

func (s *ACL) Middleware(next http.Handler) http.Handler

Middleware provides middleware which allows requests only for user only with selected role

type Diff added in v0.0.4

type Diff struct {
	// contains filtered or unexported fields
}

Diff service generates diff for files

func NewDiff added in v0.0.4

func NewDiff() *Diff

NewDiff creates Diff service

func (*Diff) Generate added in v0.0.4

func (d *Diff) Generate(nameA, nameB, contentA, contentB string, preprocessors ...DiffPreprocessorFunc) (string, error)

Generate return unified diff string for 2 files

type DiffPreprocessorFunc added in v0.0.6

type DiffPreprocessorFunc func(string) string

DiffPreprocessorFunc type is function signature to preprocess diffs

type GithubUser added in v0.0.1

type GithubUser struct {
	ID        int        `json:"id"`
	Login     string     `json:"login"`
	Username  string     `json:"name"`
	AvatarURL string     `json:"avatar_url"`
	Role      model.Role `json:"-"`
}

GithubUser represents the user response returned by the GitHub auth.

type JWT

type JWT struct {
	// contains filtered or unexported fields
}

JWT service abstracts JWT implementation

func NewJWT

func NewJWT(signingKey string) *JWT

NewJWT return new JWT service

func (*JWT) MakeToken

func (j *JWT) MakeToken(user *model.User) (string, error)

MakeToken generates token string for a user

func (*JWT) Middleware

func (j *JWT) Middleware(next http.Handler) http.Handler

Middleware return http.Handler which validates token and set user id in context

type JWTConfig

type JWTConfig struct {
	SigningKey string `envconfig:"SIGNING_KEY" required:"true"`
}

JWTConfig defines enviroment variables for JWT

type OAuth

type OAuth struct {
	// contains filtered or unexported fields
}

OAuth service abstracts OAuth implementation

func NewOAuth

func NewOAuth(clientID, clientSecret, restrictAccess, restrictRequesterAccess string) *OAuth

NewOAuth return new OAuth service

func (*OAuth) GetUser

func (o *OAuth) GetUser(ctx context.Context, code string) (*GithubUser, error)

GetUser gets user from provider and return user model

func (*OAuth) MakeAuthURL

func (o *OAuth) MakeAuthURL(w http.ResponseWriter, r *http.Request) (string, error)

MakeAuthURL returns string for redirect to provider

func (*OAuth) ValidateState

func (o *OAuth) ValidateState(r *http.Request, state string) error

ValidateState protects the user from CSRF attacks

type OAuthConfig

type OAuthConfig struct {
	ClientID                string `envconfig:"CLIENT_ID" required:"true"`
	ClientSecret            string `envconfig:"CLIENT_SECRET" required:"true"`
	RestrictAccess          string `envconfig:"RESTRICT_ACCESS"`
	RestrictRequesterAccess string `envconfig:"RESTRICT_REQUESTER_ACCESS"`
}

OAuthConfig defines enviroment variables for OAuth

Jump to

Keyboard shortcuts

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