generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sync CLI options with SDK options #402
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
use chrono::{DateTime, Utc}; | ||
use chrono::{DateTime, FixedOffset}; | ||
use clap::Subcommand; | ||
use std::time::SystemTime; | ||
use web5::{ | ||
credentials::{ | ||
CredentialSubject, Issuer, VerifiableCredential, VerifiableCredentialCreateOptions, | ||
|
@@ -10,6 +9,8 @@ use web5::{ | |
}; | ||
|
||
#[derive(Subcommand, Debug)] | ||
// We allow the warning because memory layout isn't important for the CLI options. | ||
#[allow(clippy::large_enum_variant)] | ||
pub enum Commands { | ||
/// Creates a VC. | ||
/// | ||
|
@@ -46,6 +47,29 @@ pub enum Commands { | |
/// If not specified, the VC will not expire | ||
#[arg(long)] | ||
expiration_date: Option<String>, | ||
/// The optional credential status, which may indicate revocation or suspension information. | ||
#[arg(long)] | ||
credential_status: Option<String>, | ||
/// The credential schema, used to validate the data structure of the credential. This is optional. | ||
/// JSON Schema validation is performed if the value is provided, and creation will fail if validation fails. | ||
#[arg(long)] | ||
credential_schema: Option<String>, | ||
/// An optional array of evidence supporting the claims made in the credential. | ||
#[arg(long)] | ||
evidence: Option<String>, | ||
/// The type(s) of the Verifiable Credential. | ||
#[arg(long)] | ||
r#type: Option<Vec<String>>, | ||
/// The context(s) for the Verifiable Credential, which define the meaning of terms within the credential. | ||
#[arg(long)] | ||
context: Option<Vec<String>>, | ||
/// The unique identifier for the Verifiable Credential. This is optional. | ||
#[arg(long)] | ||
id: Option<String>, | ||
/// The issuance date of the credential (in ISO 8601 standard format). | ||
/// If not provided, defaults to the current date and time. | ||
#[arg(long)] | ||
issuance_date: Option<String>, | ||
/// If true, output will be minified | ||
#[arg(long)] | ||
no_indent: bool, | ||
|
@@ -70,6 +94,13 @@ impl Commands { | |
portable_did, | ||
issuer, | ||
expiration_date, | ||
credential_status, | ||
credential_schema, | ||
evidence, | ||
r#type, | ||
context, | ||
id, | ||
issuance_date, | ||
no_indent, | ||
json_escape, | ||
} => { | ||
|
@@ -85,13 +116,31 @@ impl Commands { | |
}); | ||
let expiration_date = match expiration_date { | ||
None => None, | ||
Some(d) => match d.parse::<DateTime<Utc>>() { | ||
Ok(datetime) => Some(SystemTime::from(datetime)), | ||
Some(d) => match d.parse::<DateTime<FixedOffset>>() { | ||
Ok(datetime) => Some(datetime.into()), | ||
Err(e) => { | ||
panic!("Error parsing date string: {}", e); | ||
} | ||
}, | ||
}; | ||
let issuance_date = match issuance_date { | ||
None => None, | ||
Some(d) => match d.parse::<DateTime<FixedOffset>>() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here it should do the issuance date now()? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The SDK will take care of that. This is just meant to be a passthrough from the CLI to the SDK function. |
||
Ok(datetime) => Some(datetime.into()), | ||
Err(e) => { | ||
panic!("Error parsing date string: {}", e); | ||
} | ||
}, | ||
}; | ||
let credential_status = credential_status.as_ref().map(|cs| { | ||
serde_json::from_str(cs).expect("Error parsing credential status JSON string") | ||
}); | ||
let credential_schema = credential_schema.as_ref().map(|cs| { | ||
serde_json::from_str(cs).expect("Error parsing credential schema JSON string") | ||
}); | ||
let evidence = evidence | ||
.as_ref() | ||
.map(|e| serde_json::from_str(e).expect("Error parsing evidence JSON string")); | ||
|
||
let vc = VerifiableCredential::create( | ||
issuer, | ||
|
@@ -100,8 +149,14 @@ impl Commands { | |
..Default::default() | ||
}, | ||
Some(VerifiableCredentialCreateOptions { | ||
id: id.clone(), | ||
context: context.clone(), | ||
r#type: r#type.clone(), | ||
issuance_date, | ||
expiration_date, | ||
..Default::default() | ||
credential_status, | ||
credential_schema, | ||
evidence, | ||
}), | ||
) | ||
.await | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can issuance date be none?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It cannot. Will default to current date and time.