3838# provided values as appropriate.
3939#
4040# Finally, if no namspacing is specified the library will make use of the
41- # `/services` branch of the REST API which provides a non- namespaced view of
42- # Splunk resources.
41+ # `/services` branch of the REST API which provides a namespaced view of
42+ # Splunk resources equivelent to using owner={currentUser} and app={defaultApp}
4343#
4444
4545import httplib
@@ -77,20 +77,20 @@ def namespace(**kwargs):
7777 kwargs, which may contain any of `sharing`, `owner` and `app`."""
7878 sharing = kwargs .get ('sharing' , None )
7979 if sharing in ["system" ]:
80- return {
80+ return record ({
8181 'sharing' : sharing ,
8282 'owner' : "nobody" ,
83- 'app' : "system" }
83+ 'app' : "system" })
8484 if sharing in ["global" , "app" ]:
85- return {
85+ return record ( {
8686 'sharing' : sharing ,
8787 'owner' : "nobody" ,
88- 'app' : kwargs .get ('app' , None )}
88+ 'app' : kwargs .get ('app' , None )})
8989 if sharing in ["user" , None ]:
90- return {
90+ return record ({
9191 'sharing' : sharing ,
9292 'owner' : kwargs .get ('owner' , None ),
93- 'app' : kwargs .get ('app' , None )}
93+ 'app' : kwargs .get ('app' , None )})
9494 raise ValueError ("Invalid value for argument: 'sharing'" )
9595
9696class Context (object ):
@@ -102,13 +102,7 @@ def __init__(self, handler=None, **kwargs):
102102 self .scheme = kwargs .get ("scheme" , DEFAULT_SCHEME )
103103 self .host = kwargs .get ("host" , DEFAULT_HOST )
104104 self .port = kwargs .get ("port" , DEFAULT_PORT )
105-
106- # The default namespace values for this context
107- result = namespace (** kwargs )
108- self .app = result ['app' ]
109- self .owner = result ['owner' ]
110- self .sharing = result ['sharing' ]
111-
105+ self .namespace = namespace (** kwargs )
112106 self .username = kwargs .get ("username" , "" )
113107 self .password = kwargs .get ("password" , "" )
114108
@@ -158,15 +152,27 @@ def logout(self):
158152 self .token = None
159153 return self
160154
161- def fullpath (self , path ):
162- """If the given path is a fragment, qualify with segments corresponding
163- to the binding context's namespace args."""
155+ def fullpath (self , path , ** kwargs ):
156+ """Returns a full resource path given a potential path fragment and
157+ then completing with namespace segments using the namespace args,
158+ if provided, otherwise using the context namespace values."""
164159 if path .startswith ('/' ):
165160 return path
166- if self .app is None and self .owner is None :
161+
162+ # Use namespace kwargs if any provided, otherwise use context defaults
163+ if 'app' in kwargs or 'owner' in kwargs or 'sharing' in kwargs :
164+ ns = namespace (** kwargs )
165+ else :
166+ ns = self .namespace
167+
168+ # If no app or owner are specified, then use the /services endpoint
169+ if ns .app is None and ns .owner is None :
167170 return "/services/%s" % path
168- oname = "-" if self .owner is None else self .owner
169- aname = "-" if self .app is None else self .app
171+
172+ # At least one of app or owner is specified, so use the /serviceNS
173+ # endpoint and if only one is specified, then wildcard the other.
174+ oname = "-" if ns .owner is None else ns .owner
175+ aname = "-" if ns .app is None else ns .app
170176 return "/servicesNS/%s/%s/%s" % (oname , aname , path )
171177
172178 # Convet the given path into a fully qualified URL by first qualifying
0 commit comments