Authentication using a service account file
Note
The article is being updated.
Below are examples of the code for authentication using a service account file in different YDB SDKs.
Go
Java
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 func() {
_ = db.Close(ctx)
}()
}
public void work(String connectionString, Path saKeyPath) {
AuthProvider authProvider = CloudAuthProvider.newAuthProvider(
ApiKeyCredentialProvider.builder()
.fromFile(saKeyPath)
.build()
);
GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
.withAuthProvider(authProvider)
.build();
TableClient tableClient = TableClient
.newClient(GrpcTableRpc.ownTransport(transport))
.build());
doWork(tableClient);
tableClient.close();
}