Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SDK includes #4498

Merged
merged 4 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ydb/docs/en/core/_includes/go/auth-static-database-sql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
```go
package main

import (
"context"

_ "github.com/ydb-platform/ydb-go-sdk/v3"
)

func main() {
db, err := sql.Open("ydb", "grpcs://login:password@localohost:2135/local")
if err != nil {
panic(err)
}
defer db.Close()
...
}
```
30 changes: 30 additions & 0 deletions ydb/docs/en/core/_includes/go/auth-static-with-database-sql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
```go
package main

import (
"context"
"os"

"github.com/ydb-platform/ydb-go-sdk/v3"
)

func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
nativeDriver, err := ydb.Open(ctx,
os.Getenv("YDB_CONNECTION_STRING"),
ydb.WithStaticCredentials("user", "password"),
)
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()
...
}
```
24 changes: 24 additions & 0 deletions ydb/docs/en/core/_includes/go/auth-static-with-native.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
```go
package main

import (
"context"
"os"

"github.com/ydb-platform/ydb-go-sdk/v3"
)

func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
db, err := ydb.Open(ctx,
os.Getenv("YDB_CONNECTION_STRING"),
ydb.WithStaticCredentials("user", "password"),
)
if err != nil {
panic(err)
}
defer db.Close(ctx)
...
}
```
15 changes: 15 additions & 0 deletions ydb/docs/en/core/_includes/nodejs/auth-access-token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```typescript
import { Driver, TokenAuthService } from 'ydb-sdk';

export async function connect(endpoint: string, database: string, accessToken: string) {
const authService = new TokenAuthService(accessToken);
const driver = new Driver({endpoint, database, authService});
const timeout = 10000;
if (!await driver.ready(timeout)) {
console.log(`Driver has not become ready in ${timeout}ms!`);
process.exit(1);
}
console.log('Driver connected')
return driver
}
```
15 changes: 15 additions & 0 deletions ydb/docs/en/core/_includes/nodejs/auth-anonymous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```typescript
import { Driver, AnonymousAuthService } from 'ydb-sdk';

export async function connect(endpoint: string, database: string) {
const authService = new AnonymousAuthService();
const driver = new Driver({endpoint, database, authService});
const timeout = 10000;
if (!await driver.ready(timeout)) {
console.log(`Driver has not become ready in ${timeout}ms!`);
process.exit(1);
}
console.log('Driver connected')
return driver
}
```
15 changes: 15 additions & 0 deletions ydb/docs/en/core/_includes/nodejs/auth-env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```typescript
import { Driver, getCredentialsFromEnv } from 'ydb-sdk';

export async function connect(endpoint: string, database: string) {
const authService = getCredentialsFromEnv();
const driver = new Driver({endpoint, database, authService});
const timeout = 10000;
if (!await driver.ready(timeout)) {
console.log(`Driver has not become ready in ${timeout}ms!`);
process.exit(1);
}
console.log('Driver connected')
return driver
}
```
15 changes: 15 additions & 0 deletions ydb/docs/en/core/_includes/nodejs/auth-metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```typescript
import { Driver, MetadataAuthService } from 'ydb-sdk';

export async function connect(endpoint: string, database: string) {
const authService = new MetadataAuthService();
const driver = new Driver({endpoint, database, authService});
const timeout = 10000;
if (!await driver.ready(timeout)) {
console.log(`Driver has not become ready in ${timeout}ms!`);
process.exit(1);
}
console.log('Driver connected')
return driver
}
```
22 changes: 22 additions & 0 deletions ydb/docs/en/core/_includes/nodejs/auth-sa-data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
```typescript
import { Driver, IamAuthService } from 'ydb-sdk';
import { IIamCredentials } from 'ydb-sdk/build/cjs/src/credentials';

export async function connect(endpoint: string, database: string) {
const saCredentials: IIamCredentials = {
serviceAccountId: 'serviceAccountId',
accessKeyId: 'accessKeyId',
privateKey: Buffer.from('-----BEGIN PRIVATE KEY-----\nyJ1yFwJq...'),
iamEndpoint: 'iam.api.cloud.yandex.net:443',
};
const authService = new IamAuthService(saCredentials);
const driver = new Driver({endpoint, database, authService});
const timeout = 10000;
if (!await driver.ready(timeout)) {
console.log(`Driver has not become ready in ${timeout}ms!`);
process.exit(1);
}
console.log('Driver connected')
return driver
}
```
16 changes: 16 additions & 0 deletions ydb/docs/en/core/_includes/nodejs/auth-sa-file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```typescript
import { Driver, getSACredentialsFromJson, IamAuthService } from 'ydb-sdk';

export async function connect(endpoint: string, database: string, serviceAccountFilename: string) {
const saCredentials = getSACredentialsFromJson(serviceAccountFilename);
const authService = new IamAuthService(saCredentials);
const driver = new Driver({endpoint, database, authService});
const timeout = 10000;
if (!await driver.ready(timeout)) {
console.log(`Driver has not become ready in ${timeout}ms!`);
process.exit(1);
}
console.log('Driver connected')
return driver
}
```
17 changes: 17 additions & 0 deletions ydb/docs/en/core/_includes/nodejs/auth-static.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```typescript
import { Driver, StaticCredentialsAuthService } from 'ydb-sdk';

export async function connect(endpoint: string, database: string, user: string, password: string) {
const authService = new StaticCredentialsAuthService(user, password, endpoint, {
tokenExpirationTimeout: 20000,
})
const driver = new Driver({endpoint, database, authService});
const timeout = 10000;
if (!await driver.ready(timeout)) {
console.log(`Driver has not become ready in ${timeout}ms!`);
process.exit(1);
}
console.log('Driver connected')
return driver
}
```
16 changes: 16 additions & 0 deletions ydb/docs/en/core/_includes/python/async/auth-access-token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```python
import os
import ydb
import asyncio

async def ydb_init():
async with ydb.aio.Driver(
endpoint=os.environ["YDB_ENDPOINT"],
database=os.environ["YDB_DATABASE"],
credentials=ydb.credentials.AccessTokenCredentials(os.environ["YDB_TOKEN"]),
) as driver:
await driver.wait()
...

asyncio.run(ydb_init())
```
16 changes: 16 additions & 0 deletions ydb/docs/en/core/_includes/python/async/auth-anonymous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```python
import os
import ydb
import asyncio

async def ydb_init():
async with ydb.aio.Driver(
endpoint=os.environ["YDB_ENDPOINT"],
database=os.environ["YDB_DATABASE"],
credentials=ydb.credentials.AnonymousCredentials(),
) as driver:
await driver.wait()
...

asyncio.run(ydb_init())
```
16 changes: 16 additions & 0 deletions ydb/docs/en/core/_includes/python/async/auth-env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```python
import os
import ydb
import asyncio

async def ydb_init():
async with ydb.aio.Driver(
endpoint=os.environ["YDB_ENDPOINT"],
database=os.environ["YDB_DATABASE"],
credentials=ydb.credentials_from_env_variables(),
) as driver:
await driver.wait()
...

asyncio.run(ydb_init())
```
17 changes: 17 additions & 0 deletions ydb/docs/en/core/_includes/python/async/auth-metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```python
import os
import ydb
import ydb.iam
import asyncio

async def ydb_init():
async with ydb.aio.Driver(
endpoint=os.environ["YDB_ENDPOINT"],
database=os.environ["YDB_DATABASE"],
credentials=ydb.iam.MetadataUrlCredentials(),
) as driver:
await driver.wait()
...

asyncio.run(ydb_init())
```
19 changes: 19 additions & 0 deletions ydb/docs/en/core/_includes/python/async/auth-service-account.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```python
import os
import asyncio
import ydb
import ydb.iam

async def ydb_init():
async with ydb.aio.Driver(
endpoint=os.environ["YDB_ENDPOINT"],
database=os.environ["YDB_DATABASE"],
# service account key should be in the local file,
# and SA_KEY_FILE environment variable should point to it
credentials=ydb.iam.ServiceAccountCredentials.from_file(os.environ["SA_KEY_FILE"]),
) as driver:
await driver.wait()
...

asyncio.run(ydb_init())
```
23 changes: 23 additions & 0 deletions ydb/docs/en/core/_includes/python/async/auth-static.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
```python
import os
import ydb
import asyncio

config = ydb.DriverConfig(
endpoint=os.environ["YDB_ENDPOINT"],
database=os.environ["YDB_DATABASE"],
)

credentials = ydb.StaticCredentials(
driver_config=config,
user=os.environ["YDB_USER"],
password=os.environ["YDB_PASSWORD"],
)

async def ydb_init():
async with ydb.aio.Driver(driver_config=config, credentials=credentials) as driver:
await driver.wait()
...

asyncio.run(ydb_init())
```
11 changes: 11 additions & 0 deletions ydb/docs/en/core/_includes/python/auth-access-token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```python
import os
import ydb

with ydb.Driver(
connection_string=os.environ["YDB_CONNECTION_STRING"],
credentials=ydb.credentials.AccessTokenCredentials(os.environ["YDB_TOKEN"]),
) as driver:
driver.wait(timeout=5)
...
```
11 changes: 11 additions & 0 deletions ydb/docs/en/core/_includes/python/auth-anonymous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```python
import os
import ydb

with ydb.Driver(
connection_string=os.environ["YDB_CONNECTION_STRING"],
credentials=ydb.credentials.AnonymousCredentials(),
) as driver:
driver.wait(timeout=5)
...
```
11 changes: 11 additions & 0 deletions ydb/docs/en/core/_includes/python/auth-env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```python
import os
import ydb

with ydb.Driver(
connection_string=os.environ["YDB_CONNECTION_STRING"],
credentials=ydb.credentials_from_env_variables(),
) as driver:
driver.wait(timeout=5)
...
```
12 changes: 12 additions & 0 deletions ydb/docs/en/core/_includes/python/auth-metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```python
import os
import ydb
import ydb.iam

with ydb.Driver(
connection_string=os.environ["YDB_CONNECTION_STRING"],
credentials=ydb.iam.MetadataUrlCredentials(),
) as driver:
driver.wait(timeout=5)
...
```
14 changes: 14 additions & 0 deletions ydb/docs/en/core/_includes/python/auth-service-account.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```python
import os
import ydb
import ydb.iam

with ydb.Driver(
connection_string=os.environ["YDB_CONNECTION_STRING"],
# service account key should be in the local file,
# and SA_KEY_FILE environment variable should point to it
credentials=ydb.iam.ServiceAccountCredentials.from_file(os.environ["SA_KEY_FILE"]),
) as driver:
driver.wait(timeout=5)
...
```
19 changes: 19 additions & 0 deletions ydb/docs/en/core/_includes/python/auth-static.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```python
import os
import ydb

config = ydb.DriverConfig(
endpoint=os.environ["YDB_ENDPOINT"],
database=os.environ["YDB_DATABASE"],
)

credentials = ydb.StaticCredentials(
driver_config=config,
user=os.environ["YDB_USER"],
password=os.environ["YDB_PASSWORD"]
)

with ydb.Driver(driver_config=config, credentials=credentials) as driver:
driver.wait(timeout=5)
...
```
Loading
Loading