Skip to content

Commit

Permalink
Expanding adoc validation python script, adding GitHub job to automat…
Browse files Browse the repository at this point in the history
…ically run it, fixing errors found within adoc files.
  • Loading branch information
DC3-DCCI authored and dc3-tsd committed Feb 16, 2024
1 parent 729fb4f commit 113961c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 39 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/extensions-asciidocs-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: AsciiDoc Validation
on: [push, pull_request]

jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set Up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Validate adoc
working-directory: extension-definition-specifications
run: |
for file in */*.adoc; do
python ../scripts/validate_adoc.py -i "$file"
done
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
cui


:stylesheet: stix.css
:stylesdir: ../../asciidoc-shared
:toc: macro
Expand Down Expand Up @@ -72,7 +69,7 @@ The tables below describe the properties of a STIX 2.1 CUI marking definition ex
|[stixtype]#{string_url}[string]#
|The extension_type property indicates the type of extension is being used.

The value of this property *MUST* be [stixtype]#<<property-extension,property-extension>>#
The value of this property *MUST* be [stixliteral]#property-extension#

|*control* (required)
|[stixtype]#{string_url}[string]#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
:list_url: https://docs.oasis-open.org/cti/stix/v2.1/os/stix-v2.1-os.html#_9w329aiwpu1y
:open_vocab_url: https://docs.oasis-open.org/cti/stix/v2.1/os/stix-v2.1-os.html#_bnnxah80y7by
:string_url: https://docs.oasis-open.org/cti/stix/v2.1/os/stix-v2.1-os.html#_uxyhzmv0vpyc
:user_account_url: https://docs.oasis-open.org/cti/stix/v2.1/os/stix-v2.1-os.html#_azo70vgj1vm2
:email_address_url: https://docs.oasis-open.org/cti/stix/v2.1/os/stix-v2.1-os.html#_wmenahkvqmgj

= [stixtitle]*Identity Contact Information Extension Version 1.0 for STIX™ Version 2.1*

Expand Down Expand Up @@ -96,7 +98,7 @@ The properties and additional types within the Identity Contact Information Exte

== 2. Additional Sub-Object Types
[[contact-number]]
=== 2.1 Contact Number Object Type
=== 2.1. Contact Number Object Type
*Type Name:* [stixtype]#contact-number#

[width="100%",cols="37%,23%,40%",options="header",]
Expand All @@ -123,7 +125,7 @@ The properties and additional types within the Identity Contact Information Exte
|===

[[email-contact]]
=== 2.2 Email Contact Object Type
=== 2.2. Email Contact Object Type
*Type Name:* [stixtype]#email-contact#

[width="100%",cols="37%,23%,40%",options="header",]
Expand All @@ -145,12 +147,12 @@ The properties and additional types within the Identity Contact Information Exte
|The type of email that address is used for. This *SHOULD* be drawn from [stixtype]#<<digital-contact-ov,digital-contact-ov>>#.

|*email_address_ref* (required)
|[stixtype]#{identifier_url}[identifer]# of type [stixtype]#<<email-addr,email-addr>>#
|[stixtype]#{identifier_url}[identifer]# of type [stixtype]#{email_address_url}[email-addr]#
|A reference to the email address itself.
|===

[[social-media-contact]]
=== 2.3 Social Media Contact Object Type
=== 2.3. Social Media Contact Object Type
*Type Name:* [stixtype]#social-media-contact#

[width="100%",cols="37%,23%,40%",options="header",]
Expand All @@ -174,7 +176,7 @@ The properties and additional types within the Identity Contact Information Exte
This *SHOULD NOT* be used to capture the social media service used. That *SHOULD* be encoded into the User Account Object that is linked to by the user_account_ref property.

|*user_account_ref* (required)
|[stixtype]#{identifier_url}[identifer]# of type [stixtype]#<<user-account,user-account>>#
|[stixtype]#{identifier_url}[identifer]# of type [stixtype]#{user_account_url}[user-account]#
|A reference to the social media account itself.
|===

Expand Down Expand Up @@ -206,7 +208,7 @@ This *SHOULD NOT* be used to capture the social media service used. That *SHOUL
|===

[[digital-contact-ov]]
=== 3.2 Digital Contact Type Vocabulary
=== 3.2. Digital Contact Type Vocabulary
*Type Name:* [stixtype]#digital-contact-ov#

[width="100%",cols="37%,63%",options="header",]
Expand All @@ -226,19 +228,18 @@ This *SHOULD NOT* be used to capture the social media service used. That *SHOUL

== 4. Identity Contact Information Examples

=== 4.1 Identitiy Contact Details Example
=== 4.1. Identitiy Contact Details Example
[source,json]
----
include::examples/individual_contact_example.json[]
----

=== 4.2 Organization Contact Details Example
=== 4.2. Organization Contact Details Example
[source,json]
----
include::examples/organization_contact_example.json[]
----

[[appendix-a]]
== Appendix A. Acknowledgements
*Primary Editor*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
:sighting_url: https://docs.oasis-open.org/cti/stix/v2.1/os/stix-v2.1-os.html#_a795guqsap3r
:threat_actor_url: https://docs.oasis-open.org/cti/stix/v2.1/os/stix-v2.1-os.html#_k017w16zutw
:tool_url: https://docs.oasis-open.org/cti/stix/v2.1/os/stix-v2.1-os.html#_z4voa9ndw8v
:sco_url: https://docs.oasis-open.org/cti/stix/v2.1/os/stix-v2.1-os.html#_mlbmudhl16lr

= [stixtitle]*Incident Core Extension Version 2.1 for STIX^TM^ Version 2.1*

Expand Down Expand Up @@ -78,7 +79,7 @@ The current STIX 2.1 Incident object was defined as a stub with the expectation
In the 1.0 version of the core incident extension, information on impact, events, and tasks were embedded within the Incident object itself, however this was found to have limitations.
Therefore, the 2.0 version of this extension has been created in which these components have been separated into independent SDOs for more complex incidents to be accurately modeled.

These extensions allow incidents to be tracked across their life cycle where [stixtype]#<<event,events>># are first flagged for investigation resulting in [stixtype]#incidents# with [stixtype]#<<task,tasks>># being worked to resolve them.
These extensions allow incidents to be tracked across their life cycle where [stixtype]#<<event,events>># are first flagged for investigation resulting in [stixtype]#{incident_url}incidents# with [stixtype]#<<task,tasks>># being worked to resolve them.
Incidents have [stixtype]#<<impact,impacts>># that change over time.
[stixtype]#<<event,events>># can cause or influence these [stixtype]#<<impact,impacts>># which are in turn mitigated and potentially resolved by [stixtype]#<<task,tasks>># performed as part of the incident response process.
Both [stixtype]#<<event,events>># and [stixtype]#<<task,tasks>># can exist independently of [stixtype]#{incident_url}[incidents]# and in most workflows will occur prior to an incident being declared.
Expand Down Expand Up @@ -259,7 +260,7 @@ Additionally, this can be used to supplement the *created_by_ref* property in ca
|===
// end::incident-relationships[]

==== 2.1.2 Example
==== 2.1.2. Example

[source,json]
----
Expand Down Expand Up @@ -432,7 +433,7 @@ For example, a dropper running led to a ransomware tool to be downloaded and run
|[stixtype]#<<event,event>>#
|[stixrelationship]#impacts#
|[stixtype]#{infrastructure_url}[infrastructure]#, +
[stixtype]#[<All STIX Cyber-observable Objects>]#
[stixtype]#{sco_url}[<All STIX Cyber-observable Objects>]#
|An event has an impact on specific infrastructure. While not all SCO types will make sense in this relationship, allowing any type of SCO prevents artificially restricting what could be used.

|[stixtype]#<<event,event>>#
Expand Down Expand Up @@ -470,7 +471,7 @@ For example, a dropper running led to a ransomware tool to be downloaded and run

// end::event-relationships[]

==== 2.2.2 Example
==== 2.2.2. Example

[source,json]
----
Expand Down Expand Up @@ -646,7 +647,7 @@ This value *MUST* be an integer between 0 to 100. This can be translated into qu

|===

===== 2.3.2.1.1 Availability Impact Example
====== 2.3.2.1.1. Availability Impact Example

[source,json]
----
Expand Down Expand Up @@ -692,7 +693,7 @@ The value of this property *MUST NOT* be negative.
The value of this property *MUST NOT* be negative.
|===

===== 2.3.2.2.1 Confidentiality Impact Example
====== 2.3.2.2.1. Confidentiality Impact Example

[source,json]
----
Expand All @@ -718,7 +719,7 @@ The value of this property *SHOULD* come from the [stixtype]#<<external-impact-o

<<<

===== 2.3.2.3.1 External Impact Example
====== 2.3.2.3.1. External Impact Example

[source,json]
----
Expand Down Expand Up @@ -767,7 +768,7 @@ The value of this property *MUST NOT* be negative.

<<<

===== 2.3.2.4.1 Integrity Impact Example
====== 2.3.2.4.1. Integrity Impact Example

[source,json]
----
Expand Down Expand Up @@ -848,7 +849,7 @@ If *min_amount* and *max_amount* properties are both defined, then *max_amount*

<<<

===== 2.3.2.5.1 Monetary Impact Example
====== 2.3.2.5.1. Monetary Impact Example

[source,json]
----
Expand Down Expand Up @@ -883,7 +884,7 @@ Including an entry with an *impact_type* of none and no asset_type indicates tha

|===

===== 2.3.2.6.1 Physical Impact Example
====== 2.3.2.6.1. Physical Impact Example

[source,json]
----
Expand All @@ -908,7 +909,7 @@ The value of this property *MUST* come from the [stixtype]#<<traceability-enum,t

|===

===== 2.3.2.7.1 Traceability Impact Example
====== 2.3.2.7.1. Traceability Impact Example

[source,json]
----
Expand Down Expand Up @@ -1107,7 +1108,7 @@ Using these embedded relationships ensures that an incomplete sequence cannot be
|[stixtype]#<<task,task>>#
|[stixrelationship]#impacts#
|[stixtype]#{infrastructure_url}[infrastructure]#, +
[stixtype]#[<All STIX Cyber-observable Objects>]#
[stixtype]#{sco_url}[<All STIX Cyber-observable Objects>]#
|A task has an impact on specific infrastructure.

|[stixtype]#<<task,task>>#
Expand Down Expand Up @@ -1155,7 +1156,7 @@ Using these embedded relationships ensures that an incomplete sequence cannot be

// end::task-relationships[]

==== 2.4.2 Example
==== 2.4.2. Example

[source,json]
----
Expand Down Expand Up @@ -1246,7 +1247,7 @@ The values of this property *MUST* come from the [stixtype]#<<activity-transitio

|===

==== 3.2.1 Example
==== 3.2.1. Example

[source,json]
----
Expand Down Expand Up @@ -1286,7 +1287,7 @@ Default value is [stixliteral]#true#.

|===

==== 3.3.1 Example
==== 3.3.1. Example

[source,json]
----
Expand All @@ -1295,7 +1296,7 @@ include::examples/example_3.2.json[]


[[incident-score]]
=== 3.4 Incident Score Object Type
=== 3.4. Incident Score Object Type

*Type Name:* [stixtype]#incident-score#
[width="100%",cols="37%,23%,40%",options="header",]
Expand All @@ -1320,7 +1321,7 @@ This is normally a system or process name or some combination of these such as "
|===

<<<
==== 3.4.1 Example
==== 3.4.1. Example

[source,json]
----
Expand Down Expand Up @@ -1372,7 +1373,7 @@ For example, an event causing a network outage.
If the *initial_ref* property is populated this *MUST* reference the same type of SDO.

|===
==== 3.5.1 Example
==== 3.5.1. Example

[source,json]
----
Expand Down Expand Up @@ -1417,7 +1418,7 @@ The values of this property *MUST* come from the [stixtype]#<<activity-transitio

|===

==== 3.6.1 Example
==== 3.6.1. Example

[source,json]
----
Expand Down Expand Up @@ -1457,7 +1458,7 @@ Default value is [stixliteral]#true#.

|===

==== 3.7.1 Example
==== 3.7.1. Example

[source,json]
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ include::examples/mission_id.json[]

== 3. Vocabularies

=== 3.1 String Purpose Vocabulary
[[string-purpose-ov]]
=== 3.1. String Purpose Vocabulary
*Type Name:* [stixtype]#string-purpose-ov#

[width="100%",cols="37%,63%",options="header",]
Expand Down Expand Up @@ -155,7 +156,7 @@ include::examples/mission_id.json[]

|===

== 4.0 Relationships
== 4. Relationships

// tag::observed-string-relationships[]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ The corresponding dictionary values *MUST* be the [stixtype]#<<pap-description,p
|[stixtype]#{string_url}[string]#
|The extension_type property indicates the type of extension is being used.

The value of this property *MUST* be [stixtype]#<<property-extension,property-extension>>#
The value of this property *MUST* be [stixliteral]#property-extension#

|*pap* (required)
|[stixtype]#{string_url}[string]#
Expand Down
9 changes: 6 additions & 3 deletions scripts/validate_adoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Validator():
def __init__(self, file_path):
self._errors = []

with open(file_path, "rt") as input_file:
with open(file_path, "rt", encoding="utf-8") as input_file:
self._content = input_file.read()

def run_jobs(self) -> list:
Expand Down Expand Up @@ -96,7 +96,9 @@ def section_ids(self, content) -> None:
self._errors.append(f"Line {line_number}: {item} should be 1 as the first item")
continue

if len(parts) == len(last_parts):
if item[-1] != ".":
self._errors.append(f"Line {line_number}: {item} has no . at the end")
elif len(parts) == len(last_parts):
if int(last_parts[-1]) != int(parts[-1]) - 1:
self._errors.append(f"Line {line_number}: {item} should be {'.'.join(last_parts[:-1])}.{int(last_parts[-1]) + 1}")
elif len(parts) > len(last_parts):
Expand Down Expand Up @@ -128,9 +130,10 @@ def section_ids(self, content) -> None:
errors = validator.run_jobs()

if len(errors) > 0:
print(f"Error Validating: {args.input_path}", file=sys.stderr)
print("\n".join(errors), file=sys.stderr)
exit(1)
else:
print("No errors found")
print(f"No errors found: {args.input_path}")

exit(0)

0 comments on commit 113961c

Please sign in to comment.