-
Notifications
You must be signed in to change notification settings - Fork 2
plugin v2 preview #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
eternal-flame-AD
wants to merge
37
commits into
master
Choose a base branch
from
v2-dev
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 20 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
21ac3bc
preview
eternal-flame-AD 5abcf5d
plugin connection auth/security
eternal-flame-AD 8a89a6b
temp
eternal-flame-AD e6fc00f
move ServerMux to server repo
eternal-flame-AD 93c24e8
wip: swap to single connection model
eternal-flame-AD b5e9886
shim impl
eternal-flame-AD f59c2eb
userid overflow checks
eternal-flame-AD 1d055c1
use SNI to mux webhooker
eternal-flame-AD 9863b12
fixup! use SNI to mux webhooker
eternal-flame-AD 4493373
fixup! fixup! use SNI to mux webhooker
eternal-flame-AD bd59ee3
v1 shim
eternal-flame-AD f237b5a
fixup userid conversion
eternal-flame-AD ee70ba4
rearrange code order
eternal-flame-AD 4cf2383
protobuf comments
eternal-flame-AD d6c86da
go mod tidy
eternal-flame-AD 4e13724
more protobuf docs
eternal-flame-AD 1a69730
example tests
eternal-flame-AD b922133
always test TCP implementation
eternal-flame-AD c55cc24
create transport package
eternal-flame-AD 5555f78
add basic pipe test
eternal-flame-AD caadabd
check stream errors in shim
eternal-flame-AD 582f2a1
change test workflow branch
eternal-flame-AD 8b7a780
suggestions in shim_v1.go
eternal-flame-AD c09e0d3
Upgrade to yaml.v3
eternal-flame-AD 12f5aeb
test typo correction
eternal-flame-AD eabaf46
hoist PEM reading function
eternal-flame-AD 60a3ba0
cli_flags suggestions
eternal-flame-AD bdd4117
try to fix pipe_test on windows
eternal-flame-AD 4fee597
Try to fix pipe_test on windows
eternal-flame-AD b493e1c
remove unused certificates and TLS configs
eternal-flame-AD cd7743e
use IPv4 loopback address
eternal-flame-AD 35d54d4
rename ServerVersionInfo -> ServerInfo
eternal-flame-AD 7822885
allow passing kex file descriptors through environment variables
eternal-flame-AD 11e6d50
remove SetEnable RPC
eternal-flame-AD dd63957
compute ping rate
eternal-flame-AD abf55e8
hoise kex logic to cli
eternal-flame-AD bfe8e52
check for nil rootCAs
eternal-flame-AD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,33 @@ | ||
| name: Test | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up Go | ||
| uses: actions/setup-go@v4 | ||
| with: | ||
| go-version: 1.24.6 | ||
| - name: Install dependencies | ||
| run: go mod download | ||
| - name: Test | ||
| run: cd v2 && go test -v ./... | ||
|
|
||
| test-windows: | ||
| runs-on: windows-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up Go | ||
| uses: actions/setup-go@v4 | ||
| with: | ||
| go-version: 1.24.6 | ||
| - name: Install dependencies | ||
| run: go mod download | ||
| - name: Test | ||
| run: cd v2 && go test -v ./... | ||
This file contains hidden or 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,75 @@ | ||
| package plugin | ||
|
|
||
| import ( | ||
| "flag" | ||
| "os" | ||
| "strconv" | ||
| "strings" | ||
| ) | ||
|
|
||
| type PluginCliFlags struct { | ||
| flagSet *flag.FlagSet | ||
| KexReqFile *os.File | ||
| KexRespFile *os.File | ||
| Debug bool | ||
| } | ||
|
|
||
| func ParsePluginCLIFlags(args []string) (*PluginCliFlags, error) { | ||
| flagSet := flag.NewFlagSet(os.Args[0], flag.ContinueOnError) | ||
| var kexReqFileName string | ||
| var kexRespFileName string | ||
| var debug bool | ||
| flagSet.StringVar(&kexReqFileName, "kex-req-file", "", "File name for the key exchange for Transport Auth. /proc/self/fd/* can be used to open a file descriptor cross platform.") | ||
jmattheis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| flagSet.StringVar(&kexRespFileName, "kex-resp-file", "", "File name for the key exchange for Transport Auth. /proc/self/fd/* can be used to open a file descriptor cross platform.") | ||
| flagSet.BoolVar(&debug, "debug", false, "Enable debug mode.") | ||
| flagSet.Parse(args) | ||
eternal-flame-AD marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| var kexReqFile *os.File | ||
| var kexRespFile *os.File | ||
| var err error | ||
|
|
||
| if fdNumber, found := strings.CutPrefix(kexReqFileName, "/proc/self/fd/"); found { | ||
| fdNumber, err := strconv.ParseUint(fdNumber, 10, 64) | ||
| kexReqFile = os.NewFile(uintptr(fdNumber), kexReqFileName) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } else { | ||
| kexReqFile, err = os.OpenFile(kexReqFileName, os.O_WRONLY, 0) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| if fdNumber, found := strings.CutPrefix(kexRespFileName, "/proc/self/fd/"); found { | ||
| fdNumber, err := strconv.ParseUint(fdNumber, 10, 64) | ||
| kexRespFile = os.NewFile(uintptr(fdNumber), kexRespFileName) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
eternal-flame-AD marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } else { | ||
| kexRespFile, err = os.OpenFile(kexRespFileName, os.O_RDONLY, 0) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| if err != nil { | ||
| return nil, err | ||
| } | ||
eternal-flame-AD marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return &PluginCliFlags{ | ||
| flagSet: flagSet, | ||
| KexReqFile: kexReqFile, | ||
| KexRespFile: kexRespFile, | ||
| Debug: debug, | ||
| }, nil | ||
| } | ||
|
|
||
| func (f *PluginCliFlags) Close() error { | ||
| if err := f.KexReqFile.Close(); err != nil { | ||
| return err | ||
| } | ||
| if err := f.KexRespFile.Close(); err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
This file contains hidden or 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,120 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "log" | ||
| "net/url" | ||
|
|
||
| "github.com/gin-gonic/gin" | ||
| "github.com/gotify/plugin-api" | ||
| ) | ||
|
|
||
| // GetGotifyPluginInfo returns gotify plugin info. | ||
| func GetGotifyPluginInfo() plugin.Info { | ||
| return plugin.Info{ | ||
| ModulePath: "github.com/gotify/server/v2/plugin/example/echo", | ||
| Name: "test plugin", | ||
| } | ||
| } | ||
|
|
||
| // EchoPlugin is the gotify plugin instance. | ||
| type EchoPlugin struct { | ||
| msgHandler plugin.MessageHandler | ||
| storageHandler plugin.StorageHandler | ||
| config *Config | ||
| basePath string | ||
| } | ||
|
|
||
| // SetStorageHandler implements plugin.Storager | ||
| func (c *EchoPlugin) SetStorageHandler(h plugin.StorageHandler) { | ||
| c.storageHandler = h | ||
| } | ||
|
|
||
| // SetMessageHandler implements plugin.Messenger. | ||
| func (c *EchoPlugin) SetMessageHandler(h plugin.MessageHandler) { | ||
| c.msgHandler = h | ||
| } | ||
|
|
||
| // Storage defines the plugin storage scheme | ||
| type Storage struct { | ||
| CalledTimes int `json:"called_times"` | ||
| } | ||
|
|
||
| // Config defines the plugin config scheme | ||
| type Config struct { | ||
| MagicString string `yaml:"magic_string"` | ||
| } | ||
|
|
||
| // DefaultConfig implements plugin.Configurer | ||
| func (c *EchoPlugin) DefaultConfig() interface{} { | ||
| return &Config{ | ||
| MagicString: "hello world", | ||
| } | ||
| } | ||
|
|
||
| // ValidateAndSetConfig implements plugin.Configurer | ||
| func (c *EchoPlugin) ValidateAndSetConfig(config interface{}) error { | ||
| c.config = config.(*Config) | ||
| return nil | ||
| } | ||
|
|
||
| // Enable enables the plugin. | ||
| func (c *EchoPlugin) Enable() error { | ||
| log.Println("echo plugin enabled") | ||
| return nil | ||
| } | ||
|
|
||
| // Disable disables the plugin. | ||
| func (c *EchoPlugin) Disable() error { | ||
| log.Println("echo plugin disbled") | ||
| return nil | ||
| } | ||
|
|
||
| // RegisterWebhook implements plugin.Webhooker. | ||
| func (c *EchoPlugin) RegisterWebhook(baseURL string, g *gin.RouterGroup) { | ||
| c.basePath = baseURL | ||
| g.GET("/echo", func(ctx *gin.Context) { | ||
|
|
||
| storage, _ := c.storageHandler.Load() | ||
| conf := new(Storage) | ||
| json.Unmarshal(storage, conf) | ||
| conf.CalledTimes++ | ||
| newStorage, _ := json.Marshal(conf) | ||
| c.storageHandler.Save(newStorage) | ||
|
|
||
| c.msgHandler.SendMessage(plugin.Message{ | ||
| Title: "Hello received", | ||
| Message: fmt.Sprintf("echo server received a hello message %d times", conf.CalledTimes), | ||
| Priority: 2, | ||
| Extras: map[string]any{ | ||
| "plugin::name": "echo", | ||
| }, | ||
| }) | ||
| ctx.Writer.WriteString(fmt.Sprintf("Magic string is: %s\r\nEcho server running at %secho", c.config.MagicString, c.basePath)) | ||
| }) | ||
| } | ||
|
|
||
| // GetDisplay implements plugin.Displayer. | ||
| func (c *EchoPlugin) GetDisplay(location *url.URL) string { | ||
| loc := &url.URL{ | ||
| Path: c.basePath, | ||
| } | ||
| if location != nil { | ||
| loc.Scheme = location.Scheme | ||
| loc.Host = location.Host | ||
| } | ||
| loc = loc.ResolveReference(&url.URL{ | ||
| Path: "echo", | ||
| }) | ||
| return "Echo plugin running at: " + loc.String() | ||
| } | ||
|
|
||
| // NewGotifyPluginInstance creates a plugin instance for a user context. | ||
| func NewGotifyPluginInstance(ctx plugin.UserContext) plugin.Plugin { | ||
| return &EchoPlugin{} | ||
| } | ||
|
|
||
| func main() { | ||
| panic("this should be built as go plugin") | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.