Port to AWS SDK 0.57/0.35

Co-authored-by: Sebastian Dröge <sebastian@centricular.com>
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1388>
This commit is contained in:
Mathieu Duponchelle 2023-11-03 10:31:10 +02:00 committed by Sebastian Dröge
parent aa491e0d54
commit 6747b11cb9
5 changed files with 76 additions and 94 deletions

View file

@ -13,15 +13,14 @@ rust-version = "1.70"
[dependencies]
async-stream = "0.3.4"
base32 = "0.4"
aws-config = "0.56.0"
aws-sdk-s3 = "0.34.0"
aws-sdk-transcribestreaming = "0.34.0"
aws-sdk-translate = "0.34.0"
aws-types = "0.56.0"
aws-credential-types = "0.56.0"
aws-sig-auth = "0.56.0"
aws-smithy-http = { version = "0.56.0", features = [ "rt-tokio" ] }
aws-smithy-types = "0.56.0"
aws-config = "0.57.0"
aws-sdk-s3 = "0.35.0"
aws-sdk-transcribestreaming = "0.35.0"
aws-sdk-translate = "0.35.0"
aws-types = "0.57.0"
aws-credential-types = "0.57.0"
aws-smithy-http = { version = "0.57.0", features = [ "rt-tokio" ] }
aws-smithy-types = "0.57.0"
bytes = "1.0"
futures = "0.3"
gio = { git = "https://github.com/gtk-rs/gtk-rs-core.git", branch = "0.18", version = "0.18", package = "gio" }

View file

@ -10,10 +10,9 @@ use aws_config::meta::region::RegionProviderChain;
use aws_sdk_s3::config::{timeout::TimeoutConfig, Credentials, Region};
use aws_types::sdk_config::SdkConfig;
use aws_smithy_http::byte_stream::{error::Error, ByteStream};
use aws_smithy_types::byte_stream::{error::Error, ByteStream};
use bytes::{buf::BufMut, Bytes, BytesMut};
use futures::stream::TryStreamExt;
use futures::{future, Future};
use gst::glib::once_cell::sync::Lazy;
use std::sync::Mutex;

View file

