Skip to content
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
21 changes: 1 addition & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,10 @@ Need to automate your infrastructure or use services provided by Yandex.Cloud? W
## Getting started

There are three options for authorization your requests:
- [OAuth Token](https://cloud.yandex.com/en-ru/docs/iam/concepts/authorization/oauth-token)
- [IAM token](https://cloud.yandex.com/en-ru/docs/iam/operations/iam-token/create)
- [Metadata Service](https://cloud.yandex.com/en-ru/docs/compute/concepts/vm-metadata) (if you're executing code inside VMs or Functions
running in Yandex.Cloud)

### OAuth Token

```typescript
import { Session, cloudApi, serviceClients } from '@yandex-cloud/nodejs-sdk';

const { resourcemanager: { cloud_service: { ListCloudsRequest } } } = cloudApi;

// Initialize SDK with your token
const session = new Session({ oauthToken: 'YOUR_TOKEN' });

// Create service client
const cloudService = session.client(serviceClients.CloudServiceClient);

// Issue request (returns Promise)
const response = await cloudService.list(ListCloudsRequest.fromPartial({
pageSize: 100,
}));
```

### Metadata Service

Expand Down Expand Up @@ -84,7 +65,7 @@ To run example scripts, you should execute the following commands:
```bash
cd examples
npm i
YC_OAUTH_TOKEN=... YC_FOLDER_ID=... npm run start path/to/example.ts
YC_IAM_TOKEN=... YC_FOLDER_ID=... npm run start path/to/example.ts
```

## Services
Expand Down
4 changes: 2 additions & 2 deletions examples/ai-translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { log } from './utils/logger';
const { ai: { translate_translation_service: { TranslateRequest, TranslateRequest_Format: Format } } } = cloudApi;

const TEXTS = ['NodeJS SDK examples', 'Powerful, but easy to use library'];
const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN');
const IAM_TOKEN = getEnv('YC_IAM_TOKEN');
const FOLDER_ID = getEnv('YC_FOLDER_ID');

(async () => {
const session = new Session({ oauthToken: AUTH_TOKEN });
const session = new Session({ iamToken: IAM_TOKEN });
const client = session.client(serviceClients.TranslationServiceClient);

const response = await client.translate(TranslateRequest.fromPartial({
Expand Down
4 changes: 2 additions & 2 deletions examples/compute-instance-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
import { getEnv } from './utils/get-env';
import { log } from './utils/logger';

const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN');
const IAM_TOKEN = getEnv('YC_IAM_TOKEN');
const FOLDER_ID = getEnv('YC_FOLDER_ID');
const TARGET_ZONE_ID = 'ru-central1-a';

Expand All @@ -30,7 +30,7 @@ const {
} = cloudApi;

(async () => {
const session = new Session({ oauthToken: AUTH_TOKEN });
const session = new Session({ iamToken: IAM_TOKEN });
const imageClient = session.client(serviceClients.ComputeImageServiceClient);
const instanceClient = session.client(serviceClients.InstanceServiceClient);
const networkClient = session.client(serviceClients.NetworkServiceClient);
Expand Down
4 changes: 2 additions & 2 deletions examples/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { getEnv } from './utils/get-env';
import { log } from './utils/logger';

const { serverless: { functions_function_service: { ListFunctionsRequest } } } = cloudApi;
const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN');
const IAM_TOKEN = getEnv('YC_IAM_TOKEN');
const FOLDER_ID = getEnv('YC_FOLDER_ID');

(async () => {
const session = new Session({ oauthToken: AUTH_TOKEN });
const session = new Session({ iamToken: IAM_TOKEN });
const client = session.client(serviceClients.FunctionServiceClient);

const response = await client.list(ListFunctionsRequest.fromPartial({ folderId: FOLDER_ID }));
Expand Down
4 changes: 2 additions & 2 deletions examples/iot-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const {
devices_registry_data_service: { PublishRegistryDataRequest },
},
} = cloudApi;
const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN');
const IAM_TOKEN = getEnv('YC_IAM_TOKEN');
const FOLDER_ID = getEnv('YC_FOLDER_ID');

(async () => {
const session = new Session({ oauthToken: AUTH_TOKEN });
const session = new Session({ iamToken: IAM_TOKEN });
const registryClient = session.client(serviceClients.IotRegistryServiceClient);
const dataClient = session.client(serviceClients.RegistryDataServiceClient);

Expand Down
4 changes: 2 additions & 2 deletions examples/kms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const {
} = cloudApi;

(async () => {
const authToken = getEnv('YC_OAUTH_TOKEN');
const iamToken = getEnv('YC_IAM_TOKEN');
const folderId = getEnv('YC_FOLDER_ID');
const session = new Session({ oauthToken: authToken });
const session = new Session({ iamToken: iamToken });
const keyClient = session.client(serviceClients.SymmetricKeyServiceClient);
const cryptoClient = session.client(serviceClients.SymmetricCryptoServiceClient);

Expand Down
4 changes: 2 additions & 2 deletions examples/resourcemanager-cloud-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { getEnv } from './utils/get-env';
import { log } from './utils/logger';

const { resourcemanager: { cloud_service: { ListCloudsRequest } } } = cloudApi;
const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN');
const IAM_TOKEN = getEnv('YC_IAM_TOKEN');

(async () => {
const session = new Session({ oauthToken: AUTH_TOKEN });
const session = new Session({ iamToken: IAM_TOKEN });
const client = session.client(serviceClients.CloudServiceClient);

const response = await client.list(ListCloudsRequest.fromPartial({ pageSize: 200 }));
Expand Down
4 changes: 2 additions & 2 deletions examples/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { getEnv } from './utils/get-env';
import { log } from './utils/logger';

const { storage: { bucket_service: { ListBucketsRequest } } } = cloudApi;
const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN');
const IAM_TOKEN = getEnv('YC_IAM_TOKEN');
const FOLDER_ID = getEnv('YC_FOLDER_ID');

(async () => {
const session = new Session({ oauthToken: AUTH_TOKEN });
const session = new Session({ iamToken: IAM_TOKEN });
const client = session.client(serviceClients.BucketServiceClient);

const response = await client.list(ListBucketsRequest.fromPartial({ folderId: FOLDER_ID }));
Expand Down
4 changes: 2 additions & 2 deletions examples/stream-stt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ file.pipe(reader);
reader.pipe(data);

(async () => {
const authToken = getEnv('YC_OAUTH_TOKEN');
const iamToken = getEnv('YC_IAM_TOKEN');
const folderId = getEnv('YC_FOLDER_ID');
const session = new Session({ oauthToken: authToken });
const session = new Session({ iamToken: iamToken });
const client = session.client(serviceClients.SttServiceClient);

async function* createRequest(): AsyncIterable<StreamingRecognitionRequest> {
Expand Down
4 changes: 4 additions & 0 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
return () => {
const iamEndpoint = getServiceClientEndpoint(serviceClients.IamTokenServiceClient);

console.warn(

Check warning on line 40 in src/session.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
'By the end of 2026 OAuthToken will be discontinued at Yandex Cloud. Please consider to use another credetials provider.',
);

return createIamToken(iamEndpoint, {
yandexPassportOauthToken: config.oauthToken,
});
Expand All @@ -62,7 +66,7 @@
credentials.createFromMetadataGenerator(
(
params: { service_url: string },
callback: (error: any, result?: any) => void,

Check warning on line 69 in src/session.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 69 in src/session.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
) => {
tokenCreator()
.then((token) => {
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export interface GenericCredentialsConfig {
headers?: Record<string, string>;
}

/**
* @deprecated By the end of 2026, the use of oauth tokens in the Yandex cloud will be discontinued.
* Please consider to use another credentials provider.
*/
export interface OAuthCredentialsConfig extends GenericCredentialsConfig {
oauthToken: string;
}
Expand Down
Loading