OLD | NEW |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """The artifact definitions CLI arguments helper.""" | 2 """The artifact definitions CLI arguments helper.""" |
3 | 3 |
| 4 import os |
| 5 |
4 from artifacts import errors as artifacts_errors | 6 from artifacts import errors as artifacts_errors |
5 from artifacts import reader as artifacts_reader | 7 from artifacts import reader as artifacts_reader |
6 from artifacts import registry as artifacts_registry | 8 from artifacts import registry as artifacts_registry |
7 | 9 |
8 from plaso.cli import tools | 10 from plaso.cli import tools |
9 from plaso.cli.helpers import interface | 11 from plaso.cli.helpers import interface |
10 from plaso.cli.helpers import manager | 12 from plaso.cli.helpers import manager |
11 from plaso.lib import errors | 13 from plaso.lib import errors |
12 | 14 |
13 | 15 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 Raises: | 51 Raises: |
50 BadConfigObject: when the configuration object is of the wrong type. | 52 BadConfigObject: when the configuration object is of the wrong type. |
51 """ | 53 """ |
52 if not isinstance(configuration_object, tools.CLITool): | 54 if not isinstance(configuration_object, tools.CLITool): |
53 raise errors.BadConfigObject( | 55 raise errors.BadConfigObject( |
54 u'Configuration object is not an instance of CLITool') | 56 u'Configuration object is not an instance of CLITool') |
55 | 57 |
56 registry = None | 58 registry = None |
57 | 59 |
58 path = getattr(options, u'artifact_definitions_path', None) | 60 path = getattr(options, u'artifact_definitions_path', None) |
59 if path: | 61 |
| 62 data_location = getattr(configuration_object, u'_data_location', None) |
| 63 if (not path or not os.path.exists(path)) and data_location: |
| 64 path = os.path.dirname(data_location) |
| 65 path = os.path.join(path, u'artifacts') |
| 66 |
| 67 if path and os.path.exists(path): |
60 registry = artifacts_registry.ArtifactDefinitionsRegistry() | 68 registry = artifacts_registry.ArtifactDefinitionsRegistry() |
61 reader = artifacts_reader.YamlArtifactsReader() | 69 reader = artifacts_reader.YamlArtifactsReader() |
62 | 70 |
63 try: | 71 try: |
64 registry.ReadFromDirectory(reader, path) | 72 registry.ReadFromDirectory(reader, path) |
65 | 73 |
66 except (KeyError, artifacts_errors.FormatError) as exception: | 74 except (KeyError, artifacts_errors.FormatError) as exception: |
67 raise errors.BadConfigObject(( | 75 raise errors.BadConfigObject(( |
68 u'Unable to read artifact definitions from: {0:s} with error: ' | 76 u'Unable to read artifact definitions from: {0:s} with error: ' |
69 u'{1!s}').format(path, exception)) | 77 u'{1!s}').format(path, exception)) |
70 | 78 |
71 setattr(configuration_object, u'_artifacts_registry', registry) | 79 setattr(configuration_object, u'_artifacts_registry', registry) |
72 | 80 |
73 | 81 |
74 manager.ArgumentHelperManager.RegisterHelper(ArtifactDefinitionsArgumentsHelper) | 82 manager.ArgumentHelperManager.RegisterHelper(ArtifactDefinitionsArgumentsHelper) |
OLD | NEW |