Skip to main content

Create

Creates an SQL Server user in the specified cluster.

import {
cloudApi,
decodeMessage,
serviceClients,
Session,
waitForOperation,
} from "@yandex-cloud/nodejs-sdk";

const CreateUserRequest =
cloudApi.mdb.clickhouse_user_service.CreateUserRequest;
const User = cloudApi.datasphere.user.User;
const UserSettings_CountDistinctImplementation =
cloudApi.mdb.clickhouse_user.UserSettings_CountDistinctImplementation;
const UserSettings_DateTimeInputFormat =
cloudApi.mdb.clickhouse_user.UserSettings_DateTimeInputFormat;
const UserSettings_DateTimeOutputFormat =
cloudApi.mdb.clickhouse_user.UserSettings_DateTimeOutputFormat;
const UserSettings_DistributedProductMode =
cloudApi.mdb.clickhouse_user.UserSettings_DistributedProductMode;
const UserSettings_FormatRegexpEscapingRule =
cloudApi.mdb.clickhouse_user.UserSettings_FormatRegexpEscapingRule;
const UserSettings_GroupByOverflowMode =
cloudApi.mdb.clickhouse_user.UserSettings_GroupByOverflowMode;
const UserSettings_JoinAlgorithm =
cloudApi.mdb.clickhouse_user.UserSettings_JoinAlgorithm;
const UserSettings_LoadBalancing =
cloudApi.mdb.clickhouse_user.UserSettings_LoadBalancing;
const UserSettings_LocalFilesystemReadMethod =
cloudApi.mdb.clickhouse_user.UserSettings_LocalFilesystemReadMethod;
const UserSettings_OverflowMode =
cloudApi.mdb.clickhouse_user.UserSettings_OverflowMode;
const UserSettings_QuotaMode =
cloudApi.mdb.clickhouse_user.UserSettings_QuotaMode;
const UserSettings_RemoteFilesystemReadMethod =
cloudApi.mdb.clickhouse_user.UserSettings_RemoteFilesystemReadMethod;

(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.UserServiceClient);

