-
Notifications
You must be signed in to change notification settings - Fork 3
/
auth.go
53 lines (41 loc) · 1.21 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package sabnzbd
import (
"fmt"
"mime/multipart"
"net/url"
)
// authenticator adds authentication parameters to a url
type authenticator interface {
Authenticate(url.Values)
AuthenticateMultipart(*multipart.Writer) error
fmt.Stringer
}
type noneAuth struct{}
func (a noneAuth) Authenticate(v url.Values) {}
func (a noneAuth) AuthenticateMultipart(m *multipart.Writer) error { return nil }
func (a noneAuth) String() string { return "None" }
type apikeyAuth struct {
Apikey string
}
func (a apikeyAuth) Authenticate(v url.Values) {
v.Set("apikey", a.Apikey)
}
func (a apikeyAuth) AuthenticateMultipart(m *multipart.Writer) error {
return m.WriteField("apikey", a.Apikey)
}
func (a apikeyAuth) String() string { return "apikey" }
type loginAuth struct {
Username string
Password string
}
func (a loginAuth) Authenticate(v url.Values) {
v.Set("ma_username", a.Username)
v.Set("ma_password", a.Password)
}
func (a loginAuth) AuthenticateMultipart(m *multipart.Writer) error {
if err := m.WriteField("ma_username", a.Username); err != nil {
return err
}
return m.WriteField("ma_password", a.Password)
}
func (a loginAuth) String() string { return "login" }