Skip to content

Commit 66494bb

Browse files
authored
Support configurations for remote logging of metal-hammer (#24)
1 parent 3b698ad commit 66494bb

File tree

5 files changed

+155
-40
lines changed

5 files changed

+155
-40
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ RUN apt update \
77
liblzma-dev \
88
&& make ipxe pixie
99

10-
FROM alpine:3.18
10+
FROM alpine:3.19
1111
RUN apk -U add ca-certificates
1212
COPY --from=builder /work/build/pixie /pixie
1313
ENTRYPOINT ["/pixie"]

api/api.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,43 @@ type MetalConfig struct {
1010
Cert string `json:"cert,omitempty"`
1111
Key string `json:"key,omitempty"`
1212
HMAC string `json:"hmac,omitempty"`
13+
// Logging contains logging configurations passed to metal-hammer
14+
Logging *Logging `json:"logging,omitempty"`
1315
}
16+
17+
type Logging struct {
18+
// Endpoint is the url where the logs must be shipped to
19+
Endpoint string `json:"endpoint,omitempty"`
20+
// BasicAuth must be set if loki requires username and password
21+
BasicAuth *BasicAuth `json:"basic_auth,omitempty"`
22+
// CertificateAuth must be set if mTLS authentication is required for loki
23+
CertificateAuth *CertificateAuth `json:"certificate_auth,omitempty"`
24+
// Type of logging
25+
Type LogType `json:"log_type,omitempty"`
26+
}
27+
28+
// BasicAuth configuration
29+
type BasicAuth struct {
30+
// User to authenticate against the logging endpoint
31+
User string `json:"user,omitempty"`
32+
// Password to authenticate against the logging endpoint
33+
Password string `json:"password,omitempty"`
34+
}
35+
36+
// CertificateAuth is used for mTLS authentication
37+
type CertificateAuth struct {
38+
// Cert the certificate
39+
Cert string `json:"cert,omitempty"`
40+
// Key is the key
41+
Key string `json:"key,omitempty"`
42+
// InsecureSkipVerify if no certificate validation should be made
43+
InsecureSkipVerify bool `json:"insecure_skip_verify,omitempty"`
44+
}
45+
46+
// LogType defines which logging backend should be used
47+
type LogType string
48+
49+
const (
50+
// LogTypeLoki loki is the logging backend
51+
LogTypeLoki = LogType("loki")
52+
)

go.mod

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ module github.com/metal-stack/pixie
33
go 1.21
44

55
require (
6-
github.com/metal-stack/metal-api v0.25.1
6+
github.com/metal-stack/metal-api v0.26.3
77
github.com/metal-stack/v v1.0.3
88
github.com/pin/tftp/v3 v3.1.0
9-
github.com/prometheus/client_golang v1.17.0
9+
github.com/prometheus/client_golang v1.18.0
1010
github.com/spf13/cobra v1.8.0
11-
github.com/spf13/viper v1.18.1
11+
github.com/spf13/viper v1.18.2
1212
github.com/stretchr/testify v1.8.4
1313
go.uber.org/zap v1.26.0
14-
golang.org/x/crypto v0.16.0
15-
golang.org/x/net v0.19.0
16-
google.golang.org/grpc v1.60.0
14+
golang.org/x/crypto v0.18.0
15+
golang.org/x/net v0.20.0
16+
google.golang.org/grpc v1.61.0
1717
)
1818

1919
require (
@@ -25,12 +25,11 @@ require (
2525
github.com/hashicorp/hcl v1.0.0 // indirect
2626
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2727
github.com/magiconair/properties v1.8.7 // indirect
28-
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
2928
github.com/mitchellh/mapstructure v1.5.0 // indirect
30-
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
29+
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
3130
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
3231
github.com/prometheus/client_model v0.5.0 // indirect
33-
github.com/prometheus/common v0.45.0 // indirect
32+
github.com/prometheus/common v0.46.0 // indirect
3433
github.com/prometheus/procfs v0.12.0 // indirect
3534
github.com/sagikazarmark/locafero v0.4.0 // indirect
3635
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
@@ -40,11 +39,11 @@ require (
4039
github.com/spf13/pflag v1.0.5 // indirect
4140
github.com/subosito/gotenv v1.6.0 // indirect
4241
go.uber.org/multierr v1.11.0 // indirect
43-
golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect
44-
golang.org/x/sys v0.15.0 // indirect
42+
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
43+
golang.org/x/sys v0.16.0 // indirect
4544
golang.org/x/text v0.14.0 // indirect
46-
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
47-
google.golang.org/protobuf v1.31.0 // indirect
45+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect
46+
google.golang.org/protobuf v1.32.0 // indirect
4847
gopkg.in/ini.v1 v1.67.0 // indirect
4948
gopkg.in/yaml.v3 v3.0.1 // indirect
5049
)

go.sum

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,25 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
2727
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
2828
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
2929
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
30-
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
31-
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
32-
github.com/metal-stack/metal-api v0.25.1 h1:ErkS2kMfNDk9RM21s77n9b5dHwnYM5iuZM2evE36XzQ=
33-
github.com/metal-stack/metal-api v0.25.1/go.mod h1:WbCawjwTneAf3FqrTKdjuG8eoPpLAMNNUKstqkgvtfw=
30+
github.com/metal-stack/metal-api v0.26.3 h1:aZq8eMTeWjf4NsdH56QwNsjkOfKZ5tVoxl4c7k1FoB4=
31+
github.com/metal-stack/metal-api v0.26.3/go.mod h1:rk/w+hoKJ9/BmZRuw+eoUxa6O7BWyDVvbBYFtZOea/Q=
3432
github.com/metal-stack/v v1.0.3 h1:Sh2oBlnxrCUD+mVpzfC8HiqL045YWkxs0gpTvkjppqs=
3533
github.com/metal-stack/v v1.0.3/go.mod h1:YTahEu7/ishwpYKnp/VaW/7nf8+PInogkfGwLcGPdXg=
3634
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
3735
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
38-
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
39-
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
36+
github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
37+
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
4038
github.com/pin/tftp/v3 v3.1.0 h1:rQaxd4pGwcAJnpId8zC+O2NX3B2/NscjDZQaqEjuE7c=
4139
github.com/pin/tftp/v3 v3.1.0/go.mod h1:xwQaN4viYL019tM4i8iecm++5cGxSqen6AJEOEyEI0w=
4240
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
4341
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
4442
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
45-
github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q=
46-
github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY=
43+
github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk=
44+
github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA=
4745
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
4846
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
49-
github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM=
50-
github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY=
47+
github.com/prometheus/common v0.46.0 h1:doXzt5ybi1HBKpsZOL0sSkaNHJJqkyfEWZGGqqScV0Y=
48+
github.com/prometheus/common v0.46.0/go.mod h1:Tp0qkxpb9Jsg54QMe+EAmqXkSV7Evdy1BTn+g2pa/hQ=
5149
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
5250
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
5351
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
@@ -67,8 +65,8 @@ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
6765
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
6866
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
6967
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
70-
github.com/spf13/viper v1.18.1 h1:rmuU42rScKWlhhJDyXZRKJQHXFX02chSVW1IvkPGiVM=
71-
github.com/spf13/viper v1.18.1/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
68+
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
69+
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
7270
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
7371
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
7472
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@@ -85,28 +83,28 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8
8583
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
8684
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
8785
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
88-
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
89-
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
90-
golang.org/x/exp v0.0.0-20231127185646-65229373498e h1:Gvh4YaCaXNs6dKTlfgismwWZKyjVZXwOPfIyUaqU3No=
91-
golang.org/x/exp v0.0.0-20231127185646-65229373498e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
86+
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
87+
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
88+
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA=
89+
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
9290
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
93-
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
94-
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
91+
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
92+
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
9593
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
96-
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
97-
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
94+
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
95+
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
9896
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
9997
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
10098
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
10199
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
102-
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f h1:ultW7fxlIvee4HYrtnaRPon9HpEgFk5zYpmfMgtKB5I=
103-
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f/go.mod h1:L9KNLi232K1/xB6f7AlSX692koaRnKaWSR0stBki0Yc=
104-
google.golang.org/grpc v1.60.0 h1:6FQAR0kM31P6MRdeluor2w2gPaS4SVNrD/DNTxrQ15k=
105-
google.golang.org/grpc v1.60.0/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM=
100+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe h1:bQnxqljG/wqi4NTXu2+DJ3n7APcEA882QZ1JvhQAq9o=
101+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s=
102+
google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0=
103+
google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs=
106104
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
107105
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
108-
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
109-
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
106+
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
107+
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
110108
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
111109
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
112110
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

pixiecore/cli/grpccmd.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919
"net/url"
2020
"os"
21+
"strings"
2122

2223
"github.com/metal-stack/pixie/api"
2324
"github.com/metal-stack/pixie/pixiecore"
@@ -74,6 +75,15 @@ func init() {
7475
grpcCmd.Flags().String("metal-api-view-hmac", "", "hmac with metal-api view access")
7576
grpcCmd.Flags().String("metal-api-url", "", "url to access metal-api")
7677
grpcCmd.Flags().Bool("metal-hammer-debug", true, "set metal-hammer to debug")
78+
79+
// metal-hammer remote logging configuration
80+
grpcCmd.Flags().String("metal-hammer-logging-endpoint", "", "set metal-hammer to send logs to this endpoint")
81+
grpcCmd.Flags().String("metal-hammer-logging-user", "", "set metal-hammer to send logs to a remote endpoint and authenticate with this user")
82+
grpcCmd.Flags().String("metal-hammer-logging-password", "", "set metal-hammer to send logs to a remote endpoint and authenticate with this password")
83+
grpcCmd.Flags().String("metal-hammer-logging-cert", "", "set metal-hammer to send logs to a remote endpoint and authenticate with this cert")
84+
grpcCmd.Flags().String("metal-hammer-logging-key", "", "set metal-hammer to send logs to a remote endpoint and authenticate with this key")
85+
grpcCmd.Flags().Bool("metal-hammer-logging-tls-insecure", false, "set metal-hammer to send logs to a remote endpoint without verifying the tls certificate")
86+
grpcCmd.Flags().String("metal-hammer-logging-type", "loki", "set metal-hammer to send logs to a remote endpoint with this logging type")
7787
}
7888

7989
func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
@@ -132,6 +142,74 @@ func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
132142
if err != nil {
133143
return nil, fmt.Errorf("error reading flag: %w", err)
134144
}
145+
146+
// Log forwarding for the metal-hammer
147+
metalHammerLoggingEndpoint, err := cmd.Flags().GetString("metal-hammer-logging-endpoint")
148+
if err != nil {
149+
return nil, fmt.Errorf("error reading flag: %w", err)
150+
}
151+
metalHammerLoggingUser, err := cmd.Flags().GetString("metal-hammer-logging-user")
152+
if err != nil {
153+
return nil, fmt.Errorf("error reading flag: %w", err)
154+
}
155+
metalHammerLoggingPassword, err := cmd.Flags().GetString("metal-hammer-logging-password")
156+
if err != nil {
157+
return nil, fmt.Errorf("error reading flag: %w", err)
158+
}
159+
metalHammerLoggingCert, err := cmd.Flags().GetString("metal-hammer-logging-cert")
160+
if err != nil {
161+
return nil, fmt.Errorf("error reading flag: %w", err)
162+
}
163+
metalHammerLoggingKey, err := cmd.Flags().GetString("metal-hammer-logging-key")
164+
if err != nil {
165+
return nil, fmt.Errorf("error reading flag: %w", err)
166+
}
167+
metalHammerLoggingTlsInsecure, err := cmd.Flags().GetBool("metal-hammer-logging-tls-insecure")
168+
if err != nil {
169+
return nil, fmt.Errorf("error reading flag: %w", err)
170+
}
171+
metalHammerLoggingType, err := cmd.Flags().GetString("metal-hammer-logging-type")
172+
if err != nil {
173+
return nil, fmt.Errorf("error reading flag: %w", err)
174+
}
175+
var logging *api.Logging
176+
if metalHammerLoggingEndpoint != "" {
177+
logging = &api.Logging{
178+
Endpoint: metalHammerLoggingEndpoint,
179+
}
180+
if metalHammerLoggingUser != "" {
181+
basicAuth := &api.BasicAuth{}
182+
basicAuth.User = metalHammerLoggingUser
183+
if metalHammerLoggingPassword != "" {
184+
basicAuth.Password = metalHammerLoggingUser
185+
}
186+
logging.BasicAuth = basicAuth
187+
}
188+
if metalHammerLoggingCert != "" && metalHammerLoggingKey != "" {
189+
cert, err := os.ReadFile(metalHammerLoggingCert)
190+
if err != nil {
191+
return nil, err
192+
}
193+
key, err := os.ReadFile(metalHammerLoggingKey)
194+
if err != nil {
195+
return nil, err
196+
}
197+
198+
logging.CertificateAuth = &api.CertificateAuth{
199+
Cert: string(cert),
200+
Key: string(key),
201+
InsecureSkipVerify: metalHammerLoggingTlsInsecure,
202+
}
203+
}
204+
205+
switch strings.ToLower(metalHammerLoggingType) {
206+
case "loki":
207+
logging.Type = api.LogTypeLoki
208+
default:
209+
return nil, fmt.Errorf("only loki currently support for metal-hammer remote logging %q was given", metalHammerLoggingType)
210+
}
211+
}
212+
135213
return &api.MetalConfig{
136214
Debug: metalHammerDebug,
137215
GRPCAddress: grpcAddress,
@@ -141,5 +219,6 @@ func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
141219
Cert: string(clientCert),
142220
Key: string(clientKey),
143221
HMAC: hmac,
222+
Logging: logging,
144223
}, nil
145224
}

0 commit comments

Comments
 (0)