Managing Couchbase Clusters from the SDK
- Developer Preview
Cluster management from the SDK.
The Couchbase Rust SDK has a management API to provision clusters. This is not the only programmatic way to deploy Couchbase, and you may wish to look at Terraform for Capella, or some of our command line tools.
User Management
The SDK lets you programmatically create users, assign them roles and associated privileges, and remove them from the system.
This is an overview of the user management API’s capabilities.
Creating a User
The syntax required for creating a user varies according to language, and is covered for each SDK in the management documentation. The basic form is as follows:
async fn upsert_user( &self, settings: User, opts: impl Into<Option<UpsertUserOptions>>, ) -> error::Result<()>
The method upsert_user creates a user and adds the user to the Couchbase Cluster. The user will subsequently be visible in the Security panel of the Couchbase Web Console. Note that successful user-addition results in a user locally defined, with username and password stored on Couchbase Server: external users (whose credentials reside on a network-available server, possibly accessed by means of LDAP) should not be created by this SDK method. If the local user created by upsert_user already exists, the previous definition is overwritten.
pub struct User {
pub username: String,
pub display_name: String,
pub groups: Vec<String>,
pub roles: Vec<Role>,
pub(crate) password: Option<String>,
}
Creation of a User is typically performer using a builder:
pub fn new(
username: impl Into<String>,
display_name: impl Into<String>,
roles: Vec<Role>,
) -> Self
Role must be non-empty and each Role takes the following form:
pub struct Role {
pub name: String,
pub bucket: Option<String>,
pub scope: Option<String>,
pub collection: Option<String>,
}
Again, creation of a Role is typically performer using a builder:
pub fn new(name: impl Into<String>) -> Self
The name specified as the role must correspond to a role supported by Couchbase Server. When specified the bucket, scope, and collection fields must either correspond to a resource currently defined on Couchbase Server; or be the asterisk character (*), meaning all.
Listing Users
The basic form of the method used to return currently defined users is as follows:
async fn get_all_users(
&self,
opts: impl Into<Option<GetAllUsersOptions>>,
) -> error::Result<Vec<UserAndMetadata>>