Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pubsys: fix AWS SDK API calls and surface service error codes #2895

Merged
merged 3 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tools/pubsys/src/aws/ami/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,11 @@ async fn _run(args: &Args, ami_args: &AmiArgs) -> Result<HashMap<String, Image>>
}
Err(e) => {
saw_error = true;
error!("Copy to {} failed: {}", region, e);
error!(
"Copy to {} failed: {}",
region,
e.into_service_error().code().unwrap_or("unknown")
);
}
}
}
Expand Down
42 changes: 29 additions & 13 deletions tools/pubsys/src/aws/publish_ami/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,12 @@ pub(crate) async fn modify_snapshots(
let response_future = ec2_client
.modify_snapshot_attribute()
.set_attribute(Some(SnapshotAttributeName::CreateVolumePermission))
.set_user_ids(Some(modify_opts.user_ids.clone()))
.set_group_names(Some(modify_opts.group_names.clone()))
.set_user_ids(
(!modify_opts.user_ids.is_empty()).then_some(modify_opts.user_ids.clone()),
)
.set_group_names(
(!modify_opts.group_names.is_empty()).then_some(modify_opts.group_names.clone()),
)
.set_operation_type(Some(operation.clone()))
.set_snapshot_id(Some(snapshot_id.clone()))
.send();
Expand Down Expand Up @@ -399,12 +403,14 @@ pub(crate) async fn modify_regional_snapshots(
}
Err(e) => {
error_count += 1;
error!(
"Failed to modify permissions in {} for snapshots [{}]: {}",
region.as_ref(),
snapshot_ids.join(", "),
e
);
if let Error::ModifyImageAttribute { source: err, .. } = e {
error!(
"Failed to modify permissions in {} for snapshots [{}]: {:?}",
region.as_ref(),
snapshot_ids.join(", "),
err.into_service_error().code().unwrap_or("unknown"),
);
}
}
}
}
Expand Down Expand Up @@ -433,10 +439,18 @@ pub(crate) async fn modify_image(
.set_attribute(Some(
ImageAttributeName::LaunchPermission.as_ref().to_string(),
))
.set_user_ids(Some(modify_opts.user_ids.clone()))
.set_user_groups(Some(modify_opts.group_names.clone()))
.set_organization_arns(Some(modify_opts.organization_arns.clone()))
.set_organizational_unit_arns(Some(modify_opts.organizational_unit_arns.clone()))
.set_user_ids((!modify_opts.user_ids.is_empty()).then_some(modify_opts.user_ids.clone()))
.set_user_groups(
(!modify_opts.group_names.is_empty()).then_some(modify_opts.group_names.clone()),
)
.set_organization_arns(
(!modify_opts.organization_arns.is_empty())
.then_some(modify_opts.organization_arns.clone()),
)
.set_organizational_unit_arns(
(!modify_opts.organizational_unit_arns.is_empty())
.then_some(modify_opts.organizational_unit_arns.clone()),
)
.set_operation_type(Some(operation.clone()))
.set_image_id(Some(image_id.to_string()))
.send()
Expand Down Expand Up @@ -483,7 +497,9 @@ pub(crate) async fn modify_regional_images(
error_count += 1;
error!(
"Modifying permissions of {} in {} failed: {}",
image_id, region, e
image_id,
region,
e.into_service_error().code().unwrap_or("unknown"),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/pubsys/src/aws/ssm/ssm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ where
let len = names_chunk.len();
let get_future = ssm_client
.get_parameters()
.set_names(Some(names_chunk.to_vec()))
.set_names((!names_chunk.is_empty()).then_some(names_chunk.to_vec().clone()))
.send();

// Store the region so we can include it in errors and the output map
Expand Down