Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

Commit

Permalink
feat!: SphereContext refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cdata committed Mar 7, 2023
1 parent a96638d commit 50ff040
Show file tree
Hide file tree
Showing 102 changed files with 3,480 additions and 2,093 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ jobs:
steps.release.outputs['rust/noosphere-collections--release_created'] ||
steps.release.outputs['rust/noosphere-core--release_created'] ||
steps.release.outputs['rust/noosphere-fs--release_created'] ||
steps.release.outputs['rust/noosphere-gateway--release_created'] ||
steps.release.outputs['rust/noosphere-ipfs--release_created'] ||
steps.release.outputs['rust/noosphere-into--release_created'] ||
steps.release.outputs['rust/noosphere-ns--release_created'] ||
steps.release.outputs['rust/noosphere-petnames--release_created'] ||
steps.release.outputs['rust/noosphere-storage--release_created'] }}
steps:
- uses: chainguard-dev/actions/setup-gitsign@main
Expand Down
1 change: 0 additions & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"rust/noosphere-into": "0.4.5",
"rust/noosphere-ns": "0.4.3",
"rust/noosphere-storage": "0.4.2",
"rust/noosphere-fs": "0.5.3",
"rust/noosphere": "0.6.3",
"rust/noosphere-ipfs": "0.1.2"
}
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
"async-trait": ["async_trait"]
}
}

73 changes: 42 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[workspace]
members = [
"rust/noosphere-storage",
"rust/noosphere",
"rust/noosphere-api",
"rust/noosphere-cli",
"rust/noosphere-collections",
"rust/noosphere-core",
"rust/noosphere-api",
"rust/noosphere-fs",
"rust/noosphere-gateway",
"rust/noosphere-into",
"rust/noosphere-ipfs",
"rust/noosphere-cli",
"rust/noosphere-ns",
"rust/noosphere"
"rust/noosphere-sphere",
"rust/noosphere-storage",
]

# See: https://github.com/rust-lang/rust/issues/90148#issuecomment-949194352
Expand Down
2 changes: 1 addition & 1 deletion release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
},
"rust/noosphere-collections": {},
"rust/noosphere-core": {},
"rust/noosphere-fs": {},
"rust/noosphere-gateway": {},
"rust/noosphere-ipfs": {},
"rust/noosphere-into": {},
"rust/noosphere-ns": {},
"rust/noosphere-sphere": {},
"rust/noosphere-storage": {},
"rust/noosphere": {
"draft": true
Expand Down
1 change: 1 addition & 0 deletions rust/noosphere-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ readme = "README.md"

[dependencies]
anyhow = "^1"
thiserror = "1.0.38"
cid = "~0.9"
url = "^2"
serde = "^1"
Expand Down
40 changes: 40 additions & 0 deletions rust/noosphere-api/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use noosphere_core::{
data::{Bundle, Did},
};
use noosphere_storage::{base64_decode, base64_encode};
use reqwest::StatusCode;
use serde::{Deserialize, Deserializer, Serialize};
use thiserror::Error;
use ucan::{
capability::{Capability, Resource, With},
chain::ProofChain,
Expand Down Expand Up @@ -111,6 +113,44 @@ pub enum PushResponse {
NoChange,
}

#[derive(Error, Debug)]
pub enum PushError {
#[error("Pushed history conflicts with canonical history")]
Conflict,
#[error("Missing some implied history")]
MissingHistory,
#[error("Replica is up to date")]
UpToDate,
#[error("Internal error")]
Internal(anyhow::Error),
}

impl From<anyhow::Error> for PushError {
fn from(value: anyhow::Error) -> Self {
PushError::Internal(value)
}
}

// impl From<NoosphereError> for PushError {
// fn from(value: NoosphereError) -> Self {
// PushError::Internal(value.into())
// }
// }

impl From<PushError> for StatusCode {
fn from(error: PushError) -> Self {
match error {
PushError::Conflict => StatusCode::CONFLICT,
PushError::MissingHistory => StatusCode::UNPROCESSABLE_ENTITY,
PushError::UpToDate => StatusCode::BAD_REQUEST,
PushError::Internal(error) => {
error!("Internal: {:?}", error);
StatusCode::INTERNAL_SERVER_ERROR
}
}
}
}

/// The response from the "identify" API route; this is a signed response that
/// allows the client to verify the authority of the API host
#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion rust/noosphere-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ globset = "~0.4"

noosphere-ipfs = { version = "0.1.2", path = "../noosphere-ipfs" }
noosphere-core = { version = "0.6.3", path = "../noosphere-core" }
noosphere-fs = { version = "0.5.3", path = "../noosphere-fs" }
noosphere-sphere = { version = "0.1.0", path = "../noosphere-sphere" }
noosphere-storage = { version = "0.4.2", path = "../noosphere-storage" }
noosphere-api = { version = "0.5.6", path = "../noosphere-api" }
noosphere-gateway = { version = "0.1.0", path = "../noosphere-gateway" }
Expand Down
10 changes: 5 additions & 5 deletions rust/noosphere-cli/src/native/commands/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub async fn auth_add(did: &str, name: Option<String>, workspace: &Workspace) ->
let latest_sphere_cid = db.require_version(&sphere_did).await?;
let sphere = Sphere::at(&latest_sphere_cid, &db);

let authority = sphere.try_get_authority().await?;
let authority = sphere.get_authority().await?;
let allowed_ucans = authority.try_get_allowed_ucans().await?;
let mut allowed_stream = allowed_ucans.stream().await?;

Expand Down Expand Up @@ -114,7 +114,7 @@ You will be able to add a new one after the old one is revoked"#,
.allowed_ucans_mut()
.set(&CidKey(delegation.jwt), &delegation);

let mut revision = sphere.try_apply_mutation(&mutation).await?;
let mut revision = sphere.apply_mutation(&mutation).await?;
let version_cid = revision.try_sign(&my_key, Some(&authorization)).await?;

db.set_version(&sphere_did, &version_cid).await?;
Expand Down Expand Up @@ -148,7 +148,7 @@ pub async fn auth_list(as_json: bool, workspace: &Workspace) -> Result<()> {

let sphere = Sphere::at(&latest_sphere_cid, &db);

let authorization = sphere.try_get_authority().await?;
let authorization = sphere.get_authority().await?;

let allowed_ucans = authorization.try_get_allowed_ucans().await?;

Expand Down Expand Up @@ -205,7 +205,7 @@ pub async fn auth_revoke(name: &str, workspace: &Workspace) -> Result<()> {

let sphere = Sphere::at(&latest_sphere_cid, &db);

let authorization = sphere.try_get_authority().await?;
let authorization = sphere.get_authority().await?;

let allowed_ucans = authorization.try_get_allowed_ucans().await?;

Expand All @@ -222,7 +222,7 @@ pub async fn auth_revoke(name: &str, workspace: &Workspace) -> Result<()> {
mutation.allowed_ucans_mut().remove(&key);
mutation.revoked_ucans_mut().set(&key, &revocation);

let mut revision = sphere.try_apply_mutation(&mutation).await?;
let mut revision = sphere.apply_mutation(&mutation).await?;
let ucan = workspace.authorization().await?;

let sphere_cid = revision.try_sign(&my_key, Some(&ucan)).await?;
Expand Down
2 changes: 1 addition & 1 deletion rust/noosphere-cli/src/native/commands/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use noosphere::sphere::GATEWAY_URL;
use noosphere_core::data::Did;
use noosphere_sphere::metadata::GATEWAY_URL;
use noosphere_storage::KeyValueStore;
use serde::{Deserialize, Serialize};
use tokio::sync::OnceCell;
Expand Down
Loading

0 comments on commit 50ff040

Please sign in to comment.