Skip to content

Commit

Permalink
feat: include arbitrary key/value storage with connection profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
tinyzimmer committed Nov 9, 2023
1 parent 75f098b commit 437c190
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/vishvananda/netlink v1.2.1-beta.2
github.com/webmeshproj/api v0.11.4-0.20231109225108-67650c62010a
github.com/webmeshproj/api v0.11.4-0.20231109232550-26b325076bc2
golang.org/x/crypto v0.14.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/net v0.17.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,8 @@ github.com/webmeshproj/api v0.11.4-0.20231109201546-44726ffeea69 h1:lnpiABZ5U10G
github.com/webmeshproj/api v0.11.4-0.20231109201546-44726ffeea69/go.mod h1:xuYk93HM4aZWWlTh96Z2nIg1YhqcRG36nOfcifzHeM4=
github.com/webmeshproj/api v0.11.4-0.20231109225108-67650c62010a h1:uCOjrwdx5/0T527YDA3v1Rtnd7Xy49847j0pkrnLKUo=
github.com/webmeshproj/api v0.11.4-0.20231109225108-67650c62010a/go.mod h1:xuYk93HM4aZWWlTh96Z2nIg1YhqcRG36nOfcifzHeM4=
github.com/webmeshproj/api v0.11.4-0.20231109232550-26b325076bc2 h1:98lTfjlJdgGcOfbzg6XpOqtR7ijF/qIG8jyHxoSE2l8=
github.com/webmeshproj/api v0.11.4-0.20231109232550-26b325076bc2/go.mod h1:xuYk93HM4aZWWlTh96Z2nIg1YhqcRG36nOfcifzHeM4=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/daemoncmd/connmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (m *ConnManager) NewConn(ctx context.Context, req *v1.ConnectRequest) (id s
}
return "", nil, status.Errorf(codes.Internal, "failed to get profile: %v", err)
}
cfg, err := m.buildConnConfig(ctx, profile.ConnectionParameters, connID, port)
cfg, err := m.buildConnConfig(ctx, profile.GetParameters(), connID, port)
if err != nil {
return "", nil, err
}
Expand Down
22 changes: 12 additions & 10 deletions pkg/cmd/daemoncmd/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,33 +115,35 @@ func (p Profiles) IDs() []ProfileID {
return ids
}

// Profile contains the details of a connection profile
// Profile contains the details of a connection profile. It is semantically
// equivalent to a PutConnectionRequest at the moment and is therefore functionally
// an alias.
type Profile struct {
*v1.ConnectionParameters
*v1.PutConnectionRequest
}

// MarshalJSON marshals the profile to JSON.
func (p Profile) MarshalJSON() ([]byte, error) {
return protojson.Marshal(p.ConnectionParameters)
return protojson.Marshal(p.PutConnectionRequest)
}

// UnmarshalJSON unmarshals the profile from JSON.
func (p *Profile) UnmarshalJSON(data []byte) error {
if p.ConnectionParameters == nil {
p.ConnectionParameters = &v1.ConnectionParameters{}
if p.PutConnectionRequest == nil {
p.PutConnectionRequest = &v1.PutConnectionRequest{}
}
return protojson.Unmarshal(data, p.ConnectionParameters)
return protojson.Unmarshal(data, p.PutConnectionRequest)
}

// MarshalProto marshals the profile to proto.
func (p Profile) MarshalProto() ([]byte, error) {
return proto.Marshal(p.ConnectionParameters)
return proto.Marshal(p.PutConnectionRequest)
}

// UnmarshalProto unmarshals the profile from proto.
func (p *Profile) UnmarshalProto(data []byte) error {
if p.ConnectionParameters == nil {
p.ConnectionParameters = &v1.ConnectionParameters{}
if p.PutConnectionRequest == nil {
p.PutConnectionRequest = &v1.PutConnectionRequest{}
}
return proto.Unmarshal(data, p.ConnectionParameters)
return proto.Unmarshal(data, p.PutConnectionRequest)
}
8 changes: 5 additions & 3 deletions pkg/cmd/daemoncmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (app *AppDaemon) PutConnection(ctx context.Context, req *v1.PutConnectionRe
}
profileID = ProfileID(id)
}
err = app.connmgr.Profiles().Put(ctx, profileID, Profile{req.GetParameters()})
err = app.connmgr.Profiles().Put(ctx, profileID, Profile{req})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to store connection: %v", err)
}
Expand Down Expand Up @@ -202,7 +202,8 @@ func (app *AppDaemon) GetConnection(ctx context.Context, req *v1.GetConnectionRe
node = meshNode.MeshNode
}
return &v1.GetConnectionResponse{
Parameters: conn.ConnectionParameters,
Parameters: conn.GetParameters(),
Metadata: conn.GetMetadata(),
Status: connStatus,
Node: node,
}, nil
Expand Down Expand Up @@ -255,7 +256,8 @@ func (app *AppDaemon) ListConnections(ctx context.Context, req *v1.ListConnectio
for id, profile := range profiles {
connStatus := app.connmgr.GetStatus(ctx, id.String())
resp.Connections[id.String()] = &v1.GetConnectionResponse{
Parameters: profile.ConnectionParameters,
Parameters: profile.GetParameters(),
Metadata: profile.GetMetadata(),
Status: connStatus,
Node: func() *v1.MeshNode {
if connStatus == v1.DaemonConnStatus_CONNECTED {
Expand Down

0 comments on commit 437c190

Please sign in to comment.