Skip to content

Commit

Permalink
Tidy up some code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
strideynet committed Oct 23, 2024
1 parent 7fdaed1 commit 379877e
Showing 1 changed file with 16 additions and 38 deletions.
54 changes: 16 additions & 38 deletions lib/auth/join/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,29 +350,25 @@ func registerThroughProxy(
return nil, trace.Wrap(err)
}

// TODO(strideynet): When the old HTTP based join RPC is completely
// removed, this section can be refactored to reduce duplication.
conn, err := proxyinsecureclient.NewConnection(
ctx,
proxyinsecureclient.ConnectionConfig{
ProxyServer: proxyAddr,
CipherSuites: params.CipherSuites,
Clock: params.Clock,
Insecure: params.Insecure,
Log: slog.Default(),
},
)
if err != nil {
return nil, trace.Wrap(err)
}
defer conn.Close()
joinServiceClient := client.NewJoinServiceClient(proto.NewJoinServiceClient(conn))

var certs *proto.Certs
switch params.JoinMethod {
case types.JoinMethodIAM, types.JoinMethodAzure, types.JoinMethodTPM:
// IAM and Azure join methods require gRPC client
conn, err := proxyinsecureclient.NewConnection(
ctx,
proxyinsecureclient.ConnectionConfig{
ProxyServer: proxyAddr,
CipherSuites: params.CipherSuites,
Clock: params.Clock,
Insecure: params.Insecure,
Log: slog.Default(),
},
)
if err != nil {
return nil, trace.Wrap(err)
}
defer conn.Close()

joinServiceClient := client.NewJoinServiceClient(proto.NewJoinServiceClient(conn))
switch params.JoinMethod {
case types.JoinMethodIAM:
certs, err = registerUsingIAMMethod(ctx, joinServiceClient, token, hostKeys, params)
Expand All @@ -387,24 +383,6 @@ func registerThroughProxy(
return nil, trace.Wrap(err)
}
default:
conn, err := proxyinsecureclient.NewConnection(
ctx,
proxyinsecureclient.ConnectionConfig{
ProxyServer: proxyAddr,
CipherSuites: params.CipherSuites,
Clock: params.Clock,
Insecure: params.Insecure,
Log: slog.Default(),
},
)
if err != nil {
return nil, trace.Wrap(err, "creating proxy client")
}
defer conn.Close()

joinServiceClient := client.NewJoinServiceClient(
proto.NewJoinServiceClient(conn),
)
certs, err = joinServiceClient.RegisterUsingToken(
ctx, registerUsingTokenRequestForParams(token, hostKeys, params),
)
Expand All @@ -427,8 +405,8 @@ func registerThroughProxy(
return nil, trace.Wrap(err)
}
}

}

return &RegisterResult{
Certs: certs,
PrivateKey: hostKeys.privateKey,
Expand Down

0 comments on commit 379877e

Please sign in to comment.