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

chore: Add create_volume to swagger docs #161

Merged
merged 5 commits into from
Aug 29, 2023
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
6 changes: 4 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ ed25519-zebra = "3.1"
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
ucan = { path = "../rs-ucan/ucan" }
ucan-key-support = { path = "../rs-ucan/ucan-key-support" }
ucan = { git = "https://github.com/blaine/rs-ucan", branch = "temporary-unscoped-fix" }
ucan-key-support = { git = "https://github.com/blaine/rs-ucan", branch = "temporary-unscoped-fix" }
url = "2.3"

# Speedup build on macOS
Expand Down
2 changes: 1 addition & 1 deletion fission-server/src/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use utoipa::OpenApi;
#[openapi(
paths(health::healthcheck, ping::get, auth::request_token,
account::create_account, account::get_account, account::update_did,
volume::get_cid, volume::update_cid),
volume::get_cid, volume::create_volume, volume::update_cid),
components(schemas(AppError, email_verification::Request, auth::VerificationCodeResponse, AccountRequest, NewVolumeRecord, health::HealthcheckResponse)),
modifiers(&UcanAddon),
tags(
Expand Down
8 changes: 4 additions & 4 deletions fission-server/src/middleware/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl ReqwestMiddleware for Logger {
}
}

fn log_reqwest(request: &reqwest::Request, extensions: &mut Extensions) {
fn log_reqwest(request: &reqwest::Request, extensions: &Extensions) {
let user_agent = request
.headers()
.get(header::USER_AGENT)
Expand Down Expand Up @@ -263,7 +263,7 @@ fn log_reqwest(request: &reqwest::Request, extensions: &mut Extensions) {

async fn log_reqwest_response(
response: reqwest::Response,
extensions: &mut Extensions,
extensions: &Extensions,
) -> Result<reqwest::Response> {
/// Turn reqwest body, headers, status, and version into
/// a generic [`http::Response`] and to capture body + parts,
Expand Down Expand Up @@ -325,7 +325,7 @@ async fn log_reqwest_response(
Ok(post_log_response)
}

fn log_reqwest_error(error: &reqwest::Error, extensions: &mut Extensions) -> Result<()> {
fn log_reqwest_error(error: &reqwest::Error, extensions: &Extensions) -> Result<()> {
let url = extensions
.get::<reqwest::Url>()
.ok_or_else(|| anyhow!("failed to find Url extension"))?;
Expand All @@ -342,7 +342,7 @@ fn log_reqwest_error(error: &reqwest::Error, extensions: &mut Extensions) -> Res
Ok(())
}

fn log_middleware_error(error: &anyhow::Error, extensions: &mut Extensions) -> Result<()> {
fn log_middleware_error(error: &anyhow::Error, extensions: &Extensions) -> Result<()> {
let url = extensions
.get::<reqwest::Url>()
.ok_or_else(|| anyhow!("failed to find Url extension"))?;
Expand Down
2 changes: 1 addition & 1 deletion fission-server/src/models/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl RootAccount {
// QUESTION: How long should these be valid for? This is basically sign-in expiry/duration.
.with_lifetime(60 * 60 * 24 * 365)
.claiming_capability(&capability)
.with_fact(json!({"username": username}))
.with_fact(json!({ "username": username }))
.build()?
.sign()
.await
Expand Down
8 changes: 4 additions & 4 deletions fission-server/src/routes/doh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ mod tests {
Method::GET,
format!(
"/dns-query?name={}&type={}",
format!("_did.{}.fission.app", username),
format_args!("_did.{}.fission.app", username),
"txt"
),
)
Expand Down Expand Up @@ -250,7 +250,7 @@ mod tests {
Method::GET,
format!(
"/dns-query?name={}&type={}",
format!("_dnslink.{}.fission.app", username),
format_args!("_dnslink.{}.fission.app", username),
"txt"
),
)
Expand Down Expand Up @@ -315,7 +315,7 @@ mod tests {
Method::GET,
format!(
"/dns-query?name={}&type={}",
format!("_dnslink.{}.fission.app", username),
format_args!("_dnslink.{}.fission.app", username),
"txt"
),
)
Expand Down Expand Up @@ -380,7 +380,7 @@ mod tests {
Method::GET,
format!(
"/dns-query?name={}&type={}",
format!("_dnslink.{}.fission.app", username),
format_args!("_dnslink.{}.fission.app", username),
"txt"
),
)
Expand Down
6 changes: 3 additions & 3 deletions fission-server/src/routes/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ mod tests {
.await?;

assert_eq!(status, StatusCode::OK);
assert_eq!(body.database_connected, true);
assert!(body.database_connected);
assert_eq!(body.database_up_to_date, Some(true));

Ok(())
Expand All @@ -125,7 +125,7 @@ mod tests {
.await?;

assert_eq!(status, StatusCode::SERVICE_UNAVAILABLE);
assert_eq!(body.database_connected, false);
assert!(!body.database_connected);
assert_eq!(body.database_up_to_date, None);

Ok(())
Expand All @@ -147,7 +147,7 @@ mod tests {
.await?;

assert_eq!(status, StatusCode::SERVICE_UNAVAILABLE);
assert_eq!(body.database_connected, true);
assert!(body.database_connected);
assert_eq!(body.database_up_to_date, Some(false));

Ok(())
Expand Down
13 changes: 13 additions & 0 deletions fission-server/src/routes/volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ pub async fn get_cid(
}
}

#[utoipa::path(
post,
path = "/api/account/{username}/volume",
security(
("ucan_bearer" = []),
),
responses(
(status = 200, description = "Successfully created Volume", body=NewVolume),
(status = 400, description = "Invalid request", body=AppError),
(status = 401, description = "Unauthorized"),
)
)]

/// Handler to create a new volume for an account
pub async fn create_volume(
State(state): State<AppState>,
Expand Down
205 changes: 101 additions & 104 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,117 +18,114 @@
flake-utils,
rust-overlay,
} @ inputs:
flake-utils.lib.eachDefaultSystem (
system: let
overlays = [(import rust-overlay)];
pkgs = import nixpkgs {inherit system overlays;};

rust-toolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override {
flake-utils.lib.eachDefaultSystem (system: let
overlays = [(import rust-overlay)];
pkgs = import nixpkgs {inherit system overlays;};

rust-toolchain =
(pkgs.rust-bin.fromRustupToolchainFile
./rust-toolchain.toml)
.override {
extensions = ["cargo" "clippy" "rustfmt" "rust-src" "rust-std"];
};

nightly-rustfmt = pkgs.rust-bin.nightly.latest.rustfmt;

format-pkgs = with pkgs; [
nixpkgs-fmt
alejandra
];

cargo-installs = with pkgs; [
cargo-deny
cargo-expand
cargo-outdated
cargo-sort
cargo-udeps
cargo-watch
diesel-cli
];
in rec
{
devShells.default = pkgs.mkShell {
name = "fission-server";
nativeBuildInputs = with pkgs;
[
# The ordering of these two items is important. For nightly rustfmt to be used instead of
# the rustfmt provided by `rust-toolchain`, it must appear first in the list. This is
# because native build inputs are added to $PATH in the order they're listed here.
nightly-rustfmt
rust-toolchain
pre-commit
protobuf
postgresql
direnv
self.packages.${system}.irust
kubo
]
++ format-pkgs
++ cargo-installs
++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.CoreFoundation
darwin.apple_sdk.frameworks.Foundation
];

shellHook = ''
[ -e .git/hooks/pre-commit ] || pre-commit install --install-hooks && pre-commit install --hook-type commit-msg

PGDATA="./.pg";
PGURL=postgres://postgres@localhost:5432/fission-server

# Initialize a local database if necessary.
if [ ! -e $PGDATA ]; then
echo -e "\nInitializing PostgreSQL in $PGDATA\n"
initdb $PGDATA --no-instructions -A trust -U postgres
if pg_ctl -D $PGDATA start; then
cd fission-server
diesel database setup --database-url $PGURL
cd ..
pg_ctl -D $PGDATA stop
else
echo "Unable to start PostgreSQL server on default port (:5432). Maybe a local database is already running?"
fi
fi

# Give instructions on how to start postgresql if it's not already running.
if [ ! -e $PGDATA/postmaster.pid ]; then
echo -e "\nPostgreSQL not running. To start, use the following command:"
echo -e " pg_ctl -D $PGDATA -l postgres.log start\n\n"
else
echo -e "\nPostgreSQL is running. To stop, use the following command:"
echo -e " pg_ctl -D $PGDATA stop\n\n"

echo -e "\nRunning pending Diesel Migrations..."
nightly-rustfmt = pkgs.rust-bin.nightly.latest.rustfmt;

format-pkgs = with pkgs; [nixpkgs-fmt alejandra];

cargo-installs = with pkgs; [
cargo-deny
cargo-expand
cargo-outdated
cargo-sort
cargo-udeps
cargo-watch
diesel-cli
];
in rec {
devShells.default = pkgs.mkShell {
name = "fission-server";
nativeBuildInputs = with pkgs;
[
# The ordering of these two items is important. For nightly rustfmt to be used instead of
# the rustfmt provided by `rust-toolchain`, it must appear first in the list. This is
# because native build inputs are added to $PATH in the order they're listed here.
nightly-rustfmt
rust-toolchain
pre-commit
protobuf
postgresql
direnv
self.packages.${system}.irust
kubo
]
++ format-pkgs
++ cargo-installs
++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.CoreFoundation
darwin.apple_sdk.frameworks.Foundation
];

shellHook = ''
[ -e .git/hooks/pre-commit ] || pre-commit install --install-hooks && pre-commit install --hook-type commit-msg

PGDATA="./.pg";
PGURL=postgres://postgres@localhost:5432/fission-server

# Initialize a local database if necessary.
if [ ! -e $PGDATA ]; then
echo -e "\nInitializing PostgreSQL in $PGDATA\n"
initdb $PGDATA --no-instructions -A trust -U postgres
if pg_ctl -o '-k /tmp' -D $PGDATA start; then
cd fission-server
diesel migration run --database-url $PGURL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh god. The formatting messed this diff up quite badly 😅
I actually didn't change anything - it just lined up the "diesel migration run" with the "diesel database setup" lines from the two versions of the file.
These scripts are literally unchanged!

diesel database setup --database-url $PGURL
cd ..
echo
fi

# Setup local Kubo config
if [ ! -e ./.ipfs ]; then
ipfs --repo-dir ./.ipfs --offline init
pg_ctl -o '-k /tmp' -D $PGDATA stop
else
echo "Unable to start PostgreSQL server on default port (:5432). Maybe a local database is already running?"
fi

# Run Kubo
echo -e "To run Kubo as a local IPFS node, use the following command:"
echo -e " . ipfs --repo-dir ./.ipfs --offline daemon"
fi

# Give instructions on how to start postgresql if it's not already running.
if [ ! -e $PGDATA/postmaster.pid ]; then
echo -e "\nPostgreSQL not running. To start, use the following command:"
echo -e " pg_ctl -o '-k /tmp' -D $PGDATA -l postgres.log start\n\n"
else
echo -e "\nPostgreSQL is running. To stop, use the following command:"
echo -e " pg_ctl -o '-k /tmp' -D $PGDATA stop\n\n"

echo -e "\nRunning pending Diesel Migrations..."
cd fission-server
diesel migration run --database-url $PGURL
cd ..
echo
'';
fi

# Setup local Kubo config
if [ ! -e ./.ipfs ]; then
ipfs --repo-dir ./.ipfs --offline init
fi

# Run Kubo
echo -e "To run Kubo as a local IPFS node, use the following command:"
echo -e " ipfs --repo-dir ./.ipfs --offline daemon"
echo
'';
};

packages.irust = pkgs.rustPlatform.buildRustPackage rec {
pname = "irust";
version = "1.65.1";
src = pkgs.fetchFromGitHub {
owner = "sigmaSd";
repo = "IRust";
rev = "v${version}";
sha256 = "sha256-AMOND5q1XzNhN5smVJp+2sGl/OqbxkGPGuPBCE48Hik=";
};

packages.irust = pkgs.rustPlatform.buildRustPackage rec {
pname = "irust";
version = "1.65.1";
src = pkgs.fetchFromGitHub {
owner = "sigmaSd";
repo = "IRust";
rev = "v${version}";
sha256 = "sha256-AMOND5q1XzNhN5smVJp+2sGl/OqbxkGPGuPBCE48Hik=";
};

doCheck = false;
cargoSha256 = "sha256-A24O3p85mCRVZfDyyjQcQosj/4COGNnqiQK2a7nCP6I=";
};
}
);
doCheck = false;
cargoSha256 = "sha256-A24O3p85mCRVZfDyyjQcQosj/4COGNnqiQK2a7nCP6I=";
};
});
}