worker: load tls certificates once on startup
This commit is contained in:
parent
16cd243300
commit
9e71df234a
1 changed files with 15 additions and 14 deletions
|
|
@ -55,18 +55,8 @@ func createTLSConfig(config *connectionConfig) (*tls.Config, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func newConnection(remoteAddress string) (net.Conn, error) {
|
||||
func newConnection(remoteAddress string, conf *tls.Config) (net.Conn, error) {
|
||||
if remoteAddress != "" {
|
||||
conf, err := createTLSConfig(&connectionConfig{
|
||||
CACertFile: "/etc/osbuild-composer/ca-crt.pem",
|
||||
ClientKeyFile: "/etc/osbuild-composer/worker-key.pem",
|
||||
ClientCertFile: "/etc/osbuild-composer/worker-crt.pem",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return tls.Dial("tcp", remoteAddress, conf)
|
||||
}
|
||||
|
||||
|
|
@ -75,11 +65,11 @@ func newConnection(remoteAddress string) (net.Conn, error) {
|
|||
|
||||
}
|
||||
|
||||
func NewClient(remoteAddress string) *ComposerClient {
|
||||
func NewClient(remoteAddress string, conf *tls.Config) *ComposerClient {
|
||||
client := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
DialContext: func(context context.Context, network, addr string) (net.Conn, error) {
|
||||
return newConnection(remoteAddress)
|
||||
return newConnection(remoteAddress, conf)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -189,11 +179,22 @@ func main() {
|
|||
flag.StringVar(&remoteAddress, "remote", "", "Connect to a remote composer using the specified address")
|
||||
flag.Parse()
|
||||
|
||||
var conf *tls.Config
|
||||
if remoteAddress != "" {
|
||||
remoteAddress = fmt.Sprintf("%s:%d", remoteAddress, RemoteWorkerPort)
|
||||
|
||||
var err error
|
||||
conf, err = createTLSConfig(&connectionConfig{
|
||||
CACertFile: "/etc/osbuild-composer/ca-crt.pem",
|
||||
ClientKeyFile: "/etc/osbuild-composer/worker-key.pem",
|
||||
ClientCertFile: "/etc/osbuild-composer/worker-crt.pem",
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("Error creating TLS config: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
client := NewClient(remoteAddress)
|
||||
client := NewClient(remoteAddress, conf)
|
||||
for {
|
||||
if err := handleJob(client); err != nil {
|
||||
log.Fatalf("Failed to handle job: " + err.Error())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue