Enhancement: Context#prefix should be a property
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)
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.
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.