Skip to content

Commit

Permalink
Merge pull request #13575 from markylaing/bug-allocated-ip-location-p…
Browse files Browse the repository at this point in the history
…arsing

lxc: Parse location header into URL
  • Loading branch information
tomponline authored Jun 10, 2024
2 parents d5ec06f + 7b0c562 commit 5495a0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lxc/network_forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net"
"net/url"
"os"
"sort"
"strings"
Expand Down Expand Up @@ -340,8 +341,13 @@ func (c *cmdNetworkForwardCreate) run(cmd *cobra.Command, args []string) error {
return err
}

networkForwardURL, err := url.Parse(transporter.location)
if err != nil {
return fmt.Errorf("Received invalid location header %q: %w", transporter.location, err)
}

forwardURLPrefix := api.NewURL().Path(version.APIVersion, "networks", networkName, "forwards").String()
_, err = fmt.Sscanf(transporter.location, forwardURLPrefix+"/%s", &listenAddress)
_, err = fmt.Sscanf(networkForwardURL.Path, forwardURLPrefix+"/%s", &listenAddress)
if err != nil {
return fmt.Errorf("Received unexpected location header %q: %w", transporter.location, err)
}
Expand Down
8 changes: 7 additions & 1 deletion lxc/network_load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net"
"net/url"
"os"
"sort"
"strings"
Expand Down Expand Up @@ -344,8 +345,13 @@ func (c *cmdNetworkLoadBalancerCreate) run(cmd *cobra.Command, args []string) er
return err
}

loadBalancerURL, err := url.Parse(transporter.location)
if err != nil {
return fmt.Errorf("Received invalid location header %q: %w", transporter.location, err)
}

loadBalancerURLPrefix := api.NewURL().Path(version.APIVersion, "networks", networkName, "load-balancers").String()
_, err = fmt.Sscanf(transporter.location, loadBalancerURLPrefix+"/%s", &listenAddress)
_, err = fmt.Sscanf(loadBalancerURL.Path, loadBalancerURLPrefix+"/%s", &listenAddress)
if err != nil {
return fmt.Errorf("Received unexpected location header %q: %w", transporter.location, err)
}
Expand Down

0 comments on commit 5495a0e

Please sign in to comment.