Skip to content

Commit

Permalink
Use a typed value for mgr.SetGeneric() in the schema_registry com…
Browse files Browse the repository at this point in the history
…ponents

Signed-off-by: Mihai Todor <[email protected]>
  • Loading branch information
mihaitodor committed Nov 19, 2024
1 parent 0b55587 commit 6bbdc41
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
6 changes: 4 additions & 2 deletions internal/impl/kafka/enterprise/redpanda_migrator_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ type RedpandaMigratorWriter struct {
replicationFactor int
translateSchemaIDs bool
inputResource string
schemaRegistryOutputResource string
schemaRegistryOutputResource srResourceKey

clientDetails *kafka.FranzConnectionDetails
clientOpts []kgo.Opt
Expand Down Expand Up @@ -208,9 +208,11 @@ func NewRedpandaMigratorWriterFromConfig(conf *service.ParsedConfig, mgr *servic
}

if w.translateSchemaIDs {
if w.schemaRegistryOutputResource, err = conf.FieldString(rmoFieldSchemaRegistryOutputResource); err != nil {
var res string
if res, err = conf.FieldString(rmoFieldSchemaRegistryOutputResource); err != nil {
return nil, err
}
w.schemaRegistryOutputResource = srResourceKey(res)
}

if w.clientLabel = mgr.Label(); w.clientLabel == "" {
Expand Down
12 changes: 12 additions & 0 deletions internal/impl/kafka/enterprise/schema_registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2024 Redpanda Data, Inc.
//
// Licensed as a Redpanda Enterprise file under the Redpanda Community
// License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://github.com/redpanda-data/connect/blob/main/licenses/rcl.md

package enterprise

// srResourceKey is a type that represents a key for registering a `schema_registry` resource.
type srResourceKey string
4 changes: 2 additions & 2 deletions internal/impl/kafka/enterprise/schema_registry_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ func inputFromParsed(pConf *service.ParsedConfig, mgr *service.Resources) (i *sc
}

if label := mgr.Label(); label != "" {
mgr.SetGeneric(mgr.Label(), i)
mgr.SetGeneric(srResourceKey(mgr.Label()), i)
} else {
mgr.SetGeneric(sriResourceDefaultLabel, i)
mgr.SetGeneric(srResourceKey(sriResourceDefaultLabel), i)
}

return
Expand Down
10 changes: 6 additions & 4 deletions internal/impl/kafka/enterprise/schema_registry_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func init() {
type schemaRegistryOutput struct {
subject *service.InterpolatedString
backfillDependencies bool
inputResource string
inputResource srResourceKey

client *sr.Client
inputClient *sr.Client
Expand Down Expand Up @@ -135,9 +135,11 @@ func outputFromParsed(pConf *service.ParsedConfig, mgr *service.Resources) (o *s
}

if o.backfillDependencies {
if o.inputResource, err = pConf.FieldString(sroFieldInputResource); err != nil {
var res string
if res, err = pConf.FieldString(sroFieldInputResource); err != nil {
return nil, err
}
o.inputResource = srResourceKey(res)
}

var reqSigner func(f fs.FS, req *http.Request) error
Expand All @@ -159,9 +161,9 @@ func outputFromParsed(pConf *service.ParsedConfig, mgr *service.Resources) (o *s
}

if label := mgr.Label(); label != "" {
mgr.SetGeneric(mgr.Label(), o)
mgr.SetGeneric(srResourceKey(mgr.Label()), o)
} else {
mgr.SetGeneric(sroResourceDefaultLabel, o)
mgr.SetGeneric(srResourceKey(sroResourceDefaultLabel), o)
}

return
Expand Down

0 comments on commit 6bbdc41

Please sign in to comment.