Create
Creates a key pair for the specified service account.
- TypeScript
- Python
import { cloudApi, serviceClients, Session } from "@yandex-cloud/nodejs-sdk";
const CreateKeyRequest = cloudApi.iam.key_service.CreateKeyRequest;
const KeyFormat = cloudApi.iam.key_service.KeyFormat;
const Key_Algorithm = cloudApi.iam.key.Key_Algorithm;
(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.KeyServiceClient);
const result = await client.create(
CreateKeyRequest.fromPartial({
// serviceAccountId: "serviceAccountId",
// description: "description",
// format: KeyFormat.undefined,
// keyAlgorithm: Key_Algorithm.RSA_2048
})
);
console.log(result);
})();
import os
import grpc
import yandexcloud
from yandex.cloud.iam.v1.key_service_pb2 import CreateKeyRequest
from yandex.cloud.iam.v1.key_service_pb2 import KeyFormat
from yandex.cloud.iam.v1.key_service_pb2_grpc import KeyServiceStub
token = os.getenv("YC_OAUTH_TOKEN")
sdk = yandexcloud.SDK(token=token)
service = sdk.client(KeyServiceStub)
response = service.Create(
CreateKeyRequest(
# service_account_id = "serviceAccountId",
# description = "description",
# format = KeyFormat.undefined,
# key_algorithm = Key.Algorithm.RSA_2048
)
)
print(response)
CreateKeyRequest
serviceAccountId
: string
ID of the service account to create a key pair for. To get the service account ID, use a yandex.cloud.iam.v1.ServiceAccountService.List request. If not specified, it defaults to the subject that made the request.
description
: string
Description of the key pair.
format
: KeyFormat
Output format of the key.
keyAlgorithm
: Key.Algorithm
An algorithm used to generate a key pair of the Key resource.
CreateKeyResponse
key
: Key
Key resource.
privateKey
: string
A private key of the Key resource. This key must be stored securely.
Key
A Key resource. For more information, see Authorized keys.
Algorithm
ALGORITHM_UNSPECIFIED
RSA_2048
RSA with a 2048-bit key size. Default value.
RSA_4096
RSA with a 4096-bit key size.
id
: string
ID of the Key resource.
One of subject
userAccountId
: stringID of the user account that the Key resource belongs to.
serviceAccountId
: stringID of the service account that the Key resource belongs to.
createdAt
: google.protobuf.Timestamp
Creation timestamp.
description
: string
Description of the Key resource. 0-256 characters long.
keyAlgorithm
: Algorithm
An algorithm used to generate a key pair of the Key resource.
publicKey
: string
A public key of the Key resource.
lastUsedAt
: google.protobuf.Timestamp
Timestamp for the last use of this key.