/
config.go
63 lines (55 loc) · 1.41 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
54
55
56
57
58
59
60
61
62
63
// Package xdserr to load test configuration updates
package xdserr
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
adminv3 "github.com/envoyproxy/go-control-plane/envoy/admin/v3"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/emptypb"
"github.com/pomerium/pomerium/internal/log"
)
type cfgDump struct {
Configs []json.RawMessage `json:"configs"`
}
// DumpConfig acquires current config from admin endpoint
func DumpConfig(ctx context.Context, adminURL string) (*adminv3.RoutesConfigDump, error) {
u, err := url.Parse(adminURL)
if err != nil {
return nil, err
}
u.Path = "/config_dump"
req := http.Request{
Method: http.MethodGet,
URL: u,
}
resp, err := http.DefaultClient.Do(req.WithContext(ctx))
if err != nil {
return nil, err
}
defer resp.Body.Close()
cfg := cfgDump{}
if err := json.NewDecoder(resp.Body).Decode(&cfg); err != nil {
return nil, err
}
any, _ := anypb.New(&emptypb.Empty{})
fmt.Println(protojson.Format(any))
opts := &protojson.UnmarshalOptions{
AllowPartial: true,
DiscardUnknown: true,
}
for i, data := range cfg.Configs {
any := new(anypb.Any)
if err = opts.Unmarshal(data, any); err != nil {
log.Error(ctx).Err(err).Int("config", i).
//RawJSON("data", data).
Msg("decode")
} else {
log.Info(ctx).Msg(any.TypeUrl)
}
}
return nil, err
}