forked from kyma-incubator/compass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
32 lines (25 loc) · 790 Bytes
/
context.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
package authentication
import (
"context"
"errors"
"fmt"
)
type ContextKey string
const (
ConnectorTokenKey ContextKey = "ConnectorToken"
ClientIdFromTokenKey ContextKey = "ClientIdFromToken"
TokenTypeKey ContextKey = "TokenType"
ClientIdFromCertificateKey ContextKey = "ClientIdFromCertificate"
ClientCertificateHashKey ContextKey = "ClientCertificateHash"
)
func GetStringFromContext(ctx context.Context, key ContextKey) (string, error) {
value := ctx.Value(key)
str, ok := value.(string)
if !ok {
return "", errors.New(fmt.Sprintf("Cannot read %s key from context", string(key)))
}
return str, nil
}
func PutIntoContext(ctx context.Context, key ContextKey, value string) context.Context {
return context.WithValue(ctx, key, value)
}