Skip to content

Commit

Permalink
fixed clippy errors
Browse files Browse the repository at this point in the history
Signed-off-by: Kelley Li <[email protected]>
  • Loading branch information
l-kli committed Dec 3, 2024
1 parent a860fea commit babcb0a
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/public/log/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ impl OpenCyberSecurityFramework {
authorizer_name: &str,
) -> Result<Self, OcsfException> {
let decision = response.decision();
return Self::create_generic(
Self::create_generic(
request,
response.diagnostics(),
format!("decision is {decision:?}").as_str(),
format!("{decision:?}"),
entities,
fields,
authorizer_name,
);
)
}

/// Converts Request, Entities, Field Set into a filtered OCSF log.
Expand Down Expand Up @@ -252,12 +252,16 @@ impl OpenCyberSecurityFramework {

let (severity_id, severity) = build_ocsf_severity(response_error.len());

let source_entity =
generate_managed_entity(&filtered_request.entities, &filtered_request.principal)?;
let resource_entity =
generate_managed_entity(&filtered_request.entities, &filtered_request.resource)?;
let source_entity = generate_managed_entity(
filtered_request.entities.as_ref(),
&filtered_request.principal,
)?;
let resource_entity = generate_managed_entity(
filtered_request.entities.as_ref(),
&filtered_request.resource,
)?;
let action_entity =
generate_managed_entity(&filtered_request.entities, &filtered_request.action)?;
generate_managed_entity(filtered_request.entities.as_ref(), &filtered_request.action)?;
unmapped.insert(
"action_entity_details".to_string(),
to_value(action_entity)?,
Expand Down Expand Up @@ -306,7 +310,7 @@ impl OpenCyberSecurityFramework {
.build()
.unwrap_or_default();

return OpenCyberSecurityFrameworkBuilder::default()
OpenCyberSecurityFrameworkBuilder::default()
.type_uid(TypeUid::Other)
.severity_id(SeverityId::Other)
.metadata(
Expand All @@ -326,7 +330,7 @@ impl OpenCyberSecurityFramework {
.activity_id(ActivityId::Other)
.message(error_message)
.build()
.unwrap_or_default();
.unwrap_or_default()
}
}

Expand Down Expand Up @@ -360,7 +364,7 @@ fn filter_request(request: &Request, entities: &Entities, fields: &FieldSet) ->
}

fn generate_managed_entity(
entities: &Option<Entities>,
entities: Option<&Entities>,
component: &EntityComponent,
) -> Result<ManagedEntity, OcsfException> {
// The map contains the useful information of entity. For now, it only contains the ancestors
Expand Down Expand Up @@ -550,9 +554,11 @@ pub enum ObservableTypeId {
IPAddress = 2,
/// Media Access Control (MAC) address. For example: 18:36:F3:98:4F:9A
MACAddress = 3,
/// User name. For example: john\_doe
#[allow(clippy::doc_markdown)]
/// User name. For example: john_doe
UserName = 4,
/// Email address. For example: john\[email protected]
#[allow(clippy::doc_markdown)]
/// Email address. For example: [email protected]
EmailAddress = 5,
/// Uniform Resource Locator (URL) string
URLString = 6,
Expand Down Expand Up @@ -962,7 +968,7 @@ mod test {
use super::build_ocsf_severity;

fn generate_metadata() -> MetaData {
return MetaDataBuilder::default()
MetaDataBuilder::default()
.version("1.0.0")
.product(
ProductBuilder::default()
Expand All @@ -971,28 +977,28 @@ mod test {
.unwrap(),
)
.build()
.unwrap();
.unwrap()
}

fn generate_entity(entity_type: String, name: String) -> ManagedEntity {
return ManagedEntityBuilder::default()
ManagedEntityBuilder::default()
.version("1.0.0".to_string())
.entity_type(entity_type)
.name(name)
.build()
.unwrap();
.unwrap()
}

fn generate_default_ocsf_model() -> OpenCyberSecurityFramework {
return OpenCyberSecurityFrameworkBuilder::default()
OpenCyberSecurityFrameworkBuilder::default()
.type_uid(TypeUid::Read)
.severity_id(SeverityId::Unknown)
.metadata(generate_metadata())
.time(1_695_275_741_i64)
.entity(generate_entity("user".to_string(), "alice".to_string()))
.activity_id(ActivityId::Read)
.build()
.unwrap();
.unwrap()
}

fn generate_validation_error() -> Result<OpenCyberSecurityFramework, OcsfException> {
Expand Down

0 comments on commit babcb0a

Please sign in to comment.