Skip to content

Commit

Permalink
Merge pull request bottlerocket-os#2895 from etungsten/sdk-pls
Browse files Browse the repository at this point in the history
pubsys: fix AWS SDK API calls and surface service error codes
  • Loading branch information
etungsten authored Mar 15, 2023
2 parents b1ac8ef + 035b533 commit 972c38b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
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

0 comments on commit 972c38b

Please sign in to comment.