-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NET-5824 Exported services api (#20015)
* Exported services api implemented * Tests added, refactored code * Adding server tests * changelog added * Proto gen added * Adding codegen changes * changing url, response object * Fixing lint error by having namespace and partition directly * Tests changes * refactoring tests * Simplified uniqueness logic for exported services, sorted the response in order of service name * Fix lint errors, refactored code
- Loading branch information
Showing
31 changed files
with
4,145 additions
and
2,262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
api: add a new api(/v1/exported-services) to list all the exported service and their consumers. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package consul | ||
|
||
import ( | ||
"github.com/hashicorp/consul/acl" | ||
"github.com/hashicorp/consul/acl/resolver" | ||
"github.com/hashicorp/consul/agent/grpc-external/services/configentry" | ||
) | ||
|
||
type ConfigEntryBackend struct { | ||
srv *Server | ||
} | ||
|
||
var _ configentry.Backend = (*ConfigEntryBackend)(nil) | ||
|
||
// NewConfigEntryBackend returns a configentry.Backend implementation that is bound to the given server. | ||
func NewConfigEntryBackend(srv *Server) *ConfigEntryBackend { | ||
return &ConfigEntryBackend{ | ||
srv: srv, | ||
} | ||
} | ||
|
||
func (b *ConfigEntryBackend) EnterpriseCheckPartitions(partition string) error { | ||
return b.enterpriseCheckPartitions(partition) | ||
} | ||
|
||
func (b *ConfigEntryBackend) ResolveTokenAndDefaultMeta(token string, entMeta *acl.EnterpriseMeta, authzCtx *acl.AuthorizerContext) (resolver.Result, error) { | ||
return b.srv.ResolveTokenAndDefaultMeta(token, entMeta, authzCtx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
//go:build !consulent | ||
|
||
package consul | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func (b *ConfigEntryBackend) enterpriseCheckPartitions(partition string) error { | ||
if partition == "" || strings.EqualFold(partition, "default") { | ||
return nil | ||
} | ||
return fmt.Errorf("Partitions are a Consul Enterprise feature") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
//go:build !consulent | ||
|
||
package consul | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
gogrpc "google.golang.org/grpc" | ||
|
||
"github.com/hashicorp/consul/proto/private/pbconfigentry" | ||
"github.com/hashicorp/consul/sdk/freeport" | ||
"github.com/hashicorp/consul/testrpc" | ||
) | ||
|
||
func TestConfigEntryBackend_RejectsPartition(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("too slow for testing.Short") | ||
} | ||
|
||
t.Parallel() | ||
|
||
_, s1 := testServerWithConfig(t, func(c *Config) { | ||
c.GRPCTLSPort = freeport.GetOne(t) | ||
}) | ||
testrpc.WaitForLeader(t, s1.RPC, "dc1") | ||
|
||
// make a grpc client to dial s1 directly | ||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) | ||
t.Cleanup(cancel) | ||
|
||
conn, err := gogrpc.DialContext(ctx, s1.config.RPCAddr.String(), | ||
gogrpc.WithContextDialer(newServerDialer(s1.config.RPCAddr.String())), | ||
//nolint:staticcheck | ||
gogrpc.WithInsecure(), | ||
gogrpc.WithBlock()) | ||
require.NoError(t, err) | ||
t.Cleanup(func() { conn.Close() }) | ||
|
||
configEntryClient := pbconfigentry.NewConfigEntryServiceClient(conn) | ||
|
||
req := pbconfigentry.GetResolvedExportedServicesRequest{ | ||
Partition: "test", | ||
} | ||
_, err = configEntryClient.GetResolvedExportedServices(ctx, &req) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "Partitions are a Consul Enterprise feature") | ||
} | ||
|
||
func TestConfigEntryBackend_IgnoresDefaultPartition(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("too slow for testing.Short") | ||
} | ||
|
||
t.Parallel() | ||
|
||
_, s1 := testServerWithConfig(t, func(c *Config) { | ||
c.GRPCTLSPort = freeport.GetOne(t) | ||
}) | ||
|
||
testrpc.WaitForLeader(t, s1.RPC, "dc1") | ||
|
||
// make a grpc client to dial s1 directly | ||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) | ||
t.Cleanup(cancel) | ||
|
||
conn, err := gogrpc.DialContext(ctx, s1.config.RPCAddr.String(), | ||
gogrpc.WithContextDialer(newServerDialer(s1.config.RPCAddr.String())), | ||
//nolint:staticcheck | ||
gogrpc.WithInsecure(), | ||
gogrpc.WithBlock()) | ||
require.NoError(t, err) | ||
t.Cleanup(func() { conn.Close() }) | ||
|
||
configEntryClient := pbconfigentry.NewConfigEntryServiceClient(conn) | ||
|
||
req := pbconfigentry.GetResolvedExportedServicesRequest{ | ||
Partition: "DeFaUlT", | ||
} | ||
_, err = configEntryClient.GetResolvedExportedServices(ctx, &req) | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package consul | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/hashicorp/consul/proto/private/pbconfigentry" | ||
"github.com/hashicorp/consul/sdk/freeport" | ||
"github.com/hashicorp/consul/testrpc" | ||
"github.com/stretchr/testify/require" | ||
gogrpc "google.golang.org/grpc" | ||
) | ||
|
||
func TestConfigEntryBackend_EmptyPartition(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("too slow for testing.Short") | ||
} | ||
|
||
t.Parallel() | ||
|
||
_, s1 := testServerWithConfig(t, func(c *Config) { | ||
c.GRPCTLSPort = freeport.GetOne(t) | ||
}) | ||
testrpc.WaitForLeader(t, s1.RPC, "dc1") | ||
|
||
// make a grpc client to dial s1 directly | ||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) | ||
t.Cleanup(cancel) | ||
|
||
conn, err := gogrpc.DialContext(ctx, s1.config.RPCAddr.String(), | ||
gogrpc.WithContextDialer(newServerDialer(s1.config.RPCAddr.String())), | ||
//nolint:staticcheck | ||
gogrpc.WithInsecure(), | ||
gogrpc.WithBlock()) | ||
require.NoError(t, err) | ||
t.Cleanup(func() { conn.Close() }) | ||
|
||
configEntryClient := pbconfigentry.NewConfigEntryServiceClient(conn) | ||
|
||
req := pbconfigentry.GetResolvedExportedServicesRequest{ | ||
Partition: "", | ||
} | ||
_, err = configEntryClient.GetResolvedExportedServices(ctx, &req) | ||
require.NoError(t, err) | ||
} |
Oops, something went wrong.