-
Notifications
You must be signed in to change notification settings - Fork 1
feat: [AH-2353]: Updated storage layer initiation for default bucket #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,8 +49,7 @@ import ( | |
| ) | ||
|
|
||
| const ( | ||
| driverName = "gcs" | ||
| dummyProjectID = "<unknown>" | ||
| driverName = "gcs" | ||
|
|
||
| minChunkSize = 256 * 1024 | ||
| defaultChunkSize = 16 * 1024 * 1024 | ||
|
|
@@ -88,6 +87,11 @@ func init() { | |
| factory.Register(driverName, &gcsDriverFactory{}) | ||
| } | ||
|
|
||
| // TODO: figure-out why init is not called automatically | ||
| func Register(ctx context.Context) { | ||
| log.Ctx(ctx).Info().Msgf("registering gcs driver") | ||
| } | ||
|
|
||
| // gcsDriverFactory implements the factory.StorageDriverFactory interface. | ||
| type gcsDriverFactory struct{} | ||
|
|
||
|
|
@@ -105,6 +109,7 @@ var _ storagedriver.StorageDriver = &driver{} | |
| // Objects are stored at absolute keys in the provided bucket. | ||
| type driver struct { | ||
| client *http.Client | ||
| gcs *storage.Client | ||
| bucket *storage.BucketHandle | ||
| email string | ||
| privateKey []byte | ||
|
|
@@ -256,6 +261,7 @@ func New(_ context.Context, params driverParameters) (storagedriver.StorageDrive | |
| return nil, fmt.Errorf("invalid chunksize: %d is not a positive multiple of %d", params.chunkSize, minChunkSize) | ||
| } | ||
| d := &driver{ | ||
| gcs: params.gcs, | ||
| bucket: params.gcs.Bucket(params.bucket), | ||
| rootDirectory: rootDirectory, | ||
| email: params.email, | ||
|
|
@@ -932,6 +938,22 @@ func (d *driver) keyToPath(key string) string { | |
| return "/" + strings.Trim(strings.TrimPrefix(key, d.rootDirectory), "/") | ||
| } | ||
|
|
||
| func (d *driver) CopyObject(_ context.Context, _, _, _ string) error { | ||
| return fmt.Errorf("not yet implemented") | ||
| func (d *driver) CopyObject(ctx context.Context, srcKey, destBucket, destKey string) error { | ||
| src := d.bucket.Object(d.pathToKey(srcKey)) | ||
|
|
||
| dst := d.gcs.Bucket(destBucket).Object(destKey) | ||
|
|
||
| copier := dst.CopierFrom(src) | ||
| copier.ContentType = blobContentType | ||
|
|
||
| _, err := copier.Run(ctx) | ||
| if err != nil { | ||
| var status *googleapi.Error | ||
| if errors.As(err, &status) && status.Code == http.StatusNotFound { | ||
| return storagedriver.PathNotFoundError{Path: srcKey} | ||
| } | ||
| return fmt.Errorf("copy %q to %q/%q: %w", srcKey, destBucket, destKey, err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
Comment on lines
+941
to
959
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Asymmetric path handling:
Additionally, consider whether this method should verify that 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,3 +45,9 @@ func GetFilesystemParams(c *types.Config) map[string]any { | |
| props["rootdirectory"] = c.Registry.Storage.FileSystemStorage.RootDirectory | ||
| return props | ||
| } | ||
|
|
||
| func GetGCSStorageParameters(c *types.Config) map[string]any { | ||
| gcsProperties := make(map[string]any) | ||
| gcsProperties["bucket"] = c.Registry.Storage.GCSStorage.Bucket | ||
| return gcsProperties | ||
| } | ||
|
Comment on lines
+49
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass This helper should forward the Suggested change (once config is updated) func GetGCSStorageParameters(c *types.Config) map[string]any {
gcsProperties := make(map[string]any)
gcsProperties["bucket"] = c.Registry.Storage.GCSStorage.Bucket
+ gcsProperties["rootdirectory"] = c.Registry.Storage.GCSStorage.RootDirectory
return gcsProperties
}🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -511,7 +511,7 @@ type Config struct { | |||||||||||||||||||||||
| Registry struct { | ||||||||||||||||||||||||
| Enable bool `envconfig:"GITNESS_REGISTRY_ENABLED" default:"true"` | ||||||||||||||||||||||||
| Storage struct { | ||||||||||||||||||||||||
| // StorageType defines the type of storage to use for the registry. Options are: `filesystem`, `s3aws` | ||||||||||||||||||||||||
| // StorageType defines the type of storage to use for the registry. Options are: `filesystem`, `s3aws`, `gcs` | ||||||||||||||||||||||||
| StorageType string `envconfig:"GITNESS_REGISTRY_STORAGE_TYPE" default:"filesystem"` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // FileSystemStorage defines the configuration for the filesystem storage if StorageType is `filesystem`. | ||||||||||||||||||||||||
|
|
@@ -544,6 +544,12 @@ type Config struct { | |||||||||||||||||||||||
| Redirect bool `envconfig:"GITNESS_REGISTRY_S3_STORAGE_REDIRECT" default:"false"` | ||||||||||||||||||||||||
| Provider string `envconfig:"GITNESS_REGISTRY_S3_PROVIDER" default:"cloudflare"` | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // GCSStorage defines the configuration for the GCS storage if StorageType is `gcs`. | ||||||||||||||||||||||||
| // Authentication is handled via workload identity (google.DefaultTokenSource). | ||||||||||||||||||||||||
| GCSStorage struct { | ||||||||||||||||||||||||
| Bucket string `envconfig:"GITNESS_REGISTRY_GCS_BUCKET"` | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+548
to
+552
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GCSStorage config is missing Both Suggested minimal addition GCSStorage struct {
- Bucket string `envconfig:"GITNESS_REGISTRY_GCS_BUCKET"`
+ Bucket string `envconfig:"GITNESS_REGISTRY_GCS_BUCKET"`
+ RootDirectory string `envconfig:"GITNESS_REGISTRY_GCS_ROOT_DIRECTORY"`
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| HTTP struct { | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unknown
StorageTypevalues silently fall through to S3.If someone mistypes the storage type (e.g.,
"gc"instead of"gcs"), thedefaultbranch will quietly initialize S3 storage instead of surfacing a configuration error. Consider adding an explicit"s3aws"case and makingdefaultreturn an error for unrecognized values.Suggested change
switch c.Registry.Storage.StorageType { case "filesystem": filesystem.Register(ctx) d, err = factory.Create(ctx, "filesystem", config.GetFilesystemParams(c)) if err != nil { log.Fatal().Stack().Err(err).Msgf("") panic(err) } case "gcs": gcs.Register(ctx) d, err = factory.Create(ctx, "gcs", config.GetGCSStorageParameters(c)) if err != nil { log.Error().Stack().Err(err).Msg("failed to init gcs Blob storage") panic(err) } -default: +case "s3aws": s3.Register(ctx) d, err = factory.Create(ctx, "s3aws", config.GetS3StorageParameters(c)) if err != nil { log.Error().Stack().Err(err).Msg("failed to init s3 Blob storage") panic(err) } +default: + return nil, fmt.Errorf("unsupported registry storage type: %q", c.Registry.Storage.StorageType) }📝 Committable suggestion
🤖 Prompt for AI Agents