const operation = await client.create(
CreateUserRequest.fromPartial({
clusterId: "clusterId",
userSpec: {
name: "name",
password: "password",
// permissions: [{
// databaseName: "databaseName"
// }],
// settings: {
// readonly: {
// value: 0
// },
// allowDdl: {
// value: true
// },
// allowIntrospectionFunctions: {
// value: true
// },
// connectTimeout: {
// value: 0
// },
// connectTimeoutWithFailover: {
// value: 0
// },
// receiveTimeout: {
// value: 0
// },
// sendTimeout: {
// value: 0
// },
// timeoutBeforeCheckingExecutionSpeed: {
// value: 0
// },
// insertQuorum: {
// value: 0
// },
// insertQuorumTimeout: {
// value: 0
// },
// insertQuorumParallel: {
// value: true
// },
// insertNullAsDefault: {
// value: true
// },
// selectSequentialConsistency: {
// value: true
// },
// deduplicateBlocksInDependentMaterializedViews: {
// value: true
// },
// replicationAlterPartitionsSync: {
// value: 0
// },
// maxReplicaDelayForDistributedQueries: {
// value: 0
// },
// fallbackToStaleReplicasForDistributedQueries: {
// value: true
// },
// distributedProductMode: UserSettings_DistributedProductMode.DISTRIBUTED_PRODUCT_MODE_DENY,
// distributedAggregationMemoryEfficient: {
// value: true
// },
// distributedDdlTaskTimeout: {
// value: 0
// },
// skipUnavailableShards: {
// value: true
// },
// compileExpressions: {
// value: true
// },
// minCountToCompileExpression: {
// value: 0
// },
// maxBlockSize: {
// value: 0
// },
// minInsertBlockSizeRows: {
// value: 0
// },
// minInsertBlockSizeBytes: {
// value: 0
// },
// maxInsertBlockSize: {
// value: 0
// },
// minBytesToUseDirectIo: {
// value: 0
// },
// useUncompressedCache: {
// value: true
// },
// mergeTreeMaxRowsToUseCache: {
// value: 0
// },
// mergeTreeMaxBytesToUseCache: {
// value: 0
// },
// mergeTreeMinRowsForConcurrentRead: {
// value: 0
// },
// mergeTreeMinBytesForConcurrentRead: {
// value: 0
// },
// maxBytesBeforeExternalGroupBy: {
// value: 0
// },
// maxBytesBeforeExternalSort: {
// value: 0
// },
// groupByTwoLevelThreshold: {
// value: 0
// },
// groupByTwoLevelThresholdBytes: {
// value: 0
// },
// priority: {
// value: 0
// },
// maxThreads: {
// value: 0
// },
// maxMemoryUsage: {
// value: 0
// },
// maxMemoryUsageForUser: {
// value: 0
// },
// maxNetworkBandwidth: {
// value: 0
// },
// maxNetworkBandwidthForUser: {
// value: 0
// },
// maxPartitionsPerInsertBlock: {
// value: 0
// },
// maxConcurrentQueriesForUser: {
// value: 0
// },
// forceIndexByDate: {
// value: true
// },
// forcePrimaryKey: {
// value: true
// },
// maxRowsToRead: {
// value: 0
// },
// maxBytesToRead: {
// value: 0
// },
// readOverflowMode: UserSettings_OverflowMode.OVERFLOW_MODE_THROW,
// maxRowsToGroupBy: {
// value: 0
// },
// groupByOverflowMode: UserSettings_GroupByOverflowMode.GROUP_BY_OVERFLOW_MODE_THROW,
// maxRowsToSort: {
// value: 0
// },
// maxBytesToSort: {
// value: 0
// },
// sortOverflowMode: UserSettings_OverflowMode.OVERFLOW_MODE_THROW,
// maxResultRows: {
// value: 0
// },
// maxResultBytes: {
// value: 0
// },
// resultOverflowMode: UserSettings_OverflowMode.OVERFLOW_MODE_THROW,
// maxRowsInDistinct: {
// value: 0
// },
// maxBytesInDistinct: {
// value: 0
// },
// distinctOverflowMode: UserSettings_OverflowMode.OVERFLOW_MODE_THROW,
// maxRowsToTransfer: {
// value: 0
// },
// maxBytesToTransfer: {
// value: 0
// },
// transferOverflowMode: UserSettings_OverflowMode.OVERFLOW_MODE_THROW,
// maxExecutionTime: {
// value: 0
// },
// timeoutOverflowMode: UserSettings_OverflowMode.OVERFLOW_MODE_THROW,
// maxRowsInSet: {
// value: 0
// },
// maxBytesInSet: {
// value: 0
// },
// setOverflowMode: UserSettings_OverflowMode.OVERFLOW_MODE_THROW,
// maxRowsInJoin: {
// value: 0
// },
// maxBytesInJoin: {
// value: 0
// },
// joinOverflowMode: UserSettings_OverflowMode.OVERFLOW_MODE_THROW,
// joinAlgorithm: [UserSettings_JoinAlgorithm.JOIN_ALGORITHM_HASH],
// anyJoinDistinctRightTableKeys: {
// value: true
// },
// maxColumnsToRead: {
// value: 0
// },
// maxTemporaryColumns: {
// value: 0
// },
// maxTemporaryNonConstColumns: {
// value: 0
// },
// maxQuerySize: {
// value: 0
// },
// maxAstDepth: {
// value: 0
// },
// maxAstElements: {
// value: 0
// },
// maxExpandedAstElements: {
// value: 0
// },
// minExecutionSpeed: {
// value: 0
// },
// minExecutionSpeedBytes: {
// value: 0
// },
// countDistinctImplementation: UserSettings_CountDistinctImplementation.COUNT_DISTINCT_IMPLEMENTATION_UNIQ,
// inputFormatValuesInterpretExpressions: {
// value: true
// },
// inputFormatDefaultsForOmittedFields: {
// value: true
// },
// inputFormatNullAsDefault: {
// value: true
// },
// dateTimeInputFormat: UserSettings_DateTimeInputFormat.DATE_TIME_INPUT_FORMAT_BEST_EFFORT,
// inputFormatWithNamesUseHeader: {
// value: true
// },
// outputFormatJsonQuote_64bitIntegers: {
// value: true
// },
// outputFormatJsonQuoteDenormals: {
// value: true
// },
// dateTimeOutputFormat: UserSettings_DateTimeOutputFormat.DATE_TIME_OUTPUT_FORMAT_SIMPLE,
// lowCardinalityAllowInNativeFormat: {
// value: true
// },
// allowSuspiciousLowCardinalityTypes: {
// value: true
// },
// emptyResultForAggregationByEmptySet: {
// value: true
// },
// httpConnectionTimeout: {
// value: 0
// },
// httpReceiveTimeout: {
// value: 0
// },
// httpSendTimeout: {
// value: 0
// },
// enableHttpCompression: {
// value: true
// },
// sendProgressInHttpHeaders: {
// value: true
// },
// httpHeadersProgressInterval: {
// value: 0
// },
// addHttpCorsHeader: {
// value: true
// },
// cancelHttpReadonlyQueriesOnClientClose: {
// value: true
// },
// maxHttpGetRedirects: {
// value: 0
// },
// joinedSubqueryRequiresAlias: {
// value: true
// },
// joinUseNulls: {
// value: true
// },
// transformNullIn: {
// value: true
// },
// quotaMode: UserSettings_QuotaMode.QUOTA_MODE_DEFAULT,
// flattenNested: {
// value: true
// },
// formatRegexp: "formatRegexp",
// formatRegexpEscapingRule: UserSettings_FormatRegexpEscapingRule.FORMAT_REGEXP_ESCAPING_RULE_ESCAPED,
// formatRegexpSkipUnmatched: {
// value: true
// },
// asyncInsert: {
// value: true
// },
// asyncInsertThreads: {
// value: 0
// },
// waitForAsyncInsert: {
// value: true
// },
// waitForAsyncInsertTimeout: {
// value: 0
// },
// asyncInsertMaxDataSize: {
// value: 0
// },
// asyncInsertBusyTimeout: {
// value: 0
// },
// asyncInsertStaleTimeout: {
// value: 0
// },
// memoryProfilerStep: {
// value: 0
// },
// memoryProfilerSampleProbability: {
// value: 0
// },
// maxFinalThreads: {
// value: 0
// },
// inputFormatParallelParsing: {
// value: true
// },
// inputFormatImportNestedJson: {
// value: true
// },
// localFilesystemReadMethod: UserSettings_LocalFilesystemReadMethod.LOCAL_FILESYSTEM_READ_METHOD_READ,
// maxReadBufferSize: {
// value: 0
// },
// insertKeeperMaxRetries: {
// value: 0
// },
// maxTemporaryDataOnDiskSizeForUser: {
// value: 0
// },
// maxTemporaryDataOnDiskSizeForQuery: {
// value: 0
// },
// maxParserDepth: {
// value: 0
// },
// remoteFilesystemReadMethod: UserSettings_RemoteFilesystemReadMethod.REMOTE_FILESYSTEM_READ_METHOD_READ,
// memoryOvercommitRatioDenominator: {
// value: 0
// },
// memoryOvercommitRatioDenominatorForUser: {
// value: 0
// },
// memoryUsageOvercommitMaxWaitMicroseconds: {
// value: 0
// },
// logQueryThreads: {
// value: true
// },
// maxInsertThreads: {
// value: 0
// },
// useHedgedRequests: {
// value: true
// },
// idleConnectionTimeout: {
// value: 0
// },
// hedgedConnectionTimeoutMs: {
// value: 0
// },
// loadBalancing: UserSettings_LoadBalancing.LOAD_BALANCING_RANDOM,
// preferLocalhostReplica: {
// value: true
// },
// compile: {
// value: true
// },
// minCountToCompile: {
// value: 0
// }
// },
// quotas: [{
// intervalDuration: {
// value: 0
// },
// queries: {
// value: 0
// },
// errors: {
// value: 0
// },
// resultRows: {
// value: 0
// },
// readRows: {
// value: 0
// },
// executionTime: {
// value: 0
// }
// }]
},
})
);
const finishedOp = await waitForOperation(operation, session);

