Skip to content

Commit

Permalink
ostree: fix proxy parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
lzap committed Nov 19, 2024
1 parent d7ae209 commit 0306c80
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 16 additions & 0 deletions cmd/otk/osbuild-resolve-ostree-commit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ type Input struct {

// Whether to use RHSM secrets when resolving and fetching the commit.
RHSM bool `json:"rhsm,omitempty"`

// MTLS information. Will be ignored if RHSM is set.
MTLS *struct {
CA string `json:"ca"`
ClientCert string `json:"client_cert"`
ClientKey string `json:"client_key"`
} `json:"mtls,omitempty"`

// HTTP proxy to use when fetching the ref.
Proxy string `json:"proxy,omitempty"`
}

// Output contains everything needed to write a manifest that requires pulling
Expand All @@ -53,6 +63,12 @@ func run(r io.Reader, w io.Writer) error {
URL: inputTree.Tree.URL,
Ref: inputTree.Tree.Ref,
RHSM: inputTree.Tree.RHSM,
MTLS: &ostree.MTLS{
CA: inputTree.Tree.MTLS.CA,
ClientCert: inputTree.Tree.MTLS.ClientCert,
ClientKey: inputTree.Tree.MTLS.ClientKey,
},
Proxy: inputTree.Tree.Proxy,
}

var commitSpec ostree.CommitSpec
Expand Down
10 changes: 8 additions & 2 deletions pkg/ostree/ostree.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"fmt"
"io"
"net"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -158,7 +159,7 @@ func resolveRef(ss SourceSpec) (string, error) {
if err != nil {
return "", NewResolveRefError("error parsing ostree repository location: %v", err)
}
u.Path = path.Join(u.Path, "refs/heads/", ss.Ref)
u.Path = path.Join(u.Path, "refs", "heads", ss.Ref)

transport := http.DefaultTransport.(*http.Transport).Clone()
if u.Scheme == "https" {
Expand Down Expand Up @@ -190,7 +191,12 @@ func resolveRef(ss SourceSpec) (string, error) {
}

if ss.Proxy != "" {
proxyURL, err := url.Parse(ss.URL)
host, port, err := net.SplitHostPort(ss.Proxy)
if err != nil {
return "", NewResolveRefError("error parsing MTLS proxy URL '%s': %v", ss.URL, err)
}

proxyURL, err := url.Parse("http://" + host + ":" + port)
if err != nil {
return "", NewResolveRefError("error parsing MTLS proxy URL '%s': %v", ss.URL, err)
}
Expand Down

0 comments on commit 0306c80

Please sign in to comment.