-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute.go
56 lines (48 loc) · 1.01 KB
/
execute.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package lbsg
import (
"fmt"
"github.com/aws/aws-sdk-go-v2/service/ec2"
log "github.com/cantara/bragi/sbragi"
"github.com/cantara/nerthus2/cloud/aws/executor"
"github.com/cantara/nerthus2/cloud/aws/security"
"github.com/cantara/nerthus2/cloud/aws/vpc"
)
type Requireing interface {
SG(security.Group) executor.Func
}
type data struct {
c *ec2.Client
env string
system string
name string
v vpc.VPC
rs []Requireing
}
func Executor(env, system string, rs []Requireing, c *ec2.Client) *data {
return &data{
c: c,
env: env,
system: system,
name: fmt.Sprintf("%s-%s-lb", env, system),
rs: rs,
}
}
func (d *data) Execute(c chan<- executor.Func) {
sg, err := security.New(d.env, d.name, d.v.Id, d.c)
if err != nil {
log.WithError(err).Error("while creating new security group")
c <- d.Execute
return
}
for _, r := range d.rs {
f := r.SG(sg)
if f == nil {
continue
}
c <- f
}
}
func (d *data) VPC(v vpc.VPC) executor.Func {
d.v = v
return d.Execute
}