-
Notifications
You must be signed in to change notification settings - Fork 550
/
utils.go
57 lines (45 loc) · 1.4 KB
/
utils.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
package authzserver
import (
"context"
"encoding/base64"
"net/http"
"github.com/flyteorg/flyte/flyteadmin/auth"
"github.com/flyteorg/flyte/flyteadmin/auth/config"
"github.com/gtank/cryptopasta"
"github.com/ory/fosite"
)
func interfaceSliceToStringSlice(raw []interface{}) []string {
res := make([]string, 0, len(raw))
for _, item := range raw {
res = append(res, item.(string))
}
return res
}
func toClientIface(clients map[string]*fosite.DefaultClient) map[string]fosite.Client {
res := make(map[string]fosite.Client, len(clients))
for clientID, client := range clients {
res[clientID] = client
}
return res
}
func GetIssuer(ctx context.Context, req *http.Request, cfg *config.Config) string {
if configIssuer := cfg.AppAuth.SelfAuthServer.Issuer; len(configIssuer) > 0 {
return configIssuer
}
return auth.GetPublicURL(ctx, req, cfg).String()
}
func encryptString(plainTextCode string, blockKey [auth.SymmetricKeyLength]byte) (string, error) {
cypher, err := cryptopasta.Encrypt([]byte(plainTextCode), &blockKey)
if err != nil {
return "", err
}
return base64.RawStdEncoding.EncodeToString(cypher), nil
}
func decryptString(encryptedEncoded string, blockKey [auth.SymmetricKeyLength]byte) (string, error) {
cypher, err := base64.RawStdEncoding.DecodeString(encryptedEncoded)
if err != nil {
return "", err
}
raw, err := cryptopasta.Decrypt(cypher, &blockKey)
return string(raw), err
}