Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions internal/cmd/schema-registry/command_cluster_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

pcmd "github.com/confluentinc/cli/internal/pkg/cmd"
v1 "github.com/confluentinc/cli/internal/pkg/config/v1"
dynamicconfig "github.com/confluentinc/cli/internal/pkg/dynamic-config"
"github.com/confluentinc/cli/internal/pkg/errors"
"github.com/confluentinc/cli/internal/pkg/examples"
"github.com/confluentinc/cli/internal/pkg/form"
Expand Down Expand Up @@ -46,8 +45,7 @@ func (c *clusterCommand) newDeleteCommand(cfg *v1.Config) *cobra.Command {
func (c *clusterCommand) delete(cmd *cobra.Command, _ []string, prompt form.Prompt) error {
ctx := context.Background()

ctxClient := dynamicconfig.NewContextClient(c.Context)
cluster, err := ctxClient.FetchSchemaRegistryByAccountId(ctx, c.EnvironmentId())
cluster, err := c.Context.FetchSchemaRegistryByAccountId(ctx, c.EnvironmentId())
if err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions internal/cmd/schema-registry/command_cluster_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"math"
"strconv"

dynamicconfig "github.com/confluentinc/cli/internal/pkg/dynamic-config"
"github.com/confluentinc/cli/internal/pkg/log"

"github.com/confluentinc/ccloud-sdk-go-v1"
Expand Down Expand Up @@ -67,8 +66,7 @@ func (c *clusterCommand) describe(cmd *cobra.Command, _ []string) error {
ctx := context.Background()

// Collect the parameters
ctxClient := dynamicconfig.NewContextClient(c.Context)
cluster, err := ctxClient.FetchSchemaRegistryByAccountId(ctx, c.EnvironmentId())
cluster, err := c.Context.FetchSchemaRegistryByAccountId(ctx, c.EnvironmentId())
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions internal/cmd/schema-registry/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ func GetSchemaRegistryClientWithApiKey(cmd *cobra.Command, cfg *dynamicconfig.Dy
if srCluster, ok := ctx.SchemaRegistryClusters[envId]; ok {
srConfig.BasePath = srCluster.SchemaRegistryEndpoint
} else {
ctxClient := dynamicconfig.NewContextClient(ctx)
srCluster, err := ctxClient.FetchSchemaRegistryByAccountId(srCtx, envId)
srCluster, err := ctx.FetchSchemaRegistryByAccountId(srCtx, envId)
if err != nil {
return nil, nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions internal/pkg/cmd/prerunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,7 @@ func getKafkaRestEndpoint(ctx *dynamicconfig.DynamicContext) (string, string, er

// if clusterConfig.RestEndpoint is empty, fetch the cluster to ensure config isn't just out of date
// potentially remove this once Rest Proxy is enabled across prod
client := dynamicconfig.NewContextClient(ctx)
kafkaCluster, err := client.FetchCluster(clusterConfig.ID)
kafkaCluster, err := ctx.FetchCluster(clusterConfig.ID)
if err != nil {
return "", "", err
}
Expand Down
27 changes: 9 additions & 18 deletions internal/pkg/dynamic-config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,24 @@ import (
"github.com/confluentinc/cli/internal/pkg/errors"
)

type contextClient struct {
context *DynamicContext
}

// NewContextClient returns a new contextClient, with the specified context and a client.
func NewContextClient(ctx *DynamicContext) *contextClient {
return &contextClient{context: ctx}
}

func (c *contextClient) FetchCluster(clusterId string) (*schedv1.KafkaCluster, error) {
envId, err := c.context.AuthenticatedEnvId()
func (d *DynamicContext) FetchCluster(clusterId string) (*schedv1.KafkaCluster, error) {
envId, err := d.AuthenticatedEnvId()
if err != nil {
return nil, err
}

req := &schedv1.KafkaCluster{AccountId: envId, Id: clusterId}
cluster, err := c.context.Client.Kafka.Describe(context.Background(), req)
cluster, err := d.Client.Kafka.Describe(context.Background(), req)
if err != nil {
return nil, errors.CatchKafkaNotFoundError(err, clusterId)
}

return cluster, nil
}

func (c *contextClient) FetchAPIKeyError(apiKey string, clusterID string) error {
func (d *DynamicContext) FetchAPIKeyError(apiKey string, clusterID string) error {
// check if this is API key exists server-side
key, _, err := c.context.V2Client.GetApiKey(apiKey)
key, _, err := d.V2Client.GetApiKey(apiKey)
if err != nil {
return err
}
Expand All @@ -51,8 +42,8 @@ func (c *contextClient) FetchAPIKeyError(apiKey string, clusterID string) error
return &errors.UnconfiguredAPISecretError{APIKey: apiKey, ClusterID: clusterID}
}

func (c *contextClient) FetchSchemaRegistryByAccountId(context context.Context, accountId string) (*schedv1.SchemaRegistryCluster, error) {
existingClusters, err := c.context.Client.SchemaRegistry.GetSchemaRegistryClusters(context, &schedv1.SchemaRegistryCluster{
func (d *DynamicContext) FetchSchemaRegistryByAccountId(context context.Context, accountId string) (*schedv1.SchemaRegistryCluster, error) {
existingClusters, err := d.Client.SchemaRegistry.GetSchemaRegistryClusters(context, &schedv1.SchemaRegistryCluster{
AccountId: accountId,
Name: "account schema-registry",
})
Expand All @@ -65,8 +56,8 @@ func (c *contextClient) FetchSchemaRegistryByAccountId(context context.Context,
return nil, errors.NewSRNotEnabledError()
}

func (c *contextClient) FetchSchemaRegistryById(context context.Context, id string, accountId string) (*schedv1.SchemaRegistryCluster, error) {
existingCluster, err := c.context.Client.SchemaRegistry.GetSchemaRegistryCluster(context, &schedv1.SchemaRegistryCluster{
func (d *DynamicContext) FetchSchemaRegistryById(context context.Context, id string, accountId string) (*schedv1.SchemaRegistryCluster, error) {
existingCluster, err := d.Client.SchemaRegistry.GetSchemaRegistryCluster(context, &schedv1.SchemaRegistryCluster{
Id: id,
AccountId: accountId,
})
Expand Down
11 changes: 4 additions & 7 deletions internal/pkg/dynamic-config/dynamic_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (d *DynamicContext) FindKafkaCluster(clusterId string) (*v1.KafkaClusterCon
}

// Resolve cluster details if not found locally.
kcc, err := NewContextClient(d).FetchCluster(clusterId)
kcc, err := d.FetchCluster(clusterId)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -162,9 +162,7 @@ func (d *DynamicContext) UseAPIKey(apiKey string, clusterId string) error {
return err
}
if _, ok := kcc.APIKeys[apiKey]; !ok {
// Fetch API key error.
ctxClient := NewContextClient(d)
return ctxClient.FetchAPIKeyError(apiKey, clusterId)
return d.FetchAPIKeyError(apiKey, clusterId)
}
kcc.APIKey = apiKey
return d.Save()
Expand All @@ -182,7 +180,6 @@ func (d *DynamicContext) SchemaRegistryCluster(cmd *cobra.Command) (*v1.SchemaRe
return nil, err
}

ctxClient := NewContextClient(d)
var cluster *v1.SchemaRegistryCluster
var clusterChanged bool
if resourceType == resource.SchemaRegistry {
Expand All @@ -192,7 +189,7 @@ func (d *DynamicContext) SchemaRegistryCluster(cmd *cobra.Command) (*v1.SchemaRe
}
}
if cluster == nil || missingDetails(cluster) {
srCluster, err := ctxClient.FetchSchemaRegistryById(context.Background(), resourceId, envId)
srCluster, err := d.FetchSchemaRegistryById(context.Background(), resourceId, envId)
if err != nil {
return nil, errors.CatchResourceNotFoundError(err, resourceId)
}
Expand All @@ -202,7 +199,7 @@ func (d *DynamicContext) SchemaRegistryCluster(cmd *cobra.Command) (*v1.SchemaRe
} else {
cluster = d.SchemaRegistryClusters[envId]
if cluster == nil || missingDetails(cluster) {
srCluster, err := ctxClient.FetchSchemaRegistryByAccountId(context.Background(), envId)
srCluster, err := d.FetchSchemaRegistryByAccountId(context.Background(), envId)
if err != nil {
return nil, errors.CatchResourceNotFoundError(err, resourceId)
}
Expand Down