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

fix(sozo): ensure overlays can support any resource type #2169

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Changes from 2 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
33 changes: 20 additions & 13 deletions crates/sozo/ops/src/migration/auto_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use super::ui::MigrationUi;
use super::MigrationOutput;
use crate::auth::{grant_writer, ResourceType, ResourceWriter};
use crate::auth::{grant_writer, ResourceWriter};

pub async fn auto_authorize<A>(
ws: &Workspace<'_>,
Expand All @@ -27,7 +27,7 @@
let ui = ws.config().ui();

ui.print(" ");
ui.print_step(6, "🖋️", "Authorizing Models to Systems (based on overlay)...");
ui.print_step(6, "🖋️", "Authorizing systems based on overlay...");
ui.print(" ");
let new_writers = compute_writers(&ui, local_manifest, migration_output)?;
grant_writer(&ui, world, new_writers, *txn_config, default_namespace).await
Expand All @@ -43,24 +43,31 @@

// From all the contracts that were migrated successfully.
for migrated_contract in migration_output.contracts.iter().flatten() {
// Find that contract from local_manifest based on its name.
// Find that contract from local_manifest based on its tag.
let contract = local_contracts
.iter()
.find(|c| migrated_contract.tag == c.inner.tag)
.expect("we know this contract exists");

ui.print_sub(format!(
"Authorizing {} for Models: {:?}",
contract.inner.tag, contract.inner.writes
));
// TODO: we may add support for `owns`?

// Read all the models that its supposed to write and collect them in a Vec<ResourceWriter>
// so we can call `grant_writer` on all of them.
for model_tag in &contract.inner.writes {
let resource = ResourceType::from_str(format!("model:{model_tag}").as_str())?;
let tag_or_address = format!("{:#x}", migrated_contract.contract_address);
if !contract.inner.writes.is_empty() {
ui.print_sub(format!(
"Authorizing {} for resources: {:?}",
contract.inner.tag, contract.inner.writes
));
}

for tag_with_prefix in &contract.inner.writes {
let resource_type = if tag_with_prefix.contains(':') {
tag_with_prefix.to_string()

Check warning on line 63 in crates/sozo/ops/src/migration/auto_auth.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migration/auto_auth.rs#L63

Added line #L63 was not covered by tests
} else {
// Default to model if no prefix was given.
format!("m:{}", tag_with_prefix)
};

res.push(ResourceWriter { resource, tag_or_address });
let resource = format!("{},{}", resource_type, migrated_contract.tag);
res.push(ResourceWriter::from_str(&resource)?);
}
}

Expand Down
Loading