mitre / stixmarx

Data Markings API for STIX 1.x
Other
8 stars 7 forks source link

Only create '.stixmarx' if it does not exist #12

Closed adamhp closed 3 years ago

adamhp commented 3 years ago

We're currently using the cti-stix-elevator in our project, and during our CI builds, an exception is being thrown indicating that this call to create the .stixmarx directory is throwing a FileExistsError.

FileExistsError: [Errno 17] File exists: '/home/jenkins/.stixmarx'
emmanvg commented 3 years ago

Hi @adamhp! I wonder if what you are experiencing is due to a different issue. When stirmarx runs for the first time, it will create a .stixmarx directory with mode 777 (read, write, execute for everyone). Therefore even if the Python interpreter is running under a different user or privileges it should still be able to check the existence of the directory. The os.path.isdir[1][2] method already performs a similar action as os.path.exists[3]. It sounds like a permission problem (maybe specific to Jenkins/ or OS used to run tests) and not an issue with the tool. We test the cti-stix-elevator regularly against GitHub Workflows (recently transitioned out of Travis CI) with ubuntu flavored machines and did not experience this behavior...

It sounds like the machine running the tests gets reused with each CI build, but I don't think that is a reason to see that error pop up. Hope this helps!

[1] https://docs.python.org/3/library/os.html#os.DirEntry.is_dir [2] https://github.com/python/cpython/blob/3.9/Lib/genericpath.py#L39 [3] https://docs.python.org/3.9/library/os.path.html#os.path.exists "On some platforms, this function may return False if permission is not granted to execute os.stat() on the requested file, even if the path physically exists."

adamhp commented 3 years ago

@emmanvg That makes sense! Thanks for the information. That may help us resolve the issue. Very well could be how the Jenkins nodes are handling it.