/
s3beefactory.go
140 lines (127 loc) 路 3.48 KB
/
s3beefactory.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
/*
* Copyright (C) 2017 Sergio Rubio
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Sergio Rubio <sergio@rubio.im>
*/
package s3bee
import (
"github.com/muesli/beehive/bees"
)
// S3BeeFactory is a factory for S3Bees.
type S3BeeFactory struct {
bees.BeeFactory
}
// New returns a new Bee instance configured with the supplied options.
func (factory *S3BeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface {
bee := S3Bee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
}
// ID returns the ID of this Bee.
func (factory *S3BeeFactory) ID() string {
return "s3bee"
}
// Name returns the name of this Bee.
func (factory *S3BeeFactory) Name() string {
return "Amazon S3"
}
// Description returns the description of this Bee.
func (factory *S3BeeFactory) Description() string {
return "Upload files to S3 compatible storage"
}
// Image returns the filename of an image for this Bee.
func (factory *S3BeeFactory) Image() string {
return factory.ID() + ".png"
}
// LogoColor returns the preferred logo background color (used by the admin interface).
func (factory *S3BeeFactory) LogoColor() string {
return "#4b4b4b"
}
// Options returns the options available to configure this Bee.
func (factory *S3BeeFactory) Options() []bees.BeeOptionDescriptor {
opts := []bees.BeeOptionDescriptor{
{
Name: "endpoint",
Description: "S3 compatible endpoint",
Type: "string",
Mandatory: true,
},
{
Name: "access_key_id",
Description: "Access Key ID",
Type: "string",
Mandatory: true,
},
{
Name: "secret_access_key",
Description: "Secret Access Key",
Type: "string",
Mandatory: true,
},
{
Name: "use_ssl",
Description: "Use SSL",
Type: "bool",
Mandatory: true,
Default: true,
},
{
Name: "region",
Description: "S3 region",
Type: "string",
Mandatory: true,
Default: "us-east-1",
},
}
return opts
}
func (factory *S3BeeFactory) Actions() []bees.ActionDescriptor {
actions := []bees.ActionDescriptor{
{
Namespace: factory.Name(),
Name: "upload",
Description: "Uploads a file to S3 compatible storage",
Options: []bees.PlaceholderDescriptor{
{
Name: "bucket",
Description: "Which bucket to upload the file to",
Type: "string",
Mandatory: true,
},
{
Name: "path",
Description: "Path to the file to upload",
Type: "string",
Mandatory: true,
},
{
Name: "object_path",
Description: "Target object path (defaults to the source file name)",
Type: "string",
Mandatory: false,
},
},
},
}
return actions
}
func init() {
f := S3BeeFactory{}
bees.RegisterFactory(&f)
}