Skip to content

Commit

Permalink
upadate libyavirt(support tls and simple auth for yavirt) (#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyang0 committed Jul 25, 2023
1 parent 5a76c4f commit 3038a70
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
19 changes: 17 additions & 2 deletions engine/virt/virt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"io"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -43,7 +44,7 @@ type Virt struct {
}

// MakeClient makes a virt. client which wraps yavirt API client.
func MakeClient(_ context.Context, config coretypes.Config, _, endpoint, _, _, _ string) (engine.API, error) {
func MakeClient(_ context.Context, config coretypes.Config, nodename, endpoint, ca, _, _ string) (engine.API, error) {
var uri string
switch {
case strings.HasPrefix(endpoint, HTTPPrefixKey):
Expand All @@ -54,7 +55,21 @@ func MakeClient(_ context.Context, config coretypes.Config, _, endpoint, _, _, _
return nil, coretypes.ErrInvaildEngineEndpoint
}

cli, err := virtapi.New(uri)
yCfg := &virttypes.Config{
URI: uri,
}
if ca != "" {
caFile, err := os.CreateTemp(config.CertPath, fmt.Sprintf("ca-%s", nodename))
if err != nil {
return nil, err
}
if _, err := caFile.WriteString(ca); err != nil {
return nil, err
}
defer os.Remove(caFile.Name())
yCfg.CA = caFile.Name()
}
cli, err := virtapi.New(yCfg)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b
github.com/panjf2000/ants/v2 v2.7.3
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/projecteru2/libyavirt v0.0.0-20230705102231-8199e310da06
github.com/projecteru2/libyavirt v0.0.0-20230725071905-9785e974d625
github.com/prometheus/client_golang v1.15.0
github.com/rs/zerolog v1.29.1
github.com/sanity-io/litter v1.5.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/projecteru2/libyavirt v0.0.0-20230705102231-8199e310da06 h1:p/1vyEftIPf9LPuMMr7STDllXlVzrWc1eUHHuUPcE9o=
github.com/projecteru2/libyavirt v0.0.0-20230705102231-8199e310da06/go.mod h1:N41KaKmqbailweGs4x/mt2H0O0Y7MizObZQ+igLdzpw=
github.com/projecteru2/libyavirt v0.0.0-20230725071905-9785e974d625 h1:liDnxQ0JxvOLC0/tUVRlz4tG9r/xbcp1NXgNVNBJsLQ=
github.com/projecteru2/libyavirt v0.0.0-20230725071905-9785e974d625/go.mod h1:N41KaKmqbailweGs4x/mt2H0O0Y7MizObZQ+igLdzpw=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g=
Expand Down

0 comments on commit 3038a70

Please sign in to comment.