forked from woodpecker-ci/woodpecker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
218 additions
and
46 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
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,17 @@ | ||
package execute | ||
|
||
import ( | ||
"github.com/hashicorp/go-plugin" | ||
|
||
"go.woodpecker-ci.org/woodpecker/shared/addon/rpc" | ||
addonTypes "go.woodpecker-ci.org/woodpecker/shared/addon/types" | ||
) | ||
|
||
func Execute[T any](addon addonTypes.Addon[T]) { | ||
plugin.Serve(&plugin.ServeConfig{ | ||
HandshakeConfig: rpc.HandshakeConfig, | ||
Plugins: plugin.PluginSet{ | ||
string(addon.Type()): &rpc.AddonPlugin[T]{Impl: addon}, | ||
}, | ||
}) | ||
} |
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,34 @@ | ||
package rpc | ||
|
||
import ( | ||
"net/rpc" | ||
|
||
"github.com/rs/zerolog/log" | ||
|
||
"go.woodpecker-ci.org/woodpecker/shared/addon/types" | ||
) | ||
|
||
type AddonRPCClient[T any] struct { | ||
client *rpc.Client | ||
} | ||
|
||
func (a *AddonRPCClient[T]) Type() types.Type { | ||
var resp types.Type | ||
err := a.client.Call("Plugin.Type", new(any), &resp) | ||
if err != nil { | ||
log.Error().Err(err).Msg("could not get addon type") | ||
return "" | ||
} | ||
|
||
return resp | ||
} | ||
|
||
func (a *AddonRPCClient[T]) Addon(env []string) (T, error) { | ||
var resp T | ||
err := a.client.Call("Plugin.Addon", map[string]any{ | ||
//"logger": logger, | ||
"env": env, | ||
}, &resp) | ||
|
||
return resp, 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,27 @@ | ||
package rpc | ||
|
||
import ( | ||
"net/rpc" | ||
|
||
"github.com/hashicorp/go-plugin" | ||
|
||
"go.woodpecker-ci.org/woodpecker/shared/addon/types" | ||
) | ||
|
||
var HandshakeConfig = plugin.HandshakeConfig{ | ||
ProtocolVersion: 1, | ||
MagicCookieKey: "woodpecker_plugin_key", | ||
MagicCookieValue: "woodpecker_plugin_value", | ||
} | ||
|
||
type AddonPlugin[T any] struct { | ||
Impl types.Addon[T] | ||
} | ||
|
||
func (a *AddonPlugin[T]) Server(_ *plugin.MuxBroker) (interface{}, error) { | ||
return &AddonRPCServer[T]{Impl: a.Impl}, nil | ||
} | ||
|
||
func (*AddonPlugin[T]) Client(_ *plugin.MuxBroker, c *rpc.Client) (interface{}, error) { | ||
return &AddonRPCClient[T]{client: c}, nil | ||
} |
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,20 @@ | ||
package rpc | ||
|
||
import ( | ||
"go.woodpecker-ci.org/woodpecker/shared/addon/types" | ||
) | ||
|
||
type AddonRPCServer[T any] struct { | ||
Impl types.Addon[T] | ||
} | ||
|
||
func (a *AddonRPCServer[T]) Type(_ interface{}, resp *types.Type) error { | ||
*resp = a.Impl.Type() | ||
return nil | ||
} | ||
|
||
func (a *AddonRPCServer[T]) Addon(args map[string]interface{}, resp *T) error { | ||
addon, err := a.Impl.Addon( /*args["logger"].(zerolog.Logger), */ args["env"].([]string)) | ||
*resp = addon | ||
return 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
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,6 @@ | ||
package types | ||
|
||
type Addon[T any] interface { | ||
Type() Type | ||
Addon([]string) (T, error) | ||
} |
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