#![allow(clippy::all, unused_variables, unused_mut, dead_code)]
use crate::generated::v1;
pub(crate) fn encode_wire_authorize_request_json(
value: &v1::AuthorizeRequest,
) -> serde_json::Value {
let mut object = serde_json::Map::new();
if !value.response_type.is_empty() {
object.insert(
"responseType".into(),
serde_json::Value::String(value.response_type.to_string()),
);
}
if !value.client_id.is_empty() {
object.insert(
"clientId".into(),
serde_json::Value::String(value.client_id.to_string()),
);
}
if !value.redirect_uri.is_empty() {
object.insert(
"redirectUri".into(),
serde_json::Value::String(value.redirect_uri.to_string()),
);
}
if !value.scope.is_empty() {
object.insert(
"scope".into(),
serde_json::Value::String(value.scope.to_string()),
);
}
if !value.state.is_empty() {
object.insert(
"state".into(),
serde_json::Value::String(value.state.to_string()),
);
}
serde_json::Value::Object(object)
}
pub(crate) fn decode_wire_authorize_request_json(
value: &serde_json::Value,
) -> Result<v1::AuthorizeRequest, crate::public::generated::rpc_support::GestaltError> {
let Some(object) = value.as_object() else {
return Err(crate::public::generated::rpc_support::GestaltError::new(
crate::public::generated::rpc_support::gestalt_error_code::INVALID_ARGUMENT,
"expected JSON object",
));
};
Ok(v1::AuthorizeRequest {
response_type: match object.get("responseType") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
client_id: match object.get("clientId") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
redirect_uri: match object.get("redirectUri") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
scope: match object.get("scope") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
state: match object.get("state") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
..Default::default()
})
}
pub(crate) fn encode_wire_authorize_response_json(
value: &v1::AuthorizeResponse,
) -> serde_json::Value {
let mut object = serde_json::Map::new();
if !value.redirect_uri.is_empty() {
object.insert(
"redirectUri".into(),
serde_json::Value::String(value.redirect_uri.to_string()),
);
}
serde_json::Value::Object(object)
}
pub(crate) fn decode_wire_authorize_response_json(
value: &serde_json::Value,
) -> Result<v1::AuthorizeResponse, crate::public::generated::rpc_support::GestaltError> {
let Some(object) = value.as_object() else {
return Err(crate::public::generated::rpc_support::GestaltError::new(
crate::public::generated::rpc_support::gestalt_error_code::INVALID_ARGUMENT,
"expected JSON object",
));
};
Ok(v1::AuthorizeResponse {
redirect_uri: match object.get("redirectUri") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
..Default::default()
})
}
pub(crate) fn encode_wire_get_grant_request_json(value: &v1::GetGrantRequest) -> serde_json::Value {
let mut object = serde_json::Map::new();
if !value.grant_id.is_empty() {
object.insert(
"grantId".into(),
serde_json::Value::String(value.grant_id.to_string()),
);
}
serde_json::Value::Object(object)
}
pub(crate) fn decode_wire_get_grant_request_json(
value: &serde_json::Value,
) -> Result<v1::GetGrantRequest, crate::public::generated::rpc_support::GestaltError> {
let Some(object) = value.as_object() else {
return Err(crate::public::generated::rpc_support::GestaltError::new(
crate::public::generated::rpc_support::gestalt_error_code::INVALID_ARGUMENT,
"expected JSON object",
));
};
Ok(v1::GetGrantRequest {
grant_id: match object.get("grantId") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
..Default::default()
})
}
pub(crate) fn encode_wire_grant_scope_json(value: &v1::GrantScope) -> serde_json::Value {
let mut object = serde_json::Map::new();
if !value.scope.is_empty() {
object.insert(
"scope".into(),
serde_json::Value::String(value.scope.to_string()),
);
}
if !value.resource.is_empty() {
object.insert(
"resource".into(),
serde_json::Value::Array(
value
.resource
.iter()
.map(|item| serde_json::Value::String(item.to_string()))
.collect(),
),
);
}
serde_json::Value::Object(object)
}
pub(crate) fn decode_wire_grant_scope_json(
value: &serde_json::Value,
) -> Result<v1::GrantScope, crate::public::generated::rpc_support::GestaltError> {
let Some(object) = value.as_object() else {
return Err(crate::public::generated::rpc_support::GestaltError::new(
crate::public::generated::rpc_support::gestalt_error_code::INVALID_ARGUMENT,
"expected JSON object",
));
};
Ok(v1::GrantScope {
scope: match object.get("scope") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
resource: match object.get("resource") {
Some(value) => value
.as_array()
.ok_or_else(|| {
crate::public::proto_json::invalid_proto_json("expected array for resource")
})?
.iter()
.map(|item| {
Ok::<String, crate::public::generated::rpc_support::GestaltError>(
crate::public::proto_json::decode_string(item)?,
)
})
.collect::<Result<Vec<_>, _>>()?,
None => Vec::new(),
},
..Default::default()
})
}
pub(crate) fn encode_wire_get_grant_response_json(
value: &v1::GetGrantResponse,
) -> serde_json::Value {
let mut object = serde_json::Map::new();
if !value.scopes.is_empty() {
object.insert(
"scopes".into(),
serde_json::Value::Array(
value
.scopes
.iter()
.map(|item| encode_wire_grant_scope_json(item))
.collect(),
),
);
}
if value.created_at != 0 {
object.insert(
"createdAt".into(),
crate::public::proto_json::encode_i64(value.created_at),
);
}
if value.expires_at != 0 {
object.insert(
"expiresAt".into(),
crate::public::proto_json::encode_i64(value.expires_at),
);
}
serde_json::Value::Object(object)
}
pub(crate) fn decode_wire_get_grant_response_json(
value: &serde_json::Value,
) -> Result<v1::GetGrantResponse, crate::public::generated::rpc_support::GestaltError> {
let Some(object) = value.as_object() else {
return Err(crate::public::generated::rpc_support::GestaltError::new(
crate::public::generated::rpc_support::gestalt_error_code::INVALID_ARGUMENT,
"expected JSON object",
));
};
Ok(v1::GetGrantResponse {
scopes: match object.get("scopes") {
Some(value) => value
.as_array()
.ok_or_else(|| {
crate::public::proto_json::invalid_proto_json("expected array for scopes")
})?
.iter()
.map(|item| decode_wire_grant_scope_json(item))
.collect::<Result<Vec<_>, _>>()?,
None => Vec::new(),
},
created_at: match object.get("createdAt") {
Some(value) => crate::public::proto_json::decode_i64(value)?,
None => 0,
},
expires_at: match object.get("expiresAt") {
Some(value) => crate::public::proto_json::decode_i64(value)?,
None => 0,
},
..Default::default()
})
}
pub(crate) fn encode_wire_introspect_request_json(
value: &v1::IntrospectRequest,
) -> serde_json::Value {
let mut object = serde_json::Map::new();
if !value.token.is_empty() {
object.insert(
"token".into(),
serde_json::Value::String(value.token.to_string()),
);
}
if !value.token_type_hint.is_empty() {
object.insert(
"tokenTypeHint".into(),
serde_json::Value::String(value.token_type_hint.to_string()),
);
}
serde_json::Value::Object(object)
}
pub(crate) fn decode_wire_introspect_request_json(
value: &serde_json::Value,
) -> Result<v1::IntrospectRequest, crate::public::generated::rpc_support::GestaltError> {
let Some(object) = value.as_object() else {
return Err(crate::public::generated::rpc_support::GestaltError::new(
crate::public::generated::rpc_support::gestalt_error_code::INVALID_ARGUMENT,
"expected JSON object",
));
};
Ok(v1::IntrospectRequest {
token: match object.get("token") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
token_type_hint: match object.get("tokenTypeHint") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
..Default::default()
})
}
pub(crate) fn encode_wire_introspect_response_json(
value: &v1::IntrospectResponse,
) -> serde_json::Value {
let mut object = serde_json::Map::new();
if value.active {
object.insert("active".into(), serde_json::Value::Bool(value.active));
}
if !value.subject.is_empty() {
object.insert(
"subject".into(),
serde_json::Value::String(value.subject.to_string()),
);
}
if !value.scope.is_empty() {
object.insert(
"scope".into(),
serde_json::Value::String(value.scope.to_string()),
);
}
if !value.client_id.is_empty() {
object.insert(
"clientId".into(),
serde_json::Value::String(value.client_id.to_string()),
);
}
if !value.audience.is_empty() {
object.insert(
"audience".into(),
serde_json::Value::Array(
value
.audience
.iter()
.map(|item| serde_json::Value::String(item.to_string()))
.collect(),
),
);
}
serde_json::Value::Object(object)
}
pub(crate) fn decode_wire_introspect_response_json(
value: &serde_json::Value,
) -> Result<v1::IntrospectResponse, crate::public::generated::rpc_support::GestaltError> {
let Some(object) = value.as_object() else {
return Err(crate::public::generated::rpc_support::GestaltError::new(
crate::public::generated::rpc_support::gestalt_error_code::INVALID_ARGUMENT,
"expected JSON object",
));
};
Ok(v1::IntrospectResponse {
active: match object.get("active") {
Some(value) => crate::public::proto_json::decode_bool(value)?,
None => false,
},
subject: match object.get("subject") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
scope: match object.get("scope") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
client_id: match object.get("clientId") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
audience: match object.get("audience") {
Some(value) => value
.as_array()
.ok_or_else(|| {
crate::public::proto_json::invalid_proto_json("expected array for audience")
})?
.iter()
.map(|item| {
Ok::<String, crate::public::generated::rpc_support::GestaltError>(
crate::public::proto_json::decode_string(item)?,
)
})
.collect::<Result<Vec<_>, _>>()?,
None => Vec::new(),
},
..Default::default()
})
}
pub(crate) fn encode_wire_list_grants_request_json(
value: &v1::ListGrantsRequest,
) -> serde_json::Value {
let mut object = serde_json::Map::new();
serde_json::Value::Object(object)
}
pub(crate) fn decode_wire_list_grants_request_json(
value: &serde_json::Value,
) -> Result<v1::ListGrantsRequest, crate::public::generated::rpc_support::GestaltError> {
let Some(object) = value.as_object() else {
return Err(crate::public::generated::rpc_support::GestaltError::new(
crate::public::generated::rpc_support::gestalt_error_code::INVALID_ARGUMENT,
"expected JSON object",
));
};
Ok(v1::ListGrantsRequest {
..Default::default()
})
}
pub(crate) fn encode_wire_list_grants_response_json(
value: &v1::ListGrantsResponse,
) -> serde_json::Value {
let mut object = serde_json::Map::new();
if !value.grant_ids.is_empty() {
object.insert(
"grantIds".into(),
serde_json::Value::Array(
value
.grant_ids
.iter()
.map(|item| serde_json::Value::String(item.to_string()))
.collect(),
),
);
}
serde_json::Value::Object(object)
}
pub(crate) fn decode_wire_list_grants_response_json(
value: &serde_json::Value,
) -> Result<v1::ListGrantsResponse, crate::public::generated::rpc_support::GestaltError> {
let Some(object) = value.as_object() else {
return Err(crate::public::generated::rpc_support::GestaltError::new(
crate::public::generated::rpc_support::gestalt_error_code::INVALID_ARGUMENT,
"expected JSON object",
));
};
Ok(v1::ListGrantsResponse {
grant_ids: match object.get("grantIds") {
Some(value) => value
.as_array()
.ok_or_else(|| {
crate::public::proto_json::invalid_proto_json("expected array for grantIds")
})?
.iter()
.map(|item| {
Ok::<String, crate::public::generated::rpc_support::GestaltError>(
crate::public::proto_json::decode_string(item)?,
)
})
.collect::<Result<Vec<_>, _>>()?,
None => Vec::new(),
},
..Default::default()
})
}
pub(crate) fn encode_wire_revoke_grant_request_json(
value: &v1::RevokeGrantRequest,
) -> serde_json::Value {
let mut object = serde_json::Map::new();
if !value.grant_id.is_empty() {
object.insert(
"grantId".into(),
serde_json::Value::String(value.grant_id.to_string()),
);
}
serde_json::Value::Object(object)
}
pub(crate) fn decode_wire_revoke_grant_request_json(
value: &serde_json::Value,
) -> Result<v1::RevokeGrantRequest, crate::public::generated::rpc_support::GestaltError> {
let Some(object) = value.as_object() else {
return Err(crate::public::generated::rpc_support::GestaltError::new(
crate::public::generated::rpc_support::gestalt_error_code::INVALID_ARGUMENT,
"expected JSON object",
));
};
Ok(v1::RevokeGrantRequest {
grant_id: match object.get("grantId") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
..Default::default()
})
}
pub(crate) fn encode_wire_revoke_grant_response_json(
value: &v1::RevokeGrantResponse,
) -> serde_json::Value {
let mut object = serde_json::Map::new();
serde_json::Value::Object(object)
}
pub(crate) fn decode_wire_revoke_grant_response_json(
value: &serde_json::Value,
) -> Result<v1::RevokeGrantResponse, crate::public::generated::rpc_support::GestaltError> {
let Some(object) = value.as_object() else {
return Err(crate::public::generated::rpc_support::GestaltError::new(
crate::public::generated::rpc_support::gestalt_error_code::INVALID_ARGUMENT,
"expected JSON object",
));
};
Ok(v1::RevokeGrantResponse {
..Default::default()
})
}
pub(crate) fn encode_wire_token_request_json(value: &v1::TokenRequest) -> serde_json::Value {
let mut object = serde_json::Map::new();
if !value.grant_type.is_empty() {
object.insert(
"grantType".into(),
serde_json::Value::String(value.grant_type.to_string()),
);
}
if !value.code.is_empty() {
object.insert(
"code".into(),
serde_json::Value::String(value.code.to_string()),
);
}
if !value.redirect_uri.is_empty() {
object.insert(
"redirectUri".into(),
serde_json::Value::String(value.redirect_uri.to_string()),
);
}
if !value.client_id.is_empty() {
object.insert(
"clientId".into(),
serde_json::Value::String(value.client_id.to_string()),
);
}
if !value.state.is_empty() {
object.insert(
"state".into(),
serde_json::Value::String(value.state.to_string()),
);
}
if !value.scope.is_empty() {
object.insert(
"scope".into(),
serde_json::Value::String(value.scope.to_string()),
);
}
if !value.subject_token.is_empty() {
object.insert(
"subjectToken".into(),
serde_json::Value::String(value.subject_token.to_string()),
);
}
if !value.subject_token_type.is_empty() {
object.insert(
"subjectTokenType".into(),
serde_json::Value::String(value.subject_token_type.to_string()),
);
}
if value.expires_in != 0 {
object.insert(
"expiresIn".into(),
crate::public::proto_json::encode_i64(value.expires_in),
);
}
serde_json::Value::Object(object)
}
pub(crate) fn decode_wire_token_request_json(
value: &serde_json::Value,
) -> Result<v1::TokenRequest, crate::public::generated::rpc_support::GestaltError> {
let Some(object) = value.as_object() else {
return Err(crate::public::generated::rpc_support::GestaltError::new(
crate::public::generated::rpc_support::gestalt_error_code::INVALID_ARGUMENT,
"expected JSON object",
));
};
Ok(v1::TokenRequest {
grant_type: match object.get("grantType") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
code: match object.get("code") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
redirect_uri: match object.get("redirectUri") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
client_id: match object.get("clientId") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
state: match object.get("state") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
scope: match object.get("scope") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
subject_token: match object.get("subjectToken") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
subject_token_type: match object.get("subjectTokenType") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
expires_in: match object.get("expiresIn") {
Some(value) => crate::public::proto_json::decode_i64(value)?,
None => 0,
},
..Default::default()
})
}
pub(crate) fn encode_wire_token_response_json(value: &v1::TokenResponse) -> serde_json::Value {
let mut object = serde_json::Map::new();
if !value.access_token.is_empty() {
object.insert(
"accessToken".into(),
serde_json::Value::String(value.access_token.to_string()),
);
}
if !value.token_type.is_empty() {
object.insert(
"tokenType".into(),
serde_json::Value::String(value.token_type.to_string()),
);
}
if value.expires_in != 0 {
object.insert(
"expiresIn".into(),
crate::public::proto_json::encode_i64(value.expires_in),
);
}
if !value.refresh_token.is_empty() {
object.insert(
"refreshToken".into(),
serde_json::Value::String(value.refresh_token.to_string()),
);
}
if !value.scope.is_empty() {
object.insert(
"scope".into(),
serde_json::Value::String(value.scope.to_string()),
);
}
if !value.grant_id.is_empty() {
object.insert(
"grantId".into(),
serde_json::Value::String(value.grant_id.to_string()),
);
}
serde_json::Value::Object(object)
}
pub(crate) fn decode_wire_token_response_json(
value: &serde_json::Value,
) -> Result<v1::TokenResponse, crate::public::generated::rpc_support::GestaltError> {
let Some(object) = value.as_object() else {
return Err(crate::public::generated::rpc_support::GestaltError::new(
crate::public::generated::rpc_support::gestalt_error_code::INVALID_ARGUMENT,
"expected JSON object",
));
};
Ok(v1::TokenResponse {
access_token: match object.get("accessToken") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
token_type: match object.get("tokenType") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
expires_in: match object.get("expiresIn") {
Some(value) => crate::public::proto_json::decode_i64(value)?,
None => 0,
},
refresh_token: match object.get("refreshToken") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
scope: match object.get("scope") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
grant_id: match object.get("grantId") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
..Default::default()
})
}
pub(crate) fn encode_wire_user_info_request_json(value: &v1::UserInfoRequest) -> serde_json::Value {
let mut object = serde_json::Map::new();
serde_json::Value::Object(object)
}
pub(crate) fn decode_wire_user_info_request_json(
value: &serde_json::Value,
) -> Result<v1::UserInfoRequest, crate::public::generated::rpc_support::GestaltError> {
let Some(object) = value.as_object() else {
return Err(crate::public::generated::rpc_support::GestaltError::new(
crate::public::generated::rpc_support::gestalt_error_code::INVALID_ARGUMENT,
"expected JSON object",
));
};
Ok(v1::UserInfoRequest {
..Default::default()
})
}
pub(crate) fn encode_wire_user_info_response_json(
value: &v1::UserInfoResponse,
) -> serde_json::Value {
let mut object = serde_json::Map::new();
if !value.subject_id.is_empty() {
object.insert(
"subjectId".into(),
serde_json::Value::String(value.subject_id.to_string()),
);
}
if !value.email.is_empty() {
object.insert(
"email".into(),
serde_json::Value::String(value.email.to_string()),
);
}
if !value.name.is_empty() {
object.insert(
"name".into(),
serde_json::Value::String(value.name.to_string()),
);
}
serde_json::Value::Object(object)
}
pub(crate) fn decode_wire_user_info_response_json(
value: &serde_json::Value,
) -> Result<v1::UserInfoResponse, crate::public::generated::rpc_support::GestaltError> {
let Some(object) = value.as_object() else {
return Err(crate::public::generated::rpc_support::GestaltError::new(
crate::public::generated::rpc_support::gestalt_error_code::INVALID_ARGUMENT,
"expected JSON object",
));
};
Ok(v1::UserInfoResponse {
subject_id: match object.get("subjectId") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
email: match object.get("email") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
name: match object.get("name") {
Some(value) => crate::public::proto_json::decode_string(value)?,
None => String::new(),
},
..Default::default()
})
}