Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions cmd/iceberg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ package main

import (
"context"
"crypto/tls"
"errors"
"fmt"
"log"
"net/url"
"os"
"strings"

Expand Down Expand Up @@ -160,6 +162,28 @@ func main() {
if len(cfg.Cred) > 0 {
opts = append(opts, rest.WithCredential(cfg.Cred))
}
if fileCfg != nil {
restCfg := fileCfg.RestConfig
if restCfg.SigV4Enabled {
opts = append(opts, rest.WithSigV4())
}

if len(restCfg.SigV4Region) > 0 && len(restCfg.SigV4Service) > 0 {
opts = append(opts, rest.WithSigV4RegionSvc(restCfg.SigV4Region, restCfg.SigV4Service))
}

if len(restCfg.AuthUrl) > 0 {
authUri, err := url.Parse(restCfg.AuthUrl)
if err != nil {
log.Fatal(err)
}
opts = append(opts, rest.WithAuthURI(authUri))
}

if restCfg.TlsSkipVerify {
opts = append(opts, rest.WithTLSConfig(&tls.Config{InsecureSkipVerify: true}))
}
}

if len(cfg.Warehouse) > 0 {
opts = append(opts, rest.WithWarehouseLocation(cfg.Warehouse))
Expand Down
19 changes: 14 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@ type Config struct {
}

type CatalogConfig struct {
CatalogType string `yaml:"type"`
URI string `yaml:"uri"`
Output string `yaml:"output"`
Credential string `yaml:"credential"`
Warehouse string `yaml:"warehouse"`
CatalogType string `yaml:"type"`
URI string `yaml:"uri"`
Output string `yaml:"output"`
Credential string `yaml:"credential"`
Warehouse string `yaml:"warehouse"`
RestConfig RestCatalogConfig `yaml:"rest-config"`
}

type RestCatalogConfig struct {
AuthUrl string `yaml:"auth-url"`
SigV4Enabled bool `yaml:"sigv4-enabled"`
SigV4Region string `yaml:"sigv4-region"`
SigV4Service string `yaml:"sigv4-service"`
TlsSkipVerify bool `yaml:"tls-skip-verify"`
}

func LoadConfig(configPath string) []byte {
Expand Down
58 changes: 58 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,38 @@ catalog:
Warehouse: "catalog_name",
},
},
// catalog with rest-config
{
[]byte(`
catalog:
rest-catalog:
type: rest
uri: https://glue.us-east-1.amazonaws.com/iceberg
output: json
credential: client-id:client-secret
warehouse: 123456789012
rest-config:
auth-url: https://auth.example.com
sigv4-enabled: true
sigv4-region: us-east-1
sigv4-service: glue
tls-skip-verify: false
`), "rest-catalog",
&CatalogConfig{
CatalogType: "rest",
URI: "https://glue.us-east-1.amazonaws.com/iceberg",
Output: "json",
Credential: "client-id:client-secret",
Warehouse: "123456789012",
RestConfig: RestCatalogConfig{
AuthUrl: "https://auth.example.com",
SigV4Enabled: true,
SigV4Region: "us-east-1",
SigV4Service: "glue",
TlsSkipVerify: false,
},
},
},
}

func TestParseConfig(t *testing.T) {
Expand All @@ -87,3 +119,29 @@ func TestParseConfig(t *testing.T) {
assert.Equal(t, tt.expected, actual)
}
}

func TestRestCatalogConfig(t *testing.T) {
yamlData := []byte(`
catalog:
default:
type: rest
uri: https://glue.us-east-1.amazonaws.com/iceberg
output: json
rest-config:
auth-url: https://auth.example.com
sigv4-enabled: true
sigv4-region: us-east-1
sigv4-service: glue
tls-skip-verify: false
`)

config := ParseConfig(yamlData, "default")
assert.NotNil(t, config)

// Test RestCatalogConfig fields
assert.Equal(t, "https://auth.example.com", config.RestConfig.AuthUrl)
assert.True(t, config.RestConfig.SigV4Enabled)
assert.Equal(t, "us-east-1", config.RestConfig.SigV4Region)
assert.Equal(t, "glue", config.RestConfig.SigV4Service)
assert.False(t, config.RestConfig.TlsSkipVerify)
}
Loading