Skip to content

Commit

Permalink
Video-2474 added fixes to credentials and s3sink class, added test (m…
Browse files Browse the repository at this point in the history
…aybe removed later since we really don't want to allow creds to be read -- but needed the test as a sanity check)
  • Loading branch information
saraboule authored and jawilson committed Nov 20, 2023
1 parent ccdeb24 commit bb10adf
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/gstawscredentials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ GST_DEBUG_CATEGORY_STATIC (gst_aws_credentials_debug);

using namespace Aws::Auth;

static GstAWSCredentials * _gst_aws_credentials_from_string (const gchar * str);

struct _GstAWSCredentials {
_GstAWSCredentials(GstAWSCredentialsProviderFactory factory) :
credentials_provider_factory(std::move(factory))
Expand Down Expand Up @@ -71,9 +73,10 @@ gst_aws_credentials_free (GstAWSCredentials * credentials)
}

GstAWSCredentials *
gst_aws_credentials_new_from_string(const gchar * str)
gst_aws_credentials_new_from_string(const gchar * s)
{
return _gst_aws_credentials_from_string (str);
// gst_aws_credentials_new_default();
return _gst_aws_credentials_from_string (s);
}


Expand Down
2 changes: 0 additions & 2 deletions src/gstawscredentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,4 @@ GstAWSCredentials * gst_aws_credentials_new_from_string(const gchar * str);

G_END_DECLS

static GstAWSCredentials * _gst_aws_credentials_from_string (const gchar * str);

#endif /* __GST_AWS_CREDENTIALS_H__ */
7 changes: 4 additions & 3 deletions src/gsts3sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ gst_s3_sink_class_init (GstS3SinkClass * klass)
g_object_class_install_property (gobject_class, PROP_CREDENTIALS_STRING,
g_param_spec_string("aws-credentials-string", "AWS credentials (string)",
"The AWS credentials to use parsed from string", NULL,
G_PARAM_WRITABLE | GST_PARAM_MUTABLE_READY | G_PARAM_STATIC_STRINGS));
G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (gobject_class, PROP_AWS_SDK_ENDPOINT,
g_param_spec_string ("aws-sdk-endpoint", "AWS SDK Endpoint",
Expand Down Expand Up @@ -427,7 +427,8 @@ gst_s3_sink_set_property (GObject * object, guint prop_id,
case PROP_CREDENTIALS_STRING:
if (sink->config.credentials)
gst_aws_credentials_free (sink->config.credentials);
sink->config.credentials = gst_aws_credentials_new_from_string(g_value_get_string (value));
gst_s3_sink_set_string_property (sink, g_value_get_string (value), &sink->credentials_string, "aws-credentials-string");
sink->config.credentials = gst_aws_credentials_new_from_string(sink->credentials_string);
break;
case PROP_AWS_SDK_ENDPOINT:
gst_s3_sink_set_string_property (sink, g_value_get_string (value),
Expand Down Expand Up @@ -523,7 +524,7 @@ gst_s3_sink_get_property (GObject * object, guint prop_id, GValue * value,
g_value_set_int (value, sink->config.cache_num_parts);
break;
case PROP_CREDENTIALS_STRING:
// g_value_set_string (value, sink->config.region);
g_value_set_string (value, sink->credentials_string);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Expand Down
2 changes: 2 additions & 0 deletions src/gsts3sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ struct _GstS3Sink {
// doing any download/copy-upload -like operations
// that would require the uploader to 'complete'
gboolean uploader_needs_complete;

gchar * credentials_string;
};

struct _GstS3SinkClass {
Expand Down
25 changes: 25 additions & 0 deletions tests/check/s3sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,30 @@ GST_START_TEST (test_location_property)
}
GST_END_TEST

GST_START_TEST (test_credentials_property)
{
GstElement *sink = gst_element_factory_make ("s3sink", "sink");
const gchar *location = "s3://bucket/key";

gchar *returned_credentials = NULL;
gchar * credentialstr = "access-key-id=someAccessKey";

fail_if (sink == NULL);

// Set location, then set bucket and key, verify location is used
g_object_set (sink, "aws-credentials-string", "access-key-id=someAccessKey", NULL);
g_object_set (sink,
"bucket", "new-bucket",
"key", "new-key",
NULL);
g_object_get (sink, "aws-credentials-string", &returned_credentials, NULL);
fail_if (0 != g_ascii_strcasecmp("access-key-id=someAccessKey", returned_credentials));
g_free (returned_credentials);

gst_object_unref (sink);
}
GST_END_TEST

GST_START_TEST (test_gst_urihandler_interface)
{
GstElement *s3Sink = gst_element_make_from_uri(GST_URI_SINK, "s3://bucket/key", "s3sink", NULL);
Expand Down Expand Up @@ -821,6 +845,7 @@ s3sink_suite (void)
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_no_bucket_and_key_then_start_should_fail);
tcase_add_test (tc_chain, test_location_property);
tcase_add_test (tc_chain, test_credentials_property);
tcase_add_test (tc_chain, test_gst_urihandler_interface);
tcase_add_test (tc_chain, test_change_properties_after_start_should_fail);
tcase_add_test (tc_chain, test_send_eos_should_flush_buffer);
Expand Down

0 comments on commit bb10adf

Please sign in to comment.