if (finishedOp.response) {
const result = decodeMessage<typeof User>(finishedOp.response);
console.log(result);
}
})();

CreateUserRequest

clusterId : string

ID of the SQL Server cluster to create a user for.

To get the cluster ID, use a ClusterService.List request.

userSpec : UserSpec

Properties of the user to be created.

UserSpec

name : string

Name of the SQL Server user.

password : string

Password of the SQL Server user.

permissions : Permission

Set of permissions to grant to the user.

serverRoles : ServerRole

Set of server roles.

Permission

Role

Role granted to the user within the database.

  • ROLE_UNSPECIFIED

    Role granted to the user within the database.

  • DB_OWNER

    Members of this fixed database role can perform all configuration and maintenance activities on a database and can also drop a database in SQL Server.

  • DB_SECURITYADMIN

    Members of this fixed database role can modify role membership for custom roles only and manage permissions. They can potentially elevate their privileges and their actions should be monitored.

  • DB_ACCESSADMIN

    Members of this fixed database role can add or remove access to a database for Windows logins, Windows groups, and SQL Server logins.

  • DB_BACKUPOPERATOR

    Members of this fixed database role can back up the database.

  • DB_DDLADMIN

    Members of this fixed database role can run any Data Definition Language (DDL) command in a database.

  • DB_DATAWRITER

    Members of this fixed database role can add, delete, or change data in all user tables.

  • DB_DATAREADER

    Members of this fixed database role can read all data from all user tables.

  • DB_DENYDATAWRITER

    Members of this fixed database role cannot add, modify, or delete any data in the user tables within a database. A denial has a higher priority than a grant, so you can use this role to quickly restrict one's privileges without explicitly revoking permissions or roles.

  • DB_DENYDATAREADER

    Members of this fixed database role cannot read any data in the user tables within a database. A denial has a higher priority than a grant, so you can use this role to quickly restrict one's privileges without explicitly revoking permissions or roles.

databaseName : string

Name of the database the permission grants access to.

roles : Role

Roles granted to the user within the database.

Operation

An Operation resource. For more information, see Operation.

id : string

ID of the operation.

description : string

Description of the operation. 0-256 characters long.

createdAt : google.protobuf.Timestamp

Creation timestamp.

createdBy : string

ID of the user or service account who initiated the operation.

modifiedAt : google.protobuf.Timestamp

The time when the Operation resource was last modified.

done : bool

If the value is false, it means the operation is still in progress. If true, the operation is completed, and either error or response is available.

metadata : google.protobuf.Any

Service-specific metadata associated with the operation. It typically contains the ID of the target resource that the operation is performed on. Any method that returns a long-running operation should document the metadata type, if any.

One of result

The operation result. If done == false and there was no failure detected, neither error nor response is set. If done == false and there was a failure detected, error is set. If done == true, exactly one of error or response is set.

  • error : google.rpc.Status

    The error result of the operation in case of failure or cancellation.

  • response : google.protobuf.Any
    The normal response of the operation in case of success.

    If the original method returns no data on success, such as Delete, the response is google.protobuf.Empty. If the original method is the standard Create/Update, the response should be the target resource of the operation. Any method that returns a long-running operation should document the response type, if any.