oasis-open / cti-stix-slider

OASIS TC Open Repository: The repository cti-stix-slider supports development of a Python application to convert STIX 2.0 content to STIX 1.x content
https://cti-stix-slider.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
21 stars 15 forks source link

Namespace is hardcoded as "example" #32

Closed cyberfox1 closed 6 years ago

cyberfox1 commented 6 years ago

In convert_stix.py, the Stix namespace is hardcoded as a global variable _ID_NAMESPACE to "example". This is then bound to several string building functions, and cannot be overridden as they refer to the variable directly, not through a package/module.

It would be good to change this value dynamically at runtime, which is not currently possible.

I would suggest defining the variable in stix2slider/init.py so functions can refer to stix2slider._ID_NAMESPACE to both change and retrieve the value.

rpiazza commented 6 years ago

Thanks @cyberfox1, this is a good idea.

I was thinking of an command line option, would that work for you?

cyberfox1 commented 6 years ago

Hi @rpiazza , actually I am integrating the library into a web server currently using the to_string(?), so part of the API interface would be preferred. Although, if it was simply a module variable that can be changed before to_string is called would be fine.

rpiazza commented 6 years ago

I assume you mean "slide_string"? How do you set up the options currently??

cyberfox1 commented 6 years ago

@rpiazza yes slide_string. Actually I am not passing in any options, its not entirely clear how to pass options using the library API as option handling seems to be based around CLI parsing...I know there is a lower level "sdv" library which might expose more options but I haven't used it directly yet.

rpiazza commented 6 years ago

Look in options.py. There are 3 methods you might want to use:

So with this new option, you could use these methods to set the namespace. Does that work for you?

cyberfox1 commented 6 years ago

@rpiazza OK thanks I'll look at that. And yes, if that allows setting the namespace for slide_string that would work for me, thanks.

cyberfox1 commented 6 years ago

Hi @rpiazza , I found there is another location in mixbox that has a hardcoded "example" namespace. To make it customizable, in idgen.py I moved EXAMPLENAMESPACE into __init__.py, and then changed the __init_\ method of IDGenerator to the following:

mixbox/idgen.py:

   def __init__(self, namespace=None, method=METHOD_UUID):
      self.namespace = namespace if namespace else mixbox.EXAMPLE_NAMESPACE
rpiazza commented 6 years ago

@emmanvg, can you look into this?

gtback commented 6 years ago

Probably want to look at mixbox.idgen.set_id_namespace, and expose a method in the slider to set that.

emmanvg commented 6 years ago

@cyberfox1, I looked into this and I have added a new argument called --use-namespace. You would use it like this: stix2_slider <file> --use-namespace="example http://example.com" if you are invoking the CLI. If you are using the slider as a library, you can do so from by calling using the following methods:

cyberfox1 commented 6 years ago

@emmanvg thanks that looks good, I will try and test this change.