Skip to content
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
2 changes: 1 addition & 1 deletion crates/fakecloud-bedrock/src/custom_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn create_custom_model(
req: &AwsRequest,
body: &Value,
) -> Result<AwsResponse, AwsServiceError> {
let default_name = Uuid::new_v4().to_string()[..8].to_string();
let default_name = crate::short_uuid();
let model_name = body["modelName"].as_str().unwrap_or(&default_name);

let model_id = Uuid::new_v4().to_string();
Expand Down
3 changes: 1 addition & 2 deletions crates/fakecloud-bedrock/src/guardrails.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use chrono::Utc;
use http::StatusCode;
use regex::Regex;
use serde_json::{json, Value};
use uuid::Uuid;

use fakecloud_core::service::{AwsRequest, AwsResponse, AwsServiceError};

Expand Down Expand Up @@ -30,7 +29,7 @@ pub fn create_guardrail(
.unwrap_or("Sorry, the model cannot answer this question.")
.to_string();

let guardrail_id = Uuid::new_v4().to_string()[..8].to_string();
let guardrail_id = crate::short_uuid();
let guardrail_arn = format!(
"arn:aws:bedrock:{}:{}:guardrail/{}",
req.region, req.account_id, guardrail_id
Expand Down
2 changes: 1 addition & 1 deletion crates/fakecloud-bedrock/src/inference_profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn create_inference_profile(
req: &AwsRequest,
body: &Value,
) -> Result<AwsResponse, AwsServiceError> {
let default_name = Uuid::new_v4().to_string()[..8].to_string();
let default_name = crate::short_uuid();
let profile_name = body["inferenceProfileName"]
.as_str()
.unwrap_or(&default_name);
Expand Down
10 changes: 10 additions & 0 deletions crates/fakecloud-bedrock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ pub mod service;
pub mod state;
pub mod streaming;
pub mod throughput;

/// Eight-character lowercase hex suffix derived from a fresh UUID.
///
/// Many Bedrock resources (guardrails, prompt routers, inference profiles,
/// custom models) generate a human-readable short identifier when the caller
/// doesn't supply one. We cut the UUID down to 8 characters so the resulting
/// name/id stays short and matches AWS's own convention for these resources.
pub(crate) fn short_uuid() -> String {
uuid::Uuid::new_v4().to_string()[..8].to_string()
}
2 changes: 1 addition & 1 deletion crates/fakecloud-bedrock/src/prompt_routers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn create_prompt_router(
req: &AwsRequest,
body: &Value,
) -> Result<AwsResponse, AwsServiceError> {
let default_name = Uuid::new_v4().to_string()[..8].to_string();
let default_name = crate::short_uuid();
let router_name = body["promptRouterName"].as_str().unwrap_or(&default_name);

let router_id = Uuid::new_v4().to_string();
Expand Down
36 changes: 6 additions & 30 deletions crates/fakecloud-cognito/src/service/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::state::{
use crate::triggers::{self, TriggerSource};

use super::{
generate_confirmation_code, generate_tokens, parse_user_attributes, require_str,
validate_password, CognitoService,
ensure_user_pool_exists, generate_confirmation_code, generate_tokens, parse_user_attributes,
require_str, validate_password, CognitoService,
};

impl CognitoService {
Expand Down Expand Up @@ -74,13 +74,7 @@ impl CognitoService {
let state = self.state.read();

// Validate pool exists
if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

// Validate client exists and belongs to pool
let client = state.user_pool_clients.get(client_id).ok_or_else(|| {
Expand Down Expand Up @@ -1657,13 +1651,7 @@ impl CognitoService {
let mut state = self.state.write();

// Validate pool exists
if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

let user = state
.users
Expand Down Expand Up @@ -1977,13 +1965,7 @@ impl CognitoService {
let mut state = self.state.write();

// Validate pool exists
if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

let user = state
.users
Expand Down Expand Up @@ -2047,13 +2029,7 @@ impl CognitoService {
let mut state = self.state.write();

// Validate pool exists
if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

// Validate user exists
if !state
Expand Down
82 changes: 11 additions & 71 deletions crates/fakecloud-cognito/src/service/branding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use fakecloud_core::service::{AwsRequest, AwsResponse, AwsServiceError};

use crate::state::WebAuthnCredential;

use super::{require_str, CognitoService};
use super::{ensure_user_pool_exists, require_str, CognitoService};

impl CognitoService {
// ── Managed Login Branding ────────────────────────────────────────
Expand All @@ -22,13 +22,7 @@ impl CognitoService {

let mut state = self.state.write();

if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

if !state.user_pool_clients.contains_key(client_id) {
return Err(AwsServiceError::aws_error(
Expand Down Expand Up @@ -78,13 +72,7 @@ impl CognitoService {

let mut state = self.state.write();

if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

match state.managed_login_brandings.get(branding_id) {
Some(b) if b["UserPoolId"].as_str() == Some(pool_id) => {
Expand Down Expand Up @@ -113,13 +101,7 @@ impl CognitoService {

let state = self.state.read();

if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

let branding = state
.managed_login_brandings
Expand Down Expand Up @@ -155,13 +137,7 @@ impl CognitoService {

let state = self.state.read();

if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

let branding = state
.managed_login_brandings
Expand Down Expand Up @@ -200,13 +176,7 @@ impl CognitoService {

let mut state = self.state.write();

if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

let branding = state
.managed_login_brandings
Expand Down Expand Up @@ -250,13 +220,7 @@ impl CognitoService {

let mut state = self.state.write();

if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

let terms_id = Uuid::new_v4().to_string();
let now = Utc::now();
Expand Down Expand Up @@ -294,13 +258,7 @@ impl CognitoService {

let mut state = self.state.write();

if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

match state.terms.get(terms_id) {
Some(t) if t["UserPoolId"].as_str() == Some(pool_id) => {
Expand All @@ -325,13 +283,7 @@ impl CognitoService {

let state = self.state.read();

if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

let terms = state
.terms
Expand All @@ -358,13 +310,7 @@ impl CognitoService {

let state = self.state.read();

if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

let mut terms_list: Vec<&serde_json::Value> = state
.terms
Expand Down Expand Up @@ -416,13 +362,7 @@ impl CognitoService {

let mut state = self.state.write();

if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

let terms = state
.terms
Expand Down
51 changes: 7 additions & 44 deletions crates/fakecloud-cognito/src/service/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use chrono::Utc;
use http::StatusCode;
use serde_json::json;

use fakecloud_core::service::{AwsRequest, AwsResponse, AwsServiceError};

use super::{require_str, CognitoService};
use super::{ensure_user_pool_exists, require_str, CognitoService};

impl CognitoService {
// ── UI Customization ──────────────────────────────────────────────
Expand All @@ -19,13 +18,7 @@ impl CognitoService {

let state = self.state.read();

if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

let key = format!("{pool_id}:{client_id}");

Expand Down Expand Up @@ -67,13 +60,7 @@ impl CognitoService {

let mut state = self.state.write();

if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

let now = Utc::now();
let key = format!("{pool_id}:{client_id}");
Expand Down Expand Up @@ -115,13 +102,7 @@ impl CognitoService {

let state = self.state.read();

if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

let config = state
.log_delivery_configs
Expand Down Expand Up @@ -149,13 +130,7 @@ impl CognitoService {

let mut state = self.state.write();

if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

let config = json!({
"UserPoolId": pool_id,
Expand Down Expand Up @@ -183,13 +158,7 @@ impl CognitoService {

let state = self.state.read();

if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

let key = format!("{pool_id}:{client_id}");

Expand Down Expand Up @@ -229,13 +198,7 @@ impl CognitoService {

let mut state = self.state.write();

if !state.user_pools.contains_key(pool_id) {
return Err(AwsServiceError::aws_error(
StatusCode::BAD_REQUEST,
"ResourceNotFoundException",
format!("User pool {pool_id} does not exist."),
));
}
ensure_user_pool_exists(&state, pool_id)?;

let key = format!("{pool_id}:{client_id}");

Expand Down
Loading
Loading