Authentication using the metadata service
Note
The article is being updated.
Below are examples of the code for authentication using environment variables in different YDB SDKs.
Go
Java
1. package main
3. import (
4. "context"
5. "os"
7. "github.com/ydb-platform/ydb-go-sdk/v3"
8. yc "github.com/ydb-platform/ydb-go-yc"
9. )
11. func main() {
12. ctx, cancel := context.WithCancel(context.Background())
13. defer cancel()
14. db, err := ydb.Open(
15. ctx,
16. os.Getenv("YDB_CONNECTION_STRING"),
17. yc.WithMetadataCredentials(ctx),
18. yc.WithInternalCA(), // append Yandex Cloud certificates
19. )
20. if err != nil {
21. panic(err)
22. }
23. defer func() {
24. _ = db.Close(ctx)
25. }()
26. }

1. public void work(String connectionString) {
2. AuthProvider authProvider = CloudAuthProvider.newAuthProvider(
3. ComputeEngineCredentialProvider.builder()
4. .build()
5. );
7. GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
8. .withAuthProvider(authProvider)
9. .build();
11. TableClient tableClient = TableClient
12. .newClient(GrpcTableRpc.ownTransport(transport))
13. .build());
15. doWork(tableClient);
17. tableClient.close();
18. }

