-
Notifications
You must be signed in to change notification settings - Fork 39
/
single.go
65 lines (54 loc) · 1.29 KB
/
single.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package clientsauth
import (
"errors"
"github.com/openrport/openrport/share/enums"
"github.com/openrport/openrport/share/query"
)
type SingleProvider struct {
client *ClientAuth
}
var _ Provider = &SingleProvider{}
func NewSingleProvider(id, password string) *SingleProvider {
return &SingleProvider{
client: &ClientAuth{
ID: id,
Password: password,
},
}
}
func (c *SingleProvider) GetFiltered(filter *query.ListOptions) ([]*ClientAuth, int, error) {
var ca = []*ClientAuth{c.client}
if len(filter.Filters) > 0 {
match, err := query.MatchesFilters(ca[0], filter.Filters)
if err != nil {
return nil, 0, err
}
if match {
return ca, 1, nil
}
return []*ClientAuth{}, 0, nil
}
start, _ := filter.Pagination.GetStartEnd(1)
if start > 0 {
return []*ClientAuth{}, 1, nil
}
return ca, 1, nil
}
func (c *SingleProvider) Get(id string) (*ClientAuth, error) {
if c.client.ID == id {
return c.client, nil
}
return nil, nil
}
func (c *SingleProvider) Add(*ClientAuth) (bool, error) {
return false, errors.New("not implemented")
}
func (c *SingleProvider) Delete(string) error {
return errors.New("not implemented")
}
func (c *SingleProvider) IsWriteable() bool {
return false
}
func (c *SingleProvider) Source() enums.ProviderSource {
return enums.ProviderSourceStatic
}