/
plugin.go
38 lines (30 loc) · 900 Bytes
/
plugin.go
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
// SPDX-License-Identifier: AGPL-3.0-only
package models
import (
"fmt"
"github.com/brainupdaters/drlm-core/context"
"github.com/brainupdaters/drlm-common/pkg/os"
"github.com/jinzhu/gorm"
)
// Plugin is an individual plugin that's installed in an Agent
type Plugin struct {
gorm.Model
Repo string `gorm:"not null"`
Name string `gorm:"not null"`
Version string `gorm:"not null"`
AgentHost string `gorm:"not null"`
Agent *Agent `gorm:"foreignkey:Host;association_foreignkey:AgentHost"`
// TODO: This should be stored in the DB
Arch []os.Arch `gorm:"-"`
OS []os.OS `gorm:"-"`
}
func (p *Plugin) String() string {
return p.Repo + "/" + p.Name
}
// Add adds a new plugin in the DB
func (p *Plugin) Add(ctx *context.Context) error {
if err := ctx.DB.Create(p).Error; err != nil {
return fmt.Errorf("error adding the plugin to the DB: %v", err)
}
return nil
}