Skip to content

Commit

Permalink
reduce dependencies in the plugin interface
Browse files Browse the repository at this point in the history
  • Loading branch information
d-rk committed Mar 12, 2024
1 parent 6f748d7 commit 600c726
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ jobs:
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --rm-dist --debug
args: release --clean --debug
env:
# create personal access token: https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
Expand Down
4 changes: 2 additions & 2 deletions internal/auth/token-provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package auth

import (
"github.com/IBM/sarama"
"github.com/deviceinsight/kafkactl/v5/pkg/plugins"
"github.com/deviceinsight/kafkactl/v5/internal/util"
"github.com/deviceinsight/kafkactl/v5/pkg/plugins/auth"
)

Expand All @@ -22,7 +22,7 @@ func LoadTokenProviderPlugin(pluginName string, options map[string]any, brokers
loadedPlugin, ok := loadedPlugins[pluginName]
if !ok {
var err error
loadedPlugin, err = plugins.LoadPlugin(pluginName, auth.TokenProviderPluginSpec)
loadedPlugin, err = util.LoadPlugin(pluginName, auth.TokenProviderPluginSpec)
if err != nil {
return nil, err
}
Expand Down
20 changes: 4 additions & 16 deletions pkg/plugins/plugin.go → internal/util/plugin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package plugins
package util

import (
"fmt"
Expand All @@ -9,25 +9,13 @@ import (

"github.com/deviceinsight/kafkactl/v5/internal/global"
"github.com/deviceinsight/kafkactl/v5/internal/output"
"github.com/deviceinsight/kafkactl/v5/pkg/plugins"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"github.com/pkg/errors"
)

const GenericInterfaceIdentifier = "generic"

type PluginSpec[P plugin.Plugin, I any] struct {
PluginImpl P
Handshake plugin.HandshakeConfig
}

func (s *PluginSpec[P, I]) GetMap() map[string]plugin.Plugin {
return map[string]plugin.Plugin{
GenericInterfaceIdentifier: s.PluginImpl,
}
}

func LoadPlugin[P plugin.Plugin, I any](pluginName string, pluginSpec PluginSpec[P, I]) (impl I, err error) {
func LoadPlugin[P plugin.Plugin, I any](pluginName string, pluginSpec plugins.PluginSpec[P, I]) (impl I, err error) {

pluginPath, err := resolvePluginPath(pluginName)
if err != nil {
Expand Down Expand Up @@ -59,7 +47,7 @@ func LoadPlugin[P plugin.Plugin, I any](pluginName string, pluginSpec PluginSpec
}

// Request the plugin
raw, err := rpcClient.Dispense(GenericInterfaceIdentifier)
raw, err := rpcClient.Dispense(pluginSpec.InterfaceIdentifier)
if err != nil {
client.Kill()
return impl, err
Expand Down
3 changes: 2 additions & 1 deletion pkg/plugins/auth/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ type AccessTokenProvider interface {
}

var TokenProviderPluginSpec = plugins.PluginSpec[*TokenProviderPlugin, AccessTokenProvider]{
PluginImpl: &TokenProviderPlugin{},
PluginImpl: &TokenProviderPlugin{},
InterfaceIdentifier: "tokenProvider",
Handshake: plugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "KAFKACTL_PLUGIN",
Expand Down
15 changes: 15 additions & 0 deletions pkg/plugins/plugins.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package plugins

import "github.com/hashicorp/go-plugin"

type PluginSpec[P plugin.Plugin, I any] struct {
PluginImpl P
InterfaceIdentifier string
Handshake plugin.HandshakeConfig
}

func (s *PluginSpec[P, I]) GetMap() map[string]plugin.Plugin {
return map[string]plugin.Plugin{
s.InterfaceIdentifier: s.PluginImpl,
}
}

0 comments on commit 600c726

Please sign in to comment.