users

package
v0.0.0-...-058eff9 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package users provides primitives to interact with the openapi HTTP API.

Code generated by github.com/deepmap/oapi-codegen version v1.11.0 DO NOT EDIT.

Package users provides primitives to interact with the openapi HTTP API.

Code generated by github.com/deepmap/oapi-codegen version v1.11.0 DO NOT EDIT.

Index

Constants

View Source
const (
	JWTAuthScopes = "JWTAuth.Scopes"
)

Variables

View Source
var ErrUsernameNotFound = errors.New("username does not exist")

Functions

func GetErrorF

func GetErrorF(errMsg string, err error) error

func RegisterHandlers

func RegisterHandlers(router EchoRouter, si ServerInterface)

RegisterHandlers adds each server route to the EchoRouter.

func RegisterHandlersWithBaseURL

func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string)

Registers handlers, and prepends BaseURL to the paths, so that the paths can be served under a prefix.

Types

type EchoRouter

type EchoRouter interface {
	CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
}

This is a simple interface which specifies echo.Route addition functions which are present on both echo.Echo and echo.Group, since we want to allow using either of them for path registration

type Error

type Error struct {
	Code    int32  `json:"code"`
	Message string `json:"message"`
}

Error defines model for Error.

type Group

type Group struct {
	Comment              *string    `json:"comment,omitempty"`
	CreateTime           time.Time  `json:"create_time"`
	Creator              int32      `json:"creator"`
	Id                   int32      `json:"id"`
	InactivationReason   *string    `json:"inactivation_reason,omitempty"`
	InactivationTime     *time.Time `json:"inactivation_time,omitempty"`
	IsActive             bool       `json:"is_active"`
	LastModificationTime *time.Time `json:"last_modification_time,omitempty"`
	LastModificationUser *int32     `json:"last_modification_user,omitempty"`
	Name                 string     `json:"name"`
}

Group defines model for Group.

type GroupCreateJSONBody

type GroupCreateJSONBody = Group

GroupCreateJSONBody defines parameters for GroupCreate.

type GroupCreateJSONRequestBody

type GroupCreateJSONRequestBody = GroupCreateJSONBody

GroupCreateJSONRequestBody defines body for GroupCreate for application/json ContentType.

type GroupList

type GroupList struct {
	Id       int32  `json:"id"`
	IsActive bool   `json:"is_active"`
	Name     string `json:"name"`
}

GroupList defines model for GroupList.

type GroupListParams

type GroupListParams struct {
	// maximum number of results to return
	Limit *int32 `form:"limit,omitempty" json:"limit,omitempty"`
}

GroupListParams defines parameters for GroupList.

type JwtCustomClaims

type JwtCustomClaims struct {
	jwt.RegisteredClaims
	Id       int32  `json:"id"`
	Name     string `json:"name"`
	Email    string `json:"email"`
	Username string `json:"username"`
	IsAdmin  bool   `json:"is_admin"`
}

JwtCustomClaims are custom claims extending default ones.

type PGX

type PGX struct {
	Db *database.PgxDB
	// contains filtered or unexported fields
}

func (*PGX) Close

func (db *PGX) Close()

Close will close the database store

func (*PGX) Count

func (db *PGX) Count() (int32, error)

Count returns the number of users stored in DB

func (*PGX) Create

func (db *PGX) Create(u User) (*User, error)

Create will store the new user in the store

func (*PGX) CreateGroup

func (db *PGX) CreateGroup(g Group) (*Group, error)

CreateGroup saves a new group in the storage.

func (*PGX) Delete

func (db *PGX) Delete(id int32) error

Delete the users stored in DB with given id

func (*PGX) DeleteGroup

func (db *PGX) DeleteGroup(id int32) error

DeleteGroup removes the group with given ID from the storage.

func (*PGX) Exist

func (db *PGX) Exist(id int32) bool

Exist returns true only if a users with the specified id exists in store.

func (*PGX) FindUsername

func (db *PGX) FindUsername(username string) (int32, error)

FindUsername retrieves the user id for the given username or err if not found.

func (*PGX) Get

func (db *PGX) Get(id int32) (*User, error)

Get will retrieve one user with given id

func (*PGX) GetGroup

func (db *PGX) GetGroup(id int32) (*Group, error)

GetGroup returns the group with the specified users ID.

func (*PGX) GetMaxId

func (db *PGX) GetMaxId() (int32, error)

GetMaxId returns the maximum value of users id existing in store.

func (*PGX) IsUserActive

func (db *PGX) IsUserActive(idUser int32) bool

IsUserActive returns true if the user with the specified id has the is_active attribute set to true

func (*PGX) IsUserAdmin

