[ARVADOS] created: c9e40c6e552bc35f661eb3ed8eff04786cf40566

git at public.curoverse.com git at public.curoverse.com
Wed Jun 3 16:40:51 EDT 2015


        at  c9e40c6e552bc35f661eb3ed8eff04786cf40566 (commit)


commit c9e40c6e552bc35f661eb3ed8eff04786cf40566
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Wed Jun 3 16:40:50 2015 -0400

    6235: Add method to get parameters from API discovery document.

diff --git a/sdk/go/arvadosclient/arvadosclient.go b/sdk/go/arvadosclient/arvadosclient.go
index ae40a89..62eda5b 100644
--- a/sdk/go/arvadosclient/arvadosclient.go
+++ b/sdk/go/arvadosclient/arvadosclient.go
@@ -68,6 +68,9 @@ type ArvadosClient struct {
 	// If true, sets the X-External-Client header to indicate
 	// the client is outside the cluster.
 	External bool
+
+	// Discovery document
+	DiscoveryDoc Dict
 }
 
 // Create a new ArvadosClient, initialized with standard Arvados environment
@@ -114,7 +117,9 @@ func (this ArvadosClient) CallRaw(method string, resource string, uuid string, a
 		Scheme: "https",
 		Host:   this.ApiServer}
 
-	u.Path = "/arvados/v1"
+	if resource != API_DISCOVERY_RESOURCE {
+		u.Path = "/arvados/v1"
+	}
 
 	if resource != "" {
 		u.Path = u.Path + "/" + resource
@@ -275,3 +280,23 @@ func (this ArvadosClient) Update(resource string, uuid string, parameters Dict,
 func (this ArvadosClient) List(resource string, parameters Dict, output interface{}) (err error) {
 	return this.Call("GET", resource, "", "", parameters, output)
 }
+
+// API Discovery
+//
+//   parameter - name of parameter to be discovered
+// return
+//   valueMap - Dict key value pair of the discovered parameter
+//   err - error accessing the resource, or nil if no error
+var API_DISCOVERY_RESOURCE string = "discovery/v1/apis/arvados/v1/rest"
+
+func (this *ArvadosClient) Discovery(parameter string) (valueMap Dict, err error) {
+	if len(this.DiscoveryDoc) == 0 {
+		this.DiscoveryDoc = make(Dict)
+		err = this.Call("GET", API_DISCOVERY_RESOURCE, "", "", nil, &this.DiscoveryDoc)
+	}
+
+	valueMap = make(Dict)
+	valueMap[parameter] = this.DiscoveryDoc[parameter]
+
+	return valueMap, err
+}
diff --git a/sdk/go/arvadosclient/arvadosclient_test.go b/sdk/go/arvadosclient/arvadosclient_test.go
index 21eff20..17911c6 100644
--- a/sdk/go/arvadosclient/arvadosclient_test.go
+++ b/sdk/go/arvadosclient/arvadosclient_test.go
@@ -102,3 +102,17 @@ func (s *ServerRequiredSuite) TestErrorResponse(c *C) {
 		c.Assert(err.(APIServerError).HttpStatusCode, Equals, 404)
 	}
 }
+
+func (s *ServerRequiredSuite) TestAPIDiscovery_Get_defaultCollectionReplication(c *C) {
+	arv, err := MakeArvadosClient()
+	valueMap, err := arv.Discovery("defaultCollectionReplication")
+	c.Assert(err, IsNil)
+	c.Assert(valueMap["defaultCollectionReplication"], NotNil)
+}
+
+func (s *ServerRequiredSuite) TestAPIDiscovery_Get_noSuchParameter(c *C) {
+	arv, err := MakeArvadosClient()
+	valueMap, err := arv.Discovery("noSuchParameter")
+	c.Assert(err, IsNil)
+	c.Assert(valueMap["noSuchParameter"], IsNil)
+}

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list