Skip to content

Commit

Permalink
feat: generate code from the updated nethsm api
Browse files Browse the repository at this point in the history
  • Loading branch information
nponsard committed Aug 30, 2023
1 parent 0c0934a commit f385e17
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nethsm-sdk-rs"
version = "0.1.0"
version = "0.3.0"
authors = ["Nitrokey <[email protected]>"]
description = "All endpoints expect exactly the specified JSON. Additional properties will cause a Bad Request Error (400). All HTTP errors contain a JSON structure with an explanation of type string. All [base64](https://tools.ietf.org/html/rfc4648#section-4) encoded values are Big Endian. "
license = "MIT"
Expand All @@ -15,9 +15,9 @@ exclude = [
]

[dependencies]
serde = "^1.0"
serde = { default-features = false, version = "^1.0" }
serde_derive = "^1.0"
serde_json = "^1.0"
serde_json = { default-features = false, version = "^1.0" }
url = "^2.2"
ureq = { version = "2", features = ["json"] }
base64ct = { version = "1.6", features = ["alloc"] }
ureq = { version = "2", features = ["json", "tls"], default-features = false }
base64 = { version = "0.21", default-features = false }
2 changes: 1 addition & 1 deletion docs/SystemInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Name | Type | Description | Notes
**firmware_version** | **String** | |
**software_version** | **String** | |
**hardware_version** | **String** | |
**build_tag** | **String** | |
**software_build** | Option<**String**> | | [optional]
**device_id** | **String** | |
**pcr** | [**serde_json::Value**](.md) | |
**ak_pub** | [**serde_json::Value**](.md) | |
Expand Down
10 changes: 5 additions & 5 deletions generator/src/main/resources/crust/Cargo.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ homepage = "{{.}}
{{/homePageUrl}}

[dependencies]
serde = "^1.0"
serde_derive = "^1.0"
{{#serdeWith}}
serde_with = "^2.0"
{{/serdeWith}}
serde_json = "^1.0"
serde = { default-features = false, version = "^1.0" }
serde_derive = "^1.0"
serde_json = { default-features = false, version = "^1.0" }
url = "^2.2"
ureq = { version = "2", features = ["json"] }
base64ct = { version = "1.6", features = ["alloc"] }
ureq = { version = "2", features = ["json", "tls"], default-features = false }
base64 = { version = "0.21", default-features = false }
5 changes: 2 additions & 3 deletions generator/src/main/resources/crust/reqwest/api_mod.mustache
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::error;
use std::fmt;
use std::collections::HashMap;

use base64ct::{Base64, Encoding};
use base64::{engine::general_purpose, Engine};

pub (crate) fn get_header_map(response : &ureq::Response) -> HashMap<String,String> {
Expand Down Expand Up @@ -111,7 +110,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String

pub(crate) fn basic_auth(auth: &configuration::BasicAuth) -> String {
let string = format!("{}:{}", auth.0, auth.1.as_ref().unwrap_or(&"".to_string()));
format!("Basic {}", Base64::encode_string(string.as_bytes()))
format!("Basic {}", general_purpose::STANDARD.encode(string)).to_string()
}

{{#apiInfo}}
Expand Down
5 changes: 2 additions & 3 deletions src/apis/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use base64::{engine::general_purpose, Engine};
use std::collections::HashMap;
use std::error;
use std::fmt;

use base64ct::{Base64, Encoding};

pub(crate) fn get_header_map(response: &ureq::Response) -> HashMap<String, String> {
let mut headers = HashMap::new();

Expand Down Expand Up @@ -111,7 +110,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String

pub(crate) fn basic_auth(auth: &configuration::BasicAuth) -> String {
let string = format!("{}:{}", auth.0, auth.1.as_ref().unwrap_or(&"".to_string()));
format!("Basic {}", Base64::encode_string(string.as_bytes()))
format!("Basic {}", general_purpose::STANDARD.encode(string)).to_string()
}

pub mod default_api;
Expand Down
7 changes: 3 additions & 4 deletions src/models/system_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub struct SystemInfo {
pub software_version: String,
#[serde(rename = "hardwareVersion")]
pub hardware_version: String,
#[serde(rename = "buildTag")]
pub build_tag: String,
#[serde(rename = "softwareBuild", skip_serializing_if = "Option::is_none")]
pub software_build: Option<String>,
#[serde(rename = "deviceId")]
pub device_id: String,
#[serde(rename = "pcr")]
Expand All @@ -31,7 +31,6 @@ impl SystemInfo {
firmware_version: String,
software_version: String,
hardware_version: String,
build_tag: String,
device_id: String,
pcr: serde_json::Value,
ak_pub: serde_json::Value,
Expand All @@ -40,7 +39,7 @@ impl SystemInfo {
firmware_version,
software_version,
hardware_version,
build_tag,
software_build: None,
device_id,
pcr,
ak_pub,
Expand Down

0 comments on commit f385e17

Please sign in to comment.