Remove remaining extraneous 'Result' RPC-related struct types

This commit is contained in:
Brian Picciano 2024-09-04 22:46:38 +02:00
parent 06a345ecd1
commit 038a28bb02
4 changed files with 29 additions and 59 deletions

View File

@ -43,13 +43,12 @@ var subCmdHostCreate = subCmd{
return errors.New("--hostname is required") return errors.New("--hostname is required")
} }
res, err := ctx.daemonRPC.CreateHost(ctx, daemon.CreateHostRequest{ res, err := ctx.daemonRPC.CreateHost(
HostName: hostName.V, ctx, hostName.V, daemon.CreateHostOpts{
Opts: daemon.CreateHostOpts{
IP: ip.V, IP: ip.V,
CanCreateHosts: *canCreateHosts, CanCreateHosts: *canCreateHosts,
}, },
}) )
if err != nil { if err != nil {
return fmt.Errorf("calling CreateHost: %w", err) return fmt.Errorf("calling CreateHost: %w", err)
} }
@ -117,9 +116,7 @@ var subCmdHostRemove = subCmd{
return errors.New("--hostname is required") return errors.New("--hostname is required")
} }
_, err := ctx.daemonRPC.RemoveHost(ctx, daemon.RemoveHostRequest{ _, err := ctx.daemonRPC.RemoveHost(ctx, hostName.V)
HostName: hostName.V,
})
if err != nil { if err != nil {
return fmt.Errorf("calling RemoveHost: %w", err) return fmt.Errorf("calling RemoveHost: %w", err)
} }

View File

@ -3,7 +3,6 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"isle/daemon"
"isle/jsonutil" "isle/jsonutil"
"isle/nebula" "isle/nebula"
"os" "os"
@ -48,16 +47,13 @@ var subCmdNebulaCreateCert = subCmd{
} }
res, err := ctx.daemonRPC.CreateNebulaCertificate( res, err := ctx.daemonRPC.CreateNebulaCertificate(
ctx, daemon.CreateNebulaCertificateRequest{ ctx, hostName.V, hostPub,
HostName: hostName.V,
HostEncryptingPublicKey: hostPub,
},
) )
if err != nil { if err != nil {
return fmt.Errorf("calling CreateNebulaCertificate: %w", err) return fmt.Errorf("calling CreateNebulaCertificate: %w", err)
} }
nebulaHostCertPEM, err := res.HostNebulaCertifcate.Unwrap().MarshalToPEM() nebulaHostCertPEM, err := res.HostNebulaCertificate.Unwrap().MarshalToPEM()
if err != nil { if err != nil {
return fmt.Errorf("marshaling cert to PEM: %w", err) return fmt.Errorf("marshaling cert to PEM: %w", err)
} }

View File

@ -22,22 +22,24 @@ func RPCFromClient(client jsonrpc2.Client) RPC {
return &rpcClient{client} return &rpcClient{client}
} }
func (c *rpcClient) CreateHost(ctx context.Context, req CreateHostRequest) (c2 CreateHostResult, err error) { func (c *rpcClient) CreateHost(ctx context.Context, hostName nebula.HostName, opts CreateHostOpts) (c2 CreateHostResult, err error) {
err = c.client.Call( err = c.client.Call(
ctx, ctx,
&c2, &c2,
"CreateHost", "CreateHost",
req, hostName,
opts,
) )
return return
} }
func (c *rpcClient) CreateNebulaCertificate(ctx context.Context, req CreateNebulaCertificateRequest) (c2 CreateNebulaCertificateResult, err error) { func (c *rpcClient) CreateNebulaCertificate(ctx context.Context, hostName nebula.HostName, hostEncryptingPublicKey nebula.EncryptingPublicKey) (c2 CreateNebulaCertificateResult, err error) {
err = c.client.Call( err = c.client.Call(
ctx, ctx,
&c2, &c2,
"CreateNebulaCertificate", "CreateNebulaCertificate",
req, hostName,
hostEncryptingPublicKey,
) )
return return
} }
@ -94,13 +96,13 @@ func (c *rpcClient) JoinNetwork(ctx context.Context, req JoiningBootstrap) (st1
return return
} }
func (c *rpcClient) RemoveHost(ctx context.Context, req RemoveHostRequest) (st1 struct { func (c *rpcClient) RemoveHost(ctx context.Context, hostName nebula.HostName) (st1 struct {
}, err error) { }, err error) {
err = c.client.Call( err = c.client.Call(
ctx, ctx,
&st1, &st1,
"RemoveHost", "RemoveHost",
req, hostName,
) )
return return
} }

View File

