splunk-sdk-python icon indicating copy to clipboard operation
splunk-sdk-python copied to clipboard

Enhancement: Context#prefix should be a property

Open ansman opened this issue 15 years ago • 2 comments

Currently the prefix is an attribute in Context but this causes some problems.

In our framework you can change the ports Splunk listens to which causes our framework to update the ports of the Service

However, writing to port does not update the prefix variable so it won't be reflected when making requests.

I suggest the following code:

class Context:
....
@property
def prefix(self):
    return "%s://%s:%s" % (self.scheme, self.host, self.port)

ansman avatar Nov 03 '11 19:11 ansman

Seems to me that if you are updating the ports, you probably want to create a new instance of Service anyway. The reason I think this is the case is that if you change the ports, presumably you need to restart Splunk to get it to listen on the new ports, so you're going to lose your auth tokens. Even if this weren't the case, there's nothing stopping you from simply creating a new instance and logging in again.

itay avatar Nov 03 '11 19:11 itay

Context is intended to be immutable with regard to the context configuration properties that it "captures", eg: scheme, host, port, namespace, username, password. The intent is that you create a new Context (or Service) when you need to make use of different context values.

I will add a separate item to investigate making it clearer in the API that these values should not be written.

Note also that I am likely to separate out username & password in order to make authentication more "composable" .. but thats a separate issue.

blovering avatar Feb 28 '12 18:02 blovering