-
Notifications
You must be signed in to change notification settings - Fork 9
/
grpccore.go
39 lines (29 loc) · 925 Bytes
/
grpccore.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
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package grpc
import (
"crypto/tls"
"google.golang.org/grpc/credentials"
"namespacelabs.dev/foundation/schema"
"namespacelabs.dev/foundation/std/go/core"
)
var ServerCreds credentials.TransportCredentials
func SetServerCredentials(creds credentials.TransportCredentials) {
core.AssertNotRunning("grpc.SetServerCredentials")
if ServerCreds != nil {
panic("serverCreds were already set")
}
ServerCreds = creds
}
func SetServerOnlyTLS(sc *schema.Certificate) {
cert, err := tls.X509KeyPair(sc.CertificateBundle, sc.PrivateKey)
if err != nil {
panic(err)
}
config := &tls.Config{
Certificates: []tls.Certificate{cert},
ClientAuth: tls.NoClientCert,
}
SetServerCredentials(credentials.NewTLS(config))
}