mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-06-29 16:37:22 -04:00
Update proto client naming
This commit is contained in:
parent
ddf94c7373
commit
c08787ce80
4 changed files with 42 additions and 44 deletions
|
@ -14,12 +14,10 @@ import (
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client wraps a AVPNClient and the connection to it.
|
// Client wraps a PubAPI client and the connection to it.
|
||||||
// The client offers a method to activate the connected
|
|
||||||
// AVPNServer as Coordinator.
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
conn *grpc.ClientConn
|
conn *grpc.ClientConn
|
||||||
avpn pubproto.APIClient
|
pubapi pubproto.APIClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect connects the client to a given server, using the handed
|
// Connect connects the client to a given server, using the handed
|
||||||
|
@ -43,7 +41,7 @@ func (c *Client) Connect(ip, port string, validators []atls.Validator) error {
|
||||||
c.conn.Close()
|
c.conn.Close()
|
||||||
}
|
}
|
||||||
c.conn = conn
|
c.conn = conn
|
||||||
c.avpn = pubproto.NewAPIClient(conn)
|
c.pubapi = pubproto.NewAPIClient(conn)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +63,7 @@ func (c *Client) Close() error {
|
||||||
// The handed IP addresses must be the private IP addresses of running AWS or GCP instances,
|
// The handed IP addresses must be the private IP addresses of running AWS or GCP instances,
|
||||||
// and the userPublicKey is the VPN key of the users WireGuard interface.
|
// and the userPublicKey is the VPN key of the users WireGuard interface.
|
||||||
func (c *Client) Activate(ctx context.Context, userPublicKey, masterSecret []byte, nodeIPs, coordinatorIPs, autoscalingNodeGroups []string, cloudServiceAccountURI string) (ActivationResponseClient, error) {
|
func (c *Client) Activate(ctx context.Context, userPublicKey, masterSecret []byte, nodeIPs, coordinatorIPs, autoscalingNodeGroups []string, cloudServiceAccountURI string) (ActivationResponseClient, error) {
|
||||||
if c.avpn == nil {
|
if c.pubapi == nil {
|
||||||
return nil, errors.New("client is not connected")
|
return nil, errors.New("client is not connected")
|
||||||
}
|
}
|
||||||
if len(userPublicKey) == 0 {
|
if len(userPublicKey) == 0 {
|
||||||
|
@ -80,7 +78,7 @@ func (c *Client) Activate(ctx context.Context, userPublicKey, masterSecret []byt
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
avpnRequest := &pubproto.ActivateAsCoordinatorRequest{
|
req := &pubproto.ActivateAsCoordinatorRequest{
|
||||||
AdminVpnPubKey: pubKey[:],
|
AdminVpnPubKey: pubKey[:],
|
||||||
NodePublicIps: nodeIPs,
|
NodePublicIps: nodeIPs,
|
||||||
CoordinatorPublicIps: coordinatorIPs,
|
CoordinatorPublicIps: coordinatorIPs,
|
||||||
|
@ -93,7 +91,7 @@ func (c *Client) Activate(ctx context.Context, userPublicKey, masterSecret []byt
|
||||||
CloudServiceAccountUri: cloudServiceAccountURI,
|
CloudServiceAccountUri: cloudServiceAccountURI,
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := c.avpn.ActivateAsCoordinator(ctx, avpnRequest)
|
client, err := c.pubapi.ActivateAsCoordinator(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,42 +70,42 @@ func TestActivate(t *testing.T) {
|
||||||
someErr := errors.New("failed")
|
someErr := errors.New("failed")
|
||||||
|
|
||||||
testCases := map[string]struct {
|
testCases := map[string]struct {
|
||||||
avpn *stubAVPNClient
|
pubAPIClient *stubPubAPIClient
|
||||||
userPublicKey string
|
userPublicKey string
|
||||||
ips []string
|
ips []string
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
"normal activation": {
|
"normal activation": {
|
||||||
avpn: &stubAVPNClient{},
|
pubAPIClient: &stubPubAPIClient{},
|
||||||
userPublicKey: testKey,
|
userPublicKey: testKey,
|
||||||
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
"client without avpn": {
|
"client without pubAPIClient": {
|
||||||
userPublicKey: testKey,
|
userPublicKey: testKey,
|
||||||
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
"empty public key parameter": {
|
"empty public key parameter": {
|
||||||
avpn: &stubAVPNClient{},
|
pubAPIClient: &stubPubAPIClient{},
|
||||||
userPublicKey: "",
|
userPublicKey: "",
|
||||||
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
"invalid public key parameter": {
|
"invalid public key parameter": {
|
||||||
avpn: &stubAVPNClient{},
|
pubAPIClient: &stubPubAPIClient{},
|
||||||
userPublicKey: "invalid Key",
|
userPublicKey: "invalid Key",
|
||||||
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
"empty ips parameter": {
|
"empty ips parameter": {
|
||||||
avpn: &stubAVPNClient{},
|
pubAPIClient: &stubPubAPIClient{},
|
||||||
userPublicKey: testKey,
|
userPublicKey: testKey,
|
||||||
ips: []string{},
|
ips: []string{},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
"fail ActivateAsCoordinator": {
|
"fail ActivateAsCoordinator": {
|
||||||
avpn: &stubAVPNClient{activateAsCoordinatorErr: someErr},
|
pubAPIClient: &stubPubAPIClient{activateAsCoordinatorErr: someErr},
|
||||||
userPublicKey: testKey,
|
userPublicKey: testKey,
|
||||||
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
ips: []string{"192.0.2.1", "192.0.2.1", "192.0.2.1"},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
|
@ -117,24 +117,24 @@ func TestActivate(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
client := Client{}
|
client := Client{}
|
||||||
if tc.avpn != nil {
|
if tc.pubAPIClient != nil {
|
||||||
client.avpn = tc.avpn
|
client.pubapi = tc.pubAPIClient
|
||||||
}
|
}
|
||||||
_, err := client.Activate(context.Background(), []byte(tc.userPublicKey), []byte("Constellation"), tc.ips, nil, nil, "serviceaccount://test")
|
_, err := client.Activate(context.Background(), []byte(tc.userPublicKey), []byte("Constellation"), tc.ips, nil, nil, "serviceaccount://test")
|
||||||
if tc.wantErr {
|
if tc.wantErr {
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
} else {
|
} else {
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.Equal("32bytesWireGuardKeyForTheTesting", string(tc.avpn.activateAsCoordinatorReqKey))
|
assert.Equal("32bytesWireGuardKeyForTheTesting", string(tc.pubAPIClient.activateAsCoordinatorReqKey))
|
||||||
assert.Equal(tc.ips, tc.avpn.activateAsCoordinatorReqIPs)
|
assert.Equal(tc.ips, tc.pubAPIClient.activateAsCoordinatorReqIPs)
|
||||||
assert.Equal("Constellation", string(tc.avpn.activateAsCoordinatorMasterSecret))
|
assert.Equal("Constellation", string(tc.pubAPIClient.activateAsCoordinatorMasterSecret))
|
||||||
assert.Equal("serviceaccount://test", tc.avpn.activateCloudServiceAccountURI)
|
assert.Equal("serviceaccount://test", tc.pubAPIClient.activateCloudServiceAccountURI)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type stubAVPNClient struct {
|
type stubPubAPIClient struct {
|
||||||
activateAsCoordinatorErr error
|
activateAsCoordinatorErr error
|
||||||
activateAdditionalNodesErr error
|
activateAdditionalNodesErr error
|
||||||
activateAsCoordinatorReqKey []byte
|
activateAsCoordinatorReqKey []byte
|
||||||
|
@ -145,19 +145,19 @@ type stubAVPNClient struct {
|
||||||
pubproto.APIClient
|
pubproto.APIClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stubAVPNClient) ActivateAsCoordinator(ctx context.Context, in *pubproto.ActivateAsCoordinatorRequest,
|
func (s *stubPubAPIClient) ActivateAsCoordinator(ctx context.Context, in *pubproto.ActivateAsCoordinatorRequest,
|
||||||
opts ...grpc.CallOption,
|
opts ...grpc.CallOption,
|
||||||
) (pubproto.API_ActivateAsCoordinatorClient, error) {
|
) (pubproto.API_ActivateAsCoordinatorClient, error) {
|
||||||
s.activateAsCoordinatorReqKey = in.AdminVpnPubKey
|
s.activateAsCoordinatorReqKey = in.AdminVpnPubKey
|
||||||
s.activateAsCoordinatorReqIPs = in.NodePublicIps
|
s.activateAsCoordinatorReqIPs = in.NodePublicIps
|
||||||
s.activateAsCoordinatorMasterSecret = in.MasterSecret
|
s.activateAsCoordinatorMasterSecret = in.MasterSecret
|
||||||
s.activateCloudServiceAccountURI = in.CloudServiceAccountUri
|
s.activateCloudServiceAccountURI = in.CloudServiceAccountUri
|
||||||
return dummyAVPNActivateAsCoordinatorClient{}, s.activateAsCoordinatorErr
|
return dummyActivateAsCoordinatorClient{}, s.activateAsCoordinatorErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stubAVPNClient) ActivateAdditionalNodes(ctx context.Context, in *pubproto.ActivateAdditionalNodesRequest,
|
func (s *stubPubAPIClient) ActivateAdditionalNodes(ctx context.Context, in *pubproto.ActivateAdditionalNodesRequest,
|
||||||
opts ...grpc.CallOption,
|
opts ...grpc.CallOption,
|
||||||
) (pubproto.API_ActivateAdditionalNodesClient, error) {
|
) (pubproto.API_ActivateAdditionalNodesClient, error) {
|
||||||
s.activateAdditionalNodesReqIPs = in.NodePublicIps
|
s.activateAdditionalNodesReqIPs = in.NodePublicIps
|
||||||
return dummyAVPNActivateAdditionalNodesClient{}, s.activateAdditionalNodesErr
|
return dummyActivateAdditionalNodesClient{}, s.activateAdditionalNodesErr
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ActivationRespClient has methods to read messages from a stream of
|
// ActivationRespClient has methods to read messages from a stream of
|
||||||
// ActivateAsCoordinatorResponses. It wraps an AVPN_ActivateAsCoordinatorClient.
|
// ActivateAsCoordinatorResponses. It wraps an API_ActivateAsCoordinatorClient.
|
||||||
type ActivationRespClient struct {
|
type ActivationRespClient struct {
|
||||||
client pubproto.API_ActivateAsCoordinatorClient
|
client pubproto.API_ActivateAsCoordinatorClient
|
||||||
kubeconfig string
|
kubeconfig string
|
||||||
|
@ -22,7 +22,7 @@ type ActivationRespClient struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewActivationRespClient creates a new ActivationRespClient with the handed
|
// NewActivationRespClient creates a new ActivationRespClient with the handed
|
||||||
// AVPN_ActivateAsCoordinatorClient.
|
// API_ActivateAsCoordinatorClient.
|
||||||
func NewActivationRespClient(client pubproto.API_ActivateAsCoordinatorClient) *ActivationRespClient {
|
func NewActivationRespClient(client pubproto.API_ActivateAsCoordinatorClient) *ActivationRespClient {
|
||||||
return &ActivationRespClient{
|
return &ActivationRespClient{
|
||||||
client: client,
|
client: client,
|
||||||
|
|
|
@ -11,34 +11,34 @@ import (
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// dummyAVPNActivateAsCoordinatorClient is a dummy and panics if Recv() is called.
|
// dummyActivateAsCoordinatorClient is a dummy and panics if Recv() is called.
|
||||||
type dummyAVPNActivateAsCoordinatorClient struct {
|
type dummyActivateAsCoordinatorClient struct {
|
||||||
grpc.ClientStream
|
grpc.ClientStream
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c dummyAVPNActivateAsCoordinatorClient) Recv() (*pubproto.ActivateAsCoordinatorResponse, error) {
|
func (c dummyActivateAsCoordinatorClient) Recv() (*pubproto.ActivateAsCoordinatorResponse, error) {
|
||||||
panic("i'm a dummy, Recv() not implemented")
|
panic("i'm a dummy, Recv() not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// dummyAVPNActivateAsCoordinatorClient is a dummy and panics if Recv() is called.
|
// dummyActivateAsCoordinatorClient is a dummy and panics if Recv() is called.
|
||||||
type dummyAVPNActivateAdditionalNodesClient struct {
|
type dummyActivateAdditionalNodesClient struct {
|
||||||
grpc.ClientStream
|
grpc.ClientStream
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c dummyAVPNActivateAdditionalNodesClient) Recv() (*pubproto.ActivateAdditionalNodesResponse, error) {
|
func (c dummyActivateAdditionalNodesClient) Recv() (*pubproto.ActivateAdditionalNodesResponse, error) {
|
||||||
panic("i'm a dummy, Recv() not implemented")
|
panic("i'm a dummy, Recv() not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// stubAVPNActivationAsCoordinatorClient recives responses from an predefined
|
// stubActivationAsCoordinatorClient recives responses from an predefined
|
||||||
// response stream iterator or a stub error.
|
// response stream iterator or a stub error.
|
||||||
type stubAVPNActivationAsCoordinatorClient struct {
|
type stubActivationAsCoordinatorClient struct {
|
||||||
grpc.ClientStream
|
grpc.ClientStream
|
||||||
|
|
||||||
stream *stubActivateAsCoordinatorResponseIter
|
stream *stubActivateAsCoordinatorResponseIter
|
||||||
recvErr error
|
recvErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c stubAVPNActivationAsCoordinatorClient) Recv() (*pubproto.ActivateAsCoordinatorResponse, error) {
|
func (c stubActivationAsCoordinatorClient) Recv() (*pubproto.ActivateAsCoordinatorResponse, error) {
|
||||||
if c.recvErr != nil {
|
if c.recvErr != nil {
|
||||||
return nil, c.recvErr
|
return nil, c.recvErr
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ func TestNextLog(t *testing.T) {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
respClient := stubAVPNActivationAsCoordinatorClient{
|
respClient := stubActivationAsCoordinatorClient{
|
||||||
stream: &stubActivateAsCoordinatorResponseIter{
|
stream: &stubActivateAsCoordinatorResponseIter{
|
||||||
msgs: tc.msgs,
|
msgs: tc.msgs,
|
||||||
},
|
},
|
||||||
|
@ -180,7 +180,7 @@ func TestPrintLogStream(t *testing.T) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
respClient := stubAVPNActivationAsCoordinatorClient{
|
respClient := stubActivationAsCoordinatorClient{
|
||||||
stream: &stubActivateAsCoordinatorResponseIter{
|
stream: &stubActivateAsCoordinatorResponseIter{
|
||||||
msgs: msgs,
|
msgs: msgs,
|
||||||
},
|
},
|
||||||
|
@ -194,7 +194,7 @@ func TestPrintLogStream(t *testing.T) {
|
||||||
// Check error handling.
|
// Check error handling.
|
||||||
//
|
//
|
||||||
someErr := errors.New("failed")
|
someErr := errors.New("failed")
|
||||||
respClient = stubAVPNActivationAsCoordinatorClient{
|
respClient = stubActivationAsCoordinatorClient{
|
||||||
recvErr: someErr,
|
recvErr: someErr,
|
||||||
}
|
}
|
||||||
client = NewActivationRespClient(respClient)
|
client = NewActivationRespClient(respClient)
|
||||||
|
@ -204,7 +204,7 @@ func TestPrintLogStream(t *testing.T) {
|
||||||
func TestGetKubeconfig(t *testing.T) {
|
func TestGetKubeconfig(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
client := NewActivationRespClient(dummyAVPNActivateAsCoordinatorClient{})
|
client := NewActivationRespClient(dummyActivateAsCoordinatorClient{})
|
||||||
_, err := client.GetKubeconfig()
|
_, err := client.GetKubeconfig()
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ func TestGetKubeconfig(t *testing.T) {
|
||||||
func TestGetCoordinatorVpnKey(t *testing.T) {
|
func TestGetCoordinatorVpnKey(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
client := NewActivationRespClient(dummyAVPNActivateAsCoordinatorClient{})
|
client := NewActivationRespClient(dummyActivateAsCoordinatorClient{})
|
||||||
_, err := client.GetCoordinatorVpnKey()
|
_, err := client.GetCoordinatorVpnKey()
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ func TestGetCoordinatorVpnKey(t *testing.T) {
|
||||||
func TestGetClientVpnIp(t *testing.T) {
|
func TestGetClientVpnIp(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
client := NewActivationRespClient(dummyAVPNActivateAsCoordinatorClient{})
|
client := NewActivationRespClient(dummyActivateAsCoordinatorClient{})
|
||||||
_, err := client.GetClientVpnIp()
|
_, err := client.GetClientVpnIp()
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue