Skip to content

Commit

Permalink
fix: API cleanup (#1036)
Browse files Browse the repository at this point in the history
* fix: api endpoint draft

Signed-off-by: bkioshn <[email protected]>

* fix: api health endpoint v1

Signed-off-by: bkioshn <[email protected]>

* fix: remove bad request from errorResponses

Signed-off-by: bkioshn <[email protected]>

* fix: add bad req to get /registration

Signed-off-by: bkioshn <[email protected]>

* fix: error logging

Signed-off-by: bkioshn <[email protected]>

* fix: remove validation error

Signed-off-by: bkioshn <[email protected]>

* fix: registration get error name

Signed-off-by: bkioshn <[email protected]>

* chore:format

Signed-off-by: bkioshn <[email protected]>

* fix: get json schema from openapi spec

Signed-off-by: bkioshn <[email protected]>

* fix: move schema utils

Signed-off-by: bkioshn <[email protected]>

* fix: optional field

Signed-off-by: bkioshn <[email protected]>

* fix: config key

Signed-off-by: bkioshn <[email protected]>

* fix: cat-gateway code gen

Signed-off-by: bkioshn <[email protected]>

* fix: api name in cat-voice

Signed-off-by: bkioshn <[email protected]>

* fix: cat-voice format

Signed-off-by: bkioshn <[email protected]>

* chore: fix spacing

Signed-off-by: bkioshn <[email protected]>

* chore: fix spacing

Signed-off-by: bkioshn <[email protected]>

* chore: change tag config description

* test: add test for default validator

* fix: add spectral ruleset

Signed-off-by: bkioshn <[email protected]>

* fix(cat-gateway): Sort the spelling words, and use latest deny.toml

* fix(cat-gateway): Fix broken pre-push justfile target

* docs(cat-gateway): cleanup

* docs(cat-gateway): Fix API Groups and document them better

* docs(cat-gateway): Add documentation to the health/inspection endpoint

* docs(cat-gateway): Add descriptions for cardano/cip36/latest_registration/stake_addr

* docs(cat-gateway): Document stake key hash and vote key endpoints for cardano

* docs(cat-gateway): add documentation to config/frontend

* docs(cat-gateway): Add api docs for frontend schema

* docs(cat-gateway): Move legacy registration endpoints into the Legacy TAG.

* docs(cat-gateway): Remaining documentable entities documented

* fix: update openapi linter

Signed-off-by: bkioshn <[email protected]>

* docs(cat-gateway): Add more constraints to parameters and json bodies

* fix: openapi lint FUNCTION name

Signed-off-by: bkioshn <[email protected]>

* fix: CIP36 example and description

Signed-off-by: bkioshn <[email protected]>

* fix(cat-gateway): cleanup error handling, and add a global 429 response to all endpoints.

* fix: config endpoint example, desc, and return

Signed-off-by: bkioshn <[email protected]>

* chore: remove todo

Signed-off-by: bkioshn <[email protected]>

* fix: move config object

Signed-off-by: bkioshn <[email protected]>

* fix: move cip36 object

Signed-off-by: bkioshn <[email protected]>

* docs(cat-gateway): Add missing headers to responses

* docs(cat-gateway): Cleanup the rest of the documentation in the api

* fix(cat-gateway): Fix OpenAPI linting and add autogenerated api file for dart.

* refactor(cat-gateway): Better generalize the OpenAPI simple string type creation macro.

* fix(cat-gateway): Add APIKey and CatToken auth to some endpoints.  Add 401 and 403 common responses.

* fix(cat-gateway): Add universal 422 response to all endpoints, and try and make all endpoint validation use it.

* fix: add cardano stake address type

Signed-off-by: bkioshn <[email protected]>

* fix(cat-gateway): stake address type

Signed-off-by: bkioshn <[email protected]>

* fix(cat-gateway): Refactor the RBAC Token auth, so it's easier to maintain.

* fix(cat-gateway): stake address name

Signed-off-by: bkioshn <[email protected]>

* fix(cat-gateway): Add no auth and no-auth+rbac auth schemes

* fix(cat-gateway): format + stake addr example

Signed-off-by: bkioshn <[email protected]>

* fix(cat-gateway): code format

* fix(cat-gateway): openapi spectral example rules

Signed-off-by: bkioshn <[email protected]>

---------

Signed-off-by: bkioshn <[email protected]>
Co-authored-by: Steven Johnson <[email protected]>
Co-authored-by: Steven Johnson <[email protected]>
  • Loading branch information
3 people authored Oct 28, 2024
1 parent e257af5 commit 32ef686
Show file tree
Hide file tree
Showing 77 changed files with 3,366 additions and 1,100 deletions.
2 changes: 2 additions & 0 deletions .config/dictionaries/project.dic
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ oneshot
openapi
opentelemetry
overprovisioned
Pbkdf2
pbxproj
Pdart
permissionless
Expand All @@ -205,6 +206,7 @@ pubspec
pytest
qrcode
rapidoc
ratelimit
redoc
reloadable
Replayability
Expand Down
2 changes: 1 addition & 1 deletion catalyst-gateway/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ build:
all-hosts-build:
BUILD --platform=linux/amd64 --platform=linux/arm64 +build

# package-cat-gateway : Create a deployable container for catalyst-gateway
# package : Create a deployable container for catalyst-gateway
package:
FROM debian:12.7-slim
WORKDIR /cat-gateway
Expand Down
2 changes: 1 addition & 1 deletion catalyst-gateway/Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pre-push: sync-cfg code-format code-lint license-check
# Make sure we can actually build inside Earthly which needs to happen in CI.
cd .. && earthly ./catalyst-gateway+check
cd .. && earthly ./catalyst-gateway+build
cd .. && earthly ./catalyst-gateway+package-cat-gateway
cd .. && earthly ./catalyst-gateway+package
cd .. && earthly ./catalyst-gateway/tests+test-lint-openapi

# Build Local release build of catalyst gateway
Expand Down
5 changes: 2 additions & 3 deletions catalyst-gateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ or you can build a docker image and run everything with the `docker-compose`.

To build and run docker images follow these steps:

1. Run `earthly +package-cat-gateway` or `earthly +package-cat-gateway-with-preprod-snapshot`
to build a cat-gateway docker image without `preprod-snapshot` or with it.
1. Run `earthly +package` to build a cat-gateway docker image.
2. Run `earthly ./event-db+build` to build an event-db docker image.
3. Run `docker-compose up cat-gateway` to spin up cat-gateway with event-db from already built images.

Note that every time when you are building an image it obsoletes an old image but does not remove it,
so dont forget to cleanup dangling images of the event-db and cat-gateway in your docker environment.
so don't forget to clean up dangling images of the event-db and cat-gateway in your docker environment.

### Rust binary

Expand Down
30 changes: 0 additions & 30 deletions catalyst-gateway/bin/src/db/event/config/jsonschema/frontend.json

This file was deleted.

90 changes: 68 additions & 22 deletions catalyst-gateway/bin/src/db/event/config/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use jsonschema::{BasicOutput, Validator};
use serde_json::{json, Value};
use tracing::error;

use crate::utils::schema::{extract_json_schema_for, SCHEMA_VERSION};

/// Configuration key
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum ConfigKey {
Expand All @@ -24,9 +26,9 @@ impl Display for ConfigKey {
}
}

/// Frontend schema.
static FRONTEND_SCHEMA: LazyLock<Value> =
LazyLock::new(|| load_json_lazy(include_str!("jsonschema/frontend.json")));
/// Frontend schema from API specification.
pub(crate) static FRONTEND_SCHEMA: LazyLock<Value> =
LazyLock::new(|| extract_json_schema_for("FrontendConfig"));

/// Frontend schema validator.
static FRONTEND_SCHEMA_VALIDATOR: LazyLock<Validator> =
Expand All @@ -43,28 +45,35 @@ static FRONTEND_IP_DEFAULT: LazyLock<Value> =
/// Helper function to create a JSON validator from a JSON schema.
/// If the schema is invalid, a default JSON validator is created.
fn schema_validator(schema: &Value) -> Validator {
jsonschema::validator_for(schema).unwrap_or_else(|err| {
error!(
id = "schema_validator",
error=?err,
"Error creating JSON validator"
);

// Create a default JSON validator as a fallback
// This should not fail since it is hard coded
#[allow(clippy::expect_used)]
Validator::new(&json!({
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object"
}))
.expect("Failed to create default JSON validator")
})
Validator::options()
.with_draft(jsonschema::Draft::Draft202012)
.build(schema)
.unwrap_or_else(|err| {
error!(
id="schema_validator",
error=?err,
"Error creating JSON validator"
);

default_validator()
})
}

/// Create a default JSON validator as a fallback
/// This should not fail since it is hard coded
fn default_validator() -> Validator {
#[allow(clippy::expect_used)]
Validator::new(&json!({
"$schema": SCHEMA_VERSION,
"type": "object"
}))
.expect("Failed to create default JSON validator")
}

/// Helper function to convert a JSON string to a JSON value.
fn load_json_lazy(data: &str) -> Value {
serde_json::from_str(data).unwrap_or_else(|err| {
error!(id = "load_json_lazy", error=?err, "Error parsing JSON");
error!(id="load_json_lazy", error=?err, "Error parsing JSON");
json!({})
})
}
Expand Down Expand Up @@ -115,15 +124,43 @@ mod tests {
use super::*;

#[test]
fn test_valid_validate() {
fn test_schema_for_schema() {
// Invalid schema
let invalid_schema = json!({
"title": "Invalid Example Schema",
"type": "object",

"properties": {
"invalidProperty": {
"type": "unknownType"
}
},

});
// This should not fail
schema_validator(&invalid_schema);
}

#[test]
fn test_valid_validate_1() {
let value = json!({
"test": "test"
"sentry": {
"dsn": "https://test.com"
}
});
let result = ConfigKey::Frontend.validate(&value);
assert!(result.is_valid());
println!("{:?}", serde_json::to_value(result).unwrap());
}

#[test]
fn test_valid_validate_2() {
let value = json!({});
let result = ConfigKey::Frontend.validate(&value);
assert!(result.is_valid());
println!("{:?}", serde_json::to_value(result).unwrap());
}

#[test]
fn test_invalid_validate() {
let value = json!([]);
Expand All @@ -137,4 +174,13 @@ mod tests {
let result = ConfigKey::Frontend.default();
assert!(result.is_object());
}

#[test]
fn test_default_validator() {
let result = std::panic::catch_unwind(|| {
default_validator();
});
// Assert that no panic occurred
assert!(result.is_ok(), "default_validator panicked");
}
}
128 changes: 0 additions & 128 deletions catalyst-gateway/bin/src/service/api/auth/endpoint.rs

This file was deleted.

4 changes: 0 additions & 4 deletions catalyst-gateway/bin/src/service/api/auth/mod.rs

This file was deleted.

Loading

0 comments on commit 32ef686

Please sign in to comment.