Skip to content

Commit 5c1b4a6

Browse files
authored
Merge pull request #4 from scality/user/tmacro/bucket_notifications_sasl_plain
Add bucket notifications deployment supporting basic auth and no auth
2 parents 1b51054 + 7697621 commit 5c1b4a6

17 files changed

+273
-248
lines changed

cmd/config.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ type ScubaFeatureConfig struct {
3838
}
3939

4040
type BucketNotificationsFeatureConfig struct {
41-
Enabled bool `yaml:"enabled"`
42-
TargetAuth struct {
41+
Enabled bool `yaml:"enabled"`
42+
DestinationAuth struct {
4343
Type string `yaml:"type"`
4444
Username string `yaml:"username"`
4545
Password string `yaml:"password"`
46-
} `yaml:"targetAuth"`
46+
} `yaml:"destinationAuth"`
4747
}
4848

4949
type CloudserverConfig struct {
@@ -150,6 +150,17 @@ func DefaultConfig() Config {
150150
LogLevel: "info",
151151
// Profile: "default",
152152
},
153+
Features: FeatureConfig{
154+
BucketNotifications: BucketNotificationsFeatureConfig{
155+
DestinationAuth: struct {
156+
Type string `yaml:"type"`
157+
Username string `yaml:"username"`
158+
Password string `yaml:"password"`
159+
}{
160+
Type: "none",
161+
},
162+
},
163+
},
153164
Cloudserver: CloudserverConfig{},
154165
S3Metadata: MetadataConfig{
155166
VFormat: Formatv1,

cmd/configure.go

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func configureEnv(cfg Config, envDir string) error {
4747
generateScubaConfig,
4848
generateS3MetadataConfig,
4949
generateScubaMetadataConfig,
50+
generateKafkaConfig,
5051
}
5152

5253
configDir := filepath.Join(envDir, "config")
@@ -75,61 +76,34 @@ func generateCloudserverConfig(cfg Config, path string) error {
7576

7677
func generateBackbeatConfig(cfg Config, path string) error {
7778
templates := []string{
78-
"Dockerfile.setup",
79-
"setup.sh",
80-
"setup-kafka-target.sh",
81-
"config.notification.json",
82-
"config.json",
83-
"supervisord.conf",
8479
"env",
80+
"supervisord.conf",
81+
"config.json",
82+
"config.notification.json",
83+
"notificationCredentials.json",
8584
}
8685

87-
for _, tmpl := range templates {
88-
templatePath := filepath.Join("templates", "backbeat", tmpl)
89-
outputPath := filepath.Join(path, "backbeat", tmpl)
90-
if err := renderTemplateToFile(getTemplates(), templatePath, cfg, outputPath); err != nil {
91-
return fmt.Errorf("failed to render template %s: %w", tmpl, err)
92-
}
93-
}
94-
return nil
86+
return renderTemplates(cfg, "templates/backbeat", filepath.Join(path, "backbeat"), templates)
9587
}
9688

9789
func generateVaultConfig(cfg Config, path string) error {
98-
err := renderTemplateToFile(getTemplates(), "templates/vault/config.json", cfg, filepath.Join(path, "vault", "config.json"))
99-
if err != nil {
100-
return err
101-
}
102-
103-
err = renderTemplateToFile(getTemplates(), "templates/vault/create-management-account.sh", cfg, filepath.Join(path, "vault", "create-management-account.sh"))
104-
if err != nil {
105-
return err
106-
}
107-
108-
err = renderTemplateToFile(getTemplates(), "templates/vault/Dockerfile.setup", cfg, filepath.Join(path, "vault", "Dockerfile.setup"))
109-
if err != nil {
110-
return err
111-
}
112-
113-
err = renderTemplateToFile(getTemplates(), "templates/vault/management-creds.json", cfg, filepath.Join(path, "vault", "management-creds.json"))
114-
if err != nil {
115-
return err
90+
templates := []string{
91+
"config.json",
92+
"create-management-account.sh",
93+
"Dockerfile.setup",
94+
"management-creds.json",
11695
}
11796

118-
return nil
97+
return renderTemplates(cfg, "templates/vault", filepath.Join(path, "vault"), templates)
11998
}
12099

121100
func generateScubaConfig(cfg Config, path string) error {
122-
err := renderTemplateToFile(getTemplates(), "templates/scuba/create-service-user.sh", cfg, filepath.Join(path, "scuba", "create-service-user.sh"))
123-
if err != nil {
124-
return err
125-
}
126-
127-
err = renderTemplateToFile(getTemplates(), "templates/scuba/Dockerfile.setup", cfg, filepath.Join(path, "scuba", "Dockerfile.setup"))
128-
if err != nil {
129-
return err
101+
templates := []string{
102+
"config.json",
103+
"create-service-user.sh",
104+
"Dockerfile.setup",
130105
}
131-
132-
return renderTemplateToFile(getTemplates(), "templates/scuba/config.json", cfg, filepath.Join(path, "scuba", "config.json"))
106+
return renderTemplates(cfg, "templates/scuba", filepath.Join(path, "scuba"), templates)
133107
}
134108

135109
func generateMetadataConfig(cfg MetadataConfig, path string) error {
@@ -145,3 +119,16 @@ func generateScubaMetadataConfig(cfg Config, path string) error {
145119
cfgPath := filepath.Join(path, "metadata-scuba")
146120
return generateMetadataConfig(cfg.ScubaMetadata, cfgPath)
147121
}
122+
123+
func generateKafkaConfig(cfg Config, path string) error {
124+
templates := []string{
125+
"Dockerfile",
126+
"setup.sh",
127+
"server.backbeat.properties",
128+
"server.destination.properties",
129+
"config.properties",
130+
"zookeeper.properties",
131+
}
132+
133+
return renderTemplates(cfg, "templates/kafka", filepath.Join(path, "kafka"), templates)
134+
}

cmd/util.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ func renderTemplateToFile(templates fs.FS, tmplPath string, data any, outPath st
4848
return nil
4949
}
5050

51+
func renderTemplates(cfg Config, srcDir, destDir string, templates []string) error {
52+
templateFS := getTemplates()
53+
for _, tmpl := range templates {
54+
templatePath := filepath.Join(srcDir, tmpl)
55+
outputPath := filepath.Join(destDir, tmpl)
56+
if err := renderTemplateToFile(templateFS, templatePath, cfg, outputPath); err != nil {
57+
return fmt.Errorf("failed to render template %s: %w", tmpl, err)
58+
}
59+
}
60+
return nil
61+
}
62+
5163
func getComposeProfiles(cfg Config) []string {
5264
profiles := []string{"base"}
5365

templates/backbeat/Dockerfile.setup

Lines changed: 0 additions & 34 deletions
This file was deleted.

templates/backbeat/config.notification.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@
3535
{
3636
"resource": "destination1",
3737
"type": "kafka",
38-
"host": "localhost:9092",
39-
"topic": "destination-topic",
38+
"host": "127.0.0.1:9094",
39+
"topic": "notifications",
40+
{{ if eq .Features.BucketNotifications.DestinationAuth.Type "basic" }}
41+
"auth": {
42+
"type": "basic",
43+
"credentialsFile": "notificationCredentials.json"
44+
}
45+
{{ else if eq .Features.BucketNotifications.DestinationAuth.Type "none" }}
4046
"auth": {}
47+
{{ end }}
4148
}
4249
]
4350
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"username": "{{ .Features.BucketNotifications.DestinationAuth.Username }}",
3+
"password": "{{ .Features.BucketNotifications.DestinationAuth.Password }}"
4+
}

templates/backbeat/setup-kafka-target.sh

Lines changed: 0 additions & 34 deletions
This file was deleted.

templates/backbeat/setup.sh

Lines changed: 0 additions & 63 deletions
This file was deleted.

templates/cloudserver/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@
8989
"resource": "destination1",
9090
"type": "kafka",
9191
"host": "127.0.0.1",
92-
"port": 9093,
93-
"topic": "destination-topic",
92+
"port": 9094,
93+
"topic": "notifications",
9494
"auth": {}
9595
}
9696
],

templates/global/config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ features:
77
enable_service_user: true
88

99
bucket_notifications:
10-
enabled: true
11-
targetAuth:
12-
type: basic
10+
enabled: false
11+
destinationAuth:
12+
type: none
1313
username: admin
1414
password: admin123
1515

0 commit comments

Comments
 (0)