pkg/certificate: properly close certificateclient.Client (#2986)

This commit is contained in:
paul cannon 2019-09-10 11:24:41 -05:00 committed by Egon Elbre
parent 2fc4d61610
commit 7cf5650560
3 changed files with 10 additions and 2 deletions

View File

@ -149,10 +149,10 @@ func cmdNewService(cmd *cobra.Command, args []string) error {
return nil
}
func cmdAuthorize(cmd *cobra.Command, args []string) error {
func cmdAuthorize(cmd *cobra.Command, args []string) (err error) {
ctx := process.Ctx(cmd)
err := version.CheckProcessVersion(ctx, zap.L(), config.Version, version.Build, "Identity")
err = version.CheckProcessVersion(ctx, zap.L(), config.Version, version.Build, "Identity")
if err != nil {
return err
}
@ -204,6 +204,9 @@ func cmdAuthorize(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
defer func() {
err = errs.Combine(err, client.Close())
}()
signedChainBytes, err := client.Sign(ctx, authToken)
if err != nil {

View File

@ -7,6 +7,7 @@ import (
"context"
"time"
"github.com/zeebo/errs"
"google.golang.org/grpc"
"gopkg.in/spacemonkeygo/monkit.v2"
@ -65,6 +66,9 @@ func (config Config) Sign(ctx context.Context, ident *identity.FullIdentity, aut
if err != nil {
return nil, err
}
defer func() {
err = errs.Combine(err, client.Close())
}()
return client.Sign(ctx, authToken)
}

View File

@ -92,6 +92,7 @@ func TestCertificateSigner_Sign_E2E(t *testing.T) {
client, err := certificateclient.New(ctx, clientTransport, peer.Server.Addr().String())
require.NoError(t, err)
require.NotNil(t, client)
defer ctx.Check(client.Close)
signedChainBytes, err := client.Sign(ctx, auths[0].Token.String())
require.NoError(t, err)