[ARVADOS] created: 1.3.0-1392-g1880df0d5

Git user git at public.curoverse.com
Wed Jul 24 13:43:29 UTC 2019


        at  1880df0d51a653c55379d19c13dfa602f3cb50b0 (commit)


commit 1880df0d51a653c55379d19c13dfa602f3cb50b0
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Wed Jul 24 09:43:18 2019 -0400

    14813: Add CORS headers to "get config" by moving it to arvados.API.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/lib/controller/federation/conn.go b/lib/controller/federation/conn.go
index 3addcf4fa..63e801b22 100644
--- a/lib/controller/federation/conn.go
+++ b/lib/controller/federation/conn.go
@@ -5,8 +5,10 @@
 package federation
 
 import (
+	"bytes"
 	"context"
 	"crypto/md5"
+	"encoding/json"
 	"errors"
 	"fmt"
 	"net/http"
@@ -14,6 +16,7 @@ import (
 	"regexp"
 	"strings"
 
+	"git.curoverse.com/arvados.git/lib/config"
 	"git.curoverse.com/arvados.git/lib/controller/railsproxy"
 	"git.curoverse.com/arvados.git/lib/controller/rpc"
 	"git.curoverse.com/arvados.git/sdk/go/arvados"
@@ -177,6 +180,12 @@ func portableDataHash(mt string) string {
 	return fmt.Sprintf("%x+%d", h.Sum(nil), size)
 }
 
+func (conn *Conn) ConfigGet(ctx context.Context) (json.RawMessage, error) {
+	var buf bytes.Buffer
+	err := config.ExportJSON(&buf, conn.cluster)
+	return json.RawMessage(buf.Bytes()), err
+}
+
 func (conn *Conn) CollectionGet(ctx context.Context, options arvados.GetOptions) (arvados.Collection, error) {
 	if len(options.UUID) == 27 {
 		// UUID is really a UUID
diff --git a/lib/controller/handler.go b/lib/controller/handler.go
index 852327fd8..f7b2362f3 100644
--- a/lib/controller/handler.go
+++ b/lib/controller/handler.go
@@ -5,19 +5,16 @@
 package controller
 
 import (
-	"bytes"
 	"context"
 	"database/sql"
 	"errors"
 	"fmt"
-	"io"
 	"net/http"
 	"net/url"
 	"strings"
 	"sync"
 	"time"
 
-	"git.curoverse.com/arvados.git/lib/config"
 	"git.curoverse.com/arvados.git/lib/controller/federation"
 	"git.curoverse.com/arvados.git/lib/controller/railsproxy"
 	"git.curoverse.com/arvados.git/lib/controller/router"
@@ -80,19 +77,10 @@ func (h *Handler) setup() {
 		Routes: health.Routes{"ping": func() error { _, err := h.db(&http.Request{}); return err }},
 	})
 
-	mux.Handle("/arvados/v1/config", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-		var buf bytes.Buffer
-		err := config.ExportJSON(&buf, h.Cluster)
-		if err != nil {
-			httpserver.Error(w, err.Error(), http.StatusInternalServerError)
-			return
-		}
-		w.Header().Set("Content-Type", "application/json")
-		io.Copy(w, &buf)
-	}))
+	rtr := router.New(federation.New(h.Cluster))
+	mux.Handle("/arvados/v1/config", rtr)
 
 	if h.Cluster.EnableBetaController14287 {
-		rtr := router.New(federation.New(h.Cluster))
 		mux.Handle("/arvados/v1/collections", rtr)
 		mux.Handle("/arvados/v1/collections/", rtr)
 	}
diff --git a/lib/controller/handler_test.go b/lib/controller/handler_test.go
index fbfb037d3..4b49e4615 100644
--- a/lib/controller/handler_test.go
+++ b/lib/controller/handler_test.go
@@ -68,6 +68,9 @@ func (s *HandlerSuite) TestConfigExport(c *check.C) {
 	resp := httptest.NewRecorder()
 	s.handler.ServeHTTP(resp, req)
 	c.Check(resp.Code, check.Equals, http.StatusOK)
+	c.Check(resp.Header().Get("Access-Control-Allow-Origin"), check.Equals, `*`)
+	c.Check(resp.Header().Get("Access-Control-Allow-Methods"), check.Matches, `.*\bGET\b.*`)
+	c.Check(resp.Header().Get("Access-Control-Allow-Headers"), check.Matches, `.+`)
 	var cluster arvados.Cluster
 	c.Log(resp.Body.String())
 	err := json.Unmarshal(resp.Body.Bytes(), &cluster)
diff --git a/lib/controller/router/router.go b/lib/controller/router/router.go
index 9c2c1f3a1..5d5602df5 100644
--- a/lib/controller/router/router.go
+++ b/lib/controller/router/router.go
@@ -41,6 +41,13 @@ func (rtr *router) addRoutes() {
 		exec        routableFunc
 	}{
 		{
+			arvados.EndpointConfigGet,
+			func() interface{} { return &struct{}{} },
+			func(ctx context.Context, opts interface{}) (interface{}, error) {
+				return rtr.fed.ConfigGet(ctx)
+			},
+		},
+		{
 			arvados.EndpointCollectionCreate,
 			func() interface{} { return &arvados.CreateOptions{} },
 			func(ctx context.Context, opts interface{}) (interface{}, error) {
diff --git a/lib/controller/rpc/conn.go b/lib/controller/rpc/conn.go
index ea3d6fb2d..1028da829 100644
--- a/lib/controller/rpc/conn.go
+++ b/lib/controller/rpc/conn.go
@@ -121,6 +121,13 @@ func (conn *Conn) requestAndDecode(ctx context.Context, dst interface{}, ep arva
 	return aClient.RequestAndDecodeContext(ctx, dst, ep.Method, path, body, params)
 }
 
+func (conn *Conn) ConfigGet(ctx context.Context) (json.RawMessage, error) {
+	ep := arvados.EndpointConfigGet
+	var resp json.RawMessage
+	err := conn.requestAndDecode(ctx, &resp, ep, nil, nil)
+	return resp, err
+}
+
 func (conn *Conn) CollectionCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Collection, error) {
 	ep := arvados.EndpointCollectionCreate
 	var resp arvados.Collection
diff --git a/sdk/go/arvados/api.go b/sdk/go/arvados/api.go
index 71265756d..772f8da97 100644
--- a/sdk/go/arvados/api.go
+++ b/sdk/go/arvados/api.go
@@ -4,7 +4,10 @@
 
 package arvados
 
-import "context"
+import (
+	"context"
+	"encoding/json"
+)
 
 type APIEndpoint struct {
 	Method string
@@ -14,6 +17,7 @@ type APIEndpoint struct {
 }
 
 var (
+	EndpointConfigGet                     = APIEndpoint{"GET", "arvados/v1/config", ""}
 	EndpointCollectionCreate              = APIEndpoint{"POST", "arvados/v1/collections", "collection"}
 	EndpointCollectionUpdate              = APIEndpoint{"PATCH", "arvados/v1/collections/:uuid", "collection"}
 	EndpointCollectionGet                 = APIEndpoint{"GET", "arvados/v1/collections/:uuid", ""}
@@ -80,6 +84,7 @@ type DeleteOptions struct {
 }
 
 type API interface {
+	ConfigGet(ctx context.Context) (json.RawMessage, error)
 	CollectionCreate(ctx context.Context, options CreateOptions) (Collection, error)
 	CollectionUpdate(ctx context.Context, options UpdateOptions) (Collection, error)
 	CollectionGet(ctx context.Context, options GetOptions) (Collection, error)
diff --git a/sdk/go/arvadostest/api.go b/sdk/go/arvadostest/api.go
index 77a26bcba..850bd0639 100644
--- a/sdk/go/arvadostest/api.go
+++ b/sdk/go/arvadostest/api.go
@@ -6,6 +6,7 @@ package arvadostest
 
 import (
 	"context"
+	"encoding/json"
 	"errors"
 	"reflect"
 	"runtime"
@@ -23,6 +24,10 @@ type APIStub struct {
 	mtx   sync.Mutex
 }
 
+func (as *APIStub) ConfigGet(ctx context.Context) (json.RawMessage, error) {
+	as.appendCall(as.ConfigGet, ctx, nil)
+	return nil, as.Error
+}
 func (as *APIStub) CollectionCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Collection, error) {
 	as.appendCall(as.CollectionCreate, ctx, options)
 	return arvados.Collection{}, as.Error

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list