From 12fca243ea22e73801de80ce954de655ad7327ba Mon Sep 17 00:00:00 2001 From: Hendrik Eeckhaut Date: Thu, 17 Oct 2024 10:56:04 +0200 Subject: [PATCH 1/3] build: add script to set the TLSN version number --- set_tlsn_version.rs | 95 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100755 set_tlsn_version.rs diff --git a/set_tlsn_version.rs b/set_tlsn_version.rs new file mode 100755 index 0000000000..5c7d2eace5 --- /dev/null +++ b/set_tlsn_version.rs @@ -0,0 +1,95 @@ +#!/usr/bin/env cargo +nightly -Zscript +--- +[package] +name = "set_tlsn_version" +version = "0.0.0" +edition = "2021" +publish = false + +[dependencies] +toml_edit = "0.22.22" +walkdir = "2.5.0" +clap = { version = "4.0", features = ["derive"] } +--- + +use clap::Parser; +use std::fs::{self, read_to_string}; +use std::path::Path; +use toml_edit::{value, DocumentMut}; +use walkdir::WalkDir; + +#[derive(Parser)] +#[command(name = "set_tlsn_version")] +#[command(about = "Sets the TLSNotary version in all relevant Cargo.toml files", long_about = None)] +struct Args { + /// Version number to set + version: String, + + /// Workspace path (default is current directory) + #[arg(short, long, default_value = ".")] + workspace: String, +} + +fn main() -> Result<(), Box> { + let args = Args::parse(); + + // Process all Cargo.toml files in the workspace + for entry in WalkDir::new(&args.workspace) + .into_iter() + .filter_map(Result::ok) + .filter(|entry| entry.file_name() == "Cargo.toml") + { + if let Err(e) = update_version_in_cargo_toml(entry.path(), &args.version) { + eprintln!( + "Failed to update version in {}: {}", + entry.path().display(), + e + ); + } + } + + println!("Version update process completed."); + Ok(()) +} + +/// Update the version in the Cargo.toml file +/// +/// Skip files with "publish = false" or "version = 0.0.0" +fn update_version_in_cargo_toml( + cargo_toml_path: &Path, + new_version: &str, +) -> Result<(), Box> { + let cargo_toml_content = read_to_string(cargo_toml_path) + .map_err(|e| format!("Failed to read {}: {}", cargo_toml_path.display(), e))?; + + let mut doc = cargo_toml_content.parse::().map_err(|e| { + format!( + "Invalid TOML format in {}: {}", + cargo_toml_path.display(), + e + ) + })?; + + if let Some(package) = doc.get_mut("package") { + if package.get("publish").and_then(|p| p.as_bool()) == Some(false) { + return Ok(()); + } + + if let Some(version) = package.get_mut("version") { + if version.as_str() == Some("0.0.0") { + return Err(format!( + "\"version\" is \"0.0.0\" and \"publish\" is true in {}", + cargo_toml_path.display() + ) + .into()); + } + + *version = value(new_version); + fs::write(cargo_toml_path, doc.to_string()) + .map_err(|e| format!("Failed to write {}: {}", cargo_toml_path.display(), e))?; + println!("Updated version in {}", cargo_toml_path.display()); + } + } + + Ok(()) +} From 42b48503e3ef261e134175194cd338af6b569649 Mon Sep 17 00:00:00 2001 From: Hendrik Eeckhaut Date: Thu, 24 Oct 2024 10:37:08 +0200 Subject: [PATCH 2/3] build: also update openapi.yaml file --- crates/notary/server/openapi.yaml | 172 +++++++++++++++--------------- crates/wasm/Cargo.toml | 2 +- set_tlsn_version.rs | 34 +++++- 3 files changed, 117 insertions(+), 91 deletions(-) diff --git a/crates/notary/server/openapi.yaml b/crates/notary/server/openapi.yaml index 680c5ecc5a..def2d7ae8a 100644 --- a/crates/notary/server/openapi.yaml +++ b/crates/notary/server/openapi.yaml @@ -1,169 +1,165 @@ openapi: 3.0.0 - info: title: Notary Server description: Notary server written in Rust to provide notarization service. - version: 0.1.0-alpha.7 - + version: 0.1.0-alpha.8-pre tags: - - name: General - - name: Notarization - +- name: General +- name: Notarization paths: /healthcheck: get: tags: - - General + - General description: Healthcheck endpoint parameters: - - in: header - name: Authorization - description: Whitelisted API key if auth module is turned on - schema: - type: string - required: false + - in: header + name: Authorization + description: Whitelisted API key if auth module is turned on + schema: + type: string + required: false responses: - "200": + '200': description: Ok response from server content: text/plain: schema: type: string - example: "Ok" - "401": + example: Ok + '401': description: API key is invalid content: text/plain: schema: type: string - example: "Unauthorized request from prover: Invalid API key." + example: 'Unauthorized request from prover: Invalid API key.' /info: get: tags: - - General + - General description: General information about the notary server parameters: - - in: header - name: Authorization - description: Whitelisted API key if auth module is turned on - schema: - type: string - required: false + - in: header + name: Authorization + description: Whitelisted API key if auth module is turned on + schema: + type: string + required: false responses: - "200": + '200': description: Info response from server content: application/json: schema: - $ref: "#/components/schemas/InfoResponse" - "401": + $ref: '#/components/schemas/InfoResponse' + '401': description: API key is invalid content: text/plain: schema: type: string - example: "Unauthorized request from prover: Invalid API key." + example: 'Unauthorized request from prover: Invalid API key.' /session: post: tags: - - Notarization + - Notarization description: Initialize and configure notarization for both TCP and WebSocket clients parameters: - - in: header - name: Content-Type - description: The value must be application/json - schema: - type: string - enum: - - "application/json" - required: true - - in: header - name: Authorization - description: Whitelisted API key if auth module is turned on - schema: - type: string - required: false + - in: header + name: Content-Type + description: The value must be application/json + schema: + type: string + enum: + - application/json + required: true + - in: header + name: Authorization + description: Whitelisted API key if auth module is turned on + schema: + type: string + required: false requestBody: description: Notarization session request to server required: true content: application/json: schema: - $ref: "#/components/schemas/NotarizationSessionRequest" + $ref: '#/components/schemas/NotarizationSessionRequest' responses: - "200": + '200': description: Notarization session response from server content: application/json: schema: - $ref: "#/components/schemas/NotarizationSessionResponse" - "400": + $ref: '#/components/schemas/NotarizationSessionResponse' + '400': description: Configuration parameters or headers provided by prover are invalid content: text/plain: schema: type: string - example: "Invalid request from prover: Failed to deserialize the JSON body into the target type" - "401": + example: 'Invalid request from prover: Failed to deserialize the JSON body into the target type' + '401': description: API key is invalid content: text/plain: schema: type: string - example: "Unauthorized request from prover: Invalid API key." - "500": + example: 'Unauthorized request from prover: Invalid API key.' + '500': description: There was some internal error when processing content: text/plain: schema: type: string - example: "Something is wrong" + example: Something is wrong /notarize: get: tags: - - Notarization + - Notarization description: Start notarization for TCP client parameters: - - in: header - name: Connection - description: The value should be 'Upgrade' - schema: - type: string - enum: - - "Upgrade" - required: true - - in: header - name: Upgrade - description: The value should be 'TCP' - schema: - type: string - enum: - - "TCP" - required: true - - in: query - name: sessionId - description: Unique ID returned from server upon calling POST /session - schema: - type: string - required: true + - in: header + name: Connection + description: The value should be 'Upgrade' + schema: + type: string + enum: + - Upgrade + required: true + - in: header + name: Upgrade + description: The value should be 'TCP' + schema: + type: string + enum: + - TCP + required: true + - in: query + name: sessionId + description: Unique ID returned from server upon calling POST /session + schema: + type: string + required: true responses: - "101": + '101': description: Switching protocol response - "400": + '400': description: Headers provided by prover are invalid content: text/plain: schema: type: string - example: "Invalid request from prover: Upgrade header is not set for client" - "500": + example: 'Invalid request from prover: Upgrade header is not set for client' + '500': description: There was some internal error when processing content: text/plain: schema: type: string - example: "Something is wrong" - + example: Something is wrong components: schemas: NotarizationSessionRequest: @@ -173,8 +169,8 @@ components: description: Types of client that the prover is using type: string enum: - - "Tcp" - - "Websocket" + - Tcp + - Websocket maxSentData: description: Maximum data that can be sent by the prover in bytes type: integer @@ -182,7 +178,7 @@ components: description: Maximum data that can be received by the prover in bytes type: integer required: - - "clientType" + - clientType NotarizationSessionResponse: type: object properties: @@ -190,7 +186,7 @@ components: description: Unique ID returned from server upon calling POST /session type: string required: - - "sessionId" + - sessionId InfoResponse: type: object properties: @@ -204,6 +200,6 @@ components: description: The git commit hash of source code that this notary server is running type: string required: - - "version" - - "publicKey" - - "gitCommitHash" + - version + - publicKey + - gitCommitHash diff --git a/crates/wasm/Cargo.toml b/crates/wasm/Cargo.toml index cd9a17e560..850cb4038c 100644 --- a/crates/wasm/Cargo.toml +++ b/crates/wasm/Cargo.toml @@ -54,4 +54,4 @@ ws_stream_wasm = { git = "https://github.com/tlsnotary/ws_stream_wasm", rev = "2 [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen-rayon = { version = "1.0" } -getrandom = { version = "0.2", features = ["js"] } \ No newline at end of file +getrandom = { version = "0.2", features = ["js"] } diff --git a/set_tlsn_version.rs b/set_tlsn_version.rs index 5c7d2eace5..46e6422b5a 100755 --- a/set_tlsn_version.rs +++ b/set_tlsn_version.rs @@ -7,12 +7,14 @@ edition = "2021" publish = false [dependencies] +clap = { version = "4.0", features = ["derive"] } +serde_yaml = "0.9" toml_edit = "0.22.22" walkdir = "2.5.0" -clap = { version = "4.0", features = ["derive"] } --- use clap::Parser; +use serde_yaml::Value; use std::fs::{self, read_to_string}; use std::path::Path; use toml_edit::{value, DocumentMut}; @@ -20,7 +22,7 @@ use walkdir::WalkDir; #[derive(Parser)] #[command(name = "set_tlsn_version")] -#[command(about = "Sets the TLSNotary version in all relevant Cargo.toml files", long_about = None)] +#[command(about = "Sets the TLSNotary version in all relevant files", long_about = None)] struct Args { /// Version number to set version: String, @@ -48,6 +50,9 @@ fn main() -> Result<(), Box> { } } + let open_api_path = Path::new(&args.workspace).join("crates/notary/server/openapi.yaml"); + update_version_in_open_api(&open_api_path, &args.version)?; + println!("Version update process completed."); Ok(()) } @@ -93,3 +98,28 @@ fn update_version_in_cargo_toml( Ok(()) } + +/// Update the version in the OpenAPI yaml file +fn update_version_in_open_api( + path: &Path, + new_version: &str, +) -> Result<(), Box> { + let yaml_content = + read_to_string(path).map_err(|e| format!("Failed to read {}: {}", path.display(), e))?; + + let mut doc: Value = serde_yaml::from_str(&yaml_content) + .map_err(|e| format!("Invalid YAML format in {}: {}", path.display(), e))?; + + if let Some(info) = doc.get_mut("info") { + if let Some(version) = info.get_mut("version") { + *version = Value::String(new_version.to_string()); + let updated_yaml = serde_yaml::to_string(&doc) + .map_err(|e| format!("Failed to serialize YAML for {}: {}", path.display(), e))?; + fs::write(path, updated_yaml) + .map_err(|e| format!("Failed to write {}: {}", path.display(), e))?; + println!("Updated version in {}", path.display()); + } + } + + Ok(()) +} From dfd8ef27dfff6e15678e464c785df8b0f7e47717 Mon Sep 17 00:00:00 2001 From: Hendrik Eeckhaut Date: Wed, 4 Dec 2024 08:57:58 +0100 Subject: [PATCH 3/3] feedback --- set_tlsn_version.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/set_tlsn_version.rs b/set_tlsn_version.rs index 46e6422b5a..aa645d5098 100755 --- a/set_tlsn_version.rs +++ b/set_tlsn_version.rs @@ -13,6 +13,9 @@ toml_edit = "0.22.22" walkdir = "2.5.0" --- +// This scripts sets the TLSNotary version in all relevant files. Run it with: +// ./set_tlsn_version + use clap::Parser; use serde_yaml::Value; use std::fs::{self, read_to_string}; @@ -24,7 +27,7 @@ use walkdir::WalkDir; #[command(name = "set_tlsn_version")] #[command(about = "Sets the TLSNotary version in all relevant files", long_about = None)] struct Args { - /// Version number to set + /// Version number to set (example: 0.1.0-alpha.8) version: String, /// Workspace path (default is current directory)