|
@@ -8,72 +8,72 @@ Below are examples of the code for authentication using a service account file i
|
|
|
|
|
|
- Go (native)
|
|
|
|
|
|
- ```go
|
|
|
- package main
|
|
|
-
|
|
|
- import (
|
|
|
- "context"
|
|
|
- "os"
|
|
|
-
|
|
|
- "github.com/ydb-platform/ydb-go-sdk/v3"
|
|
|
- yc "github.com/ydb-platform/ydb-go-yc"
|
|
|
- )
|
|
|
-
|
|
|
- func main() {
|
|
|
- ctx, cancel := context.WithCancel(context.Background())
|
|
|
- defer cancel()
|
|
|
- db, err := ydb.Open(ctx,
|
|
|
- os.Getenv("YDB_CONNECTION_STRING"),
|
|
|
- yc.WithServiceAccountKeyFileCredentials(
|
|
|
- os.Getenv("YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS"),
|
|
|
- ),
|
|
|
- yc.WithInternalCA(), // append Yandex Cloud certificates
|
|
|
- )
|
|
|
- if err != nil {
|
|
|
- panic(err)
|
|
|
- }
|
|
|
- defer db.Close(ctx)
|
|
|
- ...
|
|
|
- }
|
|
|
- ```
|
|
|
+ ```go
|
|
|
+ package main
|
|
|
+
|
|
|
+ import (
|
|
|
+ "context"
|
|
|
+ "os"
|
|
|
+
|
|
|
+ "github.com/ydb-platform/ydb-go-sdk/v3"
|
|
|
+ yc "github.com/ydb-platform/ydb-go-yc"
|
|
|
+ )
|
|
|
+
|
|
|
+ func main() {
|
|
|
+ ctx, cancel := context.WithCancel(context.Background())
|
|
|
+ defer cancel()
|
|
|
+ db, err := ydb.Open(ctx,
|
|
|
+ os.Getenv("YDB_CONNECTION_STRING"),
|
|
|
+ yc.WithServiceAccountKeyFileCredentials(
|
|
|
+ os.Getenv("YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS"),
|
|
|
+ ),
|
|
|
+ yc.WithInternalCA(), // append Yandex Cloud certificates
|
|
|
+ )
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+ defer db.Close(ctx)
|
|
|
+ ...
|
|
|
+ }
|
|
|
+ ```
|
|
|
|
|
|
- Go (database/sql)
|
|
|
|
|
|
- ```go
|
|
|
- package main
|
|
|
-
|
|
|
- import (
|
|
|
- "context"
|
|
|
- "database/sql"
|
|
|
- "os"
|
|
|
-
|
|
|
- "github.com/ydb-platform/ydb-go-sdk/v3"
|
|
|
- yc "github.com/ydb-platform/ydb-go-yc"
|
|
|
- )
|
|
|
-
|
|
|
- func main() {
|
|
|
- ctx, cancel := context.WithCancel(context.Background())
|
|
|
- defer cancel()
|
|
|
- nativeDriver, err := ydb.Open(ctx,
|
|
|
- os.Getenv("YDB_CONNECTION_STRING"),
|
|
|
- yc.WithServiceAccountKeyFileCredentials(
|
|
|
- os.Getenv("YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS"),
|
|
|
- ),
|
|
|
- yc.WithInternalCA(), // append Yandex Cloud certificates
|
|
|
- )
|
|
|
- if err != nil {
|
|
|
- panic(err)
|
|
|
- }
|
|
|
- defer nativeDriver.Close(ctx)
|
|
|
- connector, err := ydb.Connector(nativeDriver)
|
|
|
- if err != nil {
|
|
|
- panic(err)
|
|
|
- }
|
|
|
- db := sql.OpenDB(connector)
|
|
|
- defer db.Close()
|
|
|
- ...
|
|
|
- }
|
|
|
- ```
|
|
|
+ ```go
|
|
|
+ package main
|
|
|
+
|
|
|
+ import (
|
|
|
+ "context"
|
|
|
+ "database/sql"
|
|
|
+ "os"
|
|
|
+
|
|
|
+ "github.com/ydb-platform/ydb-go-sdk/v3"
|
|
|
+ yc "github.com/ydb-platform/ydb-go-yc"
|
|
|
+ )
|
|
|
+
|
|
|
+ func main() {
|
|
|
+ ctx, cancel := context.WithCancel(context.Background())
|
|
|
+ defer cancel()
|
|
|
+ nativeDriver, err := ydb.Open(ctx,
|
|
|
+ os.Getenv("YDB_CONNECTION_STRING"),
|
|
|
+ yc.WithServiceAccountKeyFileCredentials(
|
|
|
+ os.Getenv("YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS"),
|
|
|
+ ),
|
|
|
+ yc.WithInternalCA(), // append Yandex Cloud certificates
|
|
|
+ )
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+ defer nativeDriver.Close(ctx)
|
|
|
+ connector, err := ydb.Connector(nativeDriver)
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+ db := sql.OpenDB(connector)
|
|
|
+ defer db.Close()
|
|
|
+ ...
|
|
|
+ }
|
|
|
+ ```
|
|
|
|
|
|
- Java
|
|
|
|
|
@@ -95,15 +95,13 @@ Below are examples of the code for authentication using a service account file i
|
|
|
```
|
|
|
|
|
|
- Node.js
|
|
|
-
|
|
|
- ### Load service account data from file
|
|
|
|
|
|
- {% include [auth-sa-file](../../../../_includes/nodejs/auth-sa-file.md) %}
|
|
|
+ Loading service account data from a file:
|
|
|
|
|
|
- ### Load service account data from other source
|
|
|
+ {% include [auth-sa-file](../../../../_includes/nodejs/auth-sa-file.md) %}
|
|
|
|
|
|
- When you need to load service account data from the outside, for example, from the secrets vault, this method is suitable:
|
|
|
+ Loading service account data from a third-party source (for example, a secret storage):
|
|
|
|
|
|
- {% include [service-account-data](../../../../_includes/nodejs/auth-sa-data.md) %}
|
|
|
+ {% include [auth-sa-data](../../../../_includes/nodejs/auth-sa-data.md) %}
|
|
|
|
|
|
{% endlist %}
|