Skip to content

Commit

Permalink
Merge pull request #10686 from stgraber/master
Browse files Browse the repository at this point in the history
Don't expose internal structs
  • Loading branch information
tomponline authored Jul 22, 2022
2 parents bb57b3c + 518991c commit 3ef9250
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 24 deletions.
File renamed without changes.
16 changes: 16 additions & 0 deletions lxd-agent/api/devlxd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package api

// DevLXDGet represents the server data which is returned as the root of the devlxd API.
type DevLXDGet struct {
// API version number
// Example: 1.0
APIVersion string `json:"api_version" yaml:"api_version"`

// Type (container or virtual-machine)
// Example: container
InstanceType string `json:"instance_type" yaml:"instance_type"`

// What cluster member this instance is located on
// Example: lxd01
Location string `json:"location" yaml:"location"`
}
3 changes: 2 additions & 1 deletion lxd-agent/api_1.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"

"github.com/lxc/lxd/client"
agentAPI "github.com/lxc/lxd/lxd-agent/api"
"github.com/lxc/lxd/lxd/response"
"github.com/lxc/lxd/lxd/vsock"
lxdshared "github.com/lxc/lxd/shared"
Expand Down Expand Up @@ -69,7 +70,7 @@ func api10Get(d *Daemon, r *http.Request) response.Response {
}

func api10Put(d *Daemon, r *http.Request) response.Response {
var data api.API10Put
var data agentAPI.API10Put

err := json.NewDecoder(r.Body).Decode(&data)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions lxd-agent/devlxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"github.com/gorilla/mux"

"github.com/lxc/lxd/client"
agentAPI "github.com/lxc/lxd/lxd-agent/api"
"github.com/lxc/lxd/lxd/daemon"
"github.com/lxc/lxd/lxd/device/config"
"github.com/lxc/lxd/lxd/util"
"github.com/lxc/lxd/shared"
"github.com/lxc/lxd/shared/api"
"github.com/lxc/lxd/shared/logger"
)

Expand Down Expand Up @@ -171,7 +171,7 @@ var devlxdAPIGet = devLxdHandler{"/1.0", func(d *Daemon, w http.ResponseWriter,
return &devLxdResponse{"internal server error", http.StatusInternalServerError, "raw"}
}

var instanceData api.VsockServerGet
var instanceData agentAPI.DevLXDGet

err = resp.MetadataAsStruct(&instanceData)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion lxd/devlxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ import (
"github.com/lxc/lxd/shared/version"
)

type devlxdGet struct {
APIVersion string `json:"api_version" yaml:"api_version"`
InstanceType string `json:"instance_type" yaml:"instance_type"`
Location string `json:"location" yaml:"location"`
}

type hoistFunc func(f func(*Daemon, instance.Instance, http.ResponseWriter, *http.Request) response.Response, d *Daemon) func(http.ResponseWriter, *http.Request)

// DevLxdServer creates an http.Server capable of handling requests against the
Expand Down Expand Up @@ -171,7 +177,7 @@ var devlxdAPIGet = devLxdHandler{"/1.0", func(d *Daemon, c instance.Instance, w
location = c.Location()
}

return response.DevLxdResponse(http.StatusOK, api.VsockServerGet{APIVersion: version.APIVersion, Location: location, InstanceType: c.Type().String()}, "json", c.Type() == instancetype.VM)
return response.DevLxdResponse(http.StatusOK, devlxdGet{APIVersion: version.APIVersion, Location: location, InstanceType: c.Type().String()}, "json", c.Type() == instancetype.VM)
}}

var devlxdDevicesGet = devLxdHandler{"/1.0/devices", func(d *Daemon, c instance.Instance, w http.ResponseWriter, r *http.Request) response.Response {
Expand Down
3 changes: 2 additions & 1 deletion lxd/instance/drivers/driver_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"gopkg.in/yaml.v2"

"github.com/lxc/lxd/client"
agentAPI "github.com/lxc/lxd/lxd-agent/api"
"github.com/lxc/lxd/lxd/apparmor"
"github.com/lxc/lxd/lxd/cgroup"
"github.com/lxc/lxd/lxd/db"
Expand Down Expand Up @@ -1599,7 +1600,7 @@ func (d *qemu) advertiseVsockAddress() error {

defer agent.Disconnect()

req := api.API10Put{
req := agentAPI.API10Put{
Certificate: string(d.state.Endpoints.NetworkCert().PublicKey()),
Devlxd: devlxdEnabled,
}
Expand Down
19 changes: 0 additions & 19 deletions shared/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,3 @@ type Server struct {
func (srv *Server) Writable() ServerPut {
return srv.ServerPut
}

// VsockServerGet represents the server data which is returned to the lxd-agent.
//
// swagger:model
//
// API extension: vsock_api.
type VsockServerGet struct {
// API version number
// Example: 1.0
APIVersion string `json:"api_version" yaml:"api_version"`

// Type (container or virtual-machine)
// Example: container
InstanceType string `json:"instance_type" yaml:"instance_type"`

// What cluster member this instance is located on
// Example: lxd01
Location string `json:"location" yaml:"location"`
}

0 comments on commit 3ef9250

Please sign in to comment.