Skip to content

Commit b552d17

Browse files
authored
feat(rust/signed-doc): Document's content static schema validation rule (#298)
* change template rule to content rule * update rust builder * define contet rule for the proposal_submission_action * wip * update tests * wip * fix * wip * fix * fix clippy * wip * fix spelling * wip * wip * wip * fix * wip * wip * fix comment
1 parent de08e1c commit b552d17

File tree

11 files changed

+276
-107
lines changed

11 files changed

+276
-107
lines changed

Earthfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ repo-docs:
4242
COPY --dir *.md LICENSE-APACHE LICENSE-MIT .
4343

4444
SAVE ARTIFACT /repo repo
45+
46+
# copy-specs : Copy the specs source folder.
47+
copy-specs:
48+
FROM scratch
49+
COPY --dir specs ./specs
50+
SAVE ARTIFACT /specs specs

rust/Earthfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
VERSION 0.8
22

33
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.4.0 AS rust-ci
4+
IMPORT ../ AS repo-ci
45

56
COPY_SRC:
67
FUNCTION
@@ -22,6 +23,8 @@ COPY_SRC:
2223
# builder : Set up our target toolchains, and copy our files.
2324
builder:
2425
DO rust-ci+SETUP
26+
# Copy specs where some document files are used inside cat-gateway
27+
COPY repo-ci+copy-specs/specs ./specs
2528

2629
# sync-cfg: Synchronize local config with CI version.
2730
# Must be run by the developer manually.

rust/signed_doc/src/validator/mod.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use catalyst_types::{
1717
};
1818
use coset::{CoseSign, CoseSignature};
1919
use rules::{
20-
CategoryRule, ContentEncodingRule, ContentTypeRule, RefRule, ReplyRule, Rules, SectionRule,
21-
SignatureKidRule, TemplateRule,
20+
CategoryRule, ContentEncodingRule, ContentRule, ContentSchema, ContentTypeRule, RefRule,
21+
ReplyRule, Rules, SectionRule, SignatureKidRule,
2222
};
2323

2424
use crate::{
@@ -46,7 +46,7 @@ fn document_rules_init() -> HashMap<Uuid, Rules> {
4646
exp: ContentEncoding::Brotli,
4747
optional: false,
4848
},
49-
template: TemplateRule::Specified {
49+
content: ContentRule::Templated {
5050
exp_template_type: PROPOSAL_TEMPLATE_UUID_TYPE
5151
.try_into()
5252
.expect("Must be a valid UUID V4"),
@@ -69,7 +69,7 @@ fn document_rules_init() -> HashMap<Uuid, Rules> {
6969
exp: ContentEncoding::Brotli,
7070
optional: false,
7171
},
72-
template: TemplateRule::Specified {
72+
content: ContentRule::Templated {
7373
exp_template_type: COMMENT_TEMPLATE_UUID_TYPE
7474
.try_into()
7575
.expect("Must be a valid UUID V4"),
@@ -94,6 +94,15 @@ fn document_rules_init() -> HashMap<Uuid, Rules> {
9494
};
9595
document_rules_map.insert(COMMENT_DOCUMENT_UUID_TYPE, comment_document_rules);
9696

97+
let proposal_action_json_schema = jsonschema::options()
98+
.with_draft(jsonschema::Draft::Draft7)
99+
.build(
100+
&serde_json::from_str(include_str!(
101+
"./../../../../specs/signed_docs/docs/payload_schemas/proposal_submission_action.schema.json"
102+
))
103+
.expect("Must be a valid json file"),
104+
)
105+
.expect("Must be a valid json scheme file");
97106
let proposal_submission_action_rules = Rules {
98107
content_type: ContentTypeRule {
99108
exp: ContentType::Json,
@@ -102,7 +111,7 @@ fn document_rules_init() -> HashMap<Uuid, Rules> {
102111
exp: ContentEncoding::Brotli,
103112
optional: false,
104113
},
105-
template: TemplateRule::NotSpecified,
114+
content: ContentRule::Static(ContentSchema::Json(proposal_action_json_schema)),
106115
category: CategoryRule::Specified { optional: true },
107116
doc_ref: RefRule::Specified {
108117
exp_ref_type: PROPOSAL_DOCUMENT_UUID_TYPE

rust/signed_doc/src/validator/rules/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(crate) use doc_ref::RefRule;
2121
pub(crate) use reply::ReplyRule;
2222
pub(crate) use section::SectionRule;
2323
pub(crate) use signature_kid::SignatureKidRule;
24-
pub(crate) use template::TemplateRule;
24+
pub(crate) use template::{ContentRule, ContentSchema};
2525

2626
/// Struct represented a full collection of rules for all fields
2727
pub(crate) struct Rules {
@@ -31,8 +31,8 @@ pub(crate) struct Rules {
3131
pub(crate) content_encoding: ContentEncodingRule,
3232
/// 'ref' field validation rule
3333
pub(crate) doc_ref: RefRule,
34-
/// 'template' field validation rule
35-
pub(crate) template: TemplateRule,
34+
/// document's content validation rule
35+
pub(crate) content: ContentRule,
3636
/// 'reply' field validation rule
3737
pub(crate) reply: ReplyRule,
3838
/// 'section' field validation rule
@@ -53,7 +53,7 @@ impl Rules {
5353
self.content_type.check(doc).boxed(),
5454
self.content_encoding.check(doc).boxed(),
5555
self.doc_ref.check(doc, provider).boxed(),
56-
self.template.check(doc, provider).boxed(),
56+
self.content.check(doc, provider).boxed(),
5757
self.reply.check(doc, provider).boxed(),
5858
self.section.check(doc).boxed(),
5959
self.category.check(doc, provider).boxed(),

0 commit comments

Comments
 (0)