OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package prpc | 5 package prpc |
6 | 6 |
7 import ( | 7 import ( |
8 "sync" | 8 "sync" |
9 | 9 |
10 "github.com/luci/luci-go/server/auth" | 10 "github.com/luci/luci-go/server/auth" |
11 ) | 11 ) |
12 | 12 |
13 var defaultAuth = struct { | 13 var defaultAuth = struct { |
14 sync.RWMutex | 14 sync.RWMutex |
15 Authenticator auth.Authenticator | 15 Authenticator auth.Authenticator |
16 }{} | 16 }{} |
17 | 17 |
18 // RegisterDefaultAuth sets a default authenticator that is used unless | 18 // RegisterDefaultAuth sets a default authenticator that is used unless |
19 // Server.CustomAuthenticator is true. | 19 // Server.CustomAuthenticator is true. |
20 // Panics if a is nil or called twice. | 20 // Panics if a is nil or called twice. |
21 func RegisterDefaultAuth(a auth.Authenticator) { | 21 func RegisterDefaultAuth(a auth.Authenticator) { |
22 if a == nil { | 22 if a == nil { |
23 » » panicf("a is nil") | 23 » » panic("a is nil") |
24 } | 24 } |
25 defaultAuth.Lock() | 25 defaultAuth.Lock() |
26 defer defaultAuth.Unlock() | 26 defer defaultAuth.Unlock() |
27 if defaultAuth.Authenticator != nil { | 27 if defaultAuth.Authenticator != nil { |
28 » » panicf("default prpc authenticator is already set") | 28 » » panic("default prpc authenticator is already set") |
29 } | 29 } |
30 defaultAuth.Authenticator = a | 30 defaultAuth.Authenticator = a |
31 } | 31 } |
32 | 32 |
33 // GetDefaultAuth returns the default authenticator set by RegisterDefaultAuth | 33 // GetDefaultAuth returns the default authenticator set by RegisterDefaultAuth |
34 // or nil if not registered. | 34 // or nil if not registered. |
35 func GetDefaultAuth() auth.Authenticator { | 35 func GetDefaultAuth() auth.Authenticator { |
36 defaultAuth.RLock() | 36 defaultAuth.RLock() |
37 defer defaultAuth.RUnlock() | 37 defer defaultAuth.RUnlock() |
38 return defaultAuth.Authenticator | 38 return defaultAuth.Authenticator |
39 } | 39 } |
OLD | NEW |