Skip to content

Commit

Permalink
out_s3: add storage_class support
Browse files Browse the repository at this point in the history
Signed-off-by: Hideo Matsumoto <[email protected]>
  • Loading branch information
pekeq authored and PettitWesley committed Apr 6, 2022
1 parent 84893f4 commit c2b1fd1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions plugins/out_s3/s3.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ static struct flb_aws_header content_md5_header = {
.val_len = 0,
};

static struct flb_aws_header storage_class_header = {
.key = "x-amz-storage-class",
.key_len = 19,
.val = "",
.val_len = 0,
};

static char *mock_error_response(char *error_env_var)
{
char *err_val = NULL;
Expand Down Expand Up @@ -138,6 +145,9 @@ static int create_headers(struct flb_s3 *ctx, char *body_md5, struct flb_aws_hea
if (body_md5 != NULL && strlen(body_md5)) {
headers_len++;
}
if (ctx->storage_class != NULL) {
headers_len++;
}
if (headers_len == 0) {
*num_headers = headers_len;
*headers = s3_headers;
Expand Down Expand Up @@ -170,6 +180,12 @@ static int create_headers(struct flb_s3 *ctx, char *body_md5, struct flb_aws_hea
s3_headers[n] = content_md5_header;
s3_headers[n].val = body_md5;
s3_headers[n].val_len = strlen(body_md5);
n++;
}
if (ctx->storage_class != NULL) {
s3_headers[n] = storage_class_header;
s3_headers[n].val = ctx->storage_class;
s3_headers[n].val_len = strlen(ctx->storage_class);
}

*num_headers = headers_len;
Expand Down Expand Up @@ -739,6 +755,16 @@ static int cb_s3_init(struct flb_output_instance *ins,
ctx->content_type = (char *) tmp;
}

tmp = flb_output_get_property("storage_class", ins);
if (tmp) {
if (ctx->use_put_object == FLB_FALSE) {
flb_plg_error(ctx->ins,
"use_put_object must be enabled when storage_class is specified");
return -1;
}
ctx->storage_class = (char *) tmp;
}

if (ctx->insecure == FLB_FALSE) {
ctx->client_tls = flb_tls_create(ins->tls_verify,
ins->tls_debug,
Expand Down Expand Up @@ -2383,6 +2409,14 @@ static struct flb_config_map config_map[] = {
"key formatters all work as expected while this feature is set to true."
},

{
FLB_CONFIG_MAP_STR, "storage_class", NULL,
0, FLB_FALSE, 0,
"Specify the storage class for S3 objects. This option can be enabled "
"when use_put_object is on. If this option is not specified, objects "
"will be stored with the default 'STANDARD' storage class."
},

/* EOF */
{0}
};
Expand Down
1 change: 1 addition & 0 deletions plugins/out_s3/s3.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ struct flb_s3 {
char *sts_endpoint;
char *canned_acl;
char *content_type;
char *storage_class;
char *log_key;
char *external_id;
int free_endpoint;
Expand Down

0 comments on commit c2b1fd1

Please sign in to comment.