17696: Adds ArvadosClient.ClusterConfig() to get the exported cluster's config.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Fri, 20 Aug 2021 16:09:39 +0000 (13:09 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Mon, 30 Aug 2021 18:37:24 +0000 (15:37 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

sdk/go/arvadosclient/arvadosclient.go
sdk/go/arvadosclient/arvadosclient_test.go

index 4c594625e700d086d7d1a68764b640b247219fda..3081f6d82075d732f4bc8eef94f3684734652654 100644 (file)
@@ -426,6 +426,24 @@ func (c *ArvadosClient) Discovery(parameter string) (value interface{}, err erro
        return value, ErrInvalidArgument
 }
 
+// ClusterConfig returns the value of the given key in the current cluster's
+// exported config. If key is an empty string, it'll return the entire config.
+func (c *ArvadosClient) ClusterConfig(key string) (config interface{}, err error) {
+       var clusterConfig interface{}
+       err = c.Call("GET", "config", "", "", nil, &clusterConfig)
+       if err != nil {
+               return nil, err
+       }
+       if key == "" {
+               return clusterConfig, nil
+       }
+       configData, ok := clusterConfig.(map[string]interface{})[key]
+       if !ok {
+               return nil, ErrInvalidArgument
+       }
+       return configData, nil
+}
+
 func (c *ArvadosClient) httpClient() *http.Client {
        if c.Client != nil {
                return c.Client
index 9d6e4fe7e8f7e702287db4865c348715c104a4ff..27e23c1aea4e3d1b4fab84811dc8dddd70b6cde4 100644 (file)
@@ -158,6 +158,36 @@ func (s *ServerRequiredSuite) TestAPIDiscovery_Get_noSuchParameter(c *C) {
        c.Assert(value, IsNil)
 }
 
+func (s *ServerRequiredSuite) TestAPIClusterConfig_Get_StorageClasses(c *C) {
+       arv, err := MakeArvadosClient()
+       c.Assert(err, IsNil)
+       data, err := arv.ClusterConfig("StorageClasses")
+       c.Assert(err, IsNil)
+       c.Assert(data, NotNil)
+       clusterConfig := data.(map[string]interface{})
+       _, ok := clusterConfig["default"]
+       c.Assert(ok, Equals, true)
+}
+
+func (s *ServerRequiredSuite) TestAPIClusterConfig_Get_All(c *C) {
+       arv, err := MakeArvadosClient()
+       c.Assert(err, IsNil)
+       data, err := arv.ClusterConfig("")
+       c.Assert(err, IsNil)
+       c.Assert(data, NotNil)
+       clusterConfig := data.(map[string]interface{})
+       _, ok := clusterConfig["StorageClasses"]
+       c.Assert(ok, Equals, true)
+}
+
+func (s *ServerRequiredSuite) TestAPIClusterConfig_Get_noSuchSection(c *C) {
+       arv, err := MakeArvadosClient()
+       c.Assert(err, IsNil)
+       data, err := arv.ClusterConfig("noSuchSection")
+       c.Assert(err, NotNil)
+       c.Assert(data, IsNil)
+}
+
 func (s *ServerRequiredSuite) TestCreateLarge(c *C) {
        arv, err := MakeArvadosClient()
        c.Assert(err, IsNil)