-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
53 lines (42 loc) · 1.07 KB
/
config.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
package hid
import (
"os"
"github.com/hafslundnett/hn-config-lib-go/libhttp"
"github.com/pkg/errors"
)
const (
defDiscovery = "/.well-known/openid-configuration"
defJWKS = "/.well-known/openid-configuration/jwks"
defTokenEP = "/connect/token"
)
var envars = map[string]string{
"addr": "HID_ADDR",
"cert": "HID_CACERT",
"discovery": "HID_DISCOVERY",
}
// Config contains the configuration information needed to do the initial setup and renewal of the HID service
type Config struct {
Addr string
JWKSuri string `json:"jwks_uri"`
TokenEP string `json:"token_endpoint"`
client libhttp.Client
}
// Configure expl
func (hid *HID) Configure(client libhttp.Client) error {
addr := os.Getenv(envars["addr"])
if addr == "" {
return errors.New("missing env var " + envars["addr"])
}
discovery := os.Getenv(envars["discovery"])
if discovery == "" {
discovery = defDiscovery
}
err := client.Get(addr+discovery, &hid)
if err != nil {
hid.JWKSuri = addr + defJWKS
hid.TokenEP = addr + defTokenEP
}
hid.Addr = addr
hid.client = client
return nil
}