Skip to content

Commit 5dfcdc9

Browse files
janiszclaude
andcommitted
refactor: rename init() to Register*() in external backup plugins
Renamed all package-level init() functions to explicit Register*() functions in 3 backup plugin files. Updated all/all.go with Init() function that calls all Register*() functions. This prevents automatic execution for all components in the busybox binary. External backup plugins are central-only and now only load when explicitly initialized. Files changed: - s3/std/s3.go: init() → RegisterS3() - s3/compatible/s3compatible.go: init() → RegisterS3Compatible() - gcs/gcs.go: init() → RegisterGCS() - all/all.go: replaced blank imports with explicit Init() calls Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 3ab5d12 commit 5dfcdc9

4 files changed

Lines changed: 23 additions & 17 deletions

File tree

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package all
22

33
import (
4-
_ "github.com/stackrox/rox/central/externalbackups/plugins/gcs" // Register GCS plugin
5-
_ "github.com/stackrox/rox/central/externalbackups/plugins/s3/compatible" // Register S3compatible plugin
6-
_ "github.com/stackrox/rox/central/externalbackups/plugins/s3/std" // Register S3 plugin
4+
"github.com/stackrox/rox/central/externalbackups/plugins/gcs"
5+
s3compatible "github.com/stackrox/rox/central/externalbackups/plugins/s3/compatible"
6+
s3std "github.com/stackrox/rox/central/externalbackups/plugins/s3/std"
77
)
8+
9+
// Init registers all external backup plugins.
10+
// Called explicitly from central/app/app.go instead of package init().
11+
func Init() {
12+
s3std.RegisterS3()
13+
s3compatible.RegisterS3Compatible()
14+
gcs.RegisterGCS()
15+
}

‎central/externalbackups/plugins/gcs/gcs.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func (s *gcs) createError(msg string, err error) error {
213213
return errors.New(msg)
214214
}
215215

216-
func init() {
216+
func RegisterGCS() {
217217
plugins.Add(types.GCSType, func(backup *storage.ExternalBackup) (types.ExternalBackup, error) {
218218
return newGCS(backup)
219219
})

‎central/externalbackups/plugins/s3/compatible/s3compatible.go‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@ import (
99
"github.com/stackrox/rox/pkg/errorhelpers"
1010
)
1111

12-
func init() {
13-
14-
// s3Compatible plugin for the S3 compatible backup integration.
15-
// As the official AWS S3 is deprecating the path-style bucket addressing, but
16-
// this style is still used in non-AWS S3 compatible providers, we decided to
17-
// implement a new plugin for the latter.
18-
// Having the two plugins allows for a clear separation between official AWS
19-
// and non-AWS features.
20-
// Having the S3 compatible plugin separate will also give us more freedom to
21-
// change to a different package if the aws-sdk decides to drop the path-style
22-
// option in the future.
23-
12+
// RegisterS3Compatible registers the S3 compatible backup integration.
13+
// As the official AWS S3 is deprecating the path-style bucket addressing, but
14+
// this style is still used in non-AWS S3 compatible providers, we decided to
15+
// implement a new plugin for the latter.
16+
// Having the two plugins allows for a clear separation between official AWS
17+
// and non-AWS features.
18+
// Having the S3 compatible plugin separate will also give us more freedom to
19+
// change to a different package if the aws-sdk decides to drop the path-style
20+
// option in the future.
21+
func RegisterS3Compatible() {
2422
plugins.Add(types.S3CompatibleType, func(backup *storage.ExternalBackup) (types.ExternalBackup, error) {
2523
return s3common.NewS3Client(&s3compatibleConfigWrapper{integration: backup})
2624
})

‎central/externalbackups/plugins/s3/std/s3.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (c *s3configWrapper) Validate() error {
105105
return errorList.ToError()
106106
}
107107

108-
func init() {
108+
func RegisterS3() {
109109
plugins.Add(types.S3Type, func(backup *storage.ExternalBackup) (types.ExternalBackup, error) {
110110
return s3common.NewS3Client(&s3configWrapper{integration: backup})
111111
})

0 commit comments

Comments
 (0)