func (db *PGX) IsUserAdmin(idUser int32) bool

IsUserAdmin returns true if the user with the specified id has the is_admin attribute set to true

func (*PGX) List

func (db *PGX) List(offset, limit int) ([]*UserList, error)

List will retrieve all users in the store

func (*PGX) ListGroup

func (db *PGX) ListGroup(offset, limit int) ([]*GroupList, error)

ListGroup will retrieve all groups in the store

func (*PGX) ResetPassword

func (db *PGX) ResetPassword(id int32, passwordHash string, idCurrentUser int) error

ResetPassword the user password stored in DB for given id

func (*PGX) Update

func (db *PGX) Update(id int32, user User) (*User, error)

Update the users stored in DB with given id and other information in struct

func (*PGX) UpdateGroup

func (db *PGX) UpdateGroup(id int32, group Group) (*Group, error)

UpdateGroup updates the group with given ID in the storage.

type ServerInterface

type ServerInterface interface {
	// GroupList returns a list of groups
	// (GET /groups)
	GroupList(ctx echo.Context, params GroupListParams) error
	// GroupCreate will create a new group
	// (POST /groups)
	GroupCreate(ctx echo.Context) error
	// GroupDelete allows to delete a specific groupId
	// (DELETE /groups/{groupId})
	GroupDelete(ctx echo.Context, groupId int32) error
	// GroupGet will retrieve in backend all information about a specific groupId
	// (GET /groups/{groupId})
	GroupGet(ctx echo.Context, groupId int32) error
	// GroupUpdate allows to modify information about a specific groupId
	// (PUT /groups/{groupId})
	GroupUpdate(ctx echo.Context, groupId int32) error
	// UserList returns a list of users
	// (GET /users)
	UserList(ctx echo.Context, params UserListParams) error
	// UserCreate will create a new user
	// (POST /users)
	UserCreate(ctx echo.Context) error
	// UserDelete allows to delete a specific userId
	// (DELETE /users/{userId})
	UserDelete(ctx echo.Context, userId int32) error
	// UserGet will retrieve in backend all information about a specific userId
	// (GET /users/{userId})
	UserGet(ctx echo.Context, userId int32) error
	// UserUpdate allows to modify information about a specific userId
	// (PUT /users/{userId})
	UserUpdate(ctx echo.Context, userId int32) error
	// UserChangePassword allows a user to change it's own password
	// (PUT /users/{userId}/changepassword)
	UserChangePassword(ctx echo.Context, userId int32) error
}

ServerInterface represents all server handlers.

type ServerInterfaceWrapper

type ServerInterfaceWrapper struct {
	Handler ServerInterface
}

ServerInterfaceWrapper converts echo contexts to parameters.

func (*ServerInterfaceWrapper) GroupCreate

func (w *ServerInterfaceWrapper) GroupCreate(ctx echo.Context) error

GroupCreate converts echo context to params.

func (*ServerInterfaceWrapper) GroupDelete

func (w *ServerInterfaceWrapper) GroupDelete(ctx echo.Context) error

GroupDelete converts echo context to params.

func (*ServerInterfaceWrapper) GroupGet

func (w *ServerInterfaceWrapper) GroupGet(ctx echo.Context) error

GroupGet converts echo context to params.

func (*ServerInterfaceWrapper) GroupList

func (w *ServerInterfaceWrapper) GroupList(ctx echo.Context) error

GroupList converts echo context to params.

func (*ServerInterfaceWrapper) GroupUpdate

func (w *ServerInterfaceWrapper) GroupUpdate(ctx echo.Context) error

GroupUpdate converts echo context to params.

func (*ServerInterfaceWrapper) UserChangePassword

func (w *ServerInterfaceWrapper) UserChangePassword(ctx echo.Context) error

UserChangePassword converts echo context to params.

func (*ServerInterfaceWrapper) UserCreate

func (w *ServerInterfaceWrapper) UserCreate(ctx echo.Context) error

UserCreate converts echo context to params.

func (*ServerInterfaceWrapper) UserDelete

func (w *ServerInterfaceWrapper) UserDelete(ctx echo.Context) error

UserDelete converts echo context to params.

func (*ServerInterfaceWrapper) UserGet

func (w *ServerInterfaceWrapper) UserGet(ctx echo.Context) error

UserGet converts echo context to params.

func (*ServerInterfaceWrapper) UserList

func (w *ServerInterfaceWrapper) UserList(ctx echo.Context) error

UserList converts echo context to params.

func (*ServerInterfaceWrapper) UserUpdate

func (w *ServerInterfaceWrapper) UserUpdate(ctx echo.Context) error

