Resolve a team slug or user UUID to a `(GrantSubjectType, Uuid)` pair. Exactly one of `team_slug` or `user_id` must be `Some`.
(
client: &atomic_remote::StorageClient,
team_slug: &Option<String>,
user_id: &Option<String>,
)
| 286 | /// |
| 287 | /// Exactly one of `team_slug` or `user_id` must be `Some`. |
| 288 | async fn resolve_subject( |
| 289 | client: &atomic_remote::StorageClient, |
| 290 | team_slug: &Option<String>, |
| 291 | user_id: &Option<String>, |
| 292 | ) -> CliResult<(atomic_teams::GrantSubjectType, uuid::Uuid)> { |
| 293 | match (team_slug, user_id) { |
| 294 | (Some(slug), None) => { |
| 295 | let teams: Vec<atomic_teams::TeamInfo> = |
| 296 | atomic_teams::team::list_teams(client, client.org_slug()) |
| 297 | .await |
| 298 | .map_err(teams_err)?; |
| 299 | |
| 300 | let team = teams.iter().find(|t| t.slug == *slug).ok_or_else(|| { |
| 301 | CliError::InvalidArgument { |
| 302 | message: format!("Team '{}' not found in org '{}'.", slug, client.org_slug()), |
| 303 | } |
| 304 | })?; |
| 305 | |
| 306 | Ok((atomic_teams::GrantSubjectType::Team, team.id)) |
| 307 | } |
| 308 | (None, Some(id)) => { |
| 309 | let uuid = uuid::Uuid::parse_str(id).map_err(|_| CliError::InvalidArgument { |
| 310 | message: format!("'{}' is not a valid UUID.", id), |
| 311 | })?; |
| 312 | Ok((atomic_teams::GrantSubjectType::User, uuid)) |
| 313 | } |
| 314 | (Some(_), Some(_)) => Err(CliError::InvalidArgument { |
| 315 | message: "Specify either --team or --user, not both.".to_string(), |
| 316 | }), |
| 317 | (None, None) => Err(CliError::InvalidArgument { |
| 318 | message: "Specify --team <slug> or --user <uuid>.".to_string(), |
| 319 | }), |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | /// Parse the user-facing `--permission` flag into a `GrantRelation`. |
| 324 | /// |
no test coverage detected