Skip to content

Commit 0fa7ff8

Browse files
authored
Merge branch 'main' into always-pull-presto
2 parents 3858d4c + 5798e0e commit 0fa7ff8

File tree

57 files changed

+1001
-434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1001
-434
lines changed

components/api-server/src/client.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ use std::pin::Pin;
33
use async_stream::stream;
44
use clp_rust_utils::{
55
aws::AWS_DEFAULT_REGION,
6-
clp_config::{
7-
AwsAuthentication,
8-
package::{
9-
config::{Config, StorageEngine, StreamOutputStorage},
10-
credentials::Credentials,
11-
},
6+
clp_config::package::{
7+
config::{Config, StorageEngine, StreamOutputStorage},
8+
credentials::Credentials,
129
},
1310
database::mysql::create_clp_db_mysql_pool,
1411
job_config::{QUERY_JOBS_TABLE_NAME, QueryJobStatus, QueryJobType, SearchJobConfig},
@@ -374,8 +371,6 @@ impl Client {
374371
unreachable!();
375372
};
376373

377-
let AwsAuthentication::Credentials { credentials } = &s3_config.aws_authentication;
378-
379374
let s3_config = s3_config.clone();
380375
if s3_config.region_code.is_none() && s3_config.endpoint_url.is_none() {
381376
return Err(ClientError::Aws {
@@ -384,15 +379,14 @@ impl Client {
384379
});
385380
}
386381

387-
let credentials = credentials.clone();
382+
let region_str = s3_config
383+
.region_code
384+
.as_ref()
385+
.map_or(AWS_DEFAULT_REGION, non_empty_string::NonEmptyString::as_str);
388386
let s3_client = clp_rust_utils::s3::create_new_client(
389-
credentials.access_key_id.as_str(),
390-
credentials.secret_access_key.as_str(),
391-
s3_config
392-
.region_code
393-
.as_ref()
394-
.map_or(AWS_DEFAULT_REGION, non_empty_string::NonEmptyString::as_str),
387+
region_str,
395388
s3_config.endpoint_url.as_ref(),
389+
&s3_config.aws_authentication,
396390
)
397391
.await;
398392

components/clp-py-utils/clp_py_utils/clp_config.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ class StorageType(LowercaseStrEnum):
165165

166166

167167
class AwsAuthType(LowercaseStrEnum):
168+
default = auto()
168169
credentials = auto()
169170
profile = auto()
170171
env_vars = auto()
171-
ec2 = auto()
172172

173173

174174
AwsAuthTypeStr = Annotated[AwsAuthType, StrEnumSerializer]
@@ -588,7 +588,7 @@ def validate_authentication(cls, data):
588588
raise ValueError(f"profile must be set when type is '{auth_enum}.'")
589589
if AwsAuthType.credentials == auth_enum and not credentials:
590590
raise ValueError(f"credentials must be set when type is '{auth_enum}.'")
591-
if auth_enum in [AwsAuthType.ec2, AwsAuthType.env_vars] and (profile or credentials):
591+
if auth_enum in [AwsAuthType.default, AwsAuthType.env_vars] and (profile or credentials):
592592
raise ValueError(f"profile and credentials must not be set when type is '{auth_enum}.'")
593593
return data
594594

@@ -951,7 +951,6 @@ def validate_tmp_dir(self, use_host_mount: bool = False):
951951
raise ValueError(f"tmp_directory is invalid: {ex}")
952952

953953
def validate_aws_config_dir(self, use_host_mount: bool = False):
954-
profile_auth_used = False
955954
auth_configs = []
956955

957956
if StorageType.S3 == self.logs_input.type:
@@ -961,16 +960,23 @@ def validate_aws_config_dir(self, use_host_mount: bool = False):
961960
if StorageType.S3 == self.stream_output.storage.type:
962961
auth_configs.append(self.stream_output.storage.s3_config.aws_authentication)
963962

964-
for auth in auth_configs:
965-
if AwsAuthType.profile == auth.type:
966-
profile_auth_used = True
967-
break
963+
auth_types_used = {auth.type for auth in auth_configs}
964+
default_auth_used = AwsAuthType.default in auth_types_used
965+
profile_auth_used = AwsAuthType.profile in auth_types_used
966+
config_dir_allowed = profile_auth_used or default_auth_used
968967

969968
if profile_auth_used:
970969
if self.aws_config_directory is None:
971970
raise ValueError(
972971
"aws_config_directory must be set when using profile authentication"
973972
)
973+
974+
if self.aws_config_directory is not None:
975+
if not config_dir_allowed:
976+
raise ValueError(
977+
"aws_config_directory is only supported with 'profile' or 'default'"
978+
" authentication"
979+
)
974980
resolved_aws_config_dir = (
975981
resolve_host_path_in_container(self.aws_config_directory)
976982
if use_host_mount
@@ -980,10 +986,6 @@ def validate_aws_config_dir(self, use_host_mount: bool = False):
980986
raise ValueError(
981987
f"aws_config_directory does not exist: '{self.aws_config_directory}'"
982988
)
983-
if not profile_auth_used and self.aws_config_directory is not None:
984-
raise ValueError(
985-
"aws_config_directory should not be set when profile authentication is not used"
986-
)
987989

988990
def validate_api_server(self):
989991
if StorageEngine.CLP == self.package.storage_engine and self.api_server is not None:

components/clp-py-utils/clp_py_utils/s3_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ def get_credential_env_vars(auth: AwsAuthentication) -> dict[str, str]:
9090
if aws_credentials is None:
9191
raise ValueError(f"Failed to authenticate with profile {auth.profile}")
9292

93-
elif AwsAuthType.ec2 == auth.type:
93+
elif AwsAuthType.default == auth.type:
9494
aws_credentials = _get_session_credentials()
9595
if aws_credentials is None:
96-
raise ValueError("Failed to authenticate with EC2 metadata.")
96+
raise ValueError("Failed to authenticate with the default credential provider chain.")
9797
else:
9898
raise ValueError(f"Unsupported authentication type: {auth.type}")
9999

@@ -206,7 +206,7 @@ def _create_s3_client(
206206
region_name=region_code,
207207
aws_session_token=credentials.session_token,
208208
)
209-
elif AwsAuthType.env_vars == s3_auth.type or AwsAuthType.ec2 == s3_auth.type:
209+
elif AwsAuthType.env_vars == s3_auth.type or AwsAuthType.default == s3_auth.type:
210210
# Use default session which will use environment variables or instance role
211211
aws_session = boto3.Session(region_name=region_code)
212212
else:

components/clp-rust-utils/src/clp_config/package/config.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,38 @@ mod tests {
345345
assert_eq!(credentials.access_key_id, ACCESS_KEY_ID);
346346
assert_eq!(credentials.secret_access_key, SECRET_ACCESS_KEY);
347347
}
348+
crate::clp_config::AwsAuthentication::Default => {
349+
panic!("Expected credentials, got `default`")
350+
}
348351
},
349352
LogsInput::Fs { .. } => panic!("Expected S3"),
350353
}
351354
}
352355

356+
#[test]
357+
fn deserialize_logs_input_s3_default_config() {
358+
let logs_input_config_json = serde_json::json!({
359+
"type": "s3",
360+
"aws_authentication": {
361+
"type": "default",
362+
}
363+
});
364+
365+
let deserialized =
366+
serde_json::from_str::<LogsInput>(logs_input_config_json.to_string().as_str())
367+
.expect("failed to deserialize `LogsInput` from JSON");
368+
369+
match deserialized {
370+
LogsInput::S3 { config } => {
371+
assert_eq!(
372+
config.aws_authentication,
373+
crate::clp_config::AwsAuthentication::Default
374+
);
375+
}
376+
LogsInput::Fs { .. } => panic!("Expected S3"),
377+
}
378+
}
379+
353380
#[test]
354381
fn deserialize_logs_input_fs_config() {
355382
const DIRECTORY: &str = "/var/logs";

components/clp-rust-utils/src/clp_config/s3_config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ pub struct S3Config {
1515
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1616
#[serde(tag = "type")]
1717
pub enum AwsAuthentication {
18+
/// Uses the default AWS SDK credential provider chain.
19+
#[serde(rename = "default")]
20+
Default,
21+
1822
#[serde(rename = "credentials")]
1923
Credentials { credentials: AwsCredentials },
2024
}

components/clp-rust-utils/src/s3/client.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ use aws_sdk_s3::{
55
};
66
use non_empty_string::NonEmptyString;
77

8+
use crate::clp_config::AwsAuthentication;
9+
810
/// Creates a new S3 client.
911
///
12+
/// When `aws_authentication` is [`AwsAuthentication::Credentials`], the client uses the given
13+
/// access key pair. When [`AwsAuthentication::Default`], the client uses the default AWS SDK
14+
/// credential provider chain.
15+
///
1016
/// # Notes
1117
///
1218
/// * The client is configured using the latest AWS SDK behavior version.
@@ -17,25 +23,23 @@ use non_empty_string::NonEmptyString;
1723
/// A newly created S3 client.
1824
#[must_use]
1925
pub async fn create_new_client(
20-
access_key_id: &str,
21-
secret_access_key: &str,
2226
region_id: &str,
2327
endpoint: Option<&NonEmptyString>,
28+
aws_authentication: &AwsAuthentication,
2429
) -> Client {
25-
let credentials = Credentials::new(
26-
access_key_id,
27-
secret_access_key,
28-
None,
29-
None,
30-
"clp-credentials-provider",
31-
);
32-
let base_config = aws_config::defaults(BehaviorVersion::latest())
33-
.credentials_provider(credentials)
34-
.region(Region::new(region_id.to_string()))
35-
.load()
36-
.await;
30+
let mut config_defaults =
31+
aws_config::defaults(BehaviorVersion::latest()).region(Region::new(region_id.to_string()));
32+
if let AwsAuthentication::Credentials { credentials } = aws_authentication {
33+
config_defaults = config_defaults.credentials_provider(Credentials::new(
34+
credentials.access_key_id.as_str(),
35+
credentials.secret_access_key.as_str(),
36+
None,
37+
None,
38+
"clp-credentials-provider",
39+
));
40+
}
41+
let base_config = config_defaults.load().await;
3742
let mut config_builder = Builder::from(&base_config).force_path_style(true);
3843
config_builder.set_endpoint_url(endpoint.map(std::string::ToString::to_string));
39-
let config = config_builder.build();
40-
Client::from_conf(config)
44+
Client::from_conf(config_builder.build())
4145
}

components/clp-rust-utils/src/sqs/client.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,37 @@ use aws_sdk_sqs::{
55
};
66
use non_empty_string::NonEmptyString;
77

8+
use crate::clp_config::AwsAuthentication;
9+
810
/// Creates a new SQS client.
11+
///
12+
/// When `aws_authentication` is [`AwsAuthentication::Credentials`], the client uses the given
13+
/// access key pair. When [`AwsAuthentication::Default`], the client uses the default AWS SDK
14+
/// credential provider chain.
15+
///
916
/// The client is configured using the latest AWS SDK behavior version.
1017
///
1118
/// # Returns
1219
///
1320
/// A newly created SQS client.
1421
#[must_use]
1522
pub async fn create_new_client(
16-
access_key_id: &str,
17-
secret_access_key: &str,
1823
region_id: &str,
1924
endpoint: Option<&NonEmptyString>,
25+
aws_authentication: &AwsAuthentication,
2026
) -> Client {
21-
let credentials = Credentials::new(
22-
access_key_id,
23-
secret_access_key,
24-
None,
25-
None,
26-
"clp-credentials-provider",
27-
);
28-
let base_config = aws_config::defaults(BehaviorVersion::latest())
29-
.credentials_provider(credentials)
30-
.region(Region::new(region_id.to_string()))
31-
.load()
32-
.await;
27+
let mut config_defaults =
28+
aws_config::defaults(BehaviorVersion::latest()).region(Region::new(region_id.to_string()));
29+
if let AwsAuthentication::Credentials { credentials } = aws_authentication {
30+
config_defaults = config_defaults.credentials_provider(Credentials::new(
31+
credentials.access_key_id.as_str(),
32+
credentials.secret_access_key.as_str(),
33+
None,
34+
None,
35+
"clp-credentials-provider",
36+
));
37+
}
38+
let base_config = config_defaults.load().await;
3339
let mut config_builder = Builder::from(&base_config);
3440
config_builder.set_endpoint_url(endpoint.map(std::string::ToString::to_string));
3541
Client::from_conf(config_builder.build())

components/core/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ set(SOURCE_FILES_clp_s_unitTest
361361
src/clp_s/FileWriter.hpp
362362
src/clp_s/FloatFormatEncoding.cpp
363363
src/clp_s/FloatFormatEncoding.hpp
364+
src/clp_s/ffi/sfa/ClpArchiveReader.cpp
365+
src/clp_s/ffi/sfa/ClpArchiveReader.hpp
366+
src/clp_s/ffi/sfa/SfaErrorCode.cpp
367+
src/clp_s/ffi/sfa/SfaErrorCode.hpp
364368
src/clp_s/InputConfig.cpp
365369
src/clp_s/InputConfig.hpp
366370
src/clp_s/JsonConstructor.cpp
@@ -500,8 +504,8 @@ set(SOURCE_FILES_unitTest
500504
src/clp/ffi/ir_stream/decoding_methods.inc
501505
src/clp/ffi/ir_stream/encoding_methods.cpp
502506
src/clp/ffi/ir_stream/encoding_methods.hpp
503-
src/clp/ffi/ir_stream/IrErrorCode.cpp
504-
src/clp/ffi/ir_stream/IrErrorCode.hpp
507+
src/clp/ffi/ir_stream/IrDeserializationError.cpp
508+
src/clp/ffi/ir_stream/IrDeserializationError.hpp
505509
src/clp/ffi/ir_stream/IrSerializationError.cpp
506510
src/clp/ffi/ir_stream/IrSerializationError.hpp
507511
src/clp/ffi/ir_stream/IrUnitHandlerReq.hpp
@@ -714,6 +718,7 @@ set(SOURCE_FILES_unitTest
714718
tests/test-BufferedReader.cpp
715719
tests/test-clp_s-delta-encode-log-order.cpp
716720
tests/test-clp_s-end_to_end.cpp
721+
tests/test-clp_s-ffi_sfa_reader.cpp
717722
tests/test-clp_s-range_index.cpp
718723
tests/test-clp_s-search.cpp
719724
tests/test-EncodedVariableInterpreter.cpp

components/core/src/clp/clg/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ set(
2121
../ffi/ir_stream/decoding_methods.cpp
2222
../ffi/ir_stream/decoding_methods.hpp
2323
../ffi/ir_stream/decoding_methods.inc
24+
../ffi/ir_stream/IrDeserializationError.cpp
25+
../ffi/ir_stream/IrDeserializationError.hpp
2426
../ffi/ir_stream/IrSerializationError.cpp
2527
../ffi/ir_stream/IrSerializationError.hpp
2628
../ffi/StringBlob.hpp

components/core/src/clp/clo/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ set(
2727
../ffi/ir_stream/decoding_methods.inc
2828
../ffi/ir_stream/encoding_methods.cpp
2929
../ffi/ir_stream/encoding_methods.hpp
30+
../ffi/ir_stream/IrDeserializationError.cpp
31+
../ffi/ir_stream/IrDeserializationError.hpp
3032
../ffi/ir_stream/IrSerializationError.cpp
3133
../ffi/ir_stream/IrSerializationError.hpp
3234
../ffi/ir_stream/utils.cpp

0 commit comments

Comments
 (0)