UserUpdate converts echo context to params.

type Service

type Service struct {
	Log         *log.Logger
	Store       Storage
	JwtSecret   []byte
	JwtDuration int
}

func (Service) GetLogin

func (s Service) GetLogin(ctx echo.Context) error

GetLogin allows client to do a preflight prepare for a login (GET /login)

func (Service) GetMaxId

func (s Service) GetMaxId(ctx echo.Context) error

GetMaxId returns the greatest users id used by now curl -H "Content-Type: application/json" 'http://localhost:8888/users/maxid'

func (Service) GetResetPasswordEmail

func (s Service) GetResetPasswordEmail(ctx echo.Context) error

func (Service) GetResetPasswordToken

func (s Service) GetResetPasswordToken(ctx echo.Context) error

func (Service) GetStatus

func (s Service) GetStatus(ctx echo.Context) error

func (Service) GroupCreate

func (s Service) GroupCreate(ctx echo.Context) error

GroupCreate will store a new Group in the store

func (Service) GroupDelete

func (s Service) GroupDelete(ctx echo.Context, id int32) error

GroupDelete will remove the given id entry from the store, and if not present will return 400 Bad Request curl -v -XDELETE -H "Content-Type: application/json" -H "Authorization: Bearer $token" 'http://localhost:8888/api/groups/3' -> 204 No Content if present and delete it

func (Service) GroupGet

func (s Service) GroupGet(ctx echo.Context, id int32) error

GroupGet will retrieve the Group in the store and return then to test it with curl you can try : curl -s -H "Content-Type: application/json" -H "Authorization: Bearer $token" 'http://localhost:8888/api/users' |jq

func (Service) GroupList

func (s Service) GroupList(ctx echo.Context, params GroupListParams) error

GroupList will retrieve all Groups in the store and return then

func (Service) GroupUpdate

func (s Service) GroupUpdate(ctx echo.Context, id int32) error

GroupUpdate will store the modified information in the store for the given id

func (Service) LoginUser

func (s Service) LoginUser(ctx echo.Context) error

LoginUser allows client to try to authenticate, and then receive a valid JWT curl -X POST -H "Content-Type: application/json" -d '{"username": "go-admin", "password_hash": "your_pwd_hash" }' http://localhost:8888/login with the received token you can try : curl -H "Authorization: Bearer $token " http://localhost:8888/restricted

func (Service) ResetPassword

func (s Service) ResetPassword(ctx echo.Context) error

func (Service) SendResetPassword

func (s Service) SendResetPassword(ctx echo.Context) error

func (Service) UserChangePassword

func (s Service) UserChangePassword(ctx echo.Context, userId int32) error

UserChangePassword allows a user to change it's own password (PUT /api/users/{userId}/changepassword)

func (Service) UserCreate

func (s Service) UserCreate(ctx echo.Context) error

UserCreate will store a new User in the store

to test it with curl you can try :

curl -s -XPOST -H "Content-Type: application/json" -H "Authorization: Bearer $token" \ -d '{"username":"cgil", "name":"Carlos GIL", "email":"c@gil.town", "password_hash":"4acf0b39d9c4766709a3689f553ac01ab550545ffa4544dfc0b2cea82fba02a3"}' 'http://localhost:8888/api/users'

func (Service) UserDelete

func (s Service) UserDelete(ctx echo.Context, userId int32) error

UserDelete will remove the given userID entry from the store, and if not present will return 400 Bad Request curl -v -XDELETE -H "Content-Type: application/json" -H "Authorization: Bearer $token" 'http://localhost:8888/api/users/3' -> 204 No Content if present and delete it curl -v -XDELETE -H "Content-Type: application/json" -H "Authorization: Bearer $token" 'http://localhost:8888/users/93333' -> 400 Bad Request

func (Service) UserGet

func (s Service) UserGet(ctx echo.Context, userId int32) error

UserGet will retrieve the User in the store and return then to test it with curl you can try : curl -s -H "Content-Type: application/json" -H "Authorization: Bearer $token" 'http://localhost:8888/api/users' |jq

func (Service) UserList

func (s Service) UserList(ctx echo.Context, params UserListParams) error

UserList will retrieve all Users in the store and return then to test it with curl you can try : curl -s -H "Content-Type: application/json" -H "Authorization: Bearer $token" 'http://localhost:8888/api/users' |jq

func (Service) UserUpdate

func (s Service) UserUpdate(ctx echo.Context, userId int32) error

UserUpdate will store the modified information in the store for the given userId curl -v -XPUT -H "Content-Type: application/json" -d '{"id": 3, "task":"learn Linux", "completed": true}' 'http://localhost:8888/users/3' curl -v -XPUT -H "Content-Type: application/json" -d '{"id": 3, "task":"learn Linux", "completed": false}' 'http://localhost:8888/users/3'

