From b2fe9103a8f42d393fdbb838106fa4d28ea9a25f Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 17 Nov 2023 09:37:28 -0500 Subject: [PATCH] 20831: Add DiscoveryDocument to arvados.API Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- lib/controller/federation/conn.go | 4 ++++ lib/controller/rpc/conn.go | 14 ++++++++++++++ sdk/go/arvados/api.go | 2 ++ sdk/go/arvados/client.go | 1 + 4 files changed, 21 insertions(+) diff --git a/lib/controller/federation/conn.go b/lib/controller/federation/conn.go index 95b50e7827..24a7b6f883 100644 --- a/lib/controller/federation/conn.go +++ b/lib/controller/federation/conn.go @@ -228,6 +228,10 @@ func (conn *Conn) VocabularyGet(ctx context.Context) (arvados.Vocabulary, error) return conn.chooseBackend(conn.cluster.ClusterID).VocabularyGet(ctx) } +func (conn *Conn) DiscoveryDocument(ctx context.Context) (arvados.DiscoveryDocument, error) { + return conn.chooseBackend(conn.cluster.ClusterID).DiscoveryDocument(ctx) +} + func (conn *Conn) Login(ctx context.Context, options arvados.LoginOptions) (arvados.LoginResponse, error) { if id := conn.cluster.Login.LoginCluster; id != "" && id != conn.cluster.ClusterID { // defer entire login procedure to designated cluster diff --git a/lib/controller/rpc/conn.go b/lib/controller/rpc/conn.go index e15e4c4702..beedf3b993 100644 --- a/lib/controller/rpc/conn.go +++ b/lib/controller/rpc/conn.go @@ -48,6 +48,7 @@ type Conn struct { httpClient http.Client baseURL url.URL tokenProvider TokenProvider + discoveryDocument *arvados.DiscoveryDocument } func NewConn(clusterID string, url *url.URL, insecure bool, tp TokenProvider) *Conn { @@ -189,6 +190,19 @@ func (conn *Conn) VocabularyGet(ctx context.Context) (arvados.Vocabulary, error) return resp, err } +func (conn *Conn) DiscoveryDocument(ctx context.Context) (arvados.DiscoveryDocument, error) { + if conn.discoveryDocument != nil { + return *conn.discoveryDocument, nil + } + var dd arvados.DiscoveryDocument + err := conn.requestAndDecode(ctx, &dd, arvados.EndpointDiscoveryDocument, nil, nil) + if err != nil { + return dd, err + } + conn.discoveryDocument = &dd + return *conn.discoveryDocument, nil +} + func (conn *Conn) Login(ctx context.Context, options arvados.LoginOptions) (arvados.LoginResponse, error) { ep := arvados.EndpointLogin var resp arvados.LoginResponse diff --git a/sdk/go/arvados/api.go b/sdk/go/arvados/api.go index f4ac1ab3c4..bff01eeda5 100644 --- a/sdk/go/arvados/api.go +++ b/sdk/go/arvados/api.go @@ -25,6 +25,7 @@ type APIEndpoint struct { var ( EndpointConfigGet = APIEndpoint{"GET", "arvados/v1/config", ""} EndpointVocabularyGet = APIEndpoint{"GET", "arvados/v1/vocabulary", ""} + EndpointDiscoveryDocument = APIEndpoint{"GET", "discovery/v1/apis/arvados/v1/rest", ""} EndpointLogin = APIEndpoint{"GET", "login", ""} EndpointLogout = APIEndpoint{"GET", "logout", ""} EndpointAuthorizedKeyCreate = APIEndpoint{"POST", "arvados/v1/authorized_keys", "authorized_key"} @@ -347,4 +348,5 @@ type API interface { APIClientAuthorizationDelete(ctx context.Context, options DeleteOptions) (APIClientAuthorization, error) APIClientAuthorizationUpdate(ctx context.Context, options UpdateOptions) (APIClientAuthorization, error) APIClientAuthorizationGet(ctx context.Context, options GetOptions) (APIClientAuthorization, error) + DiscoveryDocument(ctx context.Context) (DiscoveryDocument, error) } diff --git a/sdk/go/arvados/client.go b/sdk/go/arvados/client.go index d71ade8a81..735a44d24c 100644 --- a/sdk/go/arvados/client.go +++ b/sdk/go/arvados/client.go @@ -630,6 +630,7 @@ type DiscoveryDocument struct { GitURL string `json:"gitUrl"` Schemas map[string]Schema `json:"schemas"` Resources map[string]Resource `json:"resources"` + Revision string `json:"revision"` } type Resource struct { -- 2.30.2