This repository has been archived on 2020-04-20. You can view files and clone it, but cannot push or open issues or pull requests.
libricochet-go/connection/authorizationmanager.go

29 lines
722 B
Go
Raw Normal View History

package connection
import (
"github.com/s-rah/go-ricochet/utils"
)
type AuthorizationManager struct {
Authorizations map[string]bool
}
// Init sets up an AuthorizationManager to be used.
func (am *AuthorizationManager) Init() {
am.Authorizations = make(map[string]bool)
}
// AddAuthorization adds the string authz to the map of allowed authorizations
func (am *AuthorizationManager) AddAuthorization(authz string) {
am.Authorizations[authz] = true
}
// Authorized returns no error in the case an authz type is authorized, error otherwise.
func (am *AuthorizationManager) Authorized(authz string) error {
_, authed := am.Authorizations[authz]
if !authed {
return utils.UnauthorizedActionError
}
return nil
}