-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathvocabstrings.py
More file actions
55 lines (44 loc) · 1.65 KB
/
vocabstrings.py
File metadata and controls
55 lines (44 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
# Copyright (c) 2017, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.
"""
File: vocabstrings.py
Demonstrates uses of VocabString for STIX Controlled Vocabularies.
"""
from stix.core import STIXHeader
from stix.common.vocabs import VocabString, PackageIntent
def main():
# Create STIXHeader instance
header = STIXHeader()
header.package_intents.append(PackageIntent.TERM_INDICATORS)
# To add a Package_Intent value that exists outside of the
# PackageIntentVocab controlled vocabulary, we pass in an
# instance of VocabString.
#
# This will create a new Package_Intent field without an
# xsi:type and will not perform any validation of input terms.
#
# Passing in an instance of VocabString works for every
# ControlledVocabularyStringType field (or in python-stix,
# every VocabString field).
non_default_value = VocabString("NON STANDARD PACKAGE INTENT")
header.package_intents.append(non_default_value)
# Print XML!
print header.to_xml()
# NOTE: Passing in a str value that is not included in the list
# of default CV terms will raise a ValueError. This is why we pass
# in a VocabString instance.
#
# Example:
try:
msg = (
"[-] Attempting to add an str instance that does not exist "
"in the PackageIntent ALLOWED_VALUES list"
)
print(msg)
header.package_intents.append("THIS WILL THROW A VALUEERROR")
except Exception as ex:
print "[!] As expected, that failed. Here's the Exception message:"
print "[!]", str(ex)
if __name__ == '__main__':
main()