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

30 lines
812 B
Go

package connection
import (
"git.openprivacy.ca/openprivacy/libricochet-go/utils"
)
// AuthorizationManager helps keep track of permissions for a connection
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
}