type Storage

type Storage interface {
	// List returns the list of existing users with the given offset and limit.
	List(offset, limit int) ([]*UserList, error)
	// Get returns the users with the specified users ID.
	Get(id int32) (*User, error)
	// GetMaxId returns the maximum value of users id existing in store.
	GetMaxId() (int32, error)
	// Exist returns true only if a users with the specified id exists in store.
	Exist(id int32) bool
	// Count returns the total number of users.
	Count() (int32, error)
	// Create saves a new users in the storage.
	Create(user User) (*User, error)
	// Update updates the users with given ID in the storage.
	Update(id int32, user User) (*User, error)
	// Delete removes the users with given ID from the storage.
	Delete(id int32) error
	// FindUsername retrieves the user id for the given username or err if not found
	FindUsername(username string) (int32, error)
	// Close terminates properly the connection to the backend
	Close()
	// IsUserAdmin returns true if the user with the specified id has the is_admin attribute set to true
	IsUserAdmin(id int32) bool
	// IsUserActive returns true if the user with the specified id has the is_active attribute set to true
	IsUserActive(id int32) bool
	// CreateGroup saves a new group in the storage.
	CreateGroup(group Group) (*Group, error)
	// UpdateGroup updates the group with given ID in the storage.
	UpdateGroup(id int32, group Group) (*Group, error)
	// DeleteGroup removes the group with given ID from the storage.
	DeleteGroup(id int32) error
	// ListGroup returns the list of active groups with the given offset and limit.
	ListGroup(offset, limit int) ([]*GroupList, error)
	// GetGroup returns the group with the specified users ID.
	GetGroup(id int32) (*Group, error)
}

Storage is an interface to different implementation of persistence for Users/Groups

func GetStorageInstance

func GetStorageInstance(dbDriver, dbConnectionString string, log *log.Logger) (Storage, error)

func NewPgxDB

func NewPgxDB(dbConnectionString string, maxConnectionsInPool int, log *log.Logger) (Storage, error)

NewPgxDB will instantiate a new storage of type postgres and ensure schema exist

type User

type User struct {
	BadPasswordCount     int32               `json:"bad_password_count"`
	Comment              *string             `json:"comment,omitempty"`
	CreateTime           time.Time           `json:"create_time"`
	Creator              int32               `json:"creator"`
	Email                openapi_types.Email `json:"email"`
	ExternalId           *int32              `json:"external_id,omitempty"`
	GroupsId             *[]int32            `json:"groups_id,omitempty"`
	Id                   int32               `json:"id"`
	InactivationReason   *string             `json:"inactivation_reason,omitempty"`
	InactivationTime     *time.Time          `json:"inactivation_time,omitempty"`
	IsActive             bool                `json:"is_active"`
	IsAdmin              bool                `json:"is_admin"`
	IsLocked             bool                `json:"is_locked"`
	LastModificationTime *time.Time          `json:"last_modification_time,omitempty"`
	LastModificationUser *int32              `json:"last_modification_user,omitempty"`
	Name                 string              `json:"name"`
	OrgunitId            *int32              `json:"orgunit_id,omitempty"`
	PasswordHash         string              `json:"password_hash"`
	Phone                *string             `json:"phone,omitempty"`
	Username             string              `json:"username"`
}

User defines model for User.

type UserCreateJSONBody

type UserCreateJSONBody = User

UserCreateJSONBody defines parameters for UserCreate.

type UserCreateJSONRequestBody

type UserCreateJSONRequestBody = UserCreateJSONBody

UserCreateJSONRequestBody defines body for UserCreate for application/json ContentType.

type UserList

type UserList struct {
	CreateTime time.Time           `json:"create_time"`
	Creator    int32               `json:"creator"`
	Email      openapi_types.Email `json:"email"`
	Id         int32               `json:"id"`
	IsActive   bool                `json:"is_active"`
	IsAdmin    bool                `json:"is_admin"`
	IsLocked   bool                `json:"is_locked"`
	Name       string              `json:"name"`
	Username   string              `json:"username"`
}

UserList defines model for UserList.

type UserListParams

type UserListParams struct {
	// maximum number of results to return
	Limit *int32 `form:"limit,omitempty" json:"limit,omitempty"`
}

UserListParams defines parameters for UserList.

type UserLogin

type UserLogin struct {
	PasswordHash string `json:"password_hash"`
	Username     string `json:"username"`
}

UserLogin defines model for UserLogin.

Jump to

Keyboard shortcuts

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