-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.go
More file actions
58 lines (46 loc) · 1.36 KB
/
plugin.go
File metadata and controls
58 lines (46 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/reglet-dev/reglet-plugin-sdk/application/plugin"
"github.com/reglet-dev/reglet-plugin-sdk/domain/entities"
"github.com/reglet-dev/reglet/plugins/aws/core"
// Import services to trigger auto-registration
_ "github.com/reglet-dev/reglet/plugins/aws/services"
)
type awsPlugin struct{}
func (p *awsPlugin) Manifest(ctx context.Context) (*entities.Manifest, error) {
return core.Plugin.Manifest(), nil
}
func (p *awsPlugin) Check(ctx context.Context, configBytes []byte) (*entities.Result, error) {
// Parse config
var cfgStruct core.AWSConfig
if err := json.Unmarshal(configBytes, &cfgStruct); err != nil {
return nil, fmt.Errorf("failed to parse config: %w", err)
}
cfg := &cfgStruct
// Get credentials and create client
creds, err := core.GetCredentials(cfg)
if err != nil {
return nil, err
}
client := core.NewAWSClient(creds, cfg.TimeoutSeconds)
// Get handler from registry
handler, ok := core.Plugin.GetHandler(cfg.Service, cfg.Operation)
if !ok {
return entities.ResultErrorPtr("configuration",
fmt.Sprintf("Unknown operation: %s/%s", cfg.Service, cfg.Operation)), nil
}
// Build request and execute
req := &plugin.Request{
Client: client,
Config: cfg,
Raw: configBytes,
}
return handler(ctx, req)
}
func init() {
plugin.Register(&awsPlugin{})
}
func main() {}