@ -16,40 +16,15 @@ type GetHostsResult struct {
Hosts []bootstrap.Host Hosts []bootstrap.Host
} }
// RemoveHostRequest contains the arguments to the RemoveHost RPC method.
//
// All fields are required.
type RemoveHostRequest struct {
HostName nebula.HostName
}
// CreateHostRequest contains the arguments to the
// CreateHost RPC method.
//
// All fields are required.
type CreateHostRequest struct {
HostName nebula.HostName
Opts CreateHostOpts
}
// CreateHostResult wraps the results from the CreateHost RPC method. // CreateHostResult wraps the results from the CreateHost RPC method.
type CreateHostResult struct { type CreateHostResult struct {
JoiningBootstrap JoiningBootstrap JoiningBootstrap JoiningBootstrap
} }
// CreateNebulaCertificateRequest contains the arguments to the
// CreateNebulaCertificate RPC method.
//
// All fields are required.
type CreateNebulaCertificateRequest struct {
HostName nebula.HostName
HostEncryptingPublicKey nebula.EncryptingPublicKey
}
// CreateNebulaCertificateResult wraps the results from the // CreateNebulaCertificateResult wraps the results from the
// CreateNebulaCertificate RPC method. // CreateNebulaCertificate RPC method.
type CreateNebulaCertificateResult struct { type CreateNebulaCertificateResult struct {
HostNebulaCertifcate nebula.Certificate HostNebulaCertificate nebula.Certificate
} }
// RPC exposes all RPC methods which are available to be called over the RPC // RPC exposes all RPC methods which are available to be called over the RPC
@ -98,14 +73,14 @@ type RPC interface {
// RemoveHost passes the call through to the Daemon method of the same name. // RemoveHost passes the call through to the Daemon method of the same name.
RemoveHost( RemoveHost(
ctx context.Context, req RemoveHostRequest, ctx context.Context, hostName nebula.HostName,
) ( ) (
struct{}, error, struct{}, error,
) )
// CreateHost passes the call through to the Daemon method of the same name. // CreateHost passes the call through to the Daemon method of the same name.
CreateHost( CreateHost(
ctx context.Context, req CreateHostRequest, ctx context.Context, hostName nebula.HostName, opts CreateHostOpts,
) ( ) (
CreateHostResult, error, CreateHostResult, error,
) )
@ -113,7 +88,9 @@ type RPC interface {
// CreateNebulaCertificate passes the call through to the Daemon method of // CreateNebulaCertificate passes the call through to the Daemon method of
// the same name. // the same name.
CreateNebulaCertificate( CreateNebulaCertificate(
ctx context.Context, req CreateNebulaCertificateRequest, ctx context.Context,
hostName nebula.HostName,
hostEncryptingPublicKey nebula.EncryptingPublicKey,
) ( ) (
CreateNebulaCertificateResult, error, CreateNebulaCertificateResult, error,
) )
@ -188,21 +165,19 @@ func (r *rpcImpl) GetNebulaCAPublicCredentials(
} }
func (r *rpcImpl) RemoveHost( func (r *rpcImpl) RemoveHost(
ctx context.Context, req RemoveHostRequest, ctx context.Context, hostName nebula.HostName,
) ( ) (
struct{}, error, struct{}, error,
) { ) {
return struct{}{}, r.daemon.RemoveHost(ctx, req.HostName) return struct{}{}, r.daemon.RemoveHost(ctx, hostName)
} }
func (r *rpcImpl) CreateHost( func (r *rpcImpl) CreateHost(
ctx context.Context, req CreateHostRequest, ctx context.Context, hostName nebula.HostName, opts CreateHostOpts,
) ( ) (
CreateHostResult, error, CreateHostResult, error,
) { ) {
joiningBootstrap, err := r.daemon.CreateHost( joiningBootstrap, err := r.daemon.CreateHost(ctx, hostName, opts)
ctx, req.HostName, req.Opts,
)
if err != nil { if err != nil {
return CreateHostResult{}, err return CreateHostResult{}, err
} }
@ -211,18 +186,18 @@ func (r *rpcImpl) CreateHost(
} }
func (r *rpcImpl) CreateNebulaCertificate( func (r *rpcImpl) CreateNebulaCertificate(
ctx context.Context, req CreateNebulaCertificateRequest, ctx context.Context,
hostName nebula.HostName,
hostEncryptingPublicKey nebula.EncryptingPublicKey,
) ( ) (
CreateNebulaCertificateResult, error, CreateNebulaCertificateResult, error,
) { ) {
cert, err := r.daemon.CreateNebulaCertificate( cert, err := r.daemon.CreateNebulaCertificate(
ctx, req.HostName, req.HostEncryptingPublicKey, ctx, hostName, hostEncryptingPublicKey,
) )
if err != nil { if err != nil {
return CreateNebulaCertificateResult{}, err return CreateNebulaCertificateResult{}, err
} }
return CreateNebulaCertificateResult{ return CreateNebulaCertificateResult{HostNebulaCertificate: cert}, nil
HostNebulaCertifcate: cert,
}, nil
} }