-
Notifications
You must be signed in to change notification settings - Fork 338
/
auth.go
33 lines (30 loc) · 863 Bytes
/
auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright 2021 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mock
type Auth struct {
AuthorizeFunc func(string) bool
GenerateKeyFunc func(string) (string, error)
EnforceFunc func(string, string, string) (bool, error)
}
func (ma *Auth) Authorize(u string) bool {
if ma.AuthorizeFunc == nil {
return true
}
return ma.AuthorizeFunc(u)
}
func (ma *Auth) GenerateKey(k string, _ int) (string, error) {
if ma.GenerateKeyFunc == nil {
return "", nil
}
return ma.GenerateKeyFunc(k)
}
func (ma *Auth) RefreshKey(k string, _ int) (string, error) {
if ma.GenerateKeyFunc == nil {
return "", nil
}
return ma.GenerateKeyFunc(k)
}
func (ma *Auth) Enforce(a1 string, a2 string, a3 string) (bool, error) {
return ma.EnforceFunc(a1, a2, a3)
}