[ARVADOS] created: 1.3.0-1392-ged17fb25d
Git user
git at public.curoverse.com
Tue Jul 23 20:50:52 UTC 2019
at ed17fb25d2e55406cef1e951c87800fd9bf72f23 (commit)
commit ed17fb25d2e55406cef1e951c87800fd9bf72f23
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date: Tue Jul 23 16:49:27 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)
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list