@ -85,12 +85,8 @@ impl TranslateLoop {
let found_output_lang = language_list
.languages()
.and_then(|langs| {
langs
.iter()
.find(|lang| lang.language_code() == Some(&self.output_lang))
})
.is_some();
.iter()
.any(|lang| lang.language_code() == self.output_lang);
if !found_output_lang {
let err = format!("Unknown output languages: {}", self.output_lang);
@ -151,8 +147,7 @@ impl TranslateLoop {
gst::info!(CAT, imp: self.pad, "{err}");
gst::error_msg!(gst::LibraryError::Failed, ["{err}"])
})?
.translated_text
.unwrap_or_default();
.translated_text;
gst::debug!(CAT, imp: self.pad, "Got translation {translated_text}");

View file

@ -33,14 +33,14 @@ gst_plugin_webrtc_protocol = { path="protocol", package = "gst-plugin-webrtc-sig
human_bytes = "0.4"
url = "2"
aws-config = "0.56.0"
aws-types = "0.56.0"
aws-credential-types = "0.56.0"
aws-sig-auth = "0.56.0"
aws-smithy-http = { version = "0.56.0", features = [ "rt-tokio" ] }
aws-smithy-types = "0.56.0"
aws-sdk-kinesisvideo = "0.34.0"
aws-sdk-kinesisvideosignaling = "0.34.0"
aws-config = "0.57.0"
aws-types = "0.57.0"
aws-credential-types = "0.57.0"
aws-sigv4 = "0.57.0"
aws-smithy-http = { version = "0.57.0", features = [ "rt-tokio" ] }
aws-smithy-types = "0.57.0"
aws-sdk-kinesisvideo = "0.35.0"
aws-sdk-kinesisvideosignaling = "0.35.0"
http = "0.2.7"
chrono = "0.4"
data-encoding = "2.3.3"

View file

@ -22,10 +22,10 @@ use aws_sdk_kinesisvideo::{
Client,
};
use aws_sdk_kinesisvideosignaling::Client as SignalingClient;
use aws_sig_auth::signer::{self, HttpSignatureType, OperationSigningConfig, RequestConfig};
use aws_smithy_http::body::SdkBody;
use aws_types::{region::SigningRegion, SigningService};
use chrono::prelude::*;
use aws_sigv4::http_request::{
sign, SignableBody, SignableRequest, SignatureLocation, SigningSettings,
};
use aws_sigv4::sign::v4;
use data_encoding::BASE64;
use http::Uri;
use std::time::{Duration, SystemTime};
@ -269,41 +269,31 @@ impl Signaller {
gst::debug!(CAT, "Endpoints: {:?}", resp.resource_endpoint_list());
let endpoint_wss_uri =
match resp
.resource_endpoint_list()
.unwrap()
.iter()
.find_map(|endpoint| {
if endpoint.protocol == Some(ChannelProtocol::Wss) {
Some(endpoint.resource_endpoint().unwrap().to_owned())
} else {
None
}
}) {
Some(endpoint_uri_str) => Uri::from_maybe_shared(endpoint_uri_str).unwrap(),
None => {
anyhow::bail!("No WSS endpoint found for {channel_name}");
}
};
let endpoint_wss_uri = match resp.resource_endpoint_list().iter().find_map(|endpoint| {
if endpoint.protocol == Some(ChannelProtocol::Wss) {
Some(endpoint.resource_endpoint().unwrap().to_owned())
} else {
None
}
}) {
Some(endpoint_uri_str) => Uri::from_maybe_shared(endpoint_uri_str).unwrap(),
None => {
anyhow::bail!("No WSS endpoint found for {channel_name}");
}
};
let endpoint_https_uri =
match resp
.resource_endpoint_list()
.unwrap()
.iter()
.find_map(|endpoint| {
if endpoint.protocol == Some(ChannelProtocol::Https) {
Some(endpoint.resource_endpoint().unwrap().to_owned())
} else {
None
}
}) {
Some(endpoint_uri_str) => endpoint_uri_str,
None => {
anyhow::bail!("No HTTPS endpoint found for {channel_name}");
}
};
let endpoint_https_uri = match resp.resource_endpoint_list().iter().find_map(|endpoint| {
if endpoint.protocol == Some(ChannelProtocol::Https) {
Some(endpoint.resource_endpoint().unwrap().to_owned())
} else {
None
}
}) {
Some(endpoint_uri_str) => endpoint_uri_str,
None => {
anyhow::bail!("No HTTPS endpoint found for {channel_name}");
}
};
gst::debug!(
CAT,
@ -331,7 +321,6 @@ impl Signaller {
let ice_servers: Vec<String> = resp
.ice_server_list()
.unwrap()
.iter()
.filter_map(|server| {
Option::zip(server.username(), server.password())
@ -340,7 +329,6 @@ impl Signaller {
.flat_map(|(username, password, server)| {
server
.uris()
.unwrap()
.iter()
.filter_map(move |uri| {
uri.split_once(':').map(|(protocol, host)| {
@ -373,20 +361,20 @@ impl Signaller {
}),
);
let current_time = Utc::now();
let signer = signer::SigV4Signer::new();
let mut operation_config = OperationSigningConfig::default_config();
operation_config.signature_type = HttpSignatureType::HttpRequestQueryParams;
operation_config.expires_in = Some(Duration::from_secs(5 * 60)); // See commit a3db85d.
let request_config = RequestConfig {
request_ts: SystemTime::from(current_time),
region: &SigningRegion::from(region),
service: &SigningService::from_static("kinesisvideo"),
payload_override: None,
};
let mut signing_settings = SigningSettings::default();
signing_settings.signature_location = SignatureLocation::QueryParams;
signing_settings.expires_in = Some(Duration::from_secs(5 * 60));
let identity = credentials.clone().into();
let region_string = region.to_string();
let signing_params = v4::SigningParams::builder()
.identity(&identity)
.region(&region_string)
.name("kinesisvideo")
.time(SystemTime::now())
.settings(signing_settings)
.build()
.unwrap()
.into();
let transcribe_uri = Uri::builder()
.scheme("wss")
.authority(endpoint_wss_uri.authority().unwrap().to_owned())
@ -399,22 +387,23 @@ impl Signaller {
gst::error!(CAT, imp: self, "Failed to build HTTP request URI: {err}");
anyhow!("Failed to build HTTP request URI: {err}")
})?;
// Convert the HTTP request into a signable request
let signable_request = SignableRequest::new(
"GET",
transcribe_uri.to_string(),
std::iter::empty(),
SignableBody::Bytes(&[]),
)
.expect("signable request");
let mut request = http::Request::builder()
.uri(transcribe_uri)
.body(SdkBody::empty())
.body(aws_smithy_types::body::SdkBody::empty())
.expect("Failed to build valid request");
let _signature = signer
.sign(
&operation_config,
&request_config,
&credentials,
&mut request,
)
.map_err(|err| {
gst::error!(CAT, imp: self, "Failed to sign HTTP request: {err}");
anyhow!("Failed to sign HTTP request: {err}")
})?;
let (signing_instructions, _signature) =
sign(signable_request, &signing_params)?.into_parts();
signing_instructions.apply_to_request(&mut request);
let url = request.uri().to_string();