Skip to content

Commit

Permalink
Adding support for content type to GCS output (#51)
Browse files Browse the repository at this point in the history
* Adding support for content type to GCS output

* update changelog

* fixing typo
  • Loading branch information
P1llus authored Jan 30, 2023
1 parent 7ae2356 commit 2a076c9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Removed

## [0.10.0]

### Added

- Added content type support to GCS output: [#51](https://github.com/elastic/stream/pull/51)

## [0.9.1]

### Changed
Expand Down
1 change: 1 addition & 0 deletions command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func ExecuteContext(ctx context.Context) error {
// GCS output flags.
rootCmd.PersistentFlags().StringVar(&opts.GcsOptions.Bucket, "gcs-bucket", "testbucket", "GCS Bucket name")
rootCmd.PersistentFlags().StringVar(&opts.GcsOptions.Object, "gcs-object", "testobject", "GCS Object name")
rootCmd.PersistentFlags().StringVar(&opts.GcsOptions.ObjectContentType, "gcs-content-type", "application/json", "The Content type of the object to be uploaded to GCS.")
rootCmd.PersistentFlags().StringVar(&opts.GcsOptions.ProjectID, "gcs-projectid", "testproject", "GCS Project name")

// Lumberjack output flags.
Expand Down
2 changes: 2 additions & 0 deletions pkg/output/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func New(opts *output.Options) (output.Output, error) {
}
obj := gcsClient.Bucket(opts.GcsOptions.Bucket).Object(opts.GcsOptions.Object)
writer := obj.NewWriter(ctx)
// System tests are failing because a default content type is not set automatically, so we set it here instead.
writer.ObjectAttrs.ContentType = opts.GcsOptions.ObjectContentType

return &Output{opts: opts, client: gcsClient, cancelFunc: cancel, writer: writer}, nil
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/output/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ type LumberjackOptions struct {
}

type GcsOptions struct {
ProjectID string // Project ID, needs to be unique with multiple buckets of the same name.
Bucket string // Bucket name. Will create it if do not exist.
Object string // Name of the object created inside the related Bucket.
ProjectID string // Project ID, needs to be unique with multiple buckets of the same name.
ObjectContentType string // The content-type set for the object that is created in the bucket, defaults to application/json
Bucket string // Bucket name. Will create it if do not exist.
Object string // Name of the object created inside the related Bucket.
}

0 comments on commit 2a076c9

Please sign in to comment.