Skip to content

Commit

Permalink
Update cli for secret format
Browse files Browse the repository at this point in the history
  • Loading branch information
augustuswm committed Nov 9, 2023
1 parent 57f29ee commit 54f68c1
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 24 deletions.
11 changes: 7 additions & 4 deletions rfd-api-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@
"type": "object",
"properties": {
"token": {
"type": "string"
"$ref": "#/components/schemas/SecretString"
}
},
"required": [
Expand Down Expand Up @@ -2409,7 +2409,7 @@
"format": "uuid"
},
"key": {
"type": "string"
"$ref": "#/components/schemas/SecretString"
},
"permissions": {
"$ref": "#/components/schemas/Permissions_for_ApiPermission"
Expand All @@ -2434,7 +2434,7 @@
"format": "uuid"
},
"key": {
"type": "string"
"$ref": "#/components/schemas/SecretString"
}
},
"required": [
Expand Down Expand Up @@ -2692,7 +2692,7 @@
"format": "uuid"
},
"client_secret": {
"type": "string"
"$ref": "#/components/schemas/SecretString"
},
"code": {
"type": "string"
Expand Down Expand Up @@ -2893,6 +2893,9 @@
},
"uniqueItems": true
},
"SecretString": {
"type": "string"
},
"Visibility": {
"type": "string",
"enum": [
Expand Down
4 changes: 2 additions & 2 deletions rfd-cli/src/generated/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ impl Cli {
.arg(
clap::Arg::new("client-secret")
.long("client-secret")
.value_parser(clap::value_parser!(String))
.value_parser(clap::value_parser!(types::SecretString))
.required_unless_present("json-body"),
)
.arg(
Expand Down Expand Up @@ -1341,7 +1341,7 @@ impl<T: CliOverride, U: CliOutput> Cli<T, U> {
request = request.body_map(|body| body.client_id(value.clone()))
}

if let Some(value) = matches.get_one::<String>("client-secret") {
if let Some(value) = matches.get_one::<types::SecretString>("client-secret") {
request = request.body_map(|body| body.client_secret(value.clone()))
}

Expand Down
4 changes: 2 additions & 2 deletions rfd-cli/src/printer/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl TabDisplay for ApiKeyResponse {
impl TabDisplay for InitialApiKeyResponse {
fn display(&self, tw: &mut TabWriter<Vec<u8>>, level: u8, printer: &RfdTabPrinter) {
printer.print_field(tw, level, "id", &self.id);
printer.print_field(tw, level, "key", &self.key);
printer.print_field(tw, level, "key", &self.key.0);
printer.print_list(
tw,
level,
Expand Down Expand Up @@ -449,7 +449,7 @@ impl TabDisplay for OAuthClientSecret {
impl TabDisplay for InitialOAuthClientSecretResponse {
fn display(&self, tw: &mut TabWriter<Vec<u8>>, level: u8, printer: &RfdTabPrinter) {
printer.print_field(tw, level, "id", &self.id);
printer.print_field(tw, level, "key", &self.key);
printer.print_field(tw, level, "key", &self.key.0);
printer.print_field(tw, level, "created_at", &self.created_at);
}
}
Expand Down
85 changes: 69 additions & 16 deletions rfd-sdk/src/generated/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ pub mod types {

#[derive(Clone, Debug, Deserialize, Serialize, schemars :: JsonSchema)]
pub struct ApiUserLinkRequestResponse {
pub token: String,
pub token: SecretString,
}

impl From<&ApiUserLinkRequestResponse> for ApiUserLinkRequestResponse {
Expand Down Expand Up @@ -468,8 +468,10 @@ pub mod types {
#[derive(Clone, Debug, Deserialize, Serialize, schemars :: JsonSchema)]
pub struct GitHubCommitPayload {
pub commits: Vec<GitHubCommit>,
pub head_commit: GitHubCommit,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub head_commit: Option<GitHubCommit>,
pub installation: GitHubInstallation,
#[serde(rename = "ref")]
pub ref_: String,
pub repository: GitHubRepository,
pub sender: GitHubSender,
Expand Down Expand Up @@ -568,7 +570,7 @@ pub mod types {
pub struct InitialApiKeyResponse {
pub created_at: chrono::DateTime<chrono::offset::Utc>,
pub id: uuid::Uuid,
pub key: String,
pub key: SecretString,
pub permissions: PermissionsForApiPermission,
}

Expand All @@ -588,7 +590,7 @@ pub mod types {
pub struct InitialOAuthClientSecretResponse {
pub created_at: chrono::DateTime<chrono::offset::Utc>,
pub id: uuid::Uuid,
pub key: String,
pub key: SecretString,
}

impl From<&InitialOAuthClientSecretResponse> for InitialOAuthClientSecretResponse {
Expand Down Expand Up @@ -739,7 +741,7 @@ pub mod types {
#[derive(Clone, Debug, Deserialize, Serialize, schemars :: JsonSchema)]
pub struct OAuthAuthzCodeExchangeBody {
pub client_id: uuid::Uuid,
pub client_secret: String,
pub client_secret: SecretString,
pub code: String,
pub grant_type: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -977,6 +979,57 @@ pub mod types {
}
}

#[derive(
Clone,
Debug,
Deserialize,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
Serialize,
schemars :: JsonSchema,
)]
pub struct SecretString(pub String);
impl std::ops::Deref for SecretString {
type Target = String;
fn deref(&self) -> &String {
&self.0
}
}

impl From<SecretString> for String {
fn from(value: SecretString) -> Self {
value.0
}
}

impl From<&SecretString> for SecretString {
fn from(value: &SecretString) -> Self {
value.clone()
}
}

impl From<String> for SecretString {
fn from(value: String) -> Self {
Self(value)
}
}

impl std::str::FromStr for SecretString {
type Err = std::convert::Infallible;
fn from_str(value: &str) -> Result<Self, Self::Err> {
Ok(Self(value.to_string()))
}
}

impl ToString for SecretString {
fn to_string(&self) -> String {
self.0.to_string()
}
}

#[derive(
Clone,
Copy,
Expand Down Expand Up @@ -1658,7 +1711,7 @@ pub mod types {

#[derive(Clone, Debug)]
pub struct ApiUserLinkRequestResponse {
token: Result<String, String>,
token: Result<super::SecretString, String>,
}

impl Default for ApiUserLinkRequestResponse {
Expand All @@ -1672,7 +1725,7 @@ pub mod types {
impl ApiUserLinkRequestResponse {
pub fn token<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<String>,
T: std::convert::TryInto<super::SecretString>,
T::Error: std::fmt::Display,
{
self.token = value
Expand Down Expand Up @@ -2509,7 +2562,7 @@ pub mod types {
#[derive(Clone, Debug)]
pub struct GitHubCommitPayload {
commits: Result<Vec<super::GitHubCommit>, String>,
head_commit: Result<super::GitHubCommit, String>,
head_commit: Result<Option<super::GitHubCommit>, String>,
installation: Result<super::GitHubInstallation, String>,
ref_: Result<String, String>,
repository: Result<super::GitHubRepository, String>,
Expand All @@ -2520,7 +2573,7 @@ pub mod types {
fn default() -> Self {
Self {
commits: Err("no value supplied for commits".to_string()),
head_commit: Err("no value supplied for head_commit".to_string()),
head_commit: Ok(Default::default()),
installation: Err("no value supplied for installation".to_string()),
ref_: Err("no value supplied for ref_".to_string()),
repository: Err("no value supplied for repository".to_string()),
Expand All @@ -2542,7 +2595,7 @@ pub mod types {
}
pub fn head_commit<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<super::GitHubCommit>,
T: std::convert::TryInto<Option<super::GitHubCommit>>,
T::Error: std::fmt::Display,
{
self.head_commit = value
Expand Down Expand Up @@ -2907,7 +2960,7 @@ pub mod types {
pub struct InitialApiKeyResponse {
created_at: Result<chrono::DateTime<chrono::offset::Utc>, String>,
id: Result<uuid::Uuid, String>,
key: Result<String, String>,
key: Result<super::SecretString, String>,
permissions: Result<super::PermissionsForApiPermission, String>,
}

Expand Down Expand Up @@ -2945,7 +2998,7 @@ pub mod types {
}
pub fn key<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<String>,
T: std::convert::TryInto<super::SecretString>,
T::Error: std::fmt::Display,
{
self.key = value
Expand Down Expand Up @@ -2992,7 +3045,7 @@ pub mod types {
pub struct InitialOAuthClientSecretResponse {
created_at: Result<chrono::DateTime<chrono::offset::Utc>, String>,
id: Result<uuid::Uuid, String>,
key: Result<String, String>,
key: Result<super::SecretString, String>,
}

impl Default for InitialOAuthClientSecretResponse {
Expand Down Expand Up @@ -3028,7 +3081,7 @@ pub mod types {
}
pub fn key<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<String>,
T: std::convert::TryInto<super::SecretString>,
T::Error: std::fmt::Display,
{
self.key = value
Expand Down Expand Up @@ -3528,7 +3581,7 @@ pub mod types {
#[derive(Clone, Debug)]
pub struct OAuthAuthzCodeExchangeBody {
client_id: Result<uuid::Uuid, String>,
client_secret: Result<String, String>,
client_secret: Result<super::SecretString, String>,
code: Result<String, String>,
grant_type: Result<String, String>,
pkce_verifier: Result<Option<String>, String>,
Expand Down Expand Up @@ -3561,7 +3614,7 @@ pub mod types {
}
pub fn client_secret<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<String>,
T: std::convert::TryInto<super::SecretString>,
T::Error: std::fmt::Display,
{
self.client_secret = value.try_into().map_err(|e| {
Expand Down

0 comments on commit 54f68c1

Please sign in to comment.