This is an automated email from the ASF dual-hosted git repository.

zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git


The following commit(s) were added to refs/heads/main by this push:
     new 24a6400  fix(catalog/rest): pass key-scope (#464)
24a6400 is described below

commit 24a6400a6b0f002ca25af16940afe49eb7bd5644
Author: Andrei Tserakhau <[email protected]>
AuthorDate: Wed Jun 25 00:49:13 2025 +0200

    fix(catalog/rest): pass key-scope (#464)
    
    closes: #451
---
 catalog/rest/rest.go               |  3 +++
 catalog/rest/rest_internal_test.go | 43 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/catalog/rest/rest.go b/catalog/rest/rest.go
index 93c88db..63c7389 100644
--- a/catalog/rest/rest.go
+++ b/catalog/rest/rest.go
@@ -56,6 +56,7 @@ const (
        keyWarehouseLocation = "warehouse"
        keyMetadataLocation  = "metadata_location"
        keyOauthCredential   = "credential"
+       keyScope             = "scope"
 
        authorizationHeader = "Authorization"
        bearerPrefix        = "Bearer"
@@ -399,6 +400,8 @@ func fromProps(props iceberg.Properties, o *options) {
                        o.authUri = u
                case keyOauthCredential:
                        o.credential = v
+               case keyScope:
+                       o.scope = v
                case keyPrefix:
                        o.prefix = v
                case keyTlsSkipVerify:
diff --git a/catalog/rest/rest_internal_test.go 
b/catalog/rest/rest_internal_test.go
index 4595c57..73daad4 100644
--- a/catalog/rest/rest_internal_test.go
+++ b/catalog/rest/rest_internal_test.go
@@ -42,6 +42,49 @@ import (
        "golang.org/x/sync/errgroup"
 )
 
+func TestScope(t *testing.T) {
+       t.Parallel()
+       mux := http.NewServeMux()
+       srv := httptest.NewServer(mux)
+
+       mux.HandleFunc("/v1/config", func(w http.ResponseWriter, r 
*http.Request) {
+               json.NewEncoder(w).Encode(map[string]any{
+                       "defaults": map[string]any{}, "overrides": 
map[string]any{},
+               })
+       })
+
+       mux.HandleFunc("/v1/oauth/tokens", func(w http.ResponseWriter, req 
*http.Request) {
+               assert.Equal(t, http.MethodPost, req.Method)
+
+               assert.Equal(t, req.Header.Get("Content-Type"), 
"application/x-www-form-urlencoded")
+
+               require.NoError(t, req.ParseForm())
+               values := req.PostForm
+               assert.Equal(t, values.Get("grant_type"), "client_credentials")
+               assert.Equal(t, values.Get("client_secret"), "secret")
+               assert.Equal(t, values.Get("scope"), "my_scope")
+
+               w.WriteHeader(http.StatusOK)
+
+               json.NewEncoder(w).Encode(map[string]any{
+                       "access_token":      "some_jwt_token",
+                       "token_type":        "Bearer",
+                       "expires_in":        86400,
+                       "issued_token_type": 
"urn:ietf:params:oauth:token-type:access_token",
+               })
+       })
+
+       cat, err := NewCatalog(
+               context.Background(),
+               "rest",
+               srv.URL,
+               WithCredential("secret"),
+               WithScope("my_scope"),
+       )
+       require.NoError(t, err)
+       assert.NotNil(t, cat)
+}
+
 func TestAuthHeader(t *testing.T) {
        t.Parallel()
        mux := http.NewServeMux()

Reply via email to