Skip to content

Commit

Permalink
add authorisation
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesjarvis committed Sep 25, 2024
1 parent e24885d commit e58f3f3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 33,10 @@ func New(
// Get accepts a user and a key, and returns either the value associated with that key,
// or an error if encountered.
func (s *Service) Get(userID string, key string) (string, error) {
if !s.access.Check(userID, "get") {
return "", Error_UNAUTHORISED
}

value, ok := s.storage.Get(key)
if !ok {
return "", fmt.Errorf("error:%w key:%q", Error_NOTFOUND, key)
Expand All @@ -43,6 47,10 @@ func (s *Service) Get(userID string, key string) (string, error) {
// Set accepts a user, key and value, and will attempt to set the value with that key,
// or return an error if encountered.
func (s *Service) Set(userID, key, value string) error {
if !s.access.Check(userID, "set") {
return Error_UNAUTHORISED
}

s.storage.Set(key, value)
return nil
}

0 comments on commit e58f3f3

Please sign in to comment.