Closed cyberfox1 closed 6 years ago
Thanks @cyberfox1, this is a good idea.
I was thinking of an command line option, would that work for you?
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.
I assume you mean "slide_string"? How do you set up the options currently??
@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.
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?
@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.
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
@emmanvg, can you look into this?
Probably want to look at mixbox.idgen.set_id_namespace
, and expose a method in the slider to set that.
@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:
@emmanvg thanks that looks good, I will try and test this change.
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.