role

package
v1.0.0-beta.7 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestHelperManagers

func TestHelperManagers(m Manager) func(t *testing.T)

Types

type Handler

type Handler struct {
	Manager Manager
	H       herodot.Writer
}

func NewHandler

func NewHandler(manager Manager, writer herodot.Writer) *Handler

func (*Handler) AddRoleMembers

func (h *Handler) AddRoleMembers(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

swagger:route POST /roles/{id}/members role addMembersToRole

Add members to a role

A Role represents a group of users that share the same role and thus permissions. A role could be an administrator, a moderator, a regular user or some other sort of role.

This endpoint allows you to add members (users, applications, ...) to a specific role. You have to know the role's ID.

Consumes:
- application/json

Produces:
- application/json

Schemes: http, https

Responses:
  204: emptyResponse
  401: genericError
  403: genericError
  500: genericError

func (*Handler) CreateRole

func (h *Handler) CreateRole(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

swagger:route POST /roles role createRole

Create a role

A Role represents a group of users that share the same role and thus permissions. A role could be an administrator, a moderator, a regular user or some other sort of role.

This endpoint allows you to create a new role. You may define members as well but you don't have to.

Consumes:
- application/json

Produces:
- application/json

Schemes: http, https

Responses:
  201: role
  401: genericError
  403: genericError
  500: genericError

func (*Handler) DeleteRole

func (h *Handler) DeleteRole(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

swagger:route DELETE /roles/{id} role deleteRole

Get a role by its ID

A Role represents a group of users that share the same role and thus permissions. A role could be an administrator, a moderator, a regular user or some other sort of role.

This endpoint allows you to delete an existing role. You have to know the role's ID.

Consumes:
- application/json

Produces:
- application/json

Schemes: http, https

Responses:
  204: emptyResponse
  401: genericError
  403: genericError
  500: genericError

func (*Handler) DeleteRoleMembers

func (h *Handler) DeleteRoleMembers(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

swagger:route DELETE /roles/{id}/members role removeMembersFromRole

Remove members from a role

A Role represents a group of users that share the same role and thus permissions. A role could be an administrator, a moderator, a regular user or some other sort of role.

This endpoint allows you to remove members (users, applications, ...) from a specific role. You have to know the role's ID.

Consumes:
- application/json

Produces:
- application/json

Schemes: http, https

Responses:
  204: emptyResponse
  401: genericError
  403: genericError
  500: genericError

func (*Handler) FindGroupNames

func (h *Handler) FindGroupNames(w http.ResponseWriter, r *http.Request, member string, limit, offset int)

func (*Handler) GetRole

func (h *Handler) GetRole(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

swagger:route GET /roles/{id} role getRole

Get a role by its ID

A Role represents a group of users that share the same role and thus permissions. A role could be an administrator, a moderator, a regular user or some other sort of role.

This endpoint allows you to retrieve an existing role. You have to know the role's ID.

Consumes:
- application/json

Produces:
- application/json

Schemes: http, https

Responses:
  201: role
  401: genericError
  403: genericError
  500: genericError

func (*Handler) ListRoles

func (h *Handler) ListRoles(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

swagger:route GET /roles role listRoles

List all roles

A Role represents a group of users that share the same role and thus permissions. A role could be an administrator, a moderator, a regular user or some other sort of role.

This endpoint allows you to retrieve all roles that are stored in the system.

Consumes:
- application/json

Produces:
- application/json

Schemes: http, https

Responses:
  200: listRolesResponse
  401: genericError
  403: genericError
  500: genericError

func (*Handler) SetRoutes

func (h *Handler) SetRoutes(r *httprouter.Router)

func (*Handler) UpdateRole

func (h *Handler) UpdateRole(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

swagger:route PUT /roles/{id} role setRole

A Role represents a group of users that share the same role and thus permissions. A role could be an administrator, a moderator, a regular user or some other sort of role.

This endpoint allows you to overwrite a role. You have to know the role's ID.

Consumes:
- application/json

Produces:
- application/json

Schemes: http, https

Responses:
  204: emptyResponse
  401: genericError
  403: genericError
  500: genericError

type Manager

type Manager interface {
	CreateRole(*Role) error
	GetRole(id string) (*Role, error)
	DeleteRole(id string) error

	AddRoleMembers(role string, members []string) error
	RemoveRoleMembers(role string, members []string) error

	FindRolesByMember(member string, limit, offset int) ([]Role, error)
	ListRoles(limit, offset int) ([]Role, error)
	UpdateRole(role Role) error
}

type MemoryManager

type MemoryManager struct {
	Roles map[string]Role
	sync.RWMutex
}

func NewMemoryManager

func NewMemoryManager() *MemoryManager

func (*MemoryManager) AddRoleMembers

func (m *MemoryManager) AddRoleMembers(role string, subjects []string) error

func (*MemoryManager) CreateRole

func (m *MemoryManager) CreateRole(r *Role) error

func (*MemoryManager) DeleteRole

func (m *MemoryManager) DeleteRole(id string) error

func (*MemoryManager) FindRolesByMember

func (m *MemoryManager) FindRolesByMember(member string, limit, offset int) ([]Role, error)

func (*MemoryManager) GetRole

func (m *MemoryManager) GetRole(id string) (*Role, error)

func (*MemoryManager) ListRoles

func (m *MemoryManager) ListRoles(limit, offset int) ([]Role, error)

func (*MemoryManager) RemoveRoleMembers

func (m *MemoryManager) RemoveRoleMembers(role string, subjects []string) error

func (*MemoryManager) UpdateRole

func (m *MemoryManager) UpdateRole(role Role) error

type Role

type Role struct {
	// ID is the role's unique id.
	ID string `json:"id"`

	// Members is who belongs to the role.
	Members []string `json:"members"`
}

Role represents a group of users that share the same role. A role could be an administrator, a moderator, a regular user or some other sort of role.

swagger:model role

type SQLManager

type SQLManager struct {
	DB *sqlx.DB

	TableRole      string
	TableMember    string
	TableMigration string
}

func NewSQLManager

func NewSQLManager(db *sqlx.DB) *SQLManager

func (*SQLManager) AddRoleMembers

func (m *SQLManager) AddRoleMembers(role string, subjects []string) error

func (*SQLManager) CreateRole

func (m *SQLManager) CreateRole(r *Role) error

func (*SQLManager) CreateSchemas

func (m *SQLManager) CreateSchemas() (int, error)

func (*SQLManager) DeleteRole

func (m *SQLManager) DeleteRole(id string) error

func (*SQLManager) FindRolesByMember

func (m *SQLManager) FindRolesByMember(member string, limit, offset int) ([]Role, error)

func (*SQLManager) GetRole

func (m *SQLManager) GetRole(id string) (*Role, error)

func (*SQLManager) ListRoles

func (m *SQLManager) ListRoles(limit, offset int) ([]Role, error)

func (*SQLManager) RemoveRoleMembers

func (m *SQLManager) RemoveRoleMembers(role string, subjects []string) error

func (*SQLManager) UpdateRole

func (m *SQLManager) UpdateRole(role Role) error

Jump to

Keyboard shortcuts

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