-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdk.go
257 lines (218 loc) · 8.44 KB
/
sdk.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package sdk
import (
"context"
"github.com/go-furnace/proto/proto"
"github.com/hashicorp/go-plugin"
"google.golang.org/grpc"
)
/*
*
* Plugin interface declarations.
*
*/
// PreCreate is the interface for anything before the build happens. The
// PreCreate plugin has the change to abort the build if returns false.
type PreCreate interface {
Execute(stackname string) bool
}
// PostCreate interface is the definition of the PostCreate api that can be
// implemented and used via plugins. This interface gives access to the
// stack name.
type PostCreate interface {
Execute(stackname string)
}
// PreDelete is the interface for anything before the delete happens. The
// PreDelete plugin has the change to abort the build if returns false.
type PreDelete interface {
Execute(stackname string) bool
}
// PostDelete interface is the definition of the PostDelete api that can be
// implemented and used via plugins. This interface gives access to the
// stack name.
type PostDelete interface {
Execute(stackname string)
}
/*
*
* PRECREATE Plugin structs and functions.
*
*/
// PreCreateGRPCPlugin is the implementation of plugin.GRPCPlugin so we can serve/consume this.
type PreCreateGRPCPlugin struct {
// GRPCPlugin must still implement the Plugin interface
plugin.Plugin
// Concrete implementation, written in Go. This is only used for plugins
// that are written in Go.
Impl PreCreate
}
// GRPCServer is the grpc server implementation which calls the
// protoc generated code to register it.
func (p *PreCreateGRPCPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
proto.RegisterPreCreateServer(s, &GRPCPreCreateServer{Impl: p.Impl})
return nil
}
// GRPCClient is the grpc client that will talk to the GRPC Server
// and calls into the generated protoc code.
func (p *PreCreateGRPCPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
return &GRPCPreCreateClient{client: proto.NewPreCreateClient(c)}, nil
}
// GRPCPreCreateClient is an implementation of PreCreate that talks over RPC.
type GRPCPreCreateClient struct{ client proto.PreCreateClient }
// Execute is the GRPC implementation of the Execute function for the
// PreCreate plugin definition. This will talk over GRPC.
func (m *GRPCPreCreateClient) Execute(key string) bool {
p, err := m.client.Execute(context.Background(), &proto.Stack{
Name: key,
})
if err != nil {
return false
}
return p.Failed
}
// GRPCPreCreateServer is the gRPC server that GRPCPreCreateClient talks to.
type GRPCPreCreateServer struct {
// This is the real implementation
Impl PreCreate
}
// Execute is the execute function of the GRPCServer which will rely the information to the
// underlying implementation of this interface.
func (m *GRPCPreCreateServer) Execute(ctx context.Context, req *proto.Stack) (*proto.Proceed, error) {
res := m.Impl.Execute(req.Name)
return &proto.Proceed{Failed: res}, nil
}
/*
*
* POSTCREATE Plugin structs and functions.
*
*/
// PostCreateGRPCPlugin is the implementation of plugin.GRPCPlugin so we can serve/consume this.
type PostCreateGRPCPlugin struct {
// GRPCPlugin must still implement the Plugin interface
plugin.Plugin
// Concrete implementation, written in Go. This is only used for plugins
// that are written in Go.
Impl PostCreate
}
// GRPCPostCreateClient is an implementation of PreCreate that talks over RPC.
type GRPCPostCreateClient struct{ client proto.PostCreateClient }
// Execute is the GRPC implementation of the Execute function for the
// PostCreate plugin definition. This will talk over GRPC.
func (m *GRPCPostCreateClient) Execute(stackname string) {
m.client.Execute(context.Background(), &proto.Stack{
Name: stackname,
})
}
// GRPCPostCreateServer is the gRPC server that GRPCPostCreateClient talks to.
type GRPCPostCreateServer struct {
// This is the real implementation
Impl PostCreate
}
// GRPCServer is the grpc server implementation which calls the
// protoc generated code to register it.
func (p *PostCreateGRPCPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
proto.RegisterPostCreateServer(s, &GRPCPostCreateServer{Impl: p.Impl})
return nil
}
// GRPCClient is the grpc client that will talk to the GRPC Server
// and calls into the generated protoc code.
func (p *PostCreateGRPCPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
return &GRPCPostCreateClient{client: proto.NewPostCreateClient(c)}, nil
}
// Execute is the execute functin of the GRPCServer which will rely the information to the
// underlying implementation of this interface.
func (m *GRPCPostCreateServer) Execute(ctx context.Context, req *proto.Stack) (*proto.Empty, error) {
m.Impl.Execute(req.Name)
return &proto.Empty{}, nil
}
/*
*
* PREDELETE Plugin structs and functions.
*
*/
// PreDeleteGRPCPlugin is the implementation of plugin.GRPCPlugin so we can serve/consume this.
type PreDeleteGRPCPlugin struct {
// GRPCPlugin must still implement the Plugin interface
plugin.Plugin
// Concrete implementation, written in Go. This is only used for plugins
// that are written in Go.
Impl PreDelete
}
// GRPCServer is the grpc server implementation which calls the
// protoc generated code to register it.
func (p *PreDeleteGRPCPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
proto.RegisterPreDeleteServer(s, &GRPCPreDeleteServer{Impl: p.Impl})
return nil
}
// GRPCClient is the grpc client that will talk to the GRPC Server
// and calls into the generated protoc code.
func (p *PreDeleteGRPCPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
return &GRPCPreDeleteClient{client: proto.NewPreDeleteClient(c)}, nil
}
// GRPCPreDeleteClient is an implementation of PreDelete that talks over RPC.
type GRPCPreDeleteClient struct{ client proto.PreDeleteClient }
// Execute is the GRPC implementation of the Execute function for the
// PreDelete plugin definition. This will talk over GRPC.
func (m *GRPCPreDeleteClient) Execute(key string) bool {
p, err := m.client.Execute(context.Background(), &proto.Stack{
Name: key,
})
if err != nil {
return false
}
return p.Failed
}
// GRPCPreDeleteServer is the gRPC server that GRPCPreCreateClient talks to.
type GRPCPreDeleteServer struct {
// This is the real implementation
Impl PreDelete
}
// Execute is the execute function of the GRPCServer which will rely the information to the
// underlying implementation of this interface.
func (m *GRPCPreDeleteServer) Execute(ctx context.Context, req *proto.Stack) (*proto.Proceed, error) {
res := m.Impl.Execute(req.Name)
return &proto.Proceed{Failed: res}, nil
}
/*
*
* POSTCREATE Plugin structs and functions.
*
*/
// PostDeleteGRPCPlugin is the implementation of plugin.GRPCPlugin so we can serve/consume this.
type PostDeleteGRPCPlugin struct {
// GRPCPlugin must still implement the Plugin interface
plugin.Plugin
// Concrete implementation, written in Go. This is only used for plugins
// that are written in Go.
Impl PostDelete
}
// GRPCPostDeleteClient is an implementation of PreCreate that talks over RPC.
type GRPCPostDeleteClient struct{ client proto.PostDeleteClient }
// Execute is the GRPC implementation of the Execute function for the
// PostDelete plugin definition. This will talk over GRPC.
func (m *GRPCPostDeleteClient) Execute(stackname string) {
m.client.Execute(context.Background(), &proto.Stack{
Name: stackname,
})
}
// GRPCPostDeleteServer is the gRPC server that GRPCPostDeleteClient talks to.
type GRPCPostDeleteServer struct {
// This is the real implementation
Impl PostDelete
}
// GRPCServer is the grpc server implementation which calls the
// protoc generated code to register it.
func (p *PostDeleteGRPCPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
proto.RegisterPostDeleteServer(s, &GRPCPostDeleteServer{Impl: p.Impl})
return nil
}
// GRPCClient is the grpc client that will talk to the GRPC Server
// and calls into the generated protoc code.
func (p *PostDeleteGRPCPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
return &GRPCPostDeleteClient{client: proto.NewPostDeleteClient(c)}, nil
}
// Execute is the execute functin of the GRPCServer which will rely the information to the
// underlying implementation of this interface.
func (m *GRPCPostDeleteServer) Execute(ctx context.Context, req *proto.Stack) (*proto.Empty, error) {
m.Impl.Execute(req.Name)
return &proto.Empty{}, nil
}