Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tag as new header in put request
Browse files Browse the repository at this point in the history
zoharsKaltura committed Feb 26, 2024
1 parent 2a78f61 commit a4c07ea
Showing 5 changed files with 61 additions and 9 deletions.
12 changes: 12 additions & 0 deletions nginx-live-module/src/persist/ngx_live_persist.c
Original file line number Diff line number Diff line change
@@ -255,6 +255,18 @@ ngx_live_persist_write_file(ngx_live_channel_t *channel,
goto failed;
}

ngx_log_error(NGX_LOG_NOTICE, &channel->log, 0,
"111111 \n");
rc = ngx_live_complex_value(vctx, conf->tag_value, &request.tag_value);
if (rc != NGX_OK) {
ngx_log_error(NGX_LOG_NOTICE, &channel->log, 0,
"ngx_live_persist_write_file: complex value failed");
goto failed;
}
ngx_log_error(NGX_LOG_NOTICE, &channel->log, 0,
"333333 \n");


write_ctx = ngx_persist_write_init(pool, type->type,
type->compress ? ppcf->comp_level : 0);
if (write_ctx == NULL) {
14 changes: 14 additions & 0 deletions nginx-live-module/src/persist/ngx_live_persist_core.c
Original file line number Diff line number Diff line change
@@ -95,6 +95,13 @@ static ngx_command_t ngx_live_persist_core_commands[] = {
offsetof(ngx_live_persist_core_preset_conf_t, cancel_read_if_empty),
NULL },

{ ngx_string("persist_media_tag_value"),
NGX_LIVE_MAIN_CONF|NGX_LIVE_PRESET_CONF|NGX_CONF_TAKE1,
ngx_live_set_complex_value_slot,
NGX_LIVE_PRESET_CONF_OFFSET,
offsetof(ngx_live_persist_core_preset_conf_t, files[NGX_LIVE_PERSIST_FILE_MEDIA].tag_value),
NULL },

ngx_null_command
};

@@ -526,7 +533,14 @@ ngx_live_persist_core_merge_preset_conf(ngx_conf_t *cf, void *parent,
} else if (conf->files[i].path == NULL) {
conf->files[i].path = prev->files[i].path;
}
if (ppcf->store == NULL) {
conf->files[i].tag_value = NULL;

} else if (conf->files[i].tag_value == NULL) {
conf->files[i].tag_value = prev->files[NGX_LIVE_PERSIST_FILE_MEDIA].tag_value;
}

//(ngx_live_complex_value_t *)"ttl=7"
max_size = i == NGX_LIVE_PERSIST_FILE_MEDIA ? 0 : 5 * 1024 * 1024;

ngx_conf_merge_size_value(conf->files[i].max_size,
1 change: 1 addition & 0 deletions nginx-live-module/src/persist/ngx_live_persist_internal.h
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
typedef struct {
ngx_live_complex_value_t *path;
size_t max_size;
ngx_live_complex_value_t *tag_value;
} ngx_live_persist_file_conf_t;


1 change: 1 addition & 0 deletions nginx-live-module/src/persist/ngx_live_store.h
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@ typedef struct {
ngx_str_t path;
ngx_chain_t *cl;
size_t size;
ngx_str_t tag_value;

ngx_live_store_write_handler_pt handler;
void *data;
42 changes: 33 additions & 9 deletions nginx-live-module/src/persist/ngx_live_store_s3.c
Original file line number Diff line number Diff line change
@@ -748,7 +748,7 @@ ngx_live_store_s3_get_request(ngx_pool_t *pool, void *arg, ngx_str_t *host,
static ngx_int_t
ngx_live_store_s3_put_request(ngx_pool_t *pool, void *arg, ngx_str_t *host,
ngx_str_t *uri, ngx_chain_t *body, size_t content_length,
ngx_buf_t **result)
ngx_buf_t **result, ngx_str_t *tag_header)
{
static const char request_template[] =
"PUT %V HTTP/1.1\r\n"
@@ -758,8 +758,9 @@ ngx_live_store_s3_put_request(ngx_pool_t *pool, void *arg, ngx_str_t *host,
"Host: %V\r\n"
"X-Amz-Content-SHA256: %V\r\n"
"X-Amz-Date: %V\r\n"
"X-Amz-Tagging: %V\r\n"
"Authorization: AWS4-HMAC-SHA256 Credential=%V/%V, "
"SignedHeaders=host;x-amz-content-sha256;x-amz-date, "
"SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-tagging, "
"Signature=%V\r\n"
"\r\n";

@@ -770,8 +771,9 @@ ngx_live_store_s3_put_request(ngx_pool_t *pool, void *arg, ngx_str_t *host,
"host:%V\n"
"x-amz-content-sha256:%V\n"
"x-amz-date:%V\n"
"x-amz-tagging:%V\n"
"\n"
"host;x-amz-content-sha256;x-amz-date\n"
"host;x-amz-content-sha256;x-amz-date;x-amz-tagging\n"
"%V";

static const char string_to_sign_template[] =
@@ -848,7 +850,7 @@ ngx_live_store_s3_put_request(ngx_pool_t *pool, void *arg, ngx_str_t *host,
canonical_request.data = p;

p = ngx_sprintf(p, canonical_request_template,
uri, host, &content_sha, &date, &content_sha);
uri, host, &content_sha, &date, tag_header, &content_sha);

canonical_request.len = p - canonical_request.data;

@@ -909,7 +911,7 @@ ngx_live_store_s3_put_request(ngx_pool_t *pool, void *arg, ngx_str_t *host,
}

b->last = ngx_sprintf(b->last, request_template,
uri, content_length, host, &content_sha, &date,
uri, content_length, host, &content_sha, &date, tag_header,
&ctx->access_key, &ctx->key_scope, &signature);

if ((size_t) (b->last - b->pos) > size) {
@@ -920,6 +922,27 @@ ngx_live_store_s3_put_request(ngx_pool_t *pool, void *arg, ngx_str_t *host,
return NGX_ERROR;
}

ngx_log_error(NGX_LOG_NOTICE, pool->log, 0,
"AAAA host %V", host);
ngx_log_error(NGX_LOG_NOTICE, pool->log, 0,
"AAAA SHA %V", &content_sha);

ngx_log_error(NGX_LOG_NOTICE, pool->log, 0,
"AAAA date %V", &date);

ngx_log_error(NGX_LOG_NOTICE, pool->log, 0,
"AAAA access %V", &ctx->access_key);
ngx_log_error(NGX_LOG_NOTICE, pool->log, 0,
"AAAA key scope %V", &ctx->key_scope);
ngx_log_error(NGX_LOG_NOTICE, pool->log, 0,
"AAAA sig %V", &signature);

ngx_log_error(NGX_LOG_NOTICE, pool->log, 0,
"AAAA signing key %V", &ctx->signing_key);
ngx_log_error(NGX_LOG_NOTICE, pool->log, 0,
"AAAA str to sigh %V", &string_to_sign);


*result = b;

return NGX_OK;
@@ -972,15 +995,17 @@ ngx_live_store_s3_write(ngx_live_store_write_request_t *request)
ctx = conf->ctx;

pool = request->pool;

// ngx_str_t tag_header = ngx_string("tag=test2");
// ngx_str_t* tag_header_p = &tag_header;
if (ngx_live_store_s3_put_request(pool, ctx, &ctx->url->host,
&request->path, request->cl, request->size, &b) != NGX_OK)
&request->path, request->cl, request->size, &b, &request->tag_value) != NGX_OK)
{
ngx_log_error(NGX_LOG_NOTICE, &channel->log, 0,
"ngx_live_store_s3_write: create request failed");
return NGX_ERROR;
}

ngx_log_error(NGX_LOG_NOTICE, pool->log, 0,
"FFFFFFF %V", &request->tag_value);
cl = ngx_alloc_chain_link(pool);
if (cl == NULL) {
ngx_log_error(NGX_LOG_NOTICE, &channel->log, 0,
@@ -990,7 +1015,6 @@ ngx_live_store_s3_write(ngx_live_store_write_request_t *request)

cl->buf = b;
cl->next = NULL;

return ngx_live_store_http_write(request, ctx->url, cl, request->cl,
&ctx->write_stats);
}

0 comments on commit a4c07ea

Please sign in to comment.