Skip to content

Commit f1e959a

Browse files
authored
Merge pull request #66 from ydb-platform/credentials
public credentials constructors
2 parents 624b982 + 1d20f45 commit f1e959a

File tree

7 files changed

+43
-30
lines changed

7 files changed

+43
-30
lines changed

.github/workflows/changelog.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1+
name: changelog
12
on:
23
pull_request_target:
3-
4-
name: changelog
5-
64
jobs:
75
changelog:
86
name: changelog
@@ -14,6 +12,6 @@ jobs:
1412
- name: Changelog updated
1513
uses: Zomzog/[email protected]
1614
with:
17-
fileName: CHANGELOG\.md
15+
fileName: CHANGELOG.md
1816
env:
1917
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/version.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1+
name: version
12
on:
23
pull_request_target:
3-
4-
name: version
5-
64
jobs:
75
changelog:
86
name: version
@@ -14,6 +12,6 @@ jobs:
1412
- name: Version updated
1513
uses: Zomzog/[email protected]
1614
with:
17-
fileName: internal\/meta\/version\.go
15+
fileName: internal/meta/version.go
1816
env:
1917
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* Added `DoTx()` API method into `table.Client`
1818
* Added `String()` method into `ConnectParams` for serialize params to connection string
1919
* Added early exit from Rollback for committed transaction
20-
* Moved `HasNextResultSet()` method from `Result` interface to common `result` interface.
21-
It provides access to `HasNextResultSet()` on both result interfaces (unary and stream results)
20+
* Moved `HasNextResultSet()` method from `Result` interface to common `result` interface. It provides access to `HasNextResultSet()` on both result interfaces (unary and stream results)
21+
* Added public credentials constructors `credentials.NewAnonymousCredentials()` and `credentials.NewAccessTokenCredentials(token)`
2222

2323
## 3.4.4
2424
* Prefer `ydb.table.types.Scanner` scanner implementation over `sql.Scanner`, when both available.

credentials/context.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

credentials/credentials.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,35 @@ package credentials
33
import "github.com/ydb-platform/ydb-go-sdk/v3/internal/meta/credentials"
44

55
type Credentials = credentials.Credentials
6+
7+
type optionsHolder struct {
8+
sourceInfo string
9+
}
10+
11+
type option func(h *optionsHolder)
12+
13+
func WithSourceInfo(sourceInfo string) option {
14+
return func(h *optionsHolder) {
15+
h.sourceInfo = sourceInfo
16+
}
17+
}
18+
19+
func NewAccessTokenCredentials(accessToken string, opts ...option) Credentials {
20+
h := &optionsHolder{
21+
sourceInfo: "credentials.NewAccessTokenCredentials(token)",
22+
}
23+
for _, o := range opts {
24+
o(h)
25+
}
26+
return credentials.NewAccessTokenCredentials(accessToken, h.sourceInfo)
27+
}
28+
29+
func NewAnonymousCredentials(opts ...option) Credentials {
30+
h := &optionsHolder{
31+
sourceInfo: "credentials.NewAnonymousCredentials()",
32+
}
33+
for _, o := range opts {
34+
o(h)
35+
}
36+
return credentials.NewAnonymousCredentials(h.sourceInfo)
37+
}

internal/meta/credentials/credentials.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ type AccessTokenCredentials struct {
4040
sourceInfo string
4141
}
4242

43-
func NewAccessTokenCredentials(AccessToken string, sourceInfo string) *AccessTokenCredentials {
43+
func NewAccessTokenCredentials(accessToken string, sourceInfo string) *AccessTokenCredentials {
4444
return &AccessTokenCredentials{
45-
AccessToken: AccessToken,
45+
AccessToken: accessToken,
4646
sourceInfo: sourceInfo,
4747
}
4848
}

options.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/ydb-platform/ydb-go-sdk/v3/config"
1313
"github.com/ydb-platform/ydb-go-sdk/v3/credentials"
1414
"github.com/ydb-platform/ydb-go-sdk/v3/internal/logger"
15-
internal "github.com/ydb-platform/ydb-go-sdk/v3/internal/meta/credentials"
1615
"github.com/ydb-platform/ydb-go-sdk/v3/log"
1716
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
1817
)
@@ -21,7 +20,7 @@ type Option func(ctx context.Context, db *db) error
2120

2221
func WithAccessTokenCredentials(accessToken string) Option {
2322
return WithCredentials(
24-
internal.NewAccessTokenCredentials(accessToken, "ydb.WithAccessTokenCredentials(accessToken)"), // hide access token for logs
23+
credentials.NewAccessTokenCredentials(accessToken, credentials.WithSourceInfo("ydb.WithAccessTokenCredentials(accessToken)")), // hide access token for logs
2524
)
2625
}
2726

@@ -100,15 +99,15 @@ func WithConnectParams(params ConnectParams) Option {
10099
db.options = append(db.options, config.WithDatabase(params.Database()))
101100
db.options = append(db.options, config.WithSecure(params.Secure()))
102101
if params.Token() != "" {
103-
db.options = append(db.options, config.WithCredentials(internal.NewAccessTokenCredentials(params.Token(), "config.WithConnectParams()")))
102+
db.options = append(db.options, config.WithCredentials(credentials.NewAccessTokenCredentials(params.Token(), credentials.WithSourceInfo("config.WithConnectParams()"))))
104103
}
105104
return nil
106105
}
107106
}
108107

109108
func WithAnonymousCredentials() Option {
110109
return WithCredentials(
111-
internal.NewAnonymousCredentials("ydb.WithAnonymousCredentials()"),
110+
credentials.NewAnonymousCredentials(credentials.WithSourceInfo("ydb.WithAnonymousCredentials()")),
112111
)
113112
}
114113

0 commit comments

Comments
 (0)