Skip to content
This repository was archived by the owner on May 14, 2022. It is now read-only.

Commit e827fc6

Browse files
committed
feat: add plugin config
1 parent 2d8f869 commit e827fc6

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# StackHead Plugin API
2+
3+
## Expected structure
4+
5+
```go
6+
package main
7+
8+
import "github.com/getstackhead/pluginlib"
9+
10+
type MyPlugin struct {
11+
}
12+
13+
func (p MyPlugin) Setup() {
14+
// implement software setup action
15+
}
16+
17+
func (p MyPlugin) Deploy(project pluginlib.Project) {
18+
// implement project deploy action
19+
}
20+
21+
func (p MyPlugin) Destroy(project pluginlib.Project) {
22+
// implement project destroy action
23+
}
24+
25+
func (p MyPlugin) HookPreTerraformPlan(project pluginlib.Project) {
26+
// pre terraform plan hook (to be implemented)
27+
}
28+
29+
// Export plugin to StackHead. Must be named "Plugin"!
30+
var Plugin MyPlugin
31+
```
32+
33+
```shell
34+
go build -buildmode=plugin -o plugin_myplugin.so main.go
35+
```

plugin.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
package pluginlib
22

3+
import (
4+
"plugin"
5+
)
6+
37
type Plugin interface {
4-
Deploy(project Project)
8+
GetConfig() PluginConfig
59
Setup()
10+
Deploy(project Project)
11+
Destroy(project Project)
12+
}
13+
14+
func LoadPlugin(path string) (Plugin, error) {
15+
// load module
16+
plug, err := plugin.Open(path)
17+
if err != nil {
18+
return nil, err
19+
}
20+
21+
// 2. look up a symbol (an exported function or variable)
22+
symPlugin, err := plug.Lookup("Plugin")
23+
if err != nil {
24+
return nil, err
25+
}
26+
27+
// 3. Assert that loaded symbol is of a desired type
28+
var plugin Plugin
29+
plugin, ok := symPlugin.(Plugin)
30+
if !ok {
31+
return nil, err
32+
}
33+
return plugin, nil
634
}

plugin_config.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package pluginlib
2+
3+
var PluginType = struct {
4+
PROXY int
5+
CONTAINER int
6+
DNS int
7+
MISC int
8+
}{
9+
PROXY: 0,
10+
CONTAINER: 1,
11+
DNS: 2,
12+
MISC: 3,
13+
}
14+
15+
type TerraformProvider struct {
16+
name string
17+
vendor string
18+
version string
19+
resourceName string
20+
init string
21+
providerPerProject bool
22+
}
23+
24+
type PluginConfig struct {
25+
Name string
26+
Description string
27+
Version string
28+
Author string
29+
PluginType int
30+
Terraform TerraformProvider
31+
}

0 commit comments

Comments
 (0)