A platform for community discussion. Free, open, simple.
FIX: Allow mediaconvert client without endpoint (#35135)
Blake Erickson05d7122570d3
diff --git a/app/services/video_conversion/aws_media_convert_adapter.rb b/app/services/video_conversion/aws_media_convert_adapter.rbindex 006fdfc435e..3c706ceda5a 100644--- a/app/services/video_conversion/aws_media_convert_adapter.rb+++ b/app/services/video_conversion/aws_media_convert_adapter.rb@@ -191,7 +191,8 @@ module VideoConversionenddef create_basic_client(endpoint: nil)- client_options = { region: SiteSetting.s3_region, endpoint: endpoint }+ client_options = { region: SiteSetting.s3_region }+ client_options[:endpoint] = endpoint if endpoint.present?if !SiteSetting.s3_use_iam_profileclient_options[:credentials] = Aws::Credentials.new(diff --git a/spec/services/video_conversion/aws_media_convert_adapter_spec.rb b/spec/services/video_conversion/aws_media_convert_adapter_spec.rbindex c499264f0eb..51f6fcb4095 100644--- a/spec/services/video_conversion/aws_media_convert_adapter_spec.rb+++ b/spec/services/video_conversion/aws_media_convert_adapter_spec.rb@@ -356,4 +356,58 @@ RSpec.describe VideoConversion::AwsMediaConvertAdapter doendendend++ describe "#create_basic_client" do+ context "when using IAM profile" do+ before do+ allow(SiteSetting).to receive(:s3_use_iam_profile).and_return(true)+ allow(SiteSetting).to receive(:s3_access_key_id).and_return("")+ allow(SiteSetting).to receive(:s3_secret_access_key).and_return("")+ end++ it "creates client without endpoint when endpoint is nil" do+ allow(Aws::MediaConvert::Client).to receive(:new).and_return(mediaconvert_client)++ adapter.send(:create_basic_client, endpoint: nil)++ expect(Aws::MediaConvert::Client).to have_received(:new).with({ region: s3_region })+ end++ it "creates client without endpoint when endpoint is empty string" do+ allow(Aws::MediaConvert::Client).to receive(:new).and_return(mediaconvert_client)++ adapter.send(:create_basic_client, endpoint: "")++ expect(Aws::MediaConvert::Client).to have_received(:new).with({ region: s3_region })+ end++ it "creates client with endpoint when endpoint is present" do+ endpoint = "https://mediaconvert.us-west-2.amazonaws.com"+ allow(Aws::MediaConvert::Client).to receive(:new).and_return(mediaconvert_client)++ adapter.send(:create_basic_client, endpoint: endpoint)++ expect(Aws::MediaConvert::Client).to have_received(:new).with(+ { region: s3_region, endpoint: endpoint },+ )+ end+ end++ context "when not using IAM profile" do+ before do+ allow(SiteSetting).to receive(:s3_use_iam_profile).and_return(false)+ allow(SiteSetting).to receive(:s3_access_key_id).and_return("test-key")+ allow(SiteSetting).to receive(:s3_secret_access_key).and_return("test-secret")+ end++ it "creates client with credentials" do+ allow(Aws::MediaConvert::Client).to receive(:new).and_return(mediaconvert_client)++ adapter.send(:create_basic_client, endpoint: nil)++ # Verify that credentials are included in the client creation+ expect(Aws::MediaConvert::Client).to have_received(:new)+ end+ end+ endend