File tree 2 files changed +9
-14
lines changed
2 files changed +9
-14
lines changed Original file line number Diff line number Diff line change @@ -52,15 +52,9 @@ type Authority interface {
52
52
Version () authority.Version
53
53
}
54
54
55
- var errAuthority = errors .New ("authority is not in context" )
56
-
57
55
// mustAuthority will be replaced on unit tests.
58
56
var mustAuthority = func (ctx context.Context ) Authority {
59
- a , ok := authority .FromContext (ctx )
60
- if ! ok {
61
- panic (errAuthority )
62
- }
63
- return a
57
+ return authority .MustFromContext (ctx )
64
58
}
65
59
66
60
// TimeDuration is an alias of provisioner.TimeDuration
Original file line number Diff line number Diff line change 7
7
"crypto/x509"
8
8
"encoding/hex"
9
9
"log"
10
- "net/http"
11
10
"strings"
12
11
"sync"
13
12
"time"
@@ -167,12 +166,14 @@ func FromContext(ctx context.Context) (a *Authority, ok bool) {
167
166
return
168
167
}
169
168
170
- // Middleware adds the current authority to the request context.
171
- func (a * Authority ) Middleware (next http.Handler ) http.Handler {
172
- return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
173
- ctx := NewContext (r .Context (), a )
174
- next .ServeHTTP (w , r .WithContext (ctx ))
175
- })
169
+ // MustFromContext returns the current authority from the given context. It will
170
+ // panic if the authority is not in the context.
171
+ func MustFromContext (ctx context.Context ) * Authority {
172
+ if a , ok := FromContext (ctx ); ! ok {
173
+ panic ("authority is not in the context" )
174
+ } else {
175
+ return a
176
+ }
176
177
}
177
178
178
179
// reloadAdminResources reloads admins and provisioners from the DB.
You can’t perform that action at this time.
0 commit comments