From 450f02c73227e1611cd0ed8178b9a7355357e971 Mon Sep 17 00:00:00 2001 From: Dmitry Shlagoff Date: Tue, 19 Jul 2022 12:54:56 +0200 Subject: [PATCH] GH Actions fixes --- .github/workflows/check.yml | 32 ++++++++++++++++++++++ .github/workflows/ci.yml | 31 --------------------- .github/workflows/deploy.yml | 2 +- .github/workflows/{mdbook.yml => docs.yml} | 3 +- Cargo.lock | 8 +++--- src/app/mod.rs | 16 ++++++----- src/app/util.rs | 7 +---- src/db/tag.rs | 3 ++ src/s3.rs | 9 ++---- src/serde.rs | 1 + 10 files changed, 55 insertions(+), 57 deletions(-) create mode 100644 .github/workflows/check.yml delete mode 100644 .github/workflows/ci.yml rename .github/workflows/{mdbook.yml => docs.yml} (91%) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..f765cae --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,32 @@ +name: Check + +on: + push: + branches: [ master ] + pull_request: + +env: + CARGO_TERM_COLOR: always + +jobs: + ci: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Install latest stable + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + components: rustfmt, clippy + - uses: Swatinem/rust-cache@v1 + - name: clippy + run: cargo clippy -- -D warnings + - name: fmt + run: cargo fmt -- --check + - name: Run tests + run: cargo test --verbose + env: + RUST_BACKTRACE: 1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 4e56f25..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Converge - -on: - workflow_dispatch: - inputs: - organization: - description: 'Deploy to organization...' - required: true - default: 'ng' - application: - description: 'Deploy to application...' - required: true - default: 'classroom' - environment: - description: 'Deploy to environment...' - required: true - default: 'testing03' - version: - description: 'Deploy commit/tag/branch' - required: false - -jobs: - converge: - name: Converge - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - ref: ${{ github.event.inputs.version }} - fetch-depth: 0 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c543346..20cdd46 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: deploy +name: Deploy on: workflow_dispatch: diff --git a/.github/workflows/mdbook.yml b/.github/workflows/docs.yml similarity index 91% rename from .github/workflows/mdbook.yml rename to .github/workflows/docs.yml index 9755875..106a8aa 100644 --- a/.github/workflows/mdbook.yml +++ b/.github/workflows/docs.yml @@ -1,4 +1,4 @@ -name: mdBook +name: Docs on: push: tags: @@ -26,3 +26,4 @@ jobs: AWS_ENDPOINT: ${{ secrets.AWS_ENDPOINT }} AWS_REGION: ${{ secrets.AWS_REGION }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + MDBOOK_BUCKET: docs.netology-group.services.website.yandexcloud.net diff --git a/Cargo.lock b/Cargo.lock index d6747bb..80a9fda 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1370,18 +1370,18 @@ dependencies = [ [[package]] name = "proc-macro-hack" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "463bf29e7f11344e58c9e01f171470ab15c925c6822ad75028cc1c0e1d1eb63b" +checksum = "d7f95648580798cc44ff8efb9bb0d7ee5205ea32e087b31b0732f3e8c2648ee2" dependencies = [ "proc-macro-hack-impl", ] [[package]] name = "proc-macro-hack-impl" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38c47dcb1594802de8c02f3b899e2018c78291168a22c281be21ea0fb4796842" +checksum = "7be55bf0ae1635f4d7c7ddd6efc05c631e98a82104a73d35550bbc52db960027" [[package]] name = "proc-macro2" diff --git a/src/app/mod.rs b/src/app/mod.rs index 2515233..6d062ba 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -63,6 +63,7 @@ struct TagListQueryString { struct TagEmptyResponse {} #[derive(Debug)] +#[allow(dead_code)] struct SignState { application_id: AccountId, authz: svc_authz::ClientMap, @@ -149,7 +150,7 @@ impl_web! { fn valid_referer(&self, bucket: &str, referer: Option) -> Result<(), Error> { let error = || Error::builder().kind("set_read_error", "Error reading an object by key"); - match self.aud_estm.estimate(&bucket) { + match self.aud_estm.estimate(bucket) { Ok(aud) => match self.audiences_settings.get(aud) { Some(aud_settings) => if !aud_settings.valid_referer(referer.as_deref()) { let e = error().status(StatusCode::FORBIDDEN).detail("Invalid request").build(); @@ -268,7 +269,7 @@ impl_web! { fn valid_referer(&self, bucket: &str, referer: Option) -> Result<(), Error> { let error = || Error::builder().kind("set_read_error", "Error reading an object using Set API"); - match self.aud_estm.estimate(&bucket) { + match self.aud_estm.estimate(bucket) { Ok(aud) => match self.audiences_settings.get(aud) { Some(aud_settings) => if !aud_settings.valid_referer(referer.as_deref()) { let e = error().status(StatusCode::FORBIDDEN).detail("Invalid request").build(); @@ -451,9 +452,9 @@ impl_web! { match self.aud_estm.parse_bucket(&query_string.filter) { Ok(filter_b) => { let include = parse_sets(&query_string.include, filter_b.audience()); - let exclude = parse_sets(&query_string.exclude.unwrap_or_else(|| String::from("")), filter_b.audience()); - let offset = query_string.offset.unwrap_or_else(|| 0); - let limit = std::cmp::min(query_string.limit.unwrap_or_else(|| MAX_LIMIT), MAX_LIMIT); + let exclude = parse_sets(&query_string.exclude.unwrap_or_default(), filter_b.audience()); + let offset = query_string.offset.unwrap_or(0); + let limit = std::cmp::min(query_string.limit.unwrap_or(MAX_LIMIT), MAX_LIMIT); future::Either::B(self.authz.authorize(filter_b.audience(), &sub, zobj, zact).and_then(move |zresp| match zresp { Err(err) => future::Either::A(wrap_error(error().status(StatusCode::FORBIDDEN).detail(&err.to_string()).build())), @@ -548,7 +549,7 @@ impl_web! { // Authz subject, object, and action let (object, zobj) = match body.set { Some(ref set) => ( - s3_object(&set, &body.object), + s3_object(set, &body.object), vec!["buckets", &body.bucket, "sets", set] ), None => ( @@ -590,7 +591,7 @@ impl_web! { fn valid_referer(&self, bucket: &str, referer: Option) -> Result<(), Error> { let error = || Error::builder().kind("sign_error", "Error signing a request"); - match self.aud_estm.estimate(&bucket) { + match self.aud_estm.estimate(bucket) { Ok(aud) => match self.audiences_settings.get(aud) { Some(aud_settings) => if !aud_settings.valid_referer(referer.as_deref()) { let e = error().status(StatusCode::FORBIDDEN).detail("Invalid request").build(); @@ -669,6 +670,7 @@ fn wrap_error(err: Error) -> impl Future, Error = ()> //////////////////////////////////////////////////////////////////////////////// +#[allow(clippy::mutable_key_type)] pub(crate) fn run(db: Option, cache: Option) { use http::{header, Method}; use std::collections::HashSet; diff --git a/src/app/util.rs b/src/app/util.rs index c849931..9f288ca 100644 --- a/src/app/util.rs +++ b/src/app/util.rs @@ -319,12 +319,7 @@ mod tower_web { let config = context.config::().expect("missing config"); let h = context.request().headers().get(http::header::AUTHORIZATION); let q = url::form_urlencoded::parse( - context - .request() - .uri() - .query() - .unwrap_or_else(|| "") - .as_bytes(), + context.request().uri().query().unwrap_or("").as_bytes(), ) .find(|(key, _)| key == "access_token") .map(|(_, val)| val); diff --git a/src/db/tag.rs b/src/db/tag.rs index 2ca6c96..9631d45 100644 --- a/src/db/tag.rs +++ b/src/db/tag.rs @@ -1,3 +1,5 @@ +#![allow(clippy::extra_unused_lifetimes)] + use chrono::{DateTime, Utc}; use diesel::pg::PgConnection; use diesel::result::Error; @@ -10,6 +12,7 @@ use crate::schema::set_tag; #[derive(Debug, Identifiable, Queryable, QueryableByName)] #[table_name = "set_tag"] +#[allow(dead_code)] pub(crate) struct Object { id: Uuid, tag: Set, diff --git a/src/s3.rs b/src/s3.rs index b37b6e4..dece606 100644 --- a/src/s3.rs +++ b/src/s3.rs @@ -53,7 +53,7 @@ impl Client { let mut parsed_url = Url::parse(&url).context("failed to parse generated uri")?; parsed_url - .set_host(Some(&proxy_host)) + .set_host(Some(proxy_host)) .context("failed to set proxy backend")?; Ok(parsed_url.to_string()) @@ -62,12 +62,7 @@ impl Client { } } - pub(crate) fn presigned_url( - self: &Self, - method: &str, - bucket: &str, - object: &str, - ) -> Result { + pub(crate) fn presigned_url(&self, method: &str, bucket: &str, object: &str) -> Result { self.sign_request(&mut self.create_request(method, bucket, object)) } } diff --git a/src/serde.rs b/src/serde.rs index 065c582..0113a44 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -51,6 +51,7 @@ impl<'de> Visitor<'de> for AllowedOriginsVisitor { } } + #[allow(clippy::mutable_key_type)] fn visit_seq(self, mut seq: A) -> Result where A: SeqAccess<'de>,