Skip to content

Commit

Permalink
YQ Connector: YQ-2708 support read using iam token
Browse files Browse the repository at this point in the history
  • Loading branch information
Woodey777 committed Jan 29, 2024
1 parent 7b25b26 commit 20d234c
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 112 deletions.
261 changes: 176 additions & 85 deletions api/common/data_source.pb.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions api/common/endpoint.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/service/connector.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 14 additions & 7 deletions api/service/connector_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/service/protos/connector.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/config/client.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions app/config/server.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion app/server/datasource/rdbms/ydb/connection_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"strings"
"time"

"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
Expand Down Expand Up @@ -87,7 +88,21 @@ func (c *connectionManager) Make(
endpoint := common.EndpointToString(dsi.Endpoint)
dsn := sugar.DSN(endpoint, dsi.Database, dsi.UseTls)

ydbDriver, err := ydb_sdk.Open(ctx, dsn)
var (
sb strings.Builder
cred ydb_sdk.Option
)

if dsi.Credentials.GetToken() != nil {
sb.WriteString(fmt.Sprintf("%s %s", dsi.Credentials.GetToken().Type, dsi.Credentials.GetToken().Value))
cred = ydb_sdk.WithAccessTokenCredentials(sb.String())

Check warning on line 98 in app/server/datasource/rdbms/ydb/connection_manager.go

View check run for this annotation

Codecov / codecov/patch

app/server/datasource/rdbms/ydb/connection_manager.go#L97-L98

Added lines #L97 - L98 were not covered by tests
} else {
cred = ydb_sdk.WithAnonymousCredentials()
}

ydbDriver, err := ydb_sdk.Open(ctx, dsn,
cred,
)
if err != nil {
return nil, fmt.Errorf("open driver error: %w", err)
}
Expand Down
4 changes: 0 additions & 4 deletions app/server/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ func validateDataSourceInstance(logger *zap.Logger, dsi *api_common.TDataSourceI
logger.Warn("connector will use insecure connection to access data source")
}

if dsi.Protocol == api_common.EProtocol_PROTOCOL_UNSPECIFIED {
return fmt.Errorf("protocol field is empty: %w", common.ErrInvalidRequest)
}

switch dsi.GetKind() {
case api_common.EDataSourceKind_POSTGRESQL:
if dsi.GetPgOptions().GetSchema() == "" {
Expand Down
21 changes: 21 additions & 0 deletions debug/config/client/ydb_iam.local.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
endpoint {
host: "localhost"
port: 50051
}

data_source_instance {
kind: YDB
endpoint {
host: "ydb-ru-prestable.yandex.net"
port: 2135
}
database: "/ru-prestable/ydb_home/woodey/ydb144"
credentials {
token {
type: "IAM"
value: "..."
}
}
use_tls: false
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ data_source_instance {
port: 2136
}
database: "local"
protocol: NATIVE
use_tls: false
}

0 comments on commit 20d234c

Please sign in to comment.