vnet

package
v0.0.0-...-3b984fc Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2020 License: MIT Imports: 22 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddEndpoint

func AddEndpoint(ep *Endpoint)

AddEndpoint - registers an REST endpoint

func AddEndpoints

func AddEndpoints(eps ...*Endpoint)

AddEndpoints - registers multiple REST categories

func AuditedSend

func AuditedSend(ctx echo.Context, res *Result) (err error)

AuditedSend - sends result as JSON while logging it as event. The event data is same as the data present in the result

func AuditedSendSecret

func AuditedSendSecret(ctx echo.Context, res *Result) (err error)

AuditedSendSecret - Sends result to client and logs everything other than the secret data field

func AuditedSendX

func AuditedSendX(ctx echo.Context, data interface{}, res *Result) (err error)

AuditedSendX - sends result as JSON while logging it as event. This method logs event data which is seperate from result data

func DefMS

func DefMS(oprn string) (int, string)

DefMS - gives default message and status, used for convenience

func DefaultSM

func DefaultSM(opern, name string) (int, string)

DefaultSM - default status and message

func DoLogin

func DoLogin(userID string, password string) (*vsec.User, error)

DoLogin - performs login using username and password

func GetDateRange

func GetDateRange(ctx echo.Context) (dr vcmn.DateRange, err error)

GetDateRange - Retrieve date range from context, assuming that there exist 2 REST params with name from and to respectively

func GetJWTKey

func GetJWTKey() []byte

GetJWTKey - gives a unique JWT key

func GetOffsetLimit

func GetOffsetLimit(ctx echo.Context) (offset, limit int, has bool)

GetOffsetLimit - retrieves offset and limit as integers provided in URL as query parameters. These parameters should have name - offset and limit respectively

func GetQueryParam

func GetQueryParam(ctx echo.Context, name string, def string) (val string)

GetQueryParam - get query param if present otherwise return the default

func GetRootPath

func GetRootPath() string

GetRootPath - get base URL of the configured application's REST Endpoints

func GetString

func GetString(ctx echo.Context, key string) (value string)

GetString - retrieves property with key from context

func GetToken

func GetToken(ctx echo.Context) (token *jwt.Token, err error)

GetToken - gets token from context or from header

func InitWithOptions

func InitWithOptions(opts Options)

InitWithOptions - initializes all the registered endpoints

func IsAdmin

func IsAdmin(ctx echo.Context) (yes bool)

IsAdmin - returns true if user associated with request is an admin

func IsNormalUser

func IsNormalUser(ctx echo.Context) (yes bool)

IsNormalUser - returns true if user is a normal user

func IsSuperUser

func IsSuperUser(ctx echo.Context) (yes bool)

IsSuperUser - returns true if user is a super user

func LoadJSONFromArgs

func LoadJSONFromArgs(ctx echo.Context, param string, out interface{}) (
	err error)

LoadJSONFromArgs - decodes argument identified by 'param' to JSON and unmarshals it into the given 'out' structure

func ModifiedHTTPErrorHandler

func ModifiedHTTPErrorHandler(err error, c echo.Context)

ModifiedHTTPErrorHandler is the default HTTP error handler. It sends a JSON response with status code. [Modefied from echo.DefaultHTTPErrorHandler]

func NoOpAuthenticator

func NoOpAuthenticator(params map[string]interface{}) (*vsec.User, error)

NoOpAuthenticator - authenticator that does not do anything

func NoOpAuthorizer

func NoOpAuthorizer(userID string) (vsec.AuthLevel, error)

NoOpAuthorizer - authorizer that does not do anything

func SendAndAuditOnErr

func SendAndAuditOnErr(ctx echo.Context, res *Result) (err error)

SendAndAuditOnErr - sends the result to client and puts an audit record in audit log if the result is error OR sending failed

func SendEmail

func SendEmail(to, subject, meesage string) (err error)

SendEmail - sends an email with given information. Uses the package level variable emainConfig for SMTP configuration - smtp.gmail.com:587

func Serve

func Serve(port int) (err error)

Serve - start the server

Types

type Authenticator

type Authenticator func(params map[string]interface{}) (*vsec.User, error)

Authenticator - a function that is used to authenticate an user. The function takes map of parameters contents of which will differ based on actual function used

type Authorizer

type Authorizer func(userID string) (vsec.AuthLevel, error)

Authorizer - a function that will be used authorize an user

type BinderFunc

type BinderFunc func(ctx echo.Context) (interface{}, error)

BinderFunc - a function that binds data struct to response body

type Client

type Client struct {
	http.Client
	Address    string
	VersionStr string
	BaseURL    string
	Token      string
	User       *vsec.User
}

Client - client for orek service

func NewClient

func NewClient(address, appName, versionStr string) *Client

NewClient - creates a new rest client

func (*Client) CreateURL

func (client *Client) CreateURL(
	access vsec.AuthLevel,
	args ...string) (str string)

CreateURL - constructs URL from base URL, access level and the given path components

func (*Client) Delete

func (client *Client) Delete(
	access vsec.AuthLevel,
	urlArgs ...string) (rr *ResultReader)

Delete - performs a delete request

func (*Client) Get

func (client *Client) Get(
	access vsec.AuthLevel,
	urlArgs ...string) (rr *ResultReader)

Get - performs a get request

func (*Client) Login

func (client *Client) Login(userID, password string) (err error)

Login - login to a vaali based service with userID and password. If successful client will have the session information and can perform REST calls that needs authentication

func (*Client) Post

func (client *Client) Post(
	content interface{},
	access vsec.AuthLevel,
	urlArgs ...string) (rr *ResultReader)

Post - performs a post request

func (*Client) Put

func (client *Client) Put(
	content interface{},
	access vsec.AuthLevel,
	urlArgs ...string) (rr *ResultReader)

Put - performs a put request

type EmailConfig

type EmailConfig struct {
	AppEMail         string `json:"appEMail"`
	AppEMailPassword string `json:"appEMailPassword"`
	SMTPHost         string `json:"smtpHost"`
	SMTPPort         int    `json:"smtpPort"`
}

EmailConfig - configuration for sending email

type Endpoint

type Endpoint struct {
	OID      bson.ObjectId  `json:"_id"`
	Method   string         `json:"method"`
	URL      string         `json:"url"`
	Access   vsec.AuthLevel `json:"access"`
	Category string         `json:"cateogry"`
	Route    *echo.Route    `json:"route"`
	Comment  string         `json:"Comment"`
	Func     echo.HandlerFunc
}

Endpoint - represents a REST endpoint with associated metadata

func GetEndpoints

func GetEndpoints() (endpoints []*Endpoint)

GetEndpoints - Export app security related APIs

func Merge

func Merge(epss ...[]*Endpoint) (eps []*Endpoint)

Merge - merges multple endpoint arrays

type M

type M map[string]interface{}

M - map of string to interface

type Options

type Options struct {
	RootName      string
	APIVersion    string
	Authenticator Authenticator
	Authorizer    Authorizer
}

Options - options for initializing web APIs

type Result

type Result struct {
	Status int         `json:"status" bson:"status"`
	Op     string      `json:"op" bson:"op"`
	Msg    string      `json:"msg" bson:"msg"`
	OK     bool        `json:"ok" bson:"ok"`
	Err    string      `json:"error" bson:"error"`
	Data   interface{} `json:"data" bson:"data"`
}

Result - result of an API call

type ResultReader

type ResultReader struct {
	RawData []byte
	Err     error
	Res     Result
}

ResultReader - proto result, use it to read the Result with proper data struct

func NewResultReader

func NewResultReader(r *http.Response) (reader *ResultReader)

NewResultReader - creates a new result-reader from response body

func (*ResultReader) Finish

func (rr *ResultReader) Finish() (err error)

Finish - decodes the server response and returns error if it failed. Use this method if data is not expected from server call

func (*ResultReader) Read

func (rr *ResultReader) Read(data interface{}) (err error)

Read - read result data from reader. The provided data object will be populatd with result's data field

type Session

type Session struct {
	UserID   string         `json:"userID"`
	UserName string         `json:"userName"`
	UserType string         `json:"userType"`
	Valid    bool           `json:"valid"`
	Role     vsec.AuthLevel `json:"role"`
}

Session - container for retrieving session & user information from JWT

func RetrieveSessionInfo

func RetrieveSessionInfo(ctx echo.Context) (uinfo Session, err error)

RetrieveSessionInfo - retrieves session information from JWT token

Jump to

Keyboard